1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_FB_H__
3 #define __NVKM_FB_H__
4 #include <core/subdev.h>
5 #include <core/falcon.h>
6 #include <core/mm.h>
7 
8 /* memory type/access flags, do not match hardware values */
9 #define NV_MEM_ACCESS_RO  1
10 #define NV_MEM_ACCESS_WO  2
11 #define NV_MEM_ACCESS_RW (NV_MEM_ACCESS_RO | NV_MEM_ACCESS_WO)
12 #define NV_MEM_ACCESS_SYS 4
13 #define NV_MEM_ACCESS_VM  8
14 #define NV_MEM_ACCESS_NOSNOOP 16
15 
16 #define NV_MEM_TARGET_VRAM        0
17 #define NV_MEM_TARGET_PCI         1
18 #define NV_MEM_TARGET_PCI_NOSNOOP 2
19 #define NV_MEM_TARGET_VM          3
20 #define NV_MEM_TARGET_GART        4
21 
22 #define NVKM_RAM_TYPE_VM 0x7f
23 #define NV_MEM_COMP_VM 0x03
24 
25 struct nvkm_fb_tile {
26 	struct nvkm_mm_node *tag;
27 	u32 addr;
28 	u32 limit;
29 	u32 pitch;
30 	u32 zcomp;
31 };
32 
33 struct nvkm_fb {
34 	const struct nvkm_fb_func *func;
35 	struct nvkm_subdev subdev;
36 
37 	struct nvkm_falcon_fw vpr_scrubber;
38 
39 	struct {
40 		struct page *flush_page;
41 		dma_addr_t flush_page_addr;
42 	} sysmem;
43 
44 	struct nvkm_ram *ram;
45 
46 	struct {
47 		struct mutex mutex; /* protects mm and nvkm_memory::tags */
48 		struct nvkm_mm mm;
49 	} tags;
50 
51 	struct {
52 		struct nvkm_fb_tile region[16];
53 		int regions;
54 	} tile;
55 
56 	u8 page;
57 
58 	struct nvkm_memory *mmu_rd;
59 	struct nvkm_memory *mmu_wr;
60 };
61 
62 int nvkm_fb_mem_unlock(struct nvkm_fb *);
63 
64 void nvkm_fb_tile_init(struct nvkm_fb *, int region, u32 addr, u32 size,
65 		       u32 pitch, u32 flags, struct nvkm_fb_tile *);
66 void nvkm_fb_tile_fini(struct nvkm_fb *, int region, struct nvkm_fb_tile *);
67 void nvkm_fb_tile_prog(struct nvkm_fb *, int region, struct nvkm_fb_tile *);
68 
69 int nv04_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
70 int nv10_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
71 int nv1a_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
72 int nv20_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
73 int nv25_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
74 int nv30_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
75 int nv35_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
76 int nv36_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
77 int nv40_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
78 int nv41_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
79 int nv44_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
80 int nv46_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
81 int nv47_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
82 int nv49_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
83 int nv4e_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
84 int nv50_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
85 int g84_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
86 int gt215_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
87 int mcp77_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
88 int mcp89_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
89 int gf100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
90 int gf108_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
91 int gk104_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
92 int gk110_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
93 int gk20a_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
94 int gm107_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
95 int gm200_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
96 int gm20b_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
97 int gp100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
98 int gp102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
99 int gp10b_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
100 int gv100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
101 int tu102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
102 int ga100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
103 int ga102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
104 
105 #include <subdev/bios.h>
106 #include <subdev/bios/ramcfg.h>
107 
108 struct nvkm_ram_data {
109 	struct list_head head;
110 	struct nvbios_ramcfg bios;
111 	u32 freq;
112 };
113 
114 enum nvkm_ram_type {
115 	NVKM_RAM_TYPE_UNKNOWN = 0,
116 	NVKM_RAM_TYPE_STOLEN,
117 	NVKM_RAM_TYPE_SGRAM,
118 	NVKM_RAM_TYPE_SDRAM,
119 	NVKM_RAM_TYPE_DDR1,
120 	NVKM_RAM_TYPE_DDR2,
121 	NVKM_RAM_TYPE_DDR3,
122 	NVKM_RAM_TYPE_GDDR2,
123 	NVKM_RAM_TYPE_GDDR3,
124 	NVKM_RAM_TYPE_GDDR4,
125 	NVKM_RAM_TYPE_GDDR5,
126 	NVKM_RAM_TYPE_GDDR5X,
127 	NVKM_RAM_TYPE_GDDR6,
128 	NVKM_RAM_TYPE_HBM2,
129 };
130 
131 struct nvkm_ram {
132 	const struct nvkm_ram_func *func;
133 	struct nvkm_fb *fb;
134 	enum nvkm_ram_type type;
135 	u64 size;
136 
137 #define NVKM_RAM_MM_SHIFT 12
138 #define NVKM_RAM_MM_ANY    (NVKM_MM_HEAP_ANY + 0)
139 #define NVKM_RAM_MM_NORMAL (NVKM_MM_HEAP_ANY + 1)
140 #define NVKM_RAM_MM_NOMAP  (NVKM_MM_HEAP_ANY + 2)
141 #define NVKM_RAM_MM_MIXED  (NVKM_MM_HEAP_ANY + 3)
142 	struct nvkm_mm vram;
143 	u64 stolen;
144 	struct mutex mutex;
145 
146 	int ranks;
147 	int parts;
148 	int part_mask;
149 
150 	u32 freq;
151 	u32 mr[16];
152 	u32 mr1_nuts;
153 
154 	struct nvkm_ram_data *next;
155 	struct nvkm_ram_data former;
156 	struct nvkm_ram_data xition;
157 	struct nvkm_ram_data target;
158 };
159 
160 int
161 nvkm_ram_get(struct nvkm_device *, u8 heap, u8 type, u8 page, u64 size,
162 	     bool contig, bool back, struct nvkm_memory **);
163 
164 struct nvkm_ram_func {
165 	u64 upper;
166 	u32 (*probe_fbp)(const struct nvkm_ram_func *, struct nvkm_device *,
167 			 int fbp, int *pltcs);
168 	u32 (*probe_fbp_amount)(const struct nvkm_ram_func *, u32 fbpao,
169 				struct nvkm_device *, int fbp, int *pltcs);
170 	u32 (*probe_fbpa_amount)(struct nvkm_device *, int fbpa);
171 	void *(*dtor)(struct nvkm_ram *);
172 	int (*init)(struct nvkm_ram *);
173 
174 	int (*calc)(struct nvkm_ram *, u32 freq);
175 	int (*prog)(struct nvkm_ram *);
176 	void (*tidy)(struct nvkm_ram *);
177 };
178 #endif
179