aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Skeggs <bskeggs@redhat.com>2010-11-02 20:45:48 -0400
committerBen Skeggs <bskeggs@redhat.com>2010-12-03 00:11:36 -0500
commit8cbe71a6e70b5439ae60bd542231c4b8878a8f1c (patch)
tree3539dd410ffaf0040735d96a1b4ae50ae0f1e70d
parent19b7fc7bf59f4bf02ee738a79baaccae31220df3 (diff)
drm/nouveau: move bitfield/enum helpers to nouveau_util.c
Reviewed-by: Francisco Jerez <currojerez@riseup.net> Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_irq.c86
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_util.c33
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_util.h12
3 files changed, 63 insertions, 68 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_irq.c b/drivers/gpu/drm/nouveau/nouveau_irq.c
index 2f546884f2ed..e8a3c400f741 100644
--- a/drivers/gpu/drm/nouveau/nouveau_irq.c
+++ b/drivers/gpu/drm/nouveau/nouveau_irq.c
@@ -267,28 +267,25 @@ nouveau_fifo_irq_handler(struct drm_device *dev)
267 nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PFIFO_PENDING); 267 nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PFIFO_PENDING);
268} 268}
269 269
270struct nouveau_bitfield_names { 270static struct nouveau_bitfield nstatus_names[] =
271 uint32_t mask;
272 const char *name;
273};
274
275static struct nouveau_bitfield_names nstatus_names[] =
276{ 271{
277 { NV04_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" }, 272 { NV04_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" },
278 { NV04_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" }, 273 { NV04_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" },
279 { NV04_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" }, 274 { NV04_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" },
280 { NV04_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" } 275 { NV04_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" },
276 {}
281}; 277};
282 278
283static struct nouveau_bitfield_names nstatus_names_nv10[] = 279static struct nouveau_bitfield nstatus_names_nv10[] =
284{ 280{
285 { NV10_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" }, 281 { NV10_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" },
286 { NV10_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" }, 282 { NV10_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" },
287 { NV10_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" }, 283 { NV10_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" },
288 { NV10_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" } 284 { NV10_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" },
285 {}
289}; 286};
290 287
291static struct nouveau_bitfield_names nsource_names[] = 288static struct nouveau_bitfield nsource_names[] =
292{ 289{
293 { NV03_PGRAPH_NSOURCE_NOTIFICATION, "NOTIFICATION" }, 290 { NV03_PGRAPH_NSOURCE_NOTIFICATION, "NOTIFICATION" },
294 { NV03_PGRAPH_NSOURCE_DATA_ERROR, "DATA_ERROR" }, 291 { NV03_PGRAPH_NSOURCE_DATA_ERROR, "DATA_ERROR" },
@@ -309,57 +306,9 @@ static struct nouveau_bitfield_names nsource_names[] =
309 { NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION, "DMA_VTX_PROTECTION" }, 306 { NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION, "DMA_VTX_PROTECTION" },
310 { NV03_PGRAPH_NSOURCE_DMA_WIDTH_A, "DMA_WIDTH_A" }, 307 { NV03_PGRAPH_NSOURCE_DMA_WIDTH_A, "DMA_WIDTH_A" },
311 { NV03_PGRAPH_NSOURCE_DMA_WIDTH_B, "DMA_WIDTH_B" }, 308 { NV03_PGRAPH_NSOURCE_DMA_WIDTH_B, "DMA_WIDTH_B" },
309 {}
312}; 310};
313 311
314static void
315nouveau_print_bitfield_names_(uint32_t value,
316 const struct nouveau_bitfield_names *namelist,
317 const int namelist_len)
318{
319 /*
320 * Caller must have already printed the KERN_* log level for us.
321 * Also the caller is responsible for adding the newline.
322 */
323 int i;
324 for (i = 0; i < namelist_len; ++i) {
325 uint32_t mask = namelist[i].mask;
326 if (value & mask) {
327 printk(" %s", namelist[i].name);
328 value &= ~mask;
329 }
330 }
331 if (value)
332 printk(" (unknown bits 0x%08x)", value);
333}
334#define nouveau_print_bitfield_names(val, namelist) \
335 nouveau_print_bitfield_names_((val), (namelist), ARRAY_SIZE(namelist))
336
337struct nouveau_enum_names {
338 uint32_t value;
339 const char *name;
340};
341
342static void
343nouveau_print_enum_names_(uint32_t value,
344 const struct nouveau_enum_names *namelist,
345 const int namelist_len)
346{
347 /*
348 * Caller must have already printed the KERN_* log level for us.
349 * Also the caller is responsible for adding the newline.
350 */
351 int i;
352 for (i = 0; i < namelist_len; ++i) {
353 if (value == namelist[i].value) {
354 printk("%s", namelist[i].name);
355 return;
356 }
357 }
358 printk("unknown value 0x%08x", value);
359}
360#define nouveau_print_enum_names(val, namelist) \
361 nouveau_print_enum_names_((val), (namelist), ARRAY_SIZE(namelist))
362
363static int 312static int
364nouveau_graph_chid_from_grctx(struct drm_device *dev) 313nouveau_graph_chid_from_grctx(struct drm_device *dev)
365{ 314{
@@ -482,12 +431,12 @@ nouveau_graph_dump_trap_info(struct drm_device *dev, const char *id,
482 431
483 if (dev_priv->card_type < NV_50) { 432 if (dev_priv->card_type < NV_50) {
484 NV_INFO(dev, "%s - nSource:", id); 433 NV_INFO(dev, "%s - nSource:", id);
485 nouveau_print_bitfield_names(nsource, nsource_names); 434 nouveau_bitfield_print(nsource_names, nsource);
486 printk(", nStatus:"); 435 printk(", nStatus:");
487 if (dev_priv->card_type < NV_10) 436 if (dev_priv->card_type < NV_10)
488 nouveau_print_bitfield_names(nstatus, nstatus_names); 437 nouveau_bitfield_print(nstatus_names, nstatus);
489 else 438 else
490 nouveau_print_bitfield_names(nstatus, nstatus_names_nv10); 439 nouveau_bitfield_print(nstatus_names_nv10, nstatus);
491 printk("\n"); 440 printk("\n");
492 } 441 }
493 442
@@ -631,13 +580,14 @@ nouveau_pgraph_irq_handler(struct drm_device *dev)
631 nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PGRAPH_PENDING); 580 nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PGRAPH_PENDING);
632} 581}
633 582
634static struct nouveau_enum_names nv50_mp_exec_error_names[] = 583static struct nouveau_enum nv50_mp_exec_error_names[] =
635{ 584{
636 { 3, "STACK_UNDERFLOW" }, 585 { 3, "STACK_UNDERFLOW" },
637 { 4, "QUADON_ACTIVE" }, 586 { 4, "QUADON_ACTIVE" },
638 { 8, "TIMEOUT" }, 587 { 8, "TIMEOUT" },
639 { 0x10, "INVALID_OPCODE" }, 588 { 0x10, "INVALID_OPCODE" },
640 { 0x40, "BREAKPOINT" }, 589 { 0x40, "BREAKPOINT" },
590 {}
641}; 591};
642 592
643static void 593static void
@@ -666,8 +616,7 @@ nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
666 ophigh= nv_rd32(dev, addr + 0x74); 616 ophigh= nv_rd32(dev, addr + 0x74);
667 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - " 617 NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
668 "TP %d MP %d: ", tpid, i); 618 "TP %d MP %d: ", tpid, i);
669 nouveau_print_enum_names(status, 619 nouveau_enum_print(nv50_mp_exec_error_names, status);
670 nv50_mp_exec_error_names);
671 printk(" at %06x warp %d, opcode %08x %08x\n", 620 printk(" at %06x warp %d, opcode %08x %08x\n",
672 pc&0xffffff, pc >> 24, 621 pc&0xffffff, pc >> 24,
673 oplow, ophigh); 622 oplow, ophigh);
@@ -1020,7 +969,7 @@ nv50_pgraph_trap_handler(struct drm_device *dev)
1020} 969}
1021 970
1022/* There must be a *lot* of these. Will take some time to gather them up. */ 971/* There must be a *lot* of these. Will take some time to gather them up. */
1023static struct nouveau_enum_names nv50_data_error_names[] = 972static struct nouveau_enum nv50_data_error_names[] =
1024{ 973{
1025 { 4, "INVALID_VALUE" }, 974 { 4, "INVALID_VALUE" },
1026 { 5, "INVALID_ENUM" }, 975 { 5, "INVALID_ENUM" },
@@ -1028,6 +977,7 @@ static struct nouveau_enum_names nv50_data_error_names[] =
1028 { 0xc, "INVALID_BITFIELD" }, 977 { 0xc, "INVALID_BITFIELD" },
1029 { 0x28, "MP_NO_REG_SPACE" }, 978 { 0x28, "MP_NO_REG_SPACE" },
1030 { 0x2b, "MP_BLOCK_SIZE_MISMATCH" }, 979 { 0x2b, "MP_BLOCK_SIZE_MISMATCH" },
980 {}
1031}; 981};
1032 982
1033static void 983static void
@@ -1126,8 +1076,8 @@ nv50_pgraph_irq_handler(struct drm_device *dev)
1126 nouveau_graph_dump_trap_info(dev, 1076 nouveau_graph_dump_trap_info(dev,
1127 "PGRAPH_DATA_ERROR", &trap); 1077 "PGRAPH_DATA_ERROR", &trap);
1128 NV_INFO (dev, "PGRAPH_DATA_ERROR - "); 1078 NV_INFO (dev, "PGRAPH_DATA_ERROR - ");
1129 nouveau_print_enum_names(nv_rd32(dev, 0x400110), 1079 nouveau_enum_print(nv50_data_error_names,
1130 nv50_data_error_names); 1080 nv_rd32(dev, 0x400110));
1131 printk("\n"); 1081 printk("\n");
1132 } 1082 }
1133 status &= ~0x00100000; 1083 status &= ~0x00100000;
diff --git a/drivers/gpu/drm/nouveau/nouveau_util.c b/drivers/gpu/drm/nouveau/nouveau_util.c
index e8b1eaaa212b..fbe0fb13bc1e 100644
--- a/drivers/gpu/drm/nouveau/nouveau_util.c
+++ b/drivers/gpu/drm/nouveau/nouveau_util.c
@@ -27,8 +27,41 @@
27 27
28#include <linux/ratelimit.h> 28#include <linux/ratelimit.h>
29 29
30#include "nouveau_util.h"
31
30static DEFINE_RATELIMIT_STATE(nouveau_ratelimit_state, 3 * HZ, 20); 32static DEFINE_RATELIMIT_STATE(nouveau_ratelimit_state, 3 * HZ, 20);
31 33
34void
35nouveau_bitfield_print(const struct nouveau_bitfield *bf, u32 value)
36{
37 while (bf->name) {
38 if (value & bf->mask) {
39 printk(" %s", bf->name);
40 value &= ~bf->mask;
41 }
42
43 bf++;
44 }
45
46 if (value)
47 printk(" (unknown bits 0x%08x)", value);
48}
49
50void
51nouveau_enum_print(const struct nouveau_enum *en, u32 value)
52{
53 while (en->name) {
54 if (value == en->value) {
55 printk("%s", en->name);
56 return;
57 }
58
59 en++;
60 }
61
62 printk("(unknown enum 0x%08x)", value);
63}
64
32int 65int
33nouveau_ratelimit(void) 66nouveau_ratelimit(void)
34{ 67{
diff --git a/drivers/gpu/drm/nouveau/nouveau_util.h b/drivers/gpu/drm/nouveau/nouveau_util.h
index 9a7a7c18c99a..d9ceaea26f4b 100644
--- a/drivers/gpu/drm/nouveau/nouveau_util.h
+++ b/drivers/gpu/drm/nouveau/nouveau_util.h
@@ -28,6 +28,18 @@
28#ifndef __NOUVEAU_UTIL_H__ 28#ifndef __NOUVEAU_UTIL_H__
29#define __NOUVEAU_UTIL_H__ 29#define __NOUVEAU_UTIL_H__
30 30
31struct nouveau_bitfield {
32 u32 mask;
33 const char *name;
34};
35
36struct nouveau_enum {
37 u32 value;
38 const char *name;
39};
40
41void nouveau_bitfield_print(const struct nouveau_bitfield *, u32 value);
42void nouveau_enum_print(const struct nouveau_enum *, u32 value);
31int nouveau_ratelimit(void); 43int nouveau_ratelimit(void);
32 44
33#endif 45#endif