1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <drm/drmP.h>
25
26#include "nouveau_drv.h"
27#include "nouveau_reg.h"
28#include "hw.h"
29
30
31
32
33
34
35
36
37
38struct nv_fifo_info {
39 int lwm;
40 int burst;
41};
42
43struct nv_sim_state {
44 int pclk_khz;
45 int mclk_khz;
46 int nvclk_khz;
47 int bpp;
48 int mem_page_miss;
49 int mem_latency;
50 int memory_type;
51 int memory_width;
52 int two_heads;
53};
54
55static void
56nv04_calc_arb(struct nv_fifo_info *fifo, struct nv_sim_state *arb)
57{
58 int pagemiss, cas, width, bpp;
59 int nvclks, mclks, pclks, crtpagemiss;
60 int found, mclk_extra, mclk_loop, cbs, m1, p1;
61 int mclk_freq, pclk_freq, nvclk_freq;
62 int us_m, us_n, us_p, crtc_drain_rate;
63 int cpm_us, us_crt, clwm;
64
65 pclk_freq = arb->pclk_khz;
66 mclk_freq = arb->mclk_khz;
67 nvclk_freq = arb->nvclk_khz;
68 pagemiss = arb->mem_page_miss;
69 cas = arb->mem_latency;
70 width = arb->memory_width >> 6;
71 bpp = arb->bpp;
72 cbs = 128;
73
74 pclks = 2;
75 nvclks = 10;
76 mclks = 13 + cas;
77 mclk_extra = 3;
78 found = 0;
79
80 while (!found) {
81 found = 1;
82
83 mclk_loop = mclks + mclk_extra;
84 us_m = mclk_loop * 1000 * 1000 / mclk_freq;
85 us_n = nvclks * 1000 * 1000 / nvclk_freq;
86 us_p = nvclks * 1000 * 1000 / pclk_freq;
87
88 crtc_drain_rate = pclk_freq * bpp / 8;
89 crtpagemiss = 2;
90 crtpagemiss += 1;
91 cpm_us = crtpagemiss * pagemiss * 1000 * 1000 / mclk_freq;
92 us_crt = cpm_us + us_m + us_n + us_p;
93 clwm = us_crt * crtc_drain_rate / (1000 * 1000);
94 clwm++;
95
96 m1 = clwm + cbs - 512;
97 p1 = m1 * pclk_freq / mclk_freq;
98 p1 = p1 * bpp / 8;
99 if ((p1 < m1 && m1 > 0) || clwm > 519) {
100 found = !mclk_extra;
101 mclk_extra--;
102 }
103 if (clwm < 384)
104 clwm = 384;
105
106 fifo->lwm = clwm;
107 fifo->burst = cbs;
108 }
109}
110
111static void
112nv10_calc_arb(struct nv_fifo_info *fifo, struct nv_sim_state *arb)
113{
114 int fill_rate, drain_rate;
115 int pclks, nvclks, mclks, xclks;
116 int pclk_freq, nvclk_freq, mclk_freq;
117 int fill_lat, extra_lat;
118 int max_burst_o, max_burst_l;
119 int fifo_len, min_lwm, max_lwm;
120 const int burst_lat = 80;
121
122
123 pclk_freq = arb->pclk_khz;
124 nvclk_freq = arb->nvclk_khz;
125 mclk_freq = arb->mclk_khz;
126
127 fill_rate = mclk_freq * arb->memory_width / 8;
128 drain_rate = pclk_freq * arb->bpp / 8;
129
130 fifo_len = arb->two_heads ? 1536 : 1024;
131
132
133
134 pclks = 4;
135
136 nvclks = 3
137 + 2
138 + 1
139
140 + 1
141 + 1
142 + 1;
143
144 mclks = 1
145
146 + 1
147 + 5
148 + 2
149 + 2
150 + 7;
151
152
153 mclks += (arb->memory_type == 0 ? 2 : 1)
154 * arb->memory_width / 32;
155
156 fill_lat = mclks * 1000 * 1000 / mclk_freq
157 + nvclks * 1000 * 1000 / nvclk_freq
158 + pclks * 1000 * 1000 / pclk_freq;
159
160
161
162 xclks = 2 * arb->mem_page_miss + mclks
163
164 + 2 * arb->mem_page_miss
165 + (arb->bpp == 32 ? 8 : 4);
166
167 extra_lat = xclks * 1000 * 1000 / mclk_freq;
168
169 if (arb->two_heads)
170
171 extra_lat += fill_lat + extra_lat + burst_lat;
172
173
174
175
176 max_burst_o = (1 + fifo_len - extra_lat * drain_rate / (1000 * 1000))
177 * (fill_rate / 1000) / ((fill_rate - drain_rate) / 1000);
178 fifo->burst = min(max_burst_o, 1024);
179
180
181 max_burst_l = burst_lat * fill_rate / (1000 * 1000);
182 fifo->burst = min(max_burst_l, fifo->burst);
183
184 fifo->burst = rounddown_pow_of_two(fifo->burst);
185
186
187
188 min_lwm = (fill_lat + extra_lat) * drain_rate / (1000 * 1000) + 1;
189 max_lwm = fifo_len - fifo->burst
190 + fill_lat * drain_rate / (1000 * 1000)
191 + fifo->burst * drain_rate / fill_rate;
192
193 fifo->lwm = min_lwm + 10 * (max_lwm - min_lwm) / 100;
194}
195
196static void
197nv04_update_arb(struct drm_device *dev, int VClk, int bpp,
198 int *burst, int *lwm)
199{
200 struct nouveau_drm *drm = nouveau_drm(dev);
201 struct nvif_object *device = &nouveau_drm(dev)->client.device.object;
202 struct nv_fifo_info fifo_data;
203 struct nv_sim_state sim_data;
204 int MClk = nouveau_hw_get_clock(dev, PLL_MEMORY);
205 int NVClk = nouveau_hw_get_clock(dev, PLL_CORE);
206 uint32_t cfg1 = nvif_rd32(device, NV04_PFB_CFG1);
207
208 sim_data.pclk_khz = VClk;
209 sim_data.mclk_khz = MClk;
210 sim_data.nvclk_khz = NVClk;
211 sim_data.bpp = bpp;
212 sim_data.two_heads = nv_two_heads(dev);
213 if ((dev->pdev->device & 0xffff) == 0x01a0 ||
214 (dev->pdev->device & 0xffff) == 0x01f0 ) {
215 uint32_t type;
216 int domain = pci_domain_nr(dev->pdev->bus);
217
218 pci_read_config_dword(pci_get_domain_bus_and_slot(domain, 0, 1),
219 0x7c, &type);
220
221 sim_data.memory_type = (type >> 12) & 1;
222 sim_data.memory_width = 64;
223 sim_data.mem_latency = 3;
224 sim_data.mem_page_miss = 10;
225 } else {
226 sim_data.memory_type = nvif_rd32(device, NV04_PFB_CFG0) & 0x1;
227 sim_data.memory_width = (nvif_rd32(device, NV_PEXTDEV_BOOT_0) & 0x10) ? 128 : 64;
228 sim_data.mem_latency = cfg1 & 0xf;
229 sim_data.mem_page_miss = ((cfg1 >> 4) & 0xf) + ((cfg1 >> 31) & 0x1);
230 }
231
232 if (drm->client.device.info.family == NV_DEVICE_INFO_V0_TNT)
233 nv04_calc_arb(&fifo_data, &sim_data);
234 else
235 nv10_calc_arb(&fifo_data, &sim_data);
236
237 *burst = ilog2(fifo_data.burst >> 4);
238 *lwm = fifo_data.lwm >> 3;
239}
240
241static void
242nv20_update_arb(int *burst, int *lwm)
243{
244 unsigned int fifo_size, burst_size, graphics_lwm;
245
246 fifo_size = 2048;
247 burst_size = 512;
248 graphics_lwm = fifo_size - burst_size;
249
250 *burst = ilog2(burst_size >> 5);
251 *lwm = graphics_lwm >> 3;
252}
253
254void
255nouveau_calc_arb(struct drm_device *dev, int vclk, int bpp, int *burst, int *lwm)
256{
257 struct nouveau_drm *drm = nouveau_drm(dev);
258
259 if (drm->client.device.info.family < NV_DEVICE_INFO_V0_KELVIN)
260 nv04_update_arb(dev, vclk, bpp, burst, lwm);
261 else if ((dev->pdev->device & 0xfff0) == 0x0240 ||
262 (dev->pdev->device & 0xfff0) == 0x03d0 ) {
263 *burst = 128;
264 *lwm = 0x0480;
265 } else
266 nv20_update_arb(burst, lwm);
267}
268