29 #include <linux/module.h>
35 #define PFP_UCODE_SIZE 576
36 #define PM4_UCODE_SIZE 1792
37 #define R700_PFP_UCODE_SIZE 848
38 #define R700_PM4_UCODE_SIZE 1360
68 # define ATI_PCIGART_PAGE_SIZE 4096
69 # define ATI_PCIGART_PAGE_MASK (~(ATI_PCIGART_PAGE_SIZE-1))
71 #define R600_PTE_VALID (1 << 0)
72 #define R600_PTE_SYSTEM (1 << 1)
73 #define R600_PTE_SNOOPED (1 << 2)
74 #define R600_PTE_READABLE (1 << 5)
75 #define R600_PTE_WRITEABLE (1 << 6)
78 #define R6XX_MAX_SH_GPRS 256
79 #define R6XX_MAX_TEMP_GPRS 16
80 #define R6XX_MAX_SH_THREADS 256
81 #define R6XX_MAX_SH_STACK_ENTRIES 4096
82 #define R6XX_MAX_BACKENDS 8
83 #define R6XX_MAX_BACKENDS_MASK 0xff
84 #define R6XX_MAX_SIMDS 8
85 #define R6XX_MAX_SIMDS_MASK 0xff
86 #define R6XX_MAX_PIPES 8
87 #define R6XX_MAX_PIPES_MASK 0xff
89 #define R7XX_MAX_SH_GPRS 256
90 #define R7XX_MAX_TEMP_GPRS 16
91 #define R7XX_MAX_SH_THREADS 256
92 #define R7XX_MAX_SH_STACK_ENTRIES 4096
93 #define R7XX_MAX_BACKENDS 8
94 #define R7XX_MAX_BACKENDS_MASK 0xff
95 #define R7XX_MAX_SIMDS 16
96 #define R7XX_MAX_SIMDS_MASK 0xffff
97 #define R7XX_MAX_PIPES 8
98 #define R7XX_MAX_PIPES_MASK 0xff
114 if (slots >= entries)
118 DRM_INFO(
"wait for fifo failed status : 0x%08X 0x%08X\n",
132 ret = r600_do_wait_for_fifo(dev_priv, 8);
134 ret = r600_do_wait_for_fifo(dev_priv, 16);
142 DRM_INFO(
"wait idle failed status : 0x%08X 0x%08X\n",
151 struct drm_sg_mem *
entry = dev->sg;
159 if (gart_info->bus_addr) {
160 max_pages = (gart_info->table_size /
sizeof(
u64));
161 pages = (entry->pages <= max_pages)
162 ? entry->pages : max_pages;
165 if (!entry->busaddr[i])
167 pci_unmap_page(dev->pdev, entry->busaddr[i],
170 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN)
171 gart_info->bus_addr = 0;
179 struct drm_ati_pcigart_info *gart_info = &dev_priv->
gart_info;
180 struct drm_local_map *
map = &gart_info->mapping;
181 struct drm_sg_mem *
entry = dev->sg;
187 int max_ati_pages, max_real_pages, gart_idx;
190 max_ati_pages = (gart_info->table_size /
sizeof(
u64));
193 pages = (entry->pages <= max_real_pages) ?
194 entry->pages : max_real_pages;
199 for (i = 0; i <
pages; i++) {
200 entry->busaddr[
i] = pci_map_page(dev->pdev,
201 entry->pagelist[i], 0,
204 if (pci_dma_mapping_error(dev->pdev, entry->busaddr[i])) {
205 DRM_ERROR(
"unable to map PCIGART pages!\n");
209 entry_addr = entry->busaddr[
i];
220 DRM_DEBUG(
"page entry %d: 0x%016llx\n",
221 i, (
unsigned long long)page_base);
242 }
while (((resp & 0xf0) == 0) && countdown);
245 static void r600_vm_init(
struct drm_device *dev)
251 u32 vm_l2_cntl, vm_l2_cntl3;
300 for (i = 1; i < 8; i++)
307 r600_vm_flush_gart_range(dev);
313 const char *chip_name;
314 size_t pfp_req_size, me_req_size;
318 pdev = platform_device_register_simple(
"r600_cp", 0,
NULL, 0);
326 case CHIP_R600: chip_name =
"R600";
break;
349 DRM_INFO(
"Loading %s CP Microcode\n", chip_name);
351 snprintf(fw_name,
sizeof(fw_name),
"radeon/%s_pfp.bin", chip_name);
355 if (dev_priv->
pfp_fw->size != pfp_req_size) {
357 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
358 dev_priv->
pfp_fw->size, fw_name);
363 snprintf(fw_name,
sizeof(fw_name),
"radeon/%s_me.bin", chip_name);
367 if (dev_priv->
me_fw->size != me_req_size) {
369 "r600_cp: Bogus length %zu in firmware \"%s\"\n",
370 dev_priv->
me_fw->size, fw_name);
379 "r600_cp: Failed to load firmware \"%s\"\n",
430 static void r700_vm_init(
struct drm_device *dev)
436 u32 vm_l2_cntl, vm_l2_cntl3;
472 for (i = 1; i < 8; i++)
479 r600_vm_flush_gart_range(dev);
541 if (val == 0xdeadbeef)
546 if (tmp < dev_priv->usec_timeout) {
548 DRM_INFO(
"writeback test succeeded in %d usecs\n", tmp);
551 DRM_INFO(
"writeback test failed\n");
555 DRM_INFO(
"writeback forced off\n");
573 u32 cp_ptr, cp_me_cntl, cp_rb_cntl;
575 DRM_INFO(
"Resetting GPU\n");
613 static u32 r600_get_tile_pipe_to_backend_map(
u32 num_tile_pipes,
615 u32 backend_disable_mask)
618 u32 enabled_backends_mask;
619 u32 enabled_backends_count;
627 if (num_tile_pipes < 1)
631 if (num_backends < 1)
634 enabled_backends_mask = 0;
635 enabled_backends_count = 0;
637 if (((backend_disable_mask >> i) & 1) == 0) {
638 enabled_backends_mask |= (1 <<
i);
639 ++enabled_backends_count;
641 if (enabled_backends_count == num_backends)
645 if (enabled_backends_count == 0) {
646 enabled_backends_mask = 1;
647 enabled_backends_count = 1;
650 if (enabled_backends_count != num_backends)
651 num_backends = enabled_backends_count;
654 switch (num_tile_pipes) {
710 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
711 while (((1 << cur_backend) & enabled_backends_mask) == 0)
712 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
714 backend_map |= (
u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
716 cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
725 for (i = 0; i < 32; i++) {
732 static void r600_gfx_init(
struct drm_device *dev,
735 int i,
j, num_qd_pipes;
739 u32 num_gs_verts_per_thread;
741 u32 gs_prim_buffer_depth = 0;
742 u32 sq_ms_fifo_sizes;
744 u32 sq_gpr_resource_mgmt_1 = 0;
745 u32 sq_gpr_resource_mgmt_2 = 0;
746 u32 sq_thread_resource_mgmt = 0;
747 u32 sq_stack_resource_mgmt_1 = 0;
748 u32 sq_stack_resource_mgmt_2 = 0;
749 u32 hdp_host_path_cntl;
751 u32 gb_tiling_config = 0;
752 u32 cc_rb_backend_disable;
753 u32 cc_gc_shader_pipe_config;
828 for (i = 0; i < 32; i++) {
876 cc_rb_backend_disable |=
880 cc_gc_shader_pipe_config |=
882 cc_gc_shader_pipe_config |=
889 (cc_rb_backend_disable >> 16));
895 if (gb_tiling_config & 0xc0) {
900 dev_priv->
r600_npipes = 1 << ((gb_tiling_config >> 1) & 0x7);
901 if (gb_tiling_config & 0x30) {
1102 gs_prim_buffer_depth = 0;
1108 gs_prim_buffer_depth = 32;
1111 gs_prim_buffer_depth = 128;
1118 vgt_gs_per_es = gs_prim_buffer_depth + num_gs_verts_per_thread;
1120 if (vgt_gs_per_es > 256)
1121 vgt_gs_per_es = 256;
1187 u32 backend_disable_mask)
1189 u32 backend_map = 0;
1190 u32 enabled_backends_mask;
1191 u32 enabled_backends_count;
1196 bool force_no_swizzle;
1200 if (num_tile_pipes < 1)
1204 if (num_backends < 1)
1207 enabled_backends_mask = 0;
1208 enabled_backends_count = 0;
1210 if (((backend_disable_mask >> i) & 1) == 0) {
1211 enabled_backends_mask |= (1 <<
i);
1212 ++enabled_backends_count;
1214 if (enabled_backends_count == num_backends)
1218 if (enabled_backends_count == 0) {
1219 enabled_backends_mask = 1;
1220 enabled_backends_count = 1;
1223 if (enabled_backends_count != num_backends)
1224 num_backends = enabled_backends_count;
1229 force_no_swizzle =
false;
1234 force_no_swizzle =
true;
1239 switch (num_tile_pipes) {
1241 swizzle_pipe[0] = 0;
1244 swizzle_pipe[0] = 0;
1245 swizzle_pipe[1] = 1;
1248 if (force_no_swizzle) {
1249 swizzle_pipe[0] = 0;
1250 swizzle_pipe[1] = 1;
1251 swizzle_pipe[2] = 2;
1253 swizzle_pipe[0] = 0;
1254 swizzle_pipe[1] = 2;
1255 swizzle_pipe[2] = 1;
1259 if (force_no_swizzle) {
1260 swizzle_pipe[0] = 0;
1261 swizzle_pipe[1] = 1;
1262 swizzle_pipe[2] = 2;
1263 swizzle_pipe[3] = 3;
1265 swizzle_pipe[0] = 0;
1266 swizzle_pipe[1] = 2;
1267 swizzle_pipe[2] = 3;
1268 swizzle_pipe[3] = 1;
1272 if (force_no_swizzle) {
1273 swizzle_pipe[0] = 0;
1274 swizzle_pipe[1] = 1;
1275 swizzle_pipe[2] = 2;
1276 swizzle_pipe[3] = 3;
1277 swizzle_pipe[4] = 4;
1279 swizzle_pipe[0] = 0;
1280 swizzle_pipe[1] = 2;
1281 swizzle_pipe[2] = 4;
1282 swizzle_pipe[3] = 1;
1283 swizzle_pipe[4] = 3;
1287 if (force_no_swizzle) {
1288 swizzle_pipe[0] = 0;
1289 swizzle_pipe[1] = 1;
1290 swizzle_pipe[2] = 2;
1291 swizzle_pipe[3] = 3;
1292 swizzle_pipe[4] = 4;
1293 swizzle_pipe[5] = 5;
1295 swizzle_pipe[0] = 0;
1296 swizzle_pipe[1] = 2;
1297 swizzle_pipe[2] = 4;
1298 swizzle_pipe[3] = 5;
1299 swizzle_pipe[4] = 3;
1300 swizzle_pipe[5] = 1;
1304 if (force_no_swizzle) {
1305 swizzle_pipe[0] = 0;
1306 swizzle_pipe[1] = 1;
1307 swizzle_pipe[2] = 2;
1308 swizzle_pipe[3] = 3;
1309 swizzle_pipe[4] = 4;
1310 swizzle_pipe[5] = 5;
1311 swizzle_pipe[6] = 6;
1313 swizzle_pipe[0] = 0;
1314 swizzle_pipe[1] = 2;
1315 swizzle_pipe[2] = 4;
1316 swizzle_pipe[3] = 6;
1317 swizzle_pipe[4] = 3;
1318 swizzle_pipe[5] = 1;
1319 swizzle_pipe[6] = 5;
1323 if (force_no_swizzle) {
1324 swizzle_pipe[0] = 0;
1325 swizzle_pipe[1] = 1;
1326 swizzle_pipe[2] = 2;
1327 swizzle_pipe[3] = 3;
1328 swizzle_pipe[4] = 4;
1329 swizzle_pipe[5] = 5;
1330 swizzle_pipe[6] = 6;
1331 swizzle_pipe[7] = 7;
1333 swizzle_pipe[0] = 0;
1334 swizzle_pipe[1] = 2;
1335 swizzle_pipe[2] = 4;
1336 swizzle_pipe[3] = 6;
1337 swizzle_pipe[4] = 3;
1338 swizzle_pipe[5] = 1;
1339 swizzle_pipe[6] = 7;
1340 swizzle_pipe[7] = 5;
1346 for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
1347 while (((1 << cur_backend) & enabled_backends_mask) == 0)
1348 cur_backend = (cur_backend + 1) % R7XX_MAX_BACKENDS;
1350 backend_map |= (
u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
1352 cur_backend = (cur_backend + 1) % R7XX_MAX_BACKENDS;
1358 static void r700_gfx_init(
struct drm_device *dev,
1361 int i,
j, num_qd_pipes;
1366 u32 num_gs_verts_per_thread;
1368 u32 gs_prim_buffer_depth = 0;
1369 u32 sq_ms_fifo_sizes;
1371 u32 sq_thread_resource_mgmt;
1372 u32 hdp_host_path_cntl;
1373 u32 sq_dyn_gpr_size_simd_ab_0;
1375 u32 gb_tiling_config = 0;
1376 u32 cc_rb_backend_disable;
1377 u32 cc_gc_shader_pipe_config;
1478 for (i = 0; i < 32; i++) {
1529 cc_rb_backend_disable |=
1533 cc_gc_shader_pipe_config |=
1535 cc_gc_shader_pipe_config |=
1541 backend_map = r700_get_tile_pipe_to_backend_map(dev_priv,
1543 (R7XX_MAX_BACKENDS -
1546 (cc_rb_backend_disable >> 16));
1552 if (gb_tiling_config & 0xc0) {
1557 dev_priv->
r600_npipes = 1 << ((gb_tiling_config >> 1) & 0x7);
1558 if (gb_tiling_config & 0x30) {
1729 gs_prim_buffer_depth = 384;
1732 gs_prim_buffer_depth = 128;
1739 vgt_gs_per_es = gs_prim_buffer_depth + num_gs_verts_per_thread;
1741 if (vgt_gs_per_es > 256)
1742 vgt_gs_per_es = 256;
1784 static void r600_cp_init_ring_buffer(
struct drm_device *dev,
1786 struct drm_file *file_priv)
1793 r700_gfx_init(dev, dev_priv);
1795 r600_gfx_init(dev, dev_priv);
1852 - ((
unsigned long) dev->sg->virtual)
1880 ring_start = (dev_priv->
cp_ring->offset
1885 ring_start = (dev_priv->
cp_ring->offset
1886 - (
unsigned long)dev->sg->virtual
1909 scratch_addr &= 0xffffffff;
1929 master_priv = file_priv->master->driver_priv;
1936 r600_do_wait_for_idle(dev_priv);
1949 if (dev->irq_enabled)
1962 if (dev->agp_buffer_map !=
NULL) {
1964 dev->agp_buffer_map =
NULL;
1973 if (dev_priv->
gart_info.gart_table_location == DRM_ATI_GART_FB) {
1985 struct drm_file *file_priv)
1996 DRM_ERROR(
"Cannot initialise DRM on this card\nThis card requires a new X.org DDX for 3D\n");
2002 DRM_DEBUG(
"Forcing AGP card to PCI mode\n");
2010 DRM_DEBUG(
"Restoring AGP flag\n");
2017 DRM_DEBUG(
"TIMEOUT problem!\n");
2034 DRM_DEBUG(
"BAD cp_mode (%x)!\n", init->
cp_mode);
2059 if (!master_priv->
sarea) {
2060 DRM_ERROR(
"could not find sarea!\n");
2067 DRM_ERROR(
"could not find cp ring region!\n");
2073 DRM_ERROR(
"could not find ring read pointer!\n");
2078 dev->agp_buffer_map = drm_core_findmap(dev, init->
buffers_offset);
2079 if (!dev->agp_buffer_map) {
2080 DRM_ERROR(
"could not find dma buffer region!\n");
2089 DRM_ERROR(
"could not find GART texture region!\n");
2101 if (!dev_priv->
cp_ring->handle ||
2103 !dev->agp_buffer_map->handle) {
2104 DRM_ERROR(
"could not find ioremap agp regions!\n");
2111 dev_priv->
cp_ring->handle = (
void *)(
unsigned long)dev_priv->
cp_ring->offset;
2113 (
void *)(
unsigned long)dev_priv->
ring_rptr->offset;
2114 dev->agp_buffer_map->handle =
2115 (
void *)(
unsigned long)dev->agp_buffer_map->offset;
2117 DRM_DEBUG(
"dev_priv->cp_ring->handle %p\n",
2119 DRM_DEBUG(
"dev_priv->ring_rptr->handle %p\n",
2121 DRM_DEBUG(
"dev->agp_buffer_map->handle %p\n",
2122 dev->agp_buffer_map->handle);
2148 DRM_INFO(
"Setting GART location based on new memory map\n");
2157 base = dev->agp->base;
2161 DRM_INFO(
"Can't use AGP base @0x%08lx, won't fit\n",
2170 if (base < dev_priv->fb_location ||
2171 ((base + dev_priv->
gart_size) & 0xfffffffful) < base)
2177 DRM_INFO(
"GART aligned down from 0x%08x to 0x%08x\n",
2190 - (
unsigned long)dev->sg->virtual
2193 DRM_DEBUG(
"fb 0x%08x size %d\n",
2195 (
unsigned int) dev_priv->
fb_size);
2196 DRM_DEBUG(
"dev_priv->gart_size %d\n", dev_priv->
gart_size);
2197 DRM_DEBUG(
"dev_priv->gart_vm_start 0x%08x\n",
2199 DRM_DEBUG(
"dev_priv->gart_buffers_offset 0x%08lx\n",
2227 DRM_ERROR(
"Need gart offset from userspace\n");
2232 DRM_DEBUG(
"Using gart offset 0x%08lx\n", dev_priv->
pcigart_offset);
2242 if (!dev_priv->
gart_info.mapping.handle) {
2243 DRM_ERROR(
"ioremap failed.\n");
2251 DRM_DEBUG(
"Setting phys_pci_gart to %p %08lX\n",
2256 DRM_ERROR(
"Failed to init GART table\n");
2268 int err = r600_cp_init_microcode(dev_priv);
2270 DRM_ERROR(
"Failed to load firmware!\n");
2276 r700_cp_load_microcode(dev_priv);
2278 r600_cp_load_microcode(dev_priv);
2280 r600_cp_init_ring_buffer(dev, dev_priv, file_priv);
2285 r600_test_writeback(dev_priv);
2297 r700_cp_load_microcode(dev_priv);
2300 r600_cp_load_microcode(dev_priv);
2302 r600_cp_init_ring_buffer(dev, dev_priv, file_priv);
2326 return r600_do_wait_for_idle(dev_priv);
2367 dev_priv->
ring.
tail = cur_read_ptr;
2391 + buf->offset +
start);
2392 int dwords = (end - start + 3) /
sizeof(
u32);
2394 DRM_DEBUG(
"dwords:%d\n", dwords);
2395 DRM_DEBUG(
"offset 0x%lx\n", offset);
2401 while (dwords & 0xf) {
2403 ((
char *)dev->agp_buffer_map->handle
2404 + buf->offset +
start);
2423 struct drm_master *master = file_priv->master;
2426 int nbox = sarea_priv->
nbox;
2428 int i,
cpp, src_pitch, dst_pitch;
2451 DRM_ERROR(
"unable to allocate vertex buffer for swap buffer\n");
2454 for (i = 0; i < nbox; i++) {
2457 int w = pbox[
i].
x2 -
x;
2458 int h = pbox[
i].
y2 -
y;
2460 DRM_DEBUG(
"%d,%d-%d,%d\n", x, y, w, h);
2465 src_pitch, dst_pitch, cpp);
2481 struct drm_file *file_priv,
2486 struct drm_buf *
buf;
2489 int size, pass_size;
2490 u64 src_offset, dst_offset;
2492 if (!radeon_check_offset(dev_priv, tex->
offset)) {
2493 DRM_ERROR(
"Invalid destination offset\n");
2498 if (!radeon_check_offset(dev_priv, tex->
offset + tex->
height * tex->
pitch - 1)) {
2499 DRM_ERROR(
"Invalid final destination offset\n");
2508 dst_offset = tex->
offset;
2511 DRM_ERROR(
"unable to allocate vertex buffer for swap buffer\n");
2520 DRM_DEBUG(
"EAGAIN\n");
2526 if (pass_size > buf->total)
2527 pass_size = buf->total;
2532 (
u32 *) ((
char *)dev->agp_buffer_map->handle + buf->offset);
2535 DRM_ERROR(
"EFAULT on pad, %d bytes\n", pass_size);
2539 buf->file_priv = file_priv;
2540 buf->used = pass_size;
2549 dst_offset += pass_size;
2577 *
id = radeon_cs_id_get(dev_priv);
2586 static int r600_ib_get(
struct drm_device *dev,
2587 struct drm_file *fpriv,
2590 struct drm_buf *
buf;
2597 buf->file_priv = fpriv;
2602 static void r600_ib_free(
struct drm_device *dev,
struct drm_buf *buf,
2603 struct drm_file *fpriv,
int l,
int r)
2619 struct drm_buf *
buf;
2624 if (dev_priv ==
NULL) {
2625 DRM_ERROR(
"called with no initialization\n");
2630 DRM_ERROR(
"cs ioctl valid only for R6XX & R7XX in legacy mode\n");
2635 r = r600_ib_get(dev, fpriv, &buf);
2637 DRM_ERROR(
"ib_get failed\n");
2640 ib = dev->agp_buffer_map->handle + buf->offset;
2648 r600_ib_free(dev, buf, fpriv, l, r);
2650 r600_cs_id_emit(dev_priv, &cs_id);