• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 u64 nvkm_fb_vidmem_size(struct nvkm_device *);
63 int nvkm_fb_mem_unlock(struct nvkm_fb *);
64 
65 void nvkm_fb_tile_init(struct nvkm_fb *, int region, u32 addr, u32 size,
66 		       u32 pitch, u32 flags, struct nvkm_fb_tile *);
67 void nvkm_fb_tile_fini(struct nvkm_fb *, int region, struct nvkm_fb_tile *);
68 void nvkm_fb_tile_prog(struct nvkm_fb *, int region, struct nvkm_fb_tile *);
69 
70 int nv04_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
71 int nv10_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
72 int nv1a_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
73 int nv20_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
74 int nv25_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
75 int nv30_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
76 int nv35_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
77 int nv36_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
78 int nv40_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
79 int nv41_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
80 int nv44_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
81 int nv46_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
82 int nv47_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
83 int nv49_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
84 int nv4e_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
85 int nv50_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
86 int g84_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
87 int gt215_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
88 int mcp77_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
89 int mcp89_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
90 int gf100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
91 int gf108_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
92 int gk104_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
93 int gk110_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
94 int gk20a_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
95 int gm107_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
96 int gm200_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
97 int gm20b_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
98 int gp100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
99 int gp102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
100 int gp10b_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
101 int gv100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
102 int tu102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
103 int ga100_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
104 int ga102_fb_new(struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
105 
106 #include <subdev/bios.h>
107 #include <subdev/bios/ramcfg.h>
108 
109 struct nvkm_ram_data {
110 	struct list_head head;
111 	struct nvbios_ramcfg bios;
112 	u32 freq;
113 };
114 
115 enum nvkm_ram_type {
116 	NVKM_RAM_TYPE_UNKNOWN = 0,
117 	NVKM_RAM_TYPE_STOLEN,
118 	NVKM_RAM_TYPE_SGRAM,
119 	NVKM_RAM_TYPE_SDRAM,
120 	NVKM_RAM_TYPE_DDR1,
121 	NVKM_RAM_TYPE_DDR2,
122 	NVKM_RAM_TYPE_DDR3,
123 	NVKM_RAM_TYPE_GDDR2,
124 	NVKM_RAM_TYPE_GDDR3,
125 	NVKM_RAM_TYPE_GDDR4,
126 	NVKM_RAM_TYPE_GDDR5,
127 	NVKM_RAM_TYPE_GDDR5X,
128 	NVKM_RAM_TYPE_GDDR6,
129 	NVKM_RAM_TYPE_HBM2,
130 };
131 
132 struct nvkm_ram {
133 	const struct nvkm_ram_func *func;
134 	struct nvkm_fb *fb;
135 	enum nvkm_ram_type type;
136 	u64 size;
137 
138 #define NVKM_RAM_MM_SHIFT 12
139 #define NVKM_RAM_MM_ANY    (NVKM_MM_HEAP_ANY + 0)
140 #define NVKM_RAM_MM_NORMAL (NVKM_MM_HEAP_ANY + 1)
141 #define NVKM_RAM_MM_NOMAP  (NVKM_MM_HEAP_ANY + 2)
142 #define NVKM_RAM_MM_MIXED  (NVKM_MM_HEAP_ANY + 3)
143 	struct nvkm_mm vram;
144 	u64 stolen;
145 	struct mutex mutex;
146 
147 	int ranks;
148 	int parts;
149 	int part_mask;
150 
151 	u32 freq;
152 	u32 mr[16];
153 	u32 mr1_nuts;
154 
155 	struct nvkm_ram_data *next;
156 	struct nvkm_ram_data former;
157 	struct nvkm_ram_data xition;
158 	struct nvkm_ram_data target;
159 };
160 
161 int
162 nvkm_ram_get(struct nvkm_device *, u8 heap, u8 type, u8 page, u64 size,
163 	     bool contig, bool back, struct nvkm_memory **);
164 
165 struct nvkm_ram_func {
166 	u64 upper;
167 	u32 (*probe_fbp)(const struct nvkm_ram_func *, struct nvkm_device *,
168 			 int fbp, int *pltcs);
169 	u32 (*probe_fbp_amount)(const struct nvkm_ram_func *, u32 fbpao,
170 				struct nvkm_device *, int fbp, int *pltcs);
171 	u32 (*probe_fbpa_amount)(struct nvkm_device *, int fbpa);
172 	void *(*dtor)(struct nvkm_ram *);
173 	int (*init)(struct nvkm_ram *);
174 
175 	int (*calc)(struct nvkm_ram *, u32 freq);
176 	int (*prog)(struct nvkm_ram *);
177 	void (*tidy)(struct nvkm_ram *);
178 };
179 #endif
180