diff options
author | Ben Skeggs <bskeggs@redhat.com> | 2015-08-20 14:54:15 +1000 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2015-08-28 12:37:36 +1000 |
commit | 558d9ac4b06b61f087c2411117096372124c2575 (patch) | |
tree | 2c74dce96d944ec2977096a9900653a6b71cc7dc /bin/util.h | |
parent | b9b0ad3ef8a6c5354c88a2571da6f5a7e790fdbb (diff) | |
download | nouveau-558d9ac4b06b61f087c2411117096372124c2575.tar.gz |
bin: punt client/device argument handling into a common helper
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'bin/util.h')
-rw-r--r-- | bin/util.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/bin/util.h b/bin/util.h new file mode 100644 index 000000000..2b07e5e79 --- /dev/null +++ b/bin/util.h @@ -0,0 +1,62 @@ +#ifndef __UTIL_H__ +#define __UTIL_H__ +#include <nvif/client.h> +#include <nvif/device.h> + +#include <unistd.h> + +#define U_GETOPT "a:b:c:d:" + +static const char *u_drv; +static const char *u_cfg; +static const char *u_dbg; +static u64 u_dev = ~0ULL; + +static inline bool +u_option(int c) +{ + switch (c) { + case 'a': u_dev = strtol(optarg, NULL, 0); break; + case 'b': u_drv = optarg; break; + case 'c': u_cfg = optarg; break; + case 'd': u_dbg = optarg; break; + default: + return false; + } + return true; +} + +static inline int +u_client(const char *drv, const char *name, const char *dbg, + bool detect, bool mmio, u64 subdev, + struct nvif_client **pclient) +{ + return nvif_client_new(u_drv ? u_drv : drv, name, u_dev, u_cfg, + u_dbg ? u_dbg : dbg, pclient); +} + +static inline int +u_device(const char *drv, const char *name, const char *dbg, + bool detect, bool mmio, u64 subdev, u32 handle, + struct nvif_device **pdevice) +{ + struct nvif_client *client; + int ret = u_client(drv, name, dbg, detect, mmio, subdev, &client); + if (ret == 0) { + ret = nvif_device_new(client->object, handle, NV_DEVICE, + &(struct nv_device_v0) { + .device = ~0ULL, + .disable = ~( + (detect ? NV_DEVICE_V0_DISABLE_IDENTIFY : 0) | + ( mmio ? NV_DEVICE_V0_DISABLE_MMIO : 0) | + ((subdev & (1ULL << NVDEV_SUBDEV_VBIOS)) ? + NV_DEVICE_V0_DISABLE_VBIOS : 0) | + (subdev ? NV_DEVICE_V0_DISABLE_CORE : 0)), + .debug0 = ~subdev, + }, sizeof(struct nv_device_v0), + pdevice); + nvif_client_ref(NULL, &client); + } + return ret; +} +#endif |