2 * Copyright 2008-2009 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
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:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Dave Airlie <airlied@redhat.com>
26 * Alex Deucher <alexander.deucher@amd.com>
29 #include "dev/drm/drmP.h"
30 #include "dev/drm/drm.h"
31 #include "dev/drm/radeon_drm.h"
32 #include "dev/drm/radeon_drv.h"
34 #include "dev/drm/r600_microcode.h"
36 # define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */
37 # define ATI_PCIGART_PAGE_MASK (~(ATI_PCIGART_PAGE_SIZE-1))
39 #define R600_PTE_VALID (1 << 0)
40 #define R600_PTE_SYSTEM (1 << 1)
41 #define R600_PTE_SNOOPED (1 << 2)
42 #define R600_PTE_READABLE (1 << 5)
43 #define R600_PTE_WRITEABLE (1 << 6)
45 /* MAX values used for gfx init */
46 #define R6XX_MAX_SH_GPRS 256
47 #define R6XX_MAX_TEMP_GPRS 16
48 #define R6XX_MAX_SH_THREADS 256
49 #define R6XX_MAX_SH_STACK_ENTRIES 4096
50 #define R6XX_MAX_BACKENDS 8
51 #define R6XX_MAX_BACKENDS_MASK 0xff
52 #define R6XX_MAX_SIMDS 8
53 #define R6XX_MAX_SIMDS_MASK 0xff
54 #define R6XX_MAX_PIPES 8
55 #define R6XX_MAX_PIPES_MASK 0xff
57 #define R7XX_MAX_SH_GPRS 256
58 #define R7XX_MAX_TEMP_GPRS 16
59 #define R7XX_MAX_SH_THREADS 256
60 #define R7XX_MAX_SH_STACK_ENTRIES 4096
61 #define R7XX_MAX_BACKENDS 8
62 #define R7XX_MAX_BACKENDS_MASK 0xff
63 #define R7XX_MAX_SIMDS 16
64 #define R7XX_MAX_SIMDS_MASK 0xffff
65 #define R7XX_MAX_PIPES 8
66 #define R7XX_MAX_PIPES_MASK 0xff
68 static int r600_do_wait_for_fifo(drm_radeon_private_t
*dev_priv
, int entries
)
72 dev_priv
->stats
.boxes
|= RADEON_BOX_WAIT_IDLE
;
74 for (i
= 0; i
< dev_priv
->usec_timeout
; i
++) {
76 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RV770
)
77 slots
= (RADEON_READ(R600_GRBM_STATUS
)
78 & R700_CMDFIFO_AVAIL_MASK
);
80 slots
= (RADEON_READ(R600_GRBM_STATUS
)
81 & R600_CMDFIFO_AVAIL_MASK
);
86 DRM_INFO("wait for fifo failed status : 0x%08X 0x%08X\n",
87 RADEON_READ(R600_GRBM_STATUS
),
88 RADEON_READ(R600_GRBM_STATUS2
));
93 static int r600_do_wait_for_idle(drm_radeon_private_t
*dev_priv
)
97 dev_priv
->stats
.boxes
|= RADEON_BOX_WAIT_IDLE
;
99 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RV770
)
100 ret
= r600_do_wait_for_fifo(dev_priv
, 8);
102 ret
= r600_do_wait_for_fifo(dev_priv
, 16);
105 for (i
= 0; i
< dev_priv
->usec_timeout
; i
++) {
106 if (!(RADEON_READ(R600_GRBM_STATUS
) & R600_GUI_ACTIVE
))
110 DRM_INFO("wait idle failed status : 0x%08X 0x%08X\n",
111 RADEON_READ(R600_GRBM_STATUS
),
112 RADEON_READ(R600_GRBM_STATUS2
));
117 void r600_page_table_cleanup(struct drm_device
*dev
, struct drm_ati_pcigart_info
*gart_info
)
120 struct drm_sg_mem
*entry
= dev
->sg
;
125 if (gart_info
->bus_addr
) {
127 max_pages
= (gart_info
->table_size
/ sizeof(u32
));
128 pages
= (entry
->pages
<= max_pages
)
129 ? entry
->pages
: max_pages
;
131 for (i
= 0; i
< pages
; i
++) {
132 if (!entry
->busaddr
[i
])
134 pci_unmap_single(dev
->pdev
, entry
->busaddr
[i
],
135 PAGE_SIZE
, PCI_DMA_TODEVICE
);
138 if (gart_info
->gart_table_location
== DRM_ATI_GART_MAIN
)
139 gart_info
->bus_addr
= 0;
143 /* R600 has page table setup */
144 int r600_page_table_init(struct drm_device
*dev
)
146 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
147 struct drm_ati_pcigart_info
*gart_info
= &dev_priv
->gart_info
;
148 struct drm_sg_mem
*entry
= dev
->sg
;
151 int max_pages
, pages
;
152 u64
*pci_gart
, page_base
;
153 dma_addr_t entry_addr
;
155 /* okay page table is available - lets rock */
157 /* PTEs are 64-bits */
158 pci_gart
= (u64
*)gart_info
->addr
;
160 max_pages
= (gart_info
->table_size
/ sizeof(u64
));
161 pages
= (entry
->pages
<= max_pages
) ? entry
->pages
: max_pages
;
163 memset(pci_gart
, 0, max_pages
* sizeof(u64
));
165 for (i
= 0; i
< pages
; i
++) {
167 entry
->busaddr
[i
] = pci_map_single(dev
->pdev
,
170 PAGE_SIZE
, PCI_DMA_TODEVICE
);
171 if (entry
->busaddr
[i
] == 0) {
172 DRM_ERROR("unable to map PCIGART pages!\n");
173 r600_page_table_cleanup(dev
, gart_info
);
177 entry_addr
= entry
->busaddr
[i
];
178 for (j
= 0; j
< (PAGE_SIZE
/ ATI_PCIGART_PAGE_SIZE
); j
++) {
179 page_base
= (u64
) entry_addr
& ATI_PCIGART_PAGE_MASK
;
180 page_base
|= R600_PTE_VALID
| R600_PTE_SYSTEM
| R600_PTE_SNOOPED
;
181 page_base
|= R600_PTE_READABLE
| R600_PTE_WRITEABLE
;
183 *pci_gart
= page_base
;
186 DRM_DEBUG("page entry %d: 0x%016llx\n",
187 i
, (unsigned long long)page_base
);
189 entry_addr
+= ATI_PCIGART_PAGE_SIZE
;
199 static void r600_vm_flush_gart_range(struct drm_device
*dev
)
201 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
202 u32 resp
, countdown
= 1000;
203 RADEON_WRITE(R600_VM_CONTEXT0_INVALIDATION_LOW_ADDR
, dev_priv
->gart_vm_start
>> 12);
204 RADEON_WRITE(R600_VM_CONTEXT0_INVALIDATION_HIGH_ADDR
, (dev_priv
->gart_vm_start
+ dev_priv
->gart_size
- 1) >> 12);
205 RADEON_WRITE(R600_VM_CONTEXT0_REQUEST_RESPONSE
, 2);
208 resp
= RADEON_READ(R600_VM_CONTEXT0_REQUEST_RESPONSE
);
211 } while (((resp
& 0xf0) == 0) && countdown
);
214 static void r600_vm_init(struct drm_device
*dev
)
216 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
217 /* initialise the VM to use the page table we constructed up there */
220 u32 vm_l2_cntl
, vm_l2_cntl3
;
221 /* okay set up the PCIE aperture type thingo */
222 RADEON_WRITE(R600_MC_VM_SYSTEM_APERTURE_LOW_ADDR
, dev_priv
->gart_vm_start
>> 12);
223 RADEON_WRITE(R600_MC_VM_SYSTEM_APERTURE_HIGH_ADDR
, (dev_priv
->gart_vm_start
+ dev_priv
->gart_size
- 1) >> 12);
224 RADEON_WRITE(R600_MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR
, 0);
227 mc_rd_a
= R600_MCD_L1_TLB
| R600_MCD_L1_FRAG_PROC
| R600_MCD_SYSTEM_ACCESS_MODE_IN_SYS
|
228 R600_MCD_SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU
| R600_MCD_EFFECTIVE_L1_TLB_SIZE(5) |
229 R600_MCD_EFFECTIVE_L1_QUEUE_SIZE(5) | R600_MCD_WAIT_L2_QUERY
;
231 RADEON_WRITE(R600_MCD_RD_A_CNTL
, mc_rd_a
);
232 RADEON_WRITE(R600_MCD_RD_B_CNTL
, mc_rd_a
);
234 RADEON_WRITE(R600_MCD_WR_A_CNTL
, mc_rd_a
);
235 RADEON_WRITE(R600_MCD_WR_B_CNTL
, mc_rd_a
);
237 RADEON_WRITE(R600_MCD_RD_GFX_CNTL
, mc_rd_a
);
238 RADEON_WRITE(R600_MCD_WR_GFX_CNTL
, mc_rd_a
);
240 RADEON_WRITE(R600_MCD_RD_SYS_CNTL
, mc_rd_a
);
241 RADEON_WRITE(R600_MCD_WR_SYS_CNTL
, mc_rd_a
);
243 RADEON_WRITE(R600_MCD_RD_HDP_CNTL
, mc_rd_a
| R600_MCD_L1_STRICT_ORDERING
);
244 RADEON_WRITE(R600_MCD_WR_HDP_CNTL
, mc_rd_a
/*| R600_MCD_L1_STRICT_ORDERING*/);
246 RADEON_WRITE(R600_MCD_RD_PDMA_CNTL
, mc_rd_a
);
247 RADEON_WRITE(R600_MCD_WR_PDMA_CNTL
, mc_rd_a
);
249 RADEON_WRITE(R600_MCD_RD_SEM_CNTL
, mc_rd_a
| R600_MCD_SEMAPHORE_MODE
);
250 RADEON_WRITE(R600_MCD_WR_SEM_CNTL
, mc_rd_a
);
252 vm_l2_cntl
= R600_VM_L2_CACHE_EN
| R600_VM_L2_FRAG_PROC
| R600_VM_ENABLE_PTE_CACHE_LRU_W
;
253 vm_l2_cntl
|= R600_VM_L2_CNTL_QUEUE_SIZE(7);
254 RADEON_WRITE(R600_VM_L2_CNTL
, vm_l2_cntl
);
256 RADEON_WRITE(R600_VM_L2_CNTL2
, 0);
257 vm_l2_cntl3
= (R600_VM_L2_CNTL3_BANK_SELECT_0(0) |
258 R600_VM_L2_CNTL3_BANK_SELECT_1(1) |
259 R600_VM_L2_CNTL3_CACHE_UPDATE_MODE(2));
260 RADEON_WRITE(R600_VM_L2_CNTL3
, vm_l2_cntl3
);
262 vm_c0
= R600_VM_ENABLE_CONTEXT
| R600_VM_PAGE_TABLE_DEPTH_FLAT
;
264 RADEON_WRITE(R600_VM_CONTEXT0_CNTL
, vm_c0
);
266 vm_c0
&= ~R600_VM_ENABLE_CONTEXT
;
268 /* disable all other contexts */
269 for (i
= 1; i
< 8; i
++)
270 RADEON_WRITE(R600_VM_CONTEXT0_CNTL
+ (i
* 4), vm_c0
);
272 RADEON_WRITE(R600_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR
, dev_priv
->gart_info
.bus_addr
>> 12);
273 RADEON_WRITE(R600_VM_CONTEXT0_PAGE_TABLE_START_ADDR
, dev_priv
->gart_vm_start
>> 12);
274 RADEON_WRITE(R600_VM_CONTEXT0_PAGE_TABLE_END_ADDR
, (dev_priv
->gart_vm_start
+ dev_priv
->gart_size
- 1) >> 12);
276 r600_vm_flush_gart_range(dev
);
279 /* load r600 microcode */
280 static void r600_cp_load_microcode(drm_radeon_private_t
*dev_priv
)
286 switch (dev_priv
->flags
& RADEON_FAMILY_MASK
) {
288 DRM_INFO("Loading R600 Microcode\n");
289 cp
= R600_cp_microcode
;
290 pfp
= R600_pfp_microcode
;
293 DRM_INFO("Loading RV610 Microcode\n");
294 cp
= RV610_cp_microcode
;
295 pfp
= RV610_pfp_microcode
;
298 DRM_INFO("Loading RV630 Microcode\n");
299 cp
= RV630_cp_microcode
;
300 pfp
= RV630_pfp_microcode
;
303 DRM_INFO("Loading RV620 Microcode\n");
304 cp
= RV620_cp_microcode
;
305 pfp
= RV620_pfp_microcode
;
308 DRM_INFO("Loading RV635 Microcode\n");
309 cp
= RV635_cp_microcode
;
310 pfp
= RV635_pfp_microcode
;
313 DRM_INFO("Loading RV670 Microcode\n");
314 cp
= RV670_cp_microcode
;
315 pfp
= RV670_pfp_microcode
;
319 DRM_INFO("Loading RS780/RS880 Microcode\n");
320 cp
= RS780_cp_microcode
;
321 pfp
= RS780_pfp_microcode
;
327 r600_do_cp_stop(dev_priv
);
329 RADEON_WRITE(R600_CP_RB_CNTL
,
334 RADEON_WRITE(R600_GRBM_SOFT_RESET
, R600_SOFT_RESET_CP
);
335 RADEON_READ(R600_GRBM_SOFT_RESET
);
337 RADEON_WRITE(R600_GRBM_SOFT_RESET
, 0);
339 RADEON_WRITE(R600_CP_ME_RAM_WADDR
, 0);
341 for (i
= 0; i
< PM4_UCODE_SIZE
; i
++) {
342 RADEON_WRITE(R600_CP_ME_RAM_DATA
, cp
[i
][0]);
343 RADEON_WRITE(R600_CP_ME_RAM_DATA
, cp
[i
][1]);
344 RADEON_WRITE(R600_CP_ME_RAM_DATA
, cp
[i
][2]);
347 RADEON_WRITE(R600_CP_PFP_UCODE_ADDR
, 0);
348 for (i
= 0; i
< PFP_UCODE_SIZE
; i
++)
349 RADEON_WRITE(R600_CP_PFP_UCODE_DATA
, pfp
[i
]);
351 RADEON_WRITE(R600_CP_PFP_UCODE_ADDR
, 0);
352 RADEON_WRITE(R600_CP_ME_RAM_WADDR
, 0);
353 RADEON_WRITE(R600_CP_ME_RAM_RADDR
, 0);
356 static void r700_vm_init(struct drm_device
*dev
)
358 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
359 /* initialise the VM to use the page table we constructed up there */
362 u32 vm_l2_cntl
, vm_l2_cntl3
;
363 /* okay set up the PCIE aperture type thingo */
364 RADEON_WRITE(R700_MC_VM_SYSTEM_APERTURE_LOW_ADDR
, dev_priv
->gart_vm_start
>> 12);
365 RADEON_WRITE(R700_MC_VM_SYSTEM_APERTURE_HIGH_ADDR
, (dev_priv
->gart_vm_start
+ dev_priv
->gart_size
- 1) >> 12);
366 RADEON_WRITE(R700_MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR
, 0);
368 mc_vm_md_l1
= R700_ENABLE_L1_TLB
|
369 R700_ENABLE_L1_FRAGMENT_PROCESSING
|
370 R700_SYSTEM_ACCESS_MODE_IN_SYS
|
371 R700_SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU
|
372 R700_EFFECTIVE_L1_TLB_SIZE(5) |
373 R700_EFFECTIVE_L1_QUEUE_SIZE(5);
375 RADEON_WRITE(R700_MC_VM_MD_L1_TLB0_CNTL
, mc_vm_md_l1
);
376 RADEON_WRITE(R700_MC_VM_MD_L1_TLB1_CNTL
, mc_vm_md_l1
);
377 RADEON_WRITE(R700_MC_VM_MD_L1_TLB2_CNTL
, mc_vm_md_l1
);
378 RADEON_WRITE(R700_MC_VM_MB_L1_TLB0_CNTL
, mc_vm_md_l1
);
379 RADEON_WRITE(R700_MC_VM_MB_L1_TLB1_CNTL
, mc_vm_md_l1
);
380 RADEON_WRITE(R700_MC_VM_MB_L1_TLB2_CNTL
, mc_vm_md_l1
);
381 RADEON_WRITE(R700_MC_VM_MB_L1_TLB3_CNTL
, mc_vm_md_l1
);
383 vm_l2_cntl
= R600_VM_L2_CACHE_EN
| R600_VM_L2_FRAG_PROC
| R600_VM_ENABLE_PTE_CACHE_LRU_W
;
384 vm_l2_cntl
|= R700_VM_L2_CNTL_QUEUE_SIZE(7);
385 RADEON_WRITE(R600_VM_L2_CNTL
, vm_l2_cntl
);
387 RADEON_WRITE(R600_VM_L2_CNTL2
, 0);
388 vm_l2_cntl3
= R700_VM_L2_CNTL3_BANK_SELECT(0) | R700_VM_L2_CNTL3_CACHE_UPDATE_MODE(2);
389 RADEON_WRITE(R600_VM_L2_CNTL3
, vm_l2_cntl3
);
391 vm_c0
= R600_VM_ENABLE_CONTEXT
| R600_VM_PAGE_TABLE_DEPTH_FLAT
;
393 RADEON_WRITE(R600_VM_CONTEXT0_CNTL
, vm_c0
);
395 vm_c0
&= ~R600_VM_ENABLE_CONTEXT
;
397 /* disable all other contexts */
398 for (i
= 1; i
< 8; i
++)
399 RADEON_WRITE(R600_VM_CONTEXT0_CNTL
+ (i
* 4), vm_c0
);
401 RADEON_WRITE(R700_VM_CONTEXT0_PAGE_TABLE_BASE_ADDR
, dev_priv
->gart_info
.bus_addr
>> 12);
402 RADEON_WRITE(R700_VM_CONTEXT0_PAGE_TABLE_START_ADDR
, dev_priv
->gart_vm_start
>> 12);
403 RADEON_WRITE(R700_VM_CONTEXT0_PAGE_TABLE_END_ADDR
, (dev_priv
->gart_vm_start
+ dev_priv
->gart_size
- 1) >> 12);
405 r600_vm_flush_gart_range(dev
);
408 /* load r600 microcode */
409 static void r700_cp_load_microcode(drm_radeon_private_t
*dev_priv
)
415 switch (dev_priv
->flags
& RADEON_FAMILY_MASK
) {
417 DRM_INFO("Loading RV770/RV790 Microcode\n");
418 pfp
= RV770_pfp_microcode
;
419 cp
= RV770_cp_microcode
;
423 DRM_INFO("Loading RV730/RV740 Microcode\n");
424 pfp
= RV730_pfp_microcode
;
425 cp
= RV730_cp_microcode
;
428 DRM_INFO("Loading RV710 Microcode\n");
429 pfp
= RV710_pfp_microcode
;
430 cp
= RV710_cp_microcode
;
436 r600_do_cp_stop(dev_priv
);
438 RADEON_WRITE(R600_CP_RB_CNTL
,
443 RADEON_WRITE(R600_GRBM_SOFT_RESET
, R600_SOFT_RESET_CP
);
444 RADEON_READ(R600_GRBM_SOFT_RESET
);
446 RADEON_WRITE(R600_GRBM_SOFT_RESET
, 0);
448 RADEON_WRITE(R600_CP_PFP_UCODE_ADDR
, 0);
449 for (i
= 0; i
< R700_PFP_UCODE_SIZE
; i
++)
450 RADEON_WRITE(R600_CP_PFP_UCODE_DATA
, pfp
[i
]);
451 RADEON_WRITE(R600_CP_PFP_UCODE_ADDR
, 0);
453 RADEON_WRITE(R600_CP_ME_RAM_WADDR
, 0);
454 for (i
= 0; i
< R700_PM4_UCODE_SIZE
; i
++)
455 RADEON_WRITE(R600_CP_ME_RAM_DATA
, cp
[i
]);
456 RADEON_WRITE(R600_CP_ME_RAM_WADDR
, 0);
458 RADEON_WRITE(R600_CP_PFP_UCODE_ADDR
, 0);
459 RADEON_WRITE(R600_CP_ME_RAM_WADDR
, 0);
460 RADEON_WRITE(R600_CP_ME_RAM_RADDR
, 0);
463 static void r600_test_writeback(drm_radeon_private_t
*dev_priv
)
467 /* Start with assuming that writeback doesn't work */
468 dev_priv
->writeback_works
= 0;
470 /* Writeback doesn't seem to work everywhere, test it here and possibly
471 * enable it if it appears to work
473 radeon_write_ring_rptr(dev_priv
, R600_SCRATCHOFF(1), 0);
475 RADEON_WRITE(R600_SCRATCH_REG1
, 0xdeadbeef);
477 for (tmp
= 0; tmp
< dev_priv
->usec_timeout
; tmp
++) {
480 val
= radeon_read_ring_rptr(dev_priv
, R600_SCRATCHOFF(1));
481 if (val
== 0xdeadbeef)
486 if (tmp
< dev_priv
->usec_timeout
) {
487 dev_priv
->writeback_works
= 1;
488 DRM_INFO("writeback test succeeded in %d usecs\n", tmp
);
490 dev_priv
->writeback_works
= 0;
491 DRM_INFO("writeback test failed\n");
493 if (radeon_no_wb
== 1) {
494 dev_priv
->writeback_works
= 0;
495 DRM_INFO("writeback forced off\n");
498 if (!dev_priv
->writeback_works
) {
499 /* Disable writeback to avoid unnecessary bus master transfer */
500 RADEON_WRITE(R600_CP_RB_CNTL
, RADEON_READ(R600_CP_RB_CNTL
) |
501 RADEON_RB_NO_UPDATE
);
502 RADEON_WRITE(R600_SCRATCH_UMSK
, 0);
506 int r600_do_engine_reset(struct drm_device
*dev
)
508 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
509 u32 cp_ptr
, cp_me_cntl
, cp_rb_cntl
;
511 DRM_INFO("Resetting GPU\n");
513 cp_ptr
= RADEON_READ(R600_CP_RB_WPTR
);
514 cp_me_cntl
= RADEON_READ(R600_CP_ME_CNTL
);
515 RADEON_WRITE(R600_CP_ME_CNTL
, R600_CP_ME_HALT
);
517 RADEON_WRITE(R600_GRBM_SOFT_RESET
, 0x7fff);
518 RADEON_READ(R600_GRBM_SOFT_RESET
);
520 RADEON_WRITE(R600_GRBM_SOFT_RESET
, 0);
521 RADEON_READ(R600_GRBM_SOFT_RESET
);
523 RADEON_WRITE(R600_CP_RB_WPTR_DELAY
, 0);
524 cp_rb_cntl
= RADEON_READ(R600_CP_RB_CNTL
);
525 RADEON_WRITE(R600_CP_RB_CNTL
, R600_RB_RPTR_WR_ENA
);
527 RADEON_WRITE(R600_CP_RB_RPTR_WR
, cp_ptr
);
528 RADEON_WRITE(R600_CP_RB_WPTR
, cp_ptr
);
529 RADEON_WRITE(R600_CP_RB_CNTL
, cp_rb_cntl
);
530 RADEON_WRITE(R600_CP_ME_CNTL
, cp_me_cntl
);
532 /* Reset the CP ring */
533 r600_do_cp_reset(dev_priv
);
535 /* The CP is no longer running after an engine reset */
536 dev_priv
->cp_running
= 0;
538 /* Reset any pending vertex, indirect buffers */
539 radeon_freelist_reset(dev
);
545 static u32
r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes
,
547 u32 backend_disable_mask
)
550 u32 enabled_backends_mask
;
551 u32 enabled_backends_count
;
553 u32 swizzle_pipe
[R6XX_MAX_PIPES
];
557 if (num_tile_pipes
> R6XX_MAX_PIPES
)
558 num_tile_pipes
= R6XX_MAX_PIPES
;
559 if (num_tile_pipes
< 1)
561 if (num_backends
> R6XX_MAX_BACKENDS
)
562 num_backends
= R6XX_MAX_BACKENDS
;
563 if (num_backends
< 1)
566 enabled_backends_mask
= 0;
567 enabled_backends_count
= 0;
568 for (i
= 0; i
< R6XX_MAX_BACKENDS
; ++i
) {
569 if (((backend_disable_mask
>> i
) & 1) == 0) {
570 enabled_backends_mask
|= (1 << i
);
571 ++enabled_backends_count
;
573 if (enabled_backends_count
== num_backends
)
577 if (enabled_backends_count
== 0) {
578 enabled_backends_mask
= 1;
579 enabled_backends_count
= 1;
582 if (enabled_backends_count
!= num_backends
)
583 num_backends
= enabled_backends_count
;
585 memset((uint8_t *)&swizzle_pipe
[0], 0, sizeof(u32
) * R6XX_MAX_PIPES
);
586 switch (num_tile_pipes
) {
642 for (cur_pipe
= 0; cur_pipe
< num_tile_pipes
; ++cur_pipe
) {
643 while (((1 << cur_backend
) & enabled_backends_mask
) == 0)
644 cur_backend
= (cur_backend
+ 1) % R6XX_MAX_BACKENDS
;
646 backend_map
|= (u32
)(((cur_backend
& 3) << (swizzle_pipe
[cur_pipe
] * 2)));
648 cur_backend
= (cur_backend
+ 1) % R6XX_MAX_BACKENDS
;
654 static int r600_count_pipe_bits(uint32_t val
)
657 for (i
= 0; i
< 32; i
++) {
664 static void r600_gfx_init(struct drm_device
*dev
,
665 drm_radeon_private_t
*dev_priv
)
667 int i
, j
, num_qd_pipes
;
671 u32 num_gs_verts_per_thread
;
673 u32 gs_prim_buffer_depth
= 0;
674 u32 sq_ms_fifo_sizes
;
676 u32 sq_gpr_resource_mgmt_1
= 0;
677 u32 sq_gpr_resource_mgmt_2
= 0;
678 u32 sq_thread_resource_mgmt
= 0;
679 u32 sq_stack_resource_mgmt_1
= 0;
680 u32 sq_stack_resource_mgmt_2
= 0;
681 u32 hdp_host_path_cntl
;
683 u32 gb_tiling_config
= 0;
684 u32 cc_rb_backend_disable
= 0;
685 u32 cc_gc_shader_pipe_config
= 0;
688 /* setup chip specs */
689 switch (dev_priv
->flags
& RADEON_FAMILY_MASK
) {
691 dev_priv
->r600_max_pipes
= 4;
692 dev_priv
->r600_max_tile_pipes
= 8;
693 dev_priv
->r600_max_simds
= 4;
694 dev_priv
->r600_max_backends
= 4;
695 dev_priv
->r600_max_gprs
= 256;
696 dev_priv
->r600_max_threads
= 192;
697 dev_priv
->r600_max_stack_entries
= 256;
698 dev_priv
->r600_max_hw_contexts
= 8;
699 dev_priv
->r600_max_gs_threads
= 16;
700 dev_priv
->r600_sx_max_export_size
= 128;
701 dev_priv
->r600_sx_max_export_pos_size
= 16;
702 dev_priv
->r600_sx_max_export_smx_size
= 128;
703 dev_priv
->r600_sq_num_cf_insts
= 2;
707 dev_priv
->r600_max_pipes
= 2;
708 dev_priv
->r600_max_tile_pipes
= 2;
709 dev_priv
->r600_max_simds
= 3;
710 dev_priv
->r600_max_backends
= 1;
711 dev_priv
->r600_max_gprs
= 128;
712 dev_priv
->r600_max_threads
= 192;
713 dev_priv
->r600_max_stack_entries
= 128;
714 dev_priv
->r600_max_hw_contexts
= 8;
715 dev_priv
->r600_max_gs_threads
= 4;
716 dev_priv
->r600_sx_max_export_size
= 128;
717 dev_priv
->r600_sx_max_export_pos_size
= 16;
718 dev_priv
->r600_sx_max_export_smx_size
= 128;
719 dev_priv
->r600_sq_num_cf_insts
= 2;
725 dev_priv
->r600_max_pipes
= 1;
726 dev_priv
->r600_max_tile_pipes
= 1;
727 dev_priv
->r600_max_simds
= 2;
728 dev_priv
->r600_max_backends
= 1;
729 dev_priv
->r600_max_gprs
= 128;
730 dev_priv
->r600_max_threads
= 192;
731 dev_priv
->r600_max_stack_entries
= 128;
732 dev_priv
->r600_max_hw_contexts
= 4;
733 dev_priv
->r600_max_gs_threads
= 4;
734 dev_priv
->r600_sx_max_export_size
= 128;
735 dev_priv
->r600_sx_max_export_pos_size
= 16;
736 dev_priv
->r600_sx_max_export_smx_size
= 128;
737 dev_priv
->r600_sq_num_cf_insts
= 1;
740 dev_priv
->r600_max_pipes
= 4;
741 dev_priv
->r600_max_tile_pipes
= 4;
742 dev_priv
->r600_max_simds
= 4;
743 dev_priv
->r600_max_backends
= 4;
744 dev_priv
->r600_max_gprs
= 192;
745 dev_priv
->r600_max_threads
= 192;
746 dev_priv
->r600_max_stack_entries
= 256;
747 dev_priv
->r600_max_hw_contexts
= 8;
748 dev_priv
->r600_max_gs_threads
= 16;
749 dev_priv
->r600_sx_max_export_size
= 128;
750 dev_priv
->r600_sx_max_export_pos_size
= 16;
751 dev_priv
->r600_sx_max_export_smx_size
= 128;
752 dev_priv
->r600_sq_num_cf_insts
= 2;
760 for (i
= 0; i
< 32; i
++) {
761 RADEON_WRITE((0x2c14 + j
), 0x00000000);
762 RADEON_WRITE((0x2c18 + j
), 0x00000000);
763 RADEON_WRITE((0x2c1c + j
), 0x00000000);
764 RADEON_WRITE((0x2c20 + j
), 0x00000000);
765 RADEON_WRITE((0x2c24 + j
), 0x00000000);
769 RADEON_WRITE(R600_GRBM_CNTL
, R600_GRBM_READ_TIMEOUT(0xff));
771 /* setup tiling, simd, pipe config */
772 ramcfg
= RADEON_READ(R600_RAMCFG
);
774 switch (dev_priv
->r600_max_tile_pipes
) {
776 gb_tiling_config
|= R600_PIPE_TILING(0);
779 gb_tiling_config
|= R600_PIPE_TILING(1);
782 gb_tiling_config
|= R600_PIPE_TILING(2);
785 gb_tiling_config
|= R600_PIPE_TILING(3);
791 gb_tiling_config
|= R600_BANK_TILING((ramcfg
>> R600_NOOFBANK_SHIFT
) & R600_NOOFBANK_MASK
);
793 gb_tiling_config
|= R600_GROUP_SIZE(0);
795 if (((ramcfg
>> R600_NOOFROWS_SHIFT
) & R600_NOOFROWS_MASK
) > 3) {
796 gb_tiling_config
|= R600_ROW_TILING(3);
797 gb_tiling_config
|= R600_SAMPLE_SPLIT(3);
800 R600_ROW_TILING(((ramcfg
>> R600_NOOFROWS_SHIFT
) & R600_NOOFROWS_MASK
));
802 R600_SAMPLE_SPLIT(((ramcfg
>> R600_NOOFROWS_SHIFT
) & R600_NOOFROWS_MASK
));
805 gb_tiling_config
|= R600_BANK_SWAPS(1);
807 backend_map
= r600_get_tile_pipe_to_backend_map(dev_priv
->r600_max_tile_pipes
,
808 dev_priv
->r600_max_backends
,
809 (0xff << dev_priv
->r600_max_backends
) & 0xff);
810 gb_tiling_config
|= R600_BACKEND_MAP(backend_map
);
812 cc_gc_shader_pipe_config
=
813 R600_INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK
<< dev_priv
->r600_max_pipes
) & R6XX_MAX_PIPES_MASK
);
814 cc_gc_shader_pipe_config
|=
815 R600_INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK
<< dev_priv
->r600_max_simds
) & R6XX_MAX_SIMDS_MASK
);
817 cc_rb_backend_disable
=
818 R600_BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK
<< dev_priv
->r600_max_backends
) & R6XX_MAX_BACKENDS_MASK
);
820 RADEON_WRITE(R600_GB_TILING_CONFIG
, gb_tiling_config
);
821 RADEON_WRITE(R600_DCP_TILING_CONFIG
, (gb_tiling_config
& 0xffff));
822 RADEON_WRITE(R600_HDP_TILING_CONFIG
, (gb_tiling_config
& 0xffff));
824 RADEON_WRITE(R600_CC_RB_BACKEND_DISABLE
, cc_rb_backend_disable
);
825 RADEON_WRITE(R600_CC_GC_SHADER_PIPE_CONFIG
, cc_gc_shader_pipe_config
);
826 RADEON_WRITE(R600_GC_USER_SHADER_PIPE_CONFIG
, cc_gc_shader_pipe_config
);
829 R6XX_MAX_BACKENDS
- r600_count_pipe_bits(cc_gc_shader_pipe_config
& R600_INACTIVE_QD_PIPES_MASK
);
830 RADEON_WRITE(R600_VGT_OUT_DEALLOC_CNTL
, (num_qd_pipes
* 4) & R600_DEALLOC_DIST_MASK
);
831 RADEON_WRITE(R600_VGT_VERTEX_REUSE_BLOCK_CNTL
, ((num_qd_pipes
* 4) - 2) & R600_VTX_REUSE_DEPTH_MASK
);
833 /* set HW defaults for 3D engine */
834 RADEON_WRITE(R600_CP_QUEUE_THRESHOLDS
, (R600_ROQ_IB1_START(0x16) |
835 R600_ROQ_IB2_START(0x2b)));
837 RADEON_WRITE(R600_CP_MEQ_THRESHOLDS
, (R600_MEQ_END(0x40) |
838 R600_ROQ_END(0x40)));
840 RADEON_WRITE(R600_TA_CNTL_AUX
, (R600_DISABLE_CUBE_ANISO
|
845 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV670
)
846 RADEON_WRITE(R600_ARB_GDEC_RD_CNTL
, 0x00000021);
848 sx_debug_1
= RADEON_READ(R600_SX_DEBUG_1
);
849 sx_debug_1
|= R600_SMX_EVENT_RELEASE
;
850 if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) > CHIP_R600
))
851 sx_debug_1
|= R600_ENABLE_NEW_SMX_ADDRESS
;
852 RADEON_WRITE(R600_SX_DEBUG_1
, sx_debug_1
);
854 if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_R600
) ||
855 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV630
) ||
856 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV610
) ||
857 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV620
) ||
858 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RS780
) ||
859 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RS880
))
860 RADEON_WRITE(R600_DB_DEBUG
, R600_PREZ_MUST_WAIT_FOR_POSTZ_DONE
);
862 RADEON_WRITE(R600_DB_DEBUG
, 0);
864 RADEON_WRITE(R600_DB_WATERMARKS
, (R600_DEPTH_FREE(4) |
865 R600_DEPTH_FLUSH(16) |
866 R600_DEPTH_PENDING_FREE(4) |
867 R600_DEPTH_CACHELINE_FREE(16)));
868 RADEON_WRITE(R600_PA_SC_MULTI_CHIP_CNTL
, 0);
869 RADEON_WRITE(R600_VGT_NUM_INSTANCES
, 0);
871 RADEON_WRITE(R600_SPI_CONFIG_CNTL
, R600_GPR_WRITE_PRIORITY(0));
872 RADEON_WRITE(R600_SPI_CONFIG_CNTL_1
, R600_VTX_DONE_DELAY(0));
874 sq_ms_fifo_sizes
= RADEON_READ(R600_SQ_MS_FIFO_SIZES
);
875 if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV610
) ||
876 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV620
) ||
877 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RS780
) ||
878 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RS880
)) {
879 sq_ms_fifo_sizes
= (R600_CACHE_FIFO_SIZE(0xa) |
880 R600_FETCH_FIFO_HIWATER(0xa) |
881 R600_DONE_FIFO_HIWATER(0xe0) |
882 R600_ALU_UPDATE_FIFO_HIWATER(0x8));
883 } else if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_R600
) ||
884 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV630
)) {
885 sq_ms_fifo_sizes
&= ~R600_DONE_FIFO_HIWATER(0xff);
886 sq_ms_fifo_sizes
|= R600_DONE_FIFO_HIWATER(0x4);
888 RADEON_WRITE(R600_SQ_MS_FIFO_SIZES
, sq_ms_fifo_sizes
);
890 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
891 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
893 sq_config
= RADEON_READ(R600_SQ_CONFIG
);
894 sq_config
&= ~(R600_PS_PRIO(3) |
898 sq_config
|= (R600_DX9_CONSTS
|
905 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_R600
) {
906 sq_gpr_resource_mgmt_1
= (R600_NUM_PS_GPRS(124) |
907 R600_NUM_VS_GPRS(124) |
908 R600_NUM_CLAUSE_TEMP_GPRS(4));
909 sq_gpr_resource_mgmt_2
= (R600_NUM_GS_GPRS(0) |
910 R600_NUM_ES_GPRS(0));
911 sq_thread_resource_mgmt
= (R600_NUM_PS_THREADS(136) |
912 R600_NUM_VS_THREADS(48) |
913 R600_NUM_GS_THREADS(4) |
914 R600_NUM_ES_THREADS(4));
915 sq_stack_resource_mgmt_1
= (R600_NUM_PS_STACK_ENTRIES(128) |
916 R600_NUM_VS_STACK_ENTRIES(128));
917 sq_stack_resource_mgmt_2
= (R600_NUM_GS_STACK_ENTRIES(0) |
918 R600_NUM_ES_STACK_ENTRIES(0));
919 } else if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV610
) ||
920 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV620
) ||
921 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RS780
) ||
922 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RS880
)) {
923 /* no vertex cache */
924 sq_config
&= ~R600_VC_ENABLE
;
926 sq_gpr_resource_mgmt_1
= (R600_NUM_PS_GPRS(44) |
927 R600_NUM_VS_GPRS(44) |
928 R600_NUM_CLAUSE_TEMP_GPRS(2));
929 sq_gpr_resource_mgmt_2
= (R600_NUM_GS_GPRS(17) |
930 R600_NUM_ES_GPRS(17));
931 sq_thread_resource_mgmt
= (R600_NUM_PS_THREADS(79) |
932 R600_NUM_VS_THREADS(78) |
933 R600_NUM_GS_THREADS(4) |
934 R600_NUM_ES_THREADS(31));
935 sq_stack_resource_mgmt_1
= (R600_NUM_PS_STACK_ENTRIES(40) |
936 R600_NUM_VS_STACK_ENTRIES(40));
937 sq_stack_resource_mgmt_2
= (R600_NUM_GS_STACK_ENTRIES(32) |
938 R600_NUM_ES_STACK_ENTRIES(16));
939 } else if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV630
) ||
940 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV635
)) {
941 sq_gpr_resource_mgmt_1
= (R600_NUM_PS_GPRS(44) |
942 R600_NUM_VS_GPRS(44) |
943 R600_NUM_CLAUSE_TEMP_GPRS(2));
944 sq_gpr_resource_mgmt_2
= (R600_NUM_GS_GPRS(18) |
945 R600_NUM_ES_GPRS(18));
946 sq_thread_resource_mgmt
= (R600_NUM_PS_THREADS(79) |
947 R600_NUM_VS_THREADS(78) |
948 R600_NUM_GS_THREADS(4) |
949 R600_NUM_ES_THREADS(31));
950 sq_stack_resource_mgmt_1
= (R600_NUM_PS_STACK_ENTRIES(40) |
951 R600_NUM_VS_STACK_ENTRIES(40));
952 sq_stack_resource_mgmt_2
= (R600_NUM_GS_STACK_ENTRIES(32) |
953 R600_NUM_ES_STACK_ENTRIES(16));
954 } else if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV670
) {
955 sq_gpr_resource_mgmt_1
= (R600_NUM_PS_GPRS(44) |
956 R600_NUM_VS_GPRS(44) |
957 R600_NUM_CLAUSE_TEMP_GPRS(2));
958 sq_gpr_resource_mgmt_2
= (R600_NUM_GS_GPRS(17) |
959 R600_NUM_ES_GPRS(17));
960 sq_thread_resource_mgmt
= (R600_NUM_PS_THREADS(79) |
961 R600_NUM_VS_THREADS(78) |
962 R600_NUM_GS_THREADS(4) |
963 R600_NUM_ES_THREADS(31));
964 sq_stack_resource_mgmt_1
= (R600_NUM_PS_STACK_ENTRIES(64) |
965 R600_NUM_VS_STACK_ENTRIES(64));
966 sq_stack_resource_mgmt_2
= (R600_NUM_GS_STACK_ENTRIES(64) |
967 R600_NUM_ES_STACK_ENTRIES(64));
970 RADEON_WRITE(R600_SQ_CONFIG
, sq_config
);
971 RADEON_WRITE(R600_SQ_GPR_RESOURCE_MGMT_1
, sq_gpr_resource_mgmt_1
);
972 RADEON_WRITE(R600_SQ_GPR_RESOURCE_MGMT_2
, sq_gpr_resource_mgmt_2
);
973 RADEON_WRITE(R600_SQ_THREAD_RESOURCE_MGMT
, sq_thread_resource_mgmt
);
974 RADEON_WRITE(R600_SQ_STACK_RESOURCE_MGMT_1
, sq_stack_resource_mgmt_1
);
975 RADEON_WRITE(R600_SQ_STACK_RESOURCE_MGMT_2
, sq_stack_resource_mgmt_2
);
977 if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV610
) ||
978 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV620
) ||
979 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RS780
) ||
980 ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RS880
))
981 RADEON_WRITE(R600_VGT_CACHE_INVALIDATION
, R600_CACHE_INVALIDATION(R600_TC_ONLY
));
983 RADEON_WRITE(R600_VGT_CACHE_INVALIDATION
, R600_CACHE_INVALIDATION(R600_VC_AND_TC
));
985 RADEON_WRITE(R600_PA_SC_AA_SAMPLE_LOCS_2S
, (R600_S0_X(0xc) |
989 RADEON_WRITE(R600_PA_SC_AA_SAMPLE_LOCS_4S
, (R600_S0_X(0xe) |
997 RADEON_WRITE(R600_PA_SC_AA_SAMPLE_LOCS_8S_WD0
, (R600_S0_X(0xe) |
1005 RADEON_WRITE(R600_PA_SC_AA_SAMPLE_LOCS_8S_WD1
, (R600_S4_X(0x6) |
1015 switch (dev_priv
->flags
& RADEON_FAMILY_MASK
) {
1019 gs_prim_buffer_depth
= 0;
1025 gs_prim_buffer_depth
= 32;
1028 gs_prim_buffer_depth
= 128;
1034 num_gs_verts_per_thread
= dev_priv
->r600_max_pipes
* 16;
1035 vgt_gs_per_es
= gs_prim_buffer_depth
+ num_gs_verts_per_thread
;
1036 /* Max value for this is 256 */
1037 if (vgt_gs_per_es
> 256)
1038 vgt_gs_per_es
= 256;
1040 RADEON_WRITE(R600_VGT_ES_PER_GS
, 128);
1041 RADEON_WRITE(R600_VGT_GS_PER_ES
, vgt_gs_per_es
);
1042 RADEON_WRITE(R600_VGT_GS_PER_VS
, 2);
1043 RADEON_WRITE(R600_VGT_GS_VERTEX_REUSE
, 16);
1045 /* more default values. 2D/3D driver should adjust as needed */
1046 RADEON_WRITE(R600_PA_SC_LINE_STIPPLE_STATE
, 0);
1047 RADEON_WRITE(R600_VGT_STRMOUT_EN
, 0);
1048 RADEON_WRITE(R600_SX_MISC
, 0);
1049 RADEON_WRITE(R600_PA_SC_MODE_CNTL
, 0);
1050 RADEON_WRITE(R600_PA_SC_AA_CONFIG
, 0);
1051 RADEON_WRITE(R600_PA_SC_LINE_STIPPLE
, 0);
1052 RADEON_WRITE(R600_SPI_INPUT_Z
, 0);
1053 RADEON_WRITE(R600_SPI_PS_IN_CONTROL_0
, R600_NUM_INTERP(2));
1054 RADEON_WRITE(R600_CB_COLOR7_FRAG
, 0);
1056 /* clear render buffer base addresses */
1057 RADEON_WRITE(R600_CB_COLOR0_BASE
, 0);
1058 RADEON_WRITE(R600_CB_COLOR1_BASE
, 0);
1059 RADEON_WRITE(R600_CB_COLOR2_BASE
, 0);
1060 RADEON_WRITE(R600_CB_COLOR3_BASE
, 0);
1061 RADEON_WRITE(R600_CB_COLOR4_BASE
, 0);
1062 RADEON_WRITE(R600_CB_COLOR5_BASE
, 0);
1063 RADEON_WRITE(R600_CB_COLOR6_BASE
, 0);
1064 RADEON_WRITE(R600_CB_COLOR7_BASE
, 0);
1066 switch (dev_priv
->flags
& RADEON_FAMILY_MASK
) {
1071 tc_cntl
= R600_TC_L2_SIZE(8);
1075 tc_cntl
= R600_TC_L2_SIZE(4);
1078 tc_cntl
= R600_TC_L2_SIZE(0) | R600_L2_DISABLE_LATE_HIT
;
1081 tc_cntl
= R600_TC_L2_SIZE(0);
1085 RADEON_WRITE(R600_TC_CNTL
, tc_cntl
);
1087 hdp_host_path_cntl
= RADEON_READ(R600_HDP_HOST_PATH_CNTL
);
1088 RADEON_WRITE(R600_HDP_HOST_PATH_CNTL
, hdp_host_path_cntl
);
1090 arb_pop
= RADEON_READ(R600_ARB_POP
);
1091 arb_pop
|= R600_ENABLE_TC128
;
1092 RADEON_WRITE(R600_ARB_POP
, arb_pop
);
1094 RADEON_WRITE(R600_PA_SC_MULTI_CHIP_CNTL
, 0);
1095 RADEON_WRITE(R600_PA_CL_ENHANCE
, (R600_CLIP_VTX_REORDER_ENA
|
1096 R600_NUM_CLIP_SEQ(3)));
1097 RADEON_WRITE(R600_PA_SC_ENHANCE
, R600_FORCE_EOV_MAX_CLK_CNT(4095));
1101 static u32
r700_get_tile_pipe_to_backend_map(u32 num_tile_pipes
,
1103 u32 backend_disable_mask
)
1105 u32 backend_map
= 0;
1106 u32 enabled_backends_mask
;
1107 u32 enabled_backends_count
;
1109 u32 swizzle_pipe
[R7XX_MAX_PIPES
];
1113 if (num_tile_pipes
> R7XX_MAX_PIPES
)
1114 num_tile_pipes
= R7XX_MAX_PIPES
;
1115 if (num_tile_pipes
< 1)
1117 if (num_backends
> R7XX_MAX_BACKENDS
)
1118 num_backends
= R7XX_MAX_BACKENDS
;
1119 if (num_backends
< 1)
1122 enabled_backends_mask
= 0;
1123 enabled_backends_count
= 0;
1124 for (i
= 0; i
< R7XX_MAX_BACKENDS
; ++i
) {
1125 if (((backend_disable_mask
>> i
) & 1) == 0) {
1126 enabled_backends_mask
|= (1 << i
);
1127 ++enabled_backends_count
;
1129 if (enabled_backends_count
== num_backends
)
1133 if (enabled_backends_count
== 0) {
1134 enabled_backends_mask
= 1;
1135 enabled_backends_count
= 1;
1138 if (enabled_backends_count
!= num_backends
)
1139 num_backends
= enabled_backends_count
;
1141 memset((uint8_t *)&swizzle_pipe
[0], 0, sizeof(u32
) * R7XX_MAX_PIPES
);
1142 switch (num_tile_pipes
) {
1144 swizzle_pipe
[0] = 0;
1147 swizzle_pipe
[0] = 0;
1148 swizzle_pipe
[1] = 1;
1151 swizzle_pipe
[0] = 0;
1152 swizzle_pipe
[1] = 2;
1153 swizzle_pipe
[2] = 1;
1156 swizzle_pipe
[0] = 0;
1157 swizzle_pipe
[1] = 2;
1158 swizzle_pipe
[2] = 3;
1159 swizzle_pipe
[3] = 1;
1162 swizzle_pipe
[0] = 0;
1163 swizzle_pipe
[1] = 2;
1164 swizzle_pipe
[2] = 4;
1165 swizzle_pipe
[3] = 1;
1166 swizzle_pipe
[4] = 3;
1169 swizzle_pipe
[0] = 0;
1170 swizzle_pipe
[1] = 2;
1171 swizzle_pipe
[2] = 4;
1172 swizzle_pipe
[3] = 5;
1173 swizzle_pipe
[4] = 3;
1174 swizzle_pipe
[5] = 1;
1177 swizzle_pipe
[0] = 0;
1178 swizzle_pipe
[1] = 2;
1179 swizzle_pipe
[2] = 4;
1180 swizzle_pipe
[3] = 6;
1181 swizzle_pipe
[4] = 3;
1182 swizzle_pipe
[5] = 1;
1183 swizzle_pipe
[6] = 5;
1186 swizzle_pipe
[0] = 0;
1187 swizzle_pipe
[1] = 2;
1188 swizzle_pipe
[2] = 4;
1189 swizzle_pipe
[3] = 6;
1190 swizzle_pipe
[4] = 3;
1191 swizzle_pipe
[5] = 1;
1192 swizzle_pipe
[6] = 7;
1193 swizzle_pipe
[7] = 5;
1198 for (cur_pipe
= 0; cur_pipe
< num_tile_pipes
; ++cur_pipe
) {
1199 while (((1 << cur_backend
) & enabled_backends_mask
) == 0)
1200 cur_backend
= (cur_backend
+ 1) % R7XX_MAX_BACKENDS
;
1202 backend_map
|= (u32
)(((cur_backend
& 3) << (swizzle_pipe
[cur_pipe
] * 2)));
1204 cur_backend
= (cur_backend
+ 1) % R7XX_MAX_BACKENDS
;
1210 static void r700_gfx_init(struct drm_device
*dev
,
1211 drm_radeon_private_t
*dev_priv
)
1213 int i
, j
, num_qd_pipes
;
1216 u32 num_gs_verts_per_thread
;
1218 u32 gs_prim_buffer_depth
= 0;
1219 u32 sq_ms_fifo_sizes
;
1221 u32 sq_thread_resource_mgmt
;
1222 u32 hdp_host_path_cntl
;
1223 u32 sq_dyn_gpr_size_simd_ab_0
;
1225 u32 gb_tiling_config
= 0;
1226 u32 cc_rb_backend_disable
= 0;
1227 u32 cc_gc_shader_pipe_config
= 0;
1231 /* setup chip specs */
1232 switch (dev_priv
->flags
& RADEON_FAMILY_MASK
) {
1234 dev_priv
->r600_max_pipes
= 4;
1235 dev_priv
->r600_max_tile_pipes
= 8;
1236 dev_priv
->r600_max_simds
= 10;
1237 dev_priv
->r600_max_backends
= 4;
1238 dev_priv
->r600_max_gprs
= 256;
1239 dev_priv
->r600_max_threads
= 248;
1240 dev_priv
->r600_max_stack_entries
= 512;
1241 dev_priv
->r600_max_hw_contexts
= 8;
1242 dev_priv
->r600_max_gs_threads
= 16 * 2;
1243 dev_priv
->r600_sx_max_export_size
= 128;
1244 dev_priv
->r600_sx_max_export_pos_size
= 16;
1245 dev_priv
->r600_sx_max_export_smx_size
= 112;
1246 dev_priv
->r600_sq_num_cf_insts
= 2;
1248 dev_priv
->r700_sx_num_of_sets
= 7;
1249 dev_priv
->r700_sc_prim_fifo_size
= 0xF9;
1250 dev_priv
->r700_sc_hiz_tile_fifo_size
= 0x30;
1251 dev_priv
->r700_sc_earlyz_tile_fifo_fize
= 0x130;
1254 dev_priv
->r600_max_pipes
= 4;
1255 dev_priv
->r600_max_tile_pipes
= 4;
1256 dev_priv
->r600_max_simds
= 8;
1257 dev_priv
->r600_max_backends
= 4;
1258 dev_priv
->r600_max_gprs
= 256;
1259 dev_priv
->r600_max_threads
= 248;
1260 dev_priv
->r600_max_stack_entries
= 512;
1261 dev_priv
->r600_max_hw_contexts
= 8;
1262 dev_priv
->r600_max_gs_threads
= 16 * 2;
1263 dev_priv
->r600_sx_max_export_size
= 256;
1264 dev_priv
->r600_sx_max_export_pos_size
= 32;
1265 dev_priv
->r600_sx_max_export_smx_size
= 224;
1266 dev_priv
->r600_sq_num_cf_insts
= 2;
1268 dev_priv
->r700_sx_num_of_sets
= 7;
1269 dev_priv
->r700_sc_prim_fifo_size
= 0x100;
1270 dev_priv
->r700_sc_hiz_tile_fifo_size
= 0x30;
1271 dev_priv
->r700_sc_earlyz_tile_fifo_fize
= 0x130;
1273 if (dev_priv
->r600_sx_max_export_pos_size
> 16) {
1274 dev_priv
->r600_sx_max_export_pos_size
-= 16;
1275 dev_priv
->r600_sx_max_export_smx_size
+= 16;
1279 dev_priv
->r600_max_pipes
= 2;
1280 dev_priv
->r600_max_tile_pipes
= 4;
1281 dev_priv
->r600_max_simds
= 8;
1282 dev_priv
->r600_max_backends
= 2;
1283 dev_priv
->r600_max_gprs
= 128;
1284 dev_priv
->r600_max_threads
= 248;
1285 dev_priv
->r600_max_stack_entries
= 256;
1286 dev_priv
->r600_max_hw_contexts
= 8;
1287 dev_priv
->r600_max_gs_threads
= 16 * 2;
1288 dev_priv
->r600_sx_max_export_size
= 256;
1289 dev_priv
->r600_sx_max_export_pos_size
= 32;
1290 dev_priv
->r600_sx_max_export_smx_size
= 224;
1291 dev_priv
->r600_sq_num_cf_insts
= 2;
1293 dev_priv
->r700_sx_num_of_sets
= 7;
1294 dev_priv
->r700_sc_prim_fifo_size
= 0xf9;
1295 dev_priv
->r700_sc_hiz_tile_fifo_size
= 0x30;
1296 dev_priv
->r700_sc_earlyz_tile_fifo_fize
= 0x130;
1298 if (dev_priv
->r600_sx_max_export_pos_size
> 16) {
1299 dev_priv
->r600_sx_max_export_pos_size
-= 16;
1300 dev_priv
->r600_sx_max_export_smx_size
+= 16;
1304 dev_priv
->r600_max_pipes
= 2;
1305 dev_priv
->r600_max_tile_pipes
= 2;
1306 dev_priv
->r600_max_simds
= 2;
1307 dev_priv
->r600_max_backends
= 1;
1308 dev_priv
->r600_max_gprs
= 256;
1309 dev_priv
->r600_max_threads
= 192;
1310 dev_priv
->r600_max_stack_entries
= 256;
1311 dev_priv
->r600_max_hw_contexts
= 4;
1312 dev_priv
->r600_max_gs_threads
= 8 * 2;
1313 dev_priv
->r600_sx_max_export_size
= 128;
1314 dev_priv
->r600_sx_max_export_pos_size
= 16;
1315 dev_priv
->r600_sx_max_export_smx_size
= 112;
1316 dev_priv
->r600_sq_num_cf_insts
= 1;
1318 dev_priv
->r700_sx_num_of_sets
= 7;
1319 dev_priv
->r700_sc_prim_fifo_size
= 0x40;
1320 dev_priv
->r700_sc_hiz_tile_fifo_size
= 0x30;
1321 dev_priv
->r700_sc_earlyz_tile_fifo_fize
= 0x130;
1327 /* Initialize HDP */
1329 for (i
= 0; i
< 32; i
++) {
1330 RADEON_WRITE((0x2c14 + j
), 0x00000000);
1331 RADEON_WRITE((0x2c18 + j
), 0x00000000);
1332 RADEON_WRITE((0x2c1c + j
), 0x00000000);
1333 RADEON_WRITE((0x2c20 + j
), 0x00000000);
1334 RADEON_WRITE((0x2c24 + j
), 0x00000000);
1338 RADEON_WRITE(R600_GRBM_CNTL
, R600_GRBM_READ_TIMEOUT(0xff));
1340 /* setup tiling, simd, pipe config */
1341 mc_arb_ramcfg
= RADEON_READ(R700_MC_ARB_RAMCFG
);
1343 switch (dev_priv
->r600_max_tile_pipes
) {
1345 gb_tiling_config
|= R600_PIPE_TILING(0);
1348 gb_tiling_config
|= R600_PIPE_TILING(1);
1351 gb_tiling_config
|= R600_PIPE_TILING(2);
1354 gb_tiling_config
|= R600_PIPE_TILING(3);
1360 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV770
)
1361 gb_tiling_config
|= R600_BANK_TILING(1);
1363 gb_tiling_config
|= R600_BANK_TILING((mc_arb_ramcfg
>> R700_NOOFBANK_SHIFT
) & R700_NOOFBANK_MASK
);
1365 gb_tiling_config
|= R600_GROUP_SIZE(0);
1367 if (((mc_arb_ramcfg
>> R700_NOOFROWS_SHIFT
) & R700_NOOFROWS_MASK
) > 3) {
1368 gb_tiling_config
|= R600_ROW_TILING(3);
1369 gb_tiling_config
|= R600_SAMPLE_SPLIT(3);
1372 R600_ROW_TILING(((mc_arb_ramcfg
>> R700_NOOFROWS_SHIFT
) & R700_NOOFROWS_MASK
));
1374 R600_SAMPLE_SPLIT(((mc_arb_ramcfg
>> R700_NOOFROWS_SHIFT
) & R700_NOOFROWS_MASK
));
1377 gb_tiling_config
|= R600_BANK_SWAPS(1);
1379 backend_map
= r700_get_tile_pipe_to_backend_map(dev_priv
->r600_max_tile_pipes
,
1380 dev_priv
->r600_max_backends
,
1381 (0xff << dev_priv
->r600_max_backends
) & 0xff);
1382 gb_tiling_config
|= R600_BACKEND_MAP(backend_map
);
1384 cc_gc_shader_pipe_config
=
1385 R600_INACTIVE_QD_PIPES((R7XX_MAX_PIPES_MASK
<< dev_priv
->r600_max_pipes
) & R7XX_MAX_PIPES_MASK
);
1386 cc_gc_shader_pipe_config
|=
1387 R600_INACTIVE_SIMDS((R7XX_MAX_SIMDS_MASK
<< dev_priv
->r600_max_simds
) & R7XX_MAX_SIMDS_MASK
);
1389 cc_rb_backend_disable
=
1390 R600_BACKEND_DISABLE((R7XX_MAX_BACKENDS_MASK
<< dev_priv
->r600_max_backends
) & R7XX_MAX_BACKENDS_MASK
);
1392 RADEON_WRITE(R600_GB_TILING_CONFIG
, gb_tiling_config
);
1393 RADEON_WRITE(R600_DCP_TILING_CONFIG
, (gb_tiling_config
& 0xffff));
1394 RADEON_WRITE(R600_HDP_TILING_CONFIG
, (gb_tiling_config
& 0xffff));
1396 RADEON_WRITE(R600_CC_RB_BACKEND_DISABLE
, cc_rb_backend_disable
);
1397 RADEON_WRITE(R600_CC_GC_SHADER_PIPE_CONFIG
, cc_gc_shader_pipe_config
);
1398 RADEON_WRITE(R600_GC_USER_SHADER_PIPE_CONFIG
, cc_gc_shader_pipe_config
);
1400 RADEON_WRITE(R700_CC_SYS_RB_BACKEND_DISABLE
, cc_rb_backend_disable
);
1401 RADEON_WRITE(R700_CGTS_SYS_TCC_DISABLE
, 0);
1402 RADEON_WRITE(R700_CGTS_TCC_DISABLE
, 0);
1403 RADEON_WRITE(R700_CGTS_USER_SYS_TCC_DISABLE
, 0);
1404 RADEON_WRITE(R700_CGTS_USER_TCC_DISABLE
, 0);
1407 R7XX_MAX_BACKENDS
- r600_count_pipe_bits(cc_gc_shader_pipe_config
& R600_INACTIVE_QD_PIPES_MASK
);
1408 RADEON_WRITE(R600_VGT_OUT_DEALLOC_CNTL
, (num_qd_pipes
* 4) & R600_DEALLOC_DIST_MASK
);
1409 RADEON_WRITE(R600_VGT_VERTEX_REUSE_BLOCK_CNTL
, ((num_qd_pipes
* 4) - 2) & R600_VTX_REUSE_DEPTH_MASK
);
1411 /* set HW defaults for 3D engine */
1412 RADEON_WRITE(R600_CP_QUEUE_THRESHOLDS
, (R600_ROQ_IB1_START(0x16) |
1413 R600_ROQ_IB2_START(0x2b)));
1415 RADEON_WRITE(R600_CP_MEQ_THRESHOLDS
, R700_STQ_SPLIT(0x30));
1417 RADEON_WRITE(R600_TA_CNTL_AUX
, (R600_DISABLE_CUBE_ANISO
|
1418 R600_SYNC_GRADIENT
|
1420 R600_SYNC_ALIGNER
));
1422 sx_debug_1
= RADEON_READ(R700_SX_DEBUG_1
);
1423 sx_debug_1
|= R700_ENABLE_NEW_SMX_ADDRESS
;
1424 RADEON_WRITE(R700_SX_DEBUG_1
, sx_debug_1
);
1426 smx_dc_ctl0
= RADEON_READ(R600_SMX_DC_CTL0
);
1427 smx_dc_ctl0
&= ~R700_CACHE_DEPTH(0x1ff);
1428 smx_dc_ctl0
|= R700_CACHE_DEPTH((dev_priv
->r700_sx_num_of_sets
* 64) - 1);
1429 RADEON_WRITE(R600_SMX_DC_CTL0
, smx_dc_ctl0
);
1431 RADEON_WRITE(R700_SMX_EVENT_CTL
, (R700_ES_FLUSH_CTL(4) |
1432 R700_GS_FLUSH_CTL(4) |
1433 R700_ACK_FLUSH_CTL(3) |
1434 R700_SYNC_FLUSH_CTL
));
1436 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV770
)
1437 RADEON_WRITE(R700_DB_DEBUG3
, R700_DB_CLK_OFF_DELAY(0x1f));
1439 db_debug4
= RADEON_READ(RV700_DB_DEBUG4
);
1440 db_debug4
|= RV700_DISABLE_TILE_COVERED_FOR_PS_ITER
;
1441 RADEON_WRITE(RV700_DB_DEBUG4
, db_debug4
);
1444 RADEON_WRITE(R600_SX_EXPORT_BUFFER_SIZES
, (R600_COLOR_BUFFER_SIZE((dev_priv
->r600_sx_max_export_size
/ 4) - 1) |
1445 R600_POSITION_BUFFER_SIZE((dev_priv
->r600_sx_max_export_pos_size
/ 4) - 1) |
1446 R600_SMX_BUFFER_SIZE((dev_priv
->r600_sx_max_export_smx_size
/ 4) - 1)));
1448 RADEON_WRITE(R700_PA_SC_FIFO_SIZE_R7XX
, (R700_SC_PRIM_FIFO_SIZE(dev_priv
->r700_sc_prim_fifo_size
) |
1449 R700_SC_HIZ_TILE_FIFO_SIZE(dev_priv
->r700_sc_hiz_tile_fifo_size
) |
1450 R700_SC_EARLYZ_TILE_FIFO_SIZE(dev_priv
->r700_sc_earlyz_tile_fifo_fize
)));
1452 RADEON_WRITE(R600_PA_SC_MULTI_CHIP_CNTL
, 0);
1454 RADEON_WRITE(R600_VGT_NUM_INSTANCES
, 1);
1456 RADEON_WRITE(R600_SPI_CONFIG_CNTL
, R600_GPR_WRITE_PRIORITY(0));
1458 RADEON_WRITE(R600_SPI_CONFIG_CNTL_1
, R600_VTX_DONE_DELAY(4));
1460 RADEON_WRITE(R600_CP_PERFMON_CNTL
, 0);
1462 sq_ms_fifo_sizes
= (R600_CACHE_FIFO_SIZE(16 * dev_priv
->r600_sq_num_cf_insts
) |
1463 R600_DONE_FIFO_HIWATER(0xe0) |
1464 R600_ALU_UPDATE_FIFO_HIWATER(0x8));
1465 switch (dev_priv
->flags
& RADEON_FAMILY_MASK
) {
1467 sq_ms_fifo_sizes
|= R600_FETCH_FIFO_HIWATER(0x1);
1473 sq_ms_fifo_sizes
|= R600_FETCH_FIFO_HIWATER(0x4);
1476 RADEON_WRITE(R600_SQ_MS_FIFO_SIZES
, sq_ms_fifo_sizes
);
1478 /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
1479 * should be adjusted as needed by the 2D/3D drivers. This just sets default values
1481 sq_config
= RADEON_READ(R600_SQ_CONFIG
);
1482 sq_config
&= ~(R600_PS_PRIO(3) |
1486 sq_config
|= (R600_DX9_CONSTS
|
1493 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV710
)
1494 /* no vertex cache */
1495 sq_config
&= ~R600_VC_ENABLE
;
1497 RADEON_WRITE(R600_SQ_CONFIG
, sq_config
);
1499 RADEON_WRITE(R600_SQ_GPR_RESOURCE_MGMT_1
, (R600_NUM_PS_GPRS((dev_priv
->r600_max_gprs
* 24)/64) |
1500 R600_NUM_VS_GPRS((dev_priv
->r600_max_gprs
* 24)/64) |
1501 R600_NUM_CLAUSE_TEMP_GPRS(((dev_priv
->r600_max_gprs
* 24)/64)/2)));
1503 RADEON_WRITE(R600_SQ_GPR_RESOURCE_MGMT_2
, (R600_NUM_GS_GPRS((dev_priv
->r600_max_gprs
* 7)/64) |
1504 R600_NUM_ES_GPRS((dev_priv
->r600_max_gprs
* 7)/64)));
1506 sq_thread_resource_mgmt
= (R600_NUM_PS_THREADS((dev_priv
->r600_max_threads
* 4)/8) |
1507 R600_NUM_VS_THREADS((dev_priv
->r600_max_threads
* 2)/8) |
1508 R600_NUM_ES_THREADS((dev_priv
->r600_max_threads
* 1)/8));
1509 if (((dev_priv
->r600_max_threads
* 1) / 8) > dev_priv
->r600_max_gs_threads
)
1510 sq_thread_resource_mgmt
|= R600_NUM_GS_THREADS(dev_priv
->r600_max_gs_threads
);
1512 sq_thread_resource_mgmt
|= R600_NUM_GS_THREADS((dev_priv
->r600_max_gs_threads
* 1)/8);
1513 RADEON_WRITE(R600_SQ_THREAD_RESOURCE_MGMT
, sq_thread_resource_mgmt
);
1515 RADEON_WRITE(R600_SQ_STACK_RESOURCE_MGMT_1
, (R600_NUM_PS_STACK_ENTRIES((dev_priv
->r600_max_stack_entries
* 1)/4) |
1516 R600_NUM_VS_STACK_ENTRIES((dev_priv
->r600_max_stack_entries
* 1)/4)));
1518 RADEON_WRITE(R600_SQ_STACK_RESOURCE_MGMT_2
, (R600_NUM_GS_STACK_ENTRIES((dev_priv
->r600_max_stack_entries
* 1)/4) |
1519 R600_NUM_ES_STACK_ENTRIES((dev_priv
->r600_max_stack_entries
* 1)/4)));
1521 sq_dyn_gpr_size_simd_ab_0
= (R700_SIMDA_RING0((dev_priv
->r600_max_gprs
* 38)/64) |
1522 R700_SIMDA_RING1((dev_priv
->r600_max_gprs
* 38)/64) |
1523 R700_SIMDB_RING0((dev_priv
->r600_max_gprs
* 38)/64) |
1524 R700_SIMDB_RING1((dev_priv
->r600_max_gprs
* 38)/64));
1526 RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_0
, sq_dyn_gpr_size_simd_ab_0
);
1527 RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_1
, sq_dyn_gpr_size_simd_ab_0
);
1528 RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_2
, sq_dyn_gpr_size_simd_ab_0
);
1529 RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_3
, sq_dyn_gpr_size_simd_ab_0
);
1530 RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_4
, sq_dyn_gpr_size_simd_ab_0
);
1531 RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_5
, sq_dyn_gpr_size_simd_ab_0
);
1532 RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_6
, sq_dyn_gpr_size_simd_ab_0
);
1533 RADEON_WRITE(R700_SQ_DYN_GPR_SIZE_SIMD_AB_7
, sq_dyn_gpr_size_simd_ab_0
);
1535 RADEON_WRITE(R700_PA_SC_FORCE_EOV_MAX_CNTS
, (R700_FORCE_EOV_MAX_CLK_CNT(4095) |
1536 R700_FORCE_EOV_MAX_REZ_CNT(255)));
1538 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) == CHIP_RV710
)
1539 RADEON_WRITE(R600_VGT_CACHE_INVALIDATION
, (R600_CACHE_INVALIDATION(R600_TC_ONLY
) |
1540 R700_AUTO_INVLD_EN(R700_ES_AND_GS_AUTO
)));
1542 RADEON_WRITE(R600_VGT_CACHE_INVALIDATION
, (R600_CACHE_INVALIDATION(R600_VC_AND_TC
) |
1543 R700_AUTO_INVLD_EN(R700_ES_AND_GS_AUTO
)));
1545 switch (dev_priv
->flags
& RADEON_FAMILY_MASK
) {
1549 gs_prim_buffer_depth
= 384;
1552 gs_prim_buffer_depth
= 128;
1558 num_gs_verts_per_thread
= dev_priv
->r600_max_pipes
* 16;
1559 vgt_gs_per_es
= gs_prim_buffer_depth
+ num_gs_verts_per_thread
;
1560 /* Max value for this is 256 */
1561 if (vgt_gs_per_es
> 256)
1562 vgt_gs_per_es
= 256;
1564 RADEON_WRITE(R600_VGT_ES_PER_GS
, 128);
1565 RADEON_WRITE(R600_VGT_GS_PER_ES
, vgt_gs_per_es
);
1566 RADEON_WRITE(R600_VGT_GS_PER_VS
, 2);
1568 /* more default values. 2D/3D driver should adjust as needed */
1569 RADEON_WRITE(R600_VGT_GS_VERTEX_REUSE
, 16);
1570 RADEON_WRITE(R600_PA_SC_LINE_STIPPLE_STATE
, 0);
1571 RADEON_WRITE(R600_VGT_STRMOUT_EN
, 0);
1572 RADEON_WRITE(R600_SX_MISC
, 0);
1573 RADEON_WRITE(R600_PA_SC_MODE_CNTL
, 0);
1574 RADEON_WRITE(R700_PA_SC_EDGERULE
, 0xaaaaaaaa);
1575 RADEON_WRITE(R600_PA_SC_AA_CONFIG
, 0);
1576 RADEON_WRITE(R600_PA_SC_CLIPRECT_RULE
, 0xffff);
1577 RADEON_WRITE(R600_PA_SC_LINE_STIPPLE
, 0);
1578 RADEON_WRITE(R600_SPI_INPUT_Z
, 0);
1579 RADEON_WRITE(R600_SPI_PS_IN_CONTROL_0
, R600_NUM_INTERP(2));
1580 RADEON_WRITE(R600_CB_COLOR7_FRAG
, 0);
1582 /* clear render buffer base addresses */
1583 RADEON_WRITE(R600_CB_COLOR0_BASE
, 0);
1584 RADEON_WRITE(R600_CB_COLOR1_BASE
, 0);
1585 RADEON_WRITE(R600_CB_COLOR2_BASE
, 0);
1586 RADEON_WRITE(R600_CB_COLOR3_BASE
, 0);
1587 RADEON_WRITE(R600_CB_COLOR4_BASE
, 0);
1588 RADEON_WRITE(R600_CB_COLOR5_BASE
, 0);
1589 RADEON_WRITE(R600_CB_COLOR6_BASE
, 0);
1590 RADEON_WRITE(R600_CB_COLOR7_BASE
, 0);
1592 RADEON_WRITE(R700_TCP_CNTL
, 0);
1594 hdp_host_path_cntl
= RADEON_READ(R600_HDP_HOST_PATH_CNTL
);
1595 RADEON_WRITE(R600_HDP_HOST_PATH_CNTL
, hdp_host_path_cntl
);
1597 RADEON_WRITE(R600_PA_SC_MULTI_CHIP_CNTL
, 0);
1599 RADEON_WRITE(R600_PA_CL_ENHANCE
, (R600_CLIP_VTX_REORDER_ENA
|
1600 R600_NUM_CLIP_SEQ(3)));
1604 static void r600_cp_init_ring_buffer(struct drm_device
*dev
,
1605 drm_radeon_private_t
*dev_priv
,
1606 struct drm_file
*file_priv
)
1611 if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RV770
))
1612 r700_gfx_init(dev
, dev_priv
);
1614 r600_gfx_init(dev
, dev_priv
);
1616 RADEON_WRITE(R600_GRBM_SOFT_RESET
, R600_SOFT_RESET_CP
);
1617 RADEON_READ(R600_GRBM_SOFT_RESET
);
1619 RADEON_WRITE(R600_GRBM_SOFT_RESET
, 0);
1622 /* Set ring buffer size */
1624 RADEON_WRITE(R600_CP_RB_CNTL
,
1625 RADEON_BUF_SWAP_32BIT
|
1626 RADEON_RB_NO_UPDATE
|
1627 (dev_priv
->ring
.rptr_update_l2qw
<< 8) |
1628 dev_priv
->ring
.size_l2qw
);
1630 RADEON_WRITE(R600_CP_RB_CNTL
,
1631 RADEON_RB_NO_UPDATE
|
1632 (dev_priv
->ring
.rptr_update_l2qw
<< 8) |
1633 dev_priv
->ring
.size_l2qw
);
1636 RADEON_WRITE(R600_CP_SEM_WAIT_TIMER
, 0x4);
1638 /* Set the write pointer delay */
1639 RADEON_WRITE(R600_CP_RB_WPTR_DELAY
, 0);
1642 RADEON_WRITE(R600_CP_RB_CNTL
,
1643 RADEON_BUF_SWAP_32BIT
|
1644 RADEON_RB_NO_UPDATE
|
1645 RADEON_RB_RPTR_WR_ENA
|
1646 (dev_priv
->ring
.rptr_update_l2qw
<< 8) |
1647 dev_priv
->ring
.size_l2qw
);
1649 RADEON_WRITE(R600_CP_RB_CNTL
,
1650 RADEON_RB_NO_UPDATE
|
1651 RADEON_RB_RPTR_WR_ENA
|
1652 (dev_priv
->ring
.rptr_update_l2qw
<< 8) |
1653 dev_priv
->ring
.size_l2qw
);
1656 /* Initialize the ring buffer's read and write pointers */
1657 RADEON_WRITE(R600_CP_RB_RPTR_WR
, 0);
1658 RADEON_WRITE(R600_CP_RB_WPTR
, 0);
1659 SET_RING_HEAD(dev_priv
, 0);
1660 dev_priv
->ring
.tail
= 0;
1663 if (dev_priv
->flags
& RADEON_IS_AGP
) {
1664 rptr_addr
= dev_priv
->ring_rptr
->offset
1666 dev_priv
->gart_vm_start
;
1670 rptr_addr
= dev_priv
->ring_rptr
->offset
1671 - ((unsigned long) dev
->sg
->virtual)
1672 + dev_priv
->gart_vm_start
;
1674 RADEON_WRITE(R600_CP_RB_RPTR_ADDR
,
1675 rptr_addr
& 0xffffffff);
1676 RADEON_WRITE(R600_CP_RB_RPTR_ADDR_HI
,
1677 upper_32_bits(rptr_addr
));
1680 RADEON_WRITE(R600_CP_RB_CNTL
,
1681 RADEON_BUF_SWAP_32BIT
|
1682 (dev_priv
->ring
.rptr_update_l2qw
<< 8) |
1683 dev_priv
->ring
.size_l2qw
);
1685 RADEON_WRITE(R600_CP_RB_CNTL
,
1686 (dev_priv
->ring
.rptr_update_l2qw
<< 8) |
1687 dev_priv
->ring
.size_l2qw
);
1691 if (dev_priv
->flags
& RADEON_IS_AGP
) {
1693 radeon_write_agp_base(dev_priv
, dev
->agp
->base
);
1696 radeon_write_agp_location(dev_priv
,
1697 (((dev_priv
->gart_vm_start
- 1 +
1698 dev_priv
->gart_size
) & 0xffff0000) |
1699 (dev_priv
->gart_vm_start
>> 16)));
1701 ring_start
= (dev_priv
->cp_ring
->offset
1703 + dev_priv
->gart_vm_start
);
1706 ring_start
= (dev_priv
->cp_ring
->offset
1707 - (unsigned long)dev
->sg
->virtual
1708 + dev_priv
->gart_vm_start
);
1710 RADEON_WRITE(R600_CP_RB_BASE
, ring_start
>> 8);
1712 RADEON_WRITE(R600_CP_ME_CNTL
, 0xff);
1714 RADEON_WRITE(R600_CP_DEBUG
, (1 << 27) | (1 << 28));
1716 /* Initialize the scratch register pointer. This will cause
1717 * the scratch register values to be written out to memory
1718 * whenever they are updated.
1720 * We simply put this behind the ring read pointer, this works
1721 * with PCI GART as well as (whatever kind of) AGP GART
1726 scratch_addr
= RADEON_READ(R600_CP_RB_RPTR_ADDR
);
1727 scratch_addr
|= ((u64
)RADEON_READ(R600_CP_RB_RPTR_ADDR_HI
)) << 32;
1728 scratch_addr
+= R600_SCRATCH_REG_OFFSET
;
1730 scratch_addr
&= 0xffffffff;
1732 RADEON_WRITE(R600_SCRATCH_ADDR
, (uint32_t)scratch_addr
);
1735 RADEON_WRITE(R600_SCRATCH_UMSK
, 0x7);
1737 /* Turn on bus mastering */
1738 radeon_enable_bm(dev_priv
);
1740 radeon_write_ring_rptr(dev_priv
, R600_SCRATCHOFF(0), 0);
1741 RADEON_WRITE(R600_LAST_FRAME_REG
, 0);
1743 radeon_write_ring_rptr(dev_priv
, R600_SCRATCHOFF(1), 0);
1744 RADEON_WRITE(R600_LAST_DISPATCH_REG
, 0);
1746 radeon_write_ring_rptr(dev_priv
, R600_SCRATCHOFF(2), 0);
1747 RADEON_WRITE(R600_LAST_CLEAR_REG
, 0);
1749 /* reset sarea copies of these */
1750 if (dev_priv
->sarea_priv
) {
1751 dev_priv
->sarea_priv
->last_frame
= 0;
1752 dev_priv
->sarea_priv
->last_dispatch
= 0;
1753 dev_priv
->sarea_priv
->last_clear
= 0;
1756 r600_do_wait_for_idle(dev_priv
);
1760 int r600_do_cleanup_cp(struct drm_device
*dev
)
1762 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
1765 /* Make sure interrupts are disabled here because the uninstall ioctl
1766 * may not have been called from userspace and after dev_private
1767 * is freed, it's too late.
1769 if (dev
->irq_enabled
)
1770 drm_irq_uninstall(dev
);
1773 if (dev_priv
->flags
& RADEON_IS_AGP
) {
1774 if (dev_priv
->cp_ring
!= NULL
) {
1775 drm_core_ioremapfree(dev_priv
->cp_ring
, dev
);
1776 dev_priv
->cp_ring
= NULL
;
1778 if (dev_priv
->ring_rptr
!= NULL
) {
1779 drm_core_ioremapfree(dev_priv
->ring_rptr
, dev
);
1780 dev_priv
->ring_rptr
= NULL
;
1782 if (dev
->agp_buffer_map
!= NULL
) {
1783 drm_core_ioremapfree(dev
->agp_buffer_map
, dev
);
1784 dev
->agp_buffer_map
= NULL
;
1790 if (dev_priv
->gart_info
.bus_addr
)
1791 r600_page_table_cleanup(dev
, &dev_priv
->gart_info
);
1793 if (dev_priv
->gart_info
.gart_table_location
== DRM_ATI_GART_FB
) {
1794 drm_core_ioremapfree(&dev_priv
->gart_info
.mapping
, dev
);
1795 dev_priv
->gart_info
.addr
= 0;
1798 /* only clear to the start of flags */
1799 memset(dev_priv
, 0, offsetof(drm_radeon_private_t
, flags
));
1804 int r600_do_init_cp(struct drm_device
*dev
, drm_radeon_init_t
*init
,
1805 struct drm_file
*file_priv
)
1807 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
1811 /* if we require new memory map but we don't have it fail */
1812 if ((dev_priv
->flags
& RADEON_NEW_MEMMAP
) && !dev_priv
->new_memmap
) {
1813 DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX for 3D\n");
1814 r600_do_cleanup_cp(dev
);
1818 if (init
->is_pci
&& (dev_priv
->flags
& RADEON_IS_AGP
)) {
1819 DRM_DEBUG("Forcing AGP card to PCI mode\n");
1820 dev_priv
->flags
&= ~RADEON_IS_AGP
;
1821 /* The writeback test succeeds, but when writeback is enabled,
1822 * the ring buffer read ptr update fails after first 128 bytes.
1825 } else if (!(dev_priv
->flags
& (RADEON_IS_AGP
| RADEON_IS_PCI
| RADEON_IS_PCIE
))
1827 DRM_DEBUG("Restoring AGP flag\n");
1828 dev_priv
->flags
|= RADEON_IS_AGP
;
1831 dev_priv
->usec_timeout
= init
->usec_timeout
;
1832 if (dev_priv
->usec_timeout
< 1 ||
1833 dev_priv
->usec_timeout
> RADEON_MAX_USEC_TIMEOUT
) {
1834 DRM_DEBUG("TIMEOUT problem!\n");
1835 r600_do_cleanup_cp(dev
);
1839 /* Enable vblank on CRTC1 for older X servers
1841 dev_priv
->vblank_crtc
= DRM_RADEON_VBLANK_CRTC1
;
1843 dev_priv
->cp_mode
= init
->cp_mode
;
1845 /* We don't support anything other than bus-mastering ring mode,
1846 * but the ring can be in either AGP or PCI space for the ring
1849 if ((init
->cp_mode
!= RADEON_CSQ_PRIBM_INDDIS
) &&
1850 (init
->cp_mode
!= RADEON_CSQ_PRIBM_INDBM
)) {
1851 DRM_DEBUG("BAD cp_mode (%x)!\n", init
->cp_mode
);
1852 r600_do_cleanup_cp(dev
);
1856 switch (init
->fb_bpp
) {
1858 dev_priv
->color_fmt
= RADEON_COLOR_FORMAT_RGB565
;
1862 dev_priv
->color_fmt
= RADEON_COLOR_FORMAT_ARGB8888
;
1865 dev_priv
->front_offset
= init
->front_offset
;
1866 dev_priv
->front_pitch
= init
->front_pitch
;
1867 dev_priv
->back_offset
= init
->back_offset
;
1868 dev_priv
->back_pitch
= init
->back_pitch
;
1870 dev_priv
->ring_offset
= init
->ring_offset
;
1871 dev_priv
->ring_rptr_offset
= init
->ring_rptr_offset
;
1872 dev_priv
->buffers_offset
= init
->buffers_offset
;
1873 dev_priv
->gart_textures_offset
= init
->gart_textures_offset
;
1875 dev_priv
->sarea
= drm_getsarea(dev
);
1876 if (!dev_priv
->sarea
) {
1877 DRM_ERROR("could not find sarea!\n");
1878 r600_do_cleanup_cp(dev
);
1882 dev_priv
->cp_ring
= drm_core_findmap(dev
, init
->ring_offset
);
1883 if (!dev_priv
->cp_ring
) {
1884 DRM_ERROR("could not find cp ring region!\n");
1885 r600_do_cleanup_cp(dev
);
1888 dev_priv
->ring_rptr
= drm_core_findmap(dev
, init
->ring_rptr_offset
);
1889 if (!dev_priv
->ring_rptr
) {
1890 DRM_ERROR("could not find ring read pointer!\n");
1891 r600_do_cleanup_cp(dev
);
1894 dev
->agp_buffer_token
= init
->buffers_offset
;
1895 dev
->agp_buffer_map
= drm_core_findmap(dev
, init
->buffers_offset
);
1896 if (!dev
->agp_buffer_map
) {
1897 DRM_ERROR("could not find dma buffer region!\n");
1898 r600_do_cleanup_cp(dev
);
1902 if (init
->gart_textures_offset
) {
1903 dev_priv
->gart_textures
=
1904 drm_core_findmap(dev
, init
->gart_textures_offset
);
1905 if (!dev_priv
->gart_textures
) {
1906 DRM_ERROR("could not find GART texture region!\n");
1907 r600_do_cleanup_cp(dev
);
1912 dev_priv
->sarea_priv
=
1913 (drm_radeon_sarea_t
*) ((u8
*) dev_priv
->sarea
->handle
+
1914 init
->sarea_priv_offset
);
1918 if (dev_priv
->flags
& RADEON_IS_AGP
) {
1919 drm_core_ioremap_wc(dev_priv
->cp_ring
, dev
);
1920 drm_core_ioremap_wc(dev_priv
->ring_rptr
, dev
);
1921 drm_core_ioremap_wc(dev
->agp_buffer_map
, dev
);
1922 if (!dev_priv
->cp_ring
->handle
||
1923 !dev_priv
->ring_rptr
->handle
||
1924 !dev
->agp_buffer_map
->handle
) {
1925 DRM_ERROR("could not find ioremap agp regions!\n");
1926 r600_do_cleanup_cp(dev
);
1932 dev_priv
->cp_ring
->handle
= (void *)dev_priv
->cp_ring
->offset
;
1933 dev_priv
->ring_rptr
->handle
=
1934 (void *)dev_priv
->ring_rptr
->offset
;
1935 dev
->agp_buffer_map
->handle
=
1936 (void *)dev
->agp_buffer_map
->offset
;
1938 DRM_DEBUG("dev_priv->cp_ring->handle %p\n",
1939 dev_priv
->cp_ring
->handle
);
1940 DRM_DEBUG("dev_priv->ring_rptr->handle %p\n",
1941 dev_priv
->ring_rptr
->handle
);
1942 DRM_DEBUG("dev->agp_buffer_map->handle %p\n",
1943 dev
->agp_buffer_map
->handle
);
1946 dev_priv
->fb_location
= (radeon_read_fb_location(dev_priv
) & 0xffff) << 24;
1948 (((radeon_read_fb_location(dev_priv
) & 0xffff0000u
) << 8) + 0x1000000)
1949 - dev_priv
->fb_location
;
1951 dev_priv
->front_pitch_offset
= (((dev_priv
->front_pitch
/ 64) << 22) |
1952 ((dev_priv
->front_offset
1953 + dev_priv
->fb_location
) >> 10));
1955 dev_priv
->back_pitch_offset
= (((dev_priv
->back_pitch
/ 64) << 22) |
1956 ((dev_priv
->back_offset
1957 + dev_priv
->fb_location
) >> 10));
1959 dev_priv
->depth_pitch_offset
= (((dev_priv
->depth_pitch
/ 64) << 22) |
1960 ((dev_priv
->depth_offset
1961 + dev_priv
->fb_location
) >> 10));
1963 dev_priv
->gart_size
= init
->gart_size
;
1965 /* New let's set the memory map ... */
1966 if (dev_priv
->new_memmap
) {
1969 DRM_INFO("Setting GART location based on new memory map\n");
1971 /* If using AGP, try to locate the AGP aperture at the same
1972 * location in the card and on the bus, though we have to
1977 if (dev_priv
->flags
& RADEON_IS_AGP
) {
1978 base
= dev
->agp
->base
;
1979 /* Check if valid */
1980 if ((base
+ dev_priv
->gart_size
- 1) >= dev_priv
->fb_location
&&
1981 base
< (dev_priv
->fb_location
+ dev_priv
->fb_size
- 1)) {
1982 DRM_INFO("Can't use AGP base @0x%08lx, won't fit\n",
1988 /* If not or if AGP is at 0 (Macs), try to put it elsewhere */
1990 base
= dev_priv
->fb_location
+ dev_priv
->fb_size
;
1991 if (base
< dev_priv
->fb_location
||
1992 ((base
+ dev_priv
->gart_size
) & 0xfffffffful
) < base
)
1993 base
= dev_priv
->fb_location
1994 - dev_priv
->gart_size
;
1996 dev_priv
->gart_vm_start
= base
& 0xffc00000u
;
1997 if (dev_priv
->gart_vm_start
!= base
)
1998 DRM_INFO("GART aligned down from 0x%08x to 0x%08x\n",
1999 base
, dev_priv
->gart_vm_start
);
2004 if (dev_priv
->flags
& RADEON_IS_AGP
)
2005 dev_priv
->gart_buffers_offset
= (dev
->agp_buffer_map
->offset
2007 + dev_priv
->gart_vm_start
);
2010 dev_priv
->gart_buffers_offset
= (dev
->agp_buffer_map
->offset
2011 - (unsigned long)dev
->sg
->virtual
2012 + dev_priv
->gart_vm_start
);
2014 DRM_DEBUG("fb 0x%08x size %d\n",
2015 (unsigned int) dev_priv
->fb_location
,
2016 (unsigned int) dev_priv
->fb_size
);
2017 DRM_DEBUG("dev_priv->gart_size %d\n", dev_priv
->gart_size
);
2018 DRM_DEBUG("dev_priv->gart_vm_start 0x%08x\n",
2019 (unsigned int) dev_priv
->gart_vm_start
);
2020 DRM_DEBUG("dev_priv->gart_buffers_offset 0x%08lx\n",
2021 dev_priv
->gart_buffers_offset
);
2023 dev_priv
->ring
.start
= (u32
*) dev_priv
->cp_ring
->handle
;
2024 dev_priv
->ring
.end
= ((u32
*) dev_priv
->cp_ring
->handle
2025 + init
->ring_size
/ sizeof(u32
));
2026 dev_priv
->ring
.size
= init
->ring_size
;
2027 dev_priv
->ring
.size_l2qw
= drm_order(init
->ring_size
/ 8);
2029 dev_priv
->ring
.rptr_update
= /* init->rptr_update */ 4096;
2030 dev_priv
->ring
.rptr_update_l2qw
= drm_order(/* init->rptr_update */ 4096 / 8);
2032 dev_priv
->ring
.fetch_size
= /* init->fetch_size */ 32;
2033 dev_priv
->ring
.fetch_size_l2ow
= drm_order(/* init->fetch_size */ 32 / 16);
2035 dev_priv
->ring
.tail_mask
= (dev_priv
->ring
.size
/ sizeof(u32
)) - 1;
2037 dev_priv
->ring
.high_mark
= RADEON_RING_HIGH_MARK
;
2040 if (dev_priv
->flags
& RADEON_IS_AGP
) {
2041 /* XXX turn off pcie gart */
2045 dev_priv
->gart_info
.table_mask
= DMA_BIT_MASK(32);
2046 /* if we have an offset set from userspace */
2047 if (!dev_priv
->pcigart_offset_set
) {
2048 DRM_ERROR("Need gart offset from userspace\n");
2049 r600_do_cleanup_cp(dev
);
2053 DRM_DEBUG("Using gart offset 0x%08lx\n", dev_priv
->pcigart_offset
);
2055 dev_priv
->gart_info
.bus_addr
=
2056 dev_priv
->pcigart_offset
+ dev_priv
->fb_location
;
2057 dev_priv
->gart_info
.mapping
.offset
=
2058 dev_priv
->pcigart_offset
+ dev_priv
->fb_aper_offset
;
2059 dev_priv
->gart_info
.mapping
.size
=
2060 dev_priv
->gart_info
.table_size
;
2062 drm_core_ioremap_wc(&dev_priv
->gart_info
.mapping
, dev
);
2063 if (!dev_priv
->gart_info
.mapping
.handle
) {
2064 DRM_ERROR("ioremap failed.\n");
2065 r600_do_cleanup_cp(dev
);
2069 dev_priv
->gart_info
.addr
=
2070 dev_priv
->gart_info
.mapping
.handle
;
2072 DRM_DEBUG("Setting phys_pci_gart to %p %08lX\n",
2073 dev_priv
->gart_info
.addr
,
2074 dev_priv
->pcigart_offset
);
2076 if (!r600_page_table_init(dev
)) {
2077 DRM_ERROR("Failed to init GART table\n");
2078 r600_do_cleanup_cp(dev
);
2082 if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RV770
))
2088 if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RV770
))
2089 r700_cp_load_microcode(dev_priv
);
2091 r600_cp_load_microcode(dev_priv
);
2093 r600_cp_init_ring_buffer(dev
, dev_priv
, file_priv
);
2095 dev_priv
->last_buf
= 0;
2097 r600_do_engine_reset(dev
);
2098 r600_test_writeback(dev_priv
);
2103 int r600_do_resume_cp(struct drm_device
*dev
, struct drm_file
*file_priv
)
2105 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2108 if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_RV770
)) {
2110 r700_cp_load_microcode(dev_priv
);
2113 r600_cp_load_microcode(dev_priv
);
2115 r600_cp_init_ring_buffer(dev
, dev_priv
, file_priv
);
2116 r600_do_engine_reset(dev
);
2121 /* Wait for the CP to go idle.
2123 int r600_do_cp_idle(drm_radeon_private_t
*dev_priv
)
2129 OUT_RING(CP_PACKET3(R600_IT_EVENT_WRITE
, 0));
2130 OUT_RING(R600_CACHE_FLUSH_AND_INV_EVENT
);
2131 /* wait for 3D idle clean */
2132 OUT_RING(CP_PACKET3(R600_IT_SET_CONFIG_REG
, 1));
2133 OUT_RING((R600_WAIT_UNTIL
- R600_SET_CONFIG_REG_OFFSET
) >> 2);
2134 OUT_RING(RADEON_WAIT_3D_IDLE
| RADEON_WAIT_3D_IDLECLEAN
);
2139 return r600_do_wait_for_idle(dev_priv
);
2142 /* Start the Command Processor.
2144 void r600_do_cp_start(drm_radeon_private_t
*dev_priv
)
2151 OUT_RING(CP_PACKET3(R600_IT_ME_INITIALIZE
, 5));
2152 OUT_RING(0x00000001);
2153 if (((dev_priv
->flags
& RADEON_FAMILY_MASK
) < CHIP_RV770
))
2154 OUT_RING(0x00000003);
2156 OUT_RING(0x00000000);
2157 OUT_RING((dev_priv
->r600_max_hw_contexts
- 1));
2158 OUT_RING(R600_ME_INITIALIZE_DEVICE_ID(1));
2159 OUT_RING(0x00000000);
2160 OUT_RING(0x00000000);
2164 /* set the mux and reset the halt bit */
2166 RADEON_WRITE(R600_CP_ME_CNTL
, cp_me
);
2168 dev_priv
->cp_running
= 1;
2172 void r600_do_cp_reset(drm_radeon_private_t
*dev_priv
)
2177 cur_read_ptr
= RADEON_READ(R600_CP_RB_RPTR
);
2178 RADEON_WRITE(R600_CP_RB_WPTR
, cur_read_ptr
);
2179 SET_RING_HEAD(dev_priv
, cur_read_ptr
);
2180 dev_priv
->ring
.tail
= cur_read_ptr
;
2183 void r600_do_cp_stop(drm_radeon_private_t
*dev_priv
)
2189 cp_me
= 0xff | R600_CP_ME_HALT
;
2191 RADEON_WRITE(R600_CP_ME_CNTL
, cp_me
);
2193 dev_priv
->cp_running
= 0;
2196 int r600_cp_dispatch_indirect(struct drm_device
*dev
,
2197 struct drm_buf
*buf
, int start
, int end
)
2199 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2203 unsigned long offset
= (dev_priv
->gart_buffers_offset
2204 + buf
->offset
+ start
);
2205 int dwords
= (end
- start
+ 3) / sizeof(u32
);
2207 DRM_DEBUG("dwords:%d\n", dwords
);
2208 DRM_DEBUG("offset 0x%lx\n", offset
);
2211 /* Indirect buffer data must be a multiple of 16 dwords.
2212 * pad the data with a Type-2 CP packet.
2214 while (dwords
& 0xf) {
2216 ((char *)dev
->agp_buffer_map
->handle
2217 + buf
->offset
+ start
);
2218 data
[dwords
++] = RADEON_CP_PACKET2
;
2221 /* Fire off the indirect buffer */
2223 OUT_RING(CP_PACKET3(R600_IT_INDIRECT_BUFFER
, 2));
2224 OUT_RING((offset
& 0xfffffffc));
2225 OUT_RING((upper_32_bits(offset
) & 0xff));