projects/linux·blob master · refs

102 lines · 3.0 KiB

1/* SPDX-License-Identifier: GPL-2.0 OR MIT
2 *
3 * Copyright 2026 Advanced Micro Devices, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 */
23#ifndef __AMDGPU_WB_H__
24#define __AMDGPU_WB_H__
25
26#include <linux/types.h>
27#include <linux/spinlock_types.h>
28#include <linux/math.h>
29
30/*
31 * Writeback
32 */
33#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
34
35/**
36 * struct amdgpu_wb - This struct is used for small GPU memory allocation.
37 *
38 * This struct is used to allocate a small amount of GPU memory that can be
39 * used to shadow certain states into the memory. This is especially useful for
40 * providing easy CPU access to some states without requiring register access
41 * (e.g., if some block is power gated, reading register may be problematic).
42 *
43 * Note: the term writeback was initially used because many of the amdgpu
44 * components had some level of writeback memory, and this struct initially
45 * described those components.
46 */
47
48struct amdgpu_bo;
49struct amdgpu_device;
50
51struct amdgpu_wb {
52
53 /**
54 * @wb_obj:
55 *
56 * Buffer Object used for the writeback memory.
57 */
58 struct amdgpu_bo *wb_obj;
59
60 /**
61 * @wb:
62 *
63 * Pointer to the first writeback slot. In terms of CPU address
64 * this value can be accessed directly by using the offset as an index.
65 * For the GPU address, it is necessary to use gpu_addr and the offset.
66 */
67 uint32_t *wb;
68
69 /**
70 * @gpu_addr:
71 *
72 * Writeback base address in the GPU.
73 */
74 uint64_t gpu_addr;
75
76 /**
77 * @num_wb:
78 *
79 * Number of writeback slots reserved for amdgpu.
80 */
81 u32 num_wb;
82
83 /**
84 * @used:
85 *
86 * Track the writeback slot already used.
87 */
88 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
89
90 /**
91 * @lock:
92 *
93 * Protects read and write of the used field array.
94 */
95 spinlock_t lock;
96};
97
98void amdgpu_wb_fini(struct amdgpu_device *adev);
99int amdgpu_wb_init(struct amdgpu_device *adev);
100int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
101void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
102#endif