drm/nouveau/core: type-safe printk macros
authorBen Skeggs <bskeggs@redhat.com>
Thu, 20 Aug 2015 04:54:11 +0000 (14:54 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 28 Aug 2015 02:40:21 +0000 (12:40 +1000)
These require an explicit pointers to nvkm_object/nvkm_subdev/nvkm_device,
depending on which macros are used.  This is unlike the previous macros
which take a void *, and work for anything derived from nvkm_object (by
way of some awful heuristics).

The output will be a bit confused until everything has been transitioned,
as the logging format used is a more standard style that previously.

In addition, usage of pr_cont(), which doesn't work correctly with the
dev_*() printk functions (and was potentially racy to begin with), will
be replaced.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
drivers/gpu/drm/nouveau/include/nvkm/core/client.h
drivers/gpu/drm/nouveau/include/nvkm/core/device.h
drivers/gpu/drm/nouveau/include/nvkm/core/enum.h
drivers/gpu/drm/nouveau/include/nvkm/core/subdev.h
drivers/gpu/drm/nouveau/nvkm/core/enum.c
drivers/gpu/drm/nouveau/nvkm/core/subdev.c

index a35b3824450222bab4dbac3cbcd8095b575bf8c5..bcd2a35836516aeb74b49471130b93ec87d1e139 100644 (file)
@@ -52,4 +52,16 @@ int nvkm_client_notify_new(struct nvkm_object *, struct nvkm_event *,
 int nvkm_client_notify_del(struct nvkm_client *, int index);
 int nvkm_client_notify_get(struct nvkm_client *, int index);
 int nvkm_client_notify_put(struct nvkm_client *, int index);
+
+/* logging for client-facing objects */
+#define nvif_printk(o,l,p,f,a...) do {                                         \
+       struct nvkm_object *_object = (o);                                     \
+       struct nvkm_client *_client = nvkm_client(_object);                    \
+       if (_client->debug >= NV_DBG_##l)                                      \
+               printk(KERN_##p "nouveau: %s: "f, _client->name, ##a);         \
+} while(0)
+#define nvif_error(o,f,a...) nvif_printk((o), ERROR,  ERR, f, ##a)
+#define nvif_debug(o,f,a...) nvif_printk((o), DEBUG, INFO, f, ##a)
+#define nvif_trace(o,f,a...) nvif_printk((o), TRACE, INFO, f, ##a)
+#define nvif_ioctl(o,f,a...) nvif_trace((o), "ioctl: "f, ##a)
 #endif
index 14f7d197e479cdb152c185600cd7e255435ffa7e..ffff6fd5a3482401ee098308af096ee2990a4090 100644 (file)
@@ -214,4 +214,19 @@ enum nv_bus_type {
 int  nvkm_device_create_(void *, enum nv_bus_type type, u64 name,
                            const char *sname, const char *cfg, const char *dbg,
                            int, void **);
+
+/* device logging */
+#define nvdev_printk_(d,l,p,f,a...) do {                                       \
+       struct nvkm_device *_device = (d);                                     \
+       if (_device->engine.subdev.debug >= (l))                               \
+               dev_##p(_device->dev, f, ##a);                                 \
+} while(0)
+#define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a)
+#define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL,   crit, f, ##a)
+#define nvdev_error(d,f,a...) nvdev_printk((d), ERROR,    err, f, ##a)
+#define nvdev_warn(d,f,a...)  nvdev_printk((d),  WARN, notice, f, ##a)
+#define nvdev_info(d,f,a...)  nvdev_printk((d),  INFO,   info, f, ##a)
+#define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG,   info, f, ##a)
+#define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE,   info, f, ##a)
+#define nvdev_spam(d,f,a...)  nvdev_printk((d),  SPAM,    dbg, f, ##a)
 #endif
index e76f76f115e9e6a5e50fbe8442fd8c4f061fada5..573b1eef4b3961cf537a210afbe10747f9ae3353 100644 (file)
@@ -18,4 +18,5 @@ struct nvkm_bitfield {
 };
 
 void nvkm_bitfield_print(const struct nvkm_bitfield *, u32 value);
+void nvkm_snprintbf(char *, int, const struct nvkm_bitfield *, u32 value);
 #endif
index ad516cf24f6cd7061b056f9c9255beefefde1d0d..e146f2758b079160425f0895d5cfb48b0412694a 100644 (file)
@@ -11,7 +11,7 @@ struct nvkm_subdev {
        struct nvkm_device *device;
 
        struct mutex mutex;
-       const char *name;
+       const char *name, *sname;
        u32 debug;
        u32 unit;
 
@@ -53,11 +53,20 @@ void _nvkm_subdev_dtor(struct nvkm_object *);
 int  _nvkm_subdev_init(struct nvkm_object *);
 int  _nvkm_subdev_fini(struct nvkm_object *, bool suspend);
 
-#define s_printk(s,l,f,a...) do {                                              \
-       if ((s)->debug >= OS_DBG_##l) {                                        \
-               nv_printk((s)->base.parent, (s)->name, l, f, ##a);             \
-       }                                                                      \
+/* subdev logging */
+#define nvkm_printk_(s,l,p,f,a...) do {                                        \
+       struct nvkm_subdev *_subdev = (s);                                     \
+       if (_subdev->debug >= (l))                                             \
+               dev_##p(_subdev->device->dev, "%s: "f, _subdev->sname, ##a);   \
 } while(0)
+#define nvkm_printk(s,l,p,f,a...) nvkm_printk_((s), NV_DBG_##l, p, f, ##a)
+#define nvkm_fatal(s,f,a...) nvkm_printk((s), FATAL,   crit, f, ##a)
+#define nvkm_error(s,f,a...) nvkm_printk((s), ERROR,    err, f, ##a)
+#define nvkm_warn(s,f,a...)  nvkm_printk((s),  WARN, notice, f, ##a)
+#define nvkm_info(s,f,a...)  nvkm_printk((s),  INFO,   info, f, ##a)
+#define nvkm_debug(s,f,a...) nvkm_printk((s), DEBUG,   info, f, ##a)
+#define nvkm_trace(s,f,a...) nvkm_printk((s), TRACE,   info, f, ##a)
+#define nvkm_spam(s,f,a...)  nvkm_printk((s),  SPAM,    dbg, f, ##a)
 
 #include <core/engine.h>
 #endif
index 4f92bfc13d6bded2dea79dd700da516fdd6edacd..2cfaec4061940b609f5340f1fab96d39d722842c 100644 (file)
@@ -64,3 +64,20 @@ nvkm_bitfield_print(const struct nvkm_bitfield *bf, u32 value)
        if (value)
                pr_cont(" (unknown bits 0x%08x)", value);
 }
+
+void
+nvkm_snprintbf(char *data, int size, const struct nvkm_bitfield *bf, u32 value)
+{
+       bool space = false;
+       while (size >= 1 && bf->name) {
+               if (value & bf->mask) {
+                       int this = snprintf(data, size, "%s%s",
+                                           space ? " " : "", bf->name);
+                       size -= this;
+                       data += this;
+                       space = true;
+               }
+               bf++;
+       }
+       data[0] = '\0';
+}
index dd2cf44bd6a119e1e834a67529bf660dc2a1e35c..476add5a4aea27cd5fe8c08280e13f4e1a3ccc32 100644 (file)
@@ -111,6 +111,7 @@ nvkm_subdev_create_(struct nvkm_object *parent, struct nvkm_object *engine,
 
        __mutex_init(&subdev->mutex, subname, &oclass->lock_class_key);
        subdev->name = subname;
+       subdev->sname = sysname;
 
        if (parent) {
                struct nvkm_device *device = nv_device(parent);