diff options
-rw-r--r-- | bin/nv_aux.c | 36 | ||||
-rw-r--r-- | bin/nv_disp.c | 2 | ||||
-rw-r--r-- | bin/nv_i2c.c | 38 | ||||
-rw-r--r-- | bin/nv_init.c | 33 | ||||
-rw-r--r-- | bin/nv_perfmon.c | 38 | ||||
-rw-r--r-- | bin/nv_rdfuc.c | 72 | ||||
-rw-r--r-- | bin/nv_rdfunc.h | 38 | ||||
-rw-r--r-- | bin/nv_rffunc.h | 2 | ||||
-rw-r--r-- | bin/nv_rifunc.h | 2 | ||||
-rw-r--r-- | bin/nv_rsfunc.h | 2 | ||||
-rw-r--r-- | bin/nv_rvfunc.h | 2 | ||||
-rw-r--r-- | bin/nv_wffunc.h | 2 | ||||
-rw-r--r-- | bin/nv_wifunc.h | 2 | ||||
-rw-r--r-- | bin/nv_wrfunc.h | 38 | ||||
-rw-r--r-- | bin/nv_wsfunc.h | 2 | ||||
-rw-r--r-- | bin/nv_wvfunc.h | 2 | ||||
-rw-r--r-- | bin/util.h | 62 |
17 files changed, 136 insertions, 237 deletions
diff --git a/bin/nv_aux.c b/bin/nv_aux.c index 743160c3e..68b72cb2e 100644 --- a/bin/nv_aux.c +++ b/bin/nv_aux.c @@ -6,6 +6,8 @@ #include <nvif/device.h> #include <nvif/class.h> +#include "util.h" + static void print_aux(struct nvkm_i2c_aux *aux) { @@ -15,11 +17,6 @@ print_aux(struct nvkm_i2c_aux *aux) int main(int argc, char **argv) { - const char *drv = "lib"; - const char *cfg = NULL; - const char *dbg = "error"; - u64 dev = ~0ULL; - struct nvif_client *client; struct nvif_device *device; struct nvkm_i2c_aux *aux; struct nvkm_i2c *i2c; @@ -28,12 +25,8 @@ main(int argc, char **argv) int ret, c; u8 data; - while ((c = getopt(argc, argv, "-a:b:c:d:")) != -1) { + while ((c = getopt(argc, argv, "-"U_GETOPT)) != -1) { switch (c) { - case 'a': dev = strtoull(optarg, NULL, 0); break; - case 'b': drv = optarg; break; - case 'c': cfg = optarg; break; - case 'd': dbg = optarg; break; case 1: if (action < 0) { if (!strcasecmp(optarg, "rd")) @@ -60,24 +53,17 @@ main(int argc, char **argv) } else return -EINVAL; break; + default: + if (!u_option(c)) + return 1; + break; } } - ret = nvif_client_new(drv, argv[0], dev, cfg, dbg, &client); - if (ret) - return ret; - - ret = nvif_device_new(nvif_object(client), 0x00000000, NV_DEVICE, - &(struct nv_device_v0) { - .device = ~0ULL, - .disable = ~(NV_DEVICE_V0_DISABLE_MMIO | - NV_DEVICE_V0_DISABLE_IDENTIFY| - NV_DEVICE_V0_DISABLE_VBIOS | - NV_DEVICE_V0_DISABLE_CORE), - .debug0 = ~((1 << NVDEV_SUBDEV_VBIOS) | - (1 << NVDEV_SUBDEV_I2C)), - }, sizeof(struct nv_device_v0), &device); - nvif_client_ref(NULL, &client); + ret = u_device("lib", argv[0], "error", true, true, + (1ULL << NVDEV_SUBDEV_VBIOS) | + (1ULL << NVDEV_SUBDEV_I2C), + 0x00000000, &device); if (ret) return ret; diff --git a/bin/nv_disp.c b/bin/nv_disp.c index 9141bed64..a092e14d7 100644 --- a/bin/nv_disp.c +++ b/bin/nv_disp.c @@ -34,7 +34,7 @@ nv_disp(struct nvif_device *device, u16 mthd, u32 data) #define CAST u32 #define WRITE(o,v) nv_disp(device, (o), (v)) #define MAIN main_ -#define ENABLE (NV_DEVICE_V0_DISABLE_MMIO | NV_DEVICE_V0_DISABLE_IDENTIFY) +#define DETECT true #include "nv_wrfunc.h" int diff --git a/bin/nv_i2c.c b/bin/nv_i2c.c index ec0ce4a6d..fd9497b7e 100644 --- a/bin/nv_i2c.c +++ b/bin/nv_i2c.c @@ -6,6 +6,8 @@ #include <nvif/device.h> #include <nvif/class.h> +#include "util.h" + static void show_adapter(struct i2c_adapter *adap, int adapter) { @@ -38,23 +40,14 @@ find_adapter(struct nvif_device *device, int adapter) int main(int argc, char **argv) { - const char *drv = "lib"; - const char *cfg = NULL; - const char *dbg = "error"; - u64 dev = ~0ULL; - struct nvif_client *client; struct nvif_device *device; struct i2c_adapter *adap; int addr = -1, reg = -1, val = -1; int action = -1, index = -1; int ret, c; - while ((c = getopt(argc, argv, "-a:b:c:d:")) != -1) { + while ((c = getopt(argc, argv, "-"U_GETOPT)) != -1) { switch (c) { - case 'a': dev = strtoull(optarg, NULL, 0); break; - case 'b': drv = optarg; break; - case 'c': cfg = optarg; break; - case 'd': dbg = optarg; break; case 1: if (action < 0) { if (!strcasecmp(optarg, "scan")) @@ -88,26 +81,17 @@ main(int argc, char **argv) } else return -EINVAL; break; + default: + if (!u_option(c)) + return 1; + break; } } - ret = nvif_client_new(drv, argv[0], dev, cfg, dbg, &client); - if (ret) - return ret; - - ret = nvif_device_new(nvif_object(client), 0, NV_DEVICE, - &(struct nv_device_v0) { - .device = ~0ULL, - .disable = ~(NV_DEVICE_V0_DISABLE_MMIO | - NV_DEVICE_V0_DISABLE_IDENTIFY| - NV_DEVICE_V0_DISABLE_VBIOS | - NV_DEVICE_V0_DISABLE_CORE), - .debug0 = ~((1 << NVDEV_SUBDEV_VBIOS) | - (1 << NVDEV_SUBDEV_I2C)), - }, sizeof(struct nv_device_v0), &device); - nvif_client_ref(NULL, &client); - if (ret) - return ret; + ret = u_device("lib", argv[0], "error", true, true, + (1ULL << NVDEV_SUBDEV_VBIOS) | + (1ULL << NVDEV_SUBDEV_I2C), + 0x00000000, &device); if (action < 0) { for (index = 0; (adap = find_adapter(device, index)); index++) { diff --git a/bin/nv_init.c b/bin/nv_init.c index 31baedbb7..a249da871 100644 --- a/bin/nv_init.c +++ b/bin/nv_init.c @@ -7,49 +7,37 @@ #include <nvif/device.h> #include <nvif/class.h> +#include "util.h" + int main(int argc, char **argv) { - const char *drv = NULL; - const char *cfg = NULL; - const char *dbg = "info"; - u64 dev = ~0ULL; - struct nvif_client *client; struct nvif_device *device; bool suspend = false, wait = false; int ret, c; - while ((c = getopt(argc, argv, "-a:b:c:d:sw")) != -1) { + while ((c = getopt(argc, argv, "sw"U_GETOPT)) != -1) { switch (c) { - case 'a': dev = strtoull(optarg, NULL, 0); break; - case 'b': drv = optarg; break; - case 'c': cfg = optarg; break; - case 'd': dbg = optarg; break; case 's': suspend = true; break; case 'w': wait = true; break; - case 1: - return -EINVAL; + default: + if (!u_option(c)) + return 1; + break; } } - ret = nvif_client_new(drv, argv[0], dev, cfg, dbg, &client); - if (ret) - return ret; - - ret = nvif_device_new(nvif_object(client), 0, NV_DEVICE, - &(struct nv_device_v0) { - .device = ~0ULL, - .disable = 0ULL, - .debug0 = 0ULL, - }, sizeof(struct nv_device_v0), &device); + ret = u_device(NULL, argv[0], "info", true, true, ~0ULL, + 0x00000000, &device); if (ret) return ret; if (suspend) { + struct nvif_client *client = nvif_client(&device->base); nvif_client_suspend(client); nvif_client_resume(client); } @@ -60,7 +48,6 @@ main(int argc, char **argv) printf("shutting down...\n"); nvif_device_ref(NULL, &device); - nvif_client_ref(NULL, &client); printf("done!\n"); return ret; } diff --git a/bin/nv_perfmon.c b/bin/nv_perfmon.c index c04fd5e57..20aa1b8ac 100644 --- a/bin/nv_perfmon.c +++ b/bin/nv_perfmon.c @@ -35,6 +35,8 @@ #include <sys/time.h> +#include "util.h" + static struct nvif_device *device; static struct nvif_object perfmon; static int nr_signals; /* number of signals for all domains */ @@ -812,43 +814,25 @@ ui_resize(void) int main(int argc, char **argv) { - const char *drv = NULL; - const char *cfg = NULL; - const char *dbg = "error"; - u64 dev = ~0ULL; - struct nvif_client *client; int ret, c, k; int scan = 0; - while ((c = getopt(argc, argv, "-a:b:c:d:s")) != -1) { + while ((c = getopt(argc, argv, "s"U_GETOPT)) != -1) { switch (c) { - case 'a': dev = strtoull(optarg, NULL, 0); break; - case 'b': drv = optarg; break; - case 'c': cfg = optarg; break; - case 'd': dbg = optarg; break; case 's': scan = 1; break; - case 1: - return -EINVAL; + default: + if (!u_option(c)) + return 1; + break; } } - ret = nvif_client_new(drv, argv[0], dev, cfg, dbg, &client); - if (ret) - return ret; - - ret = nvif_device_new(nvif_object(client), 0x00000000, - NV_DEVICE, &(struct nv_device_v0) { - .device = ~0ULL, - .disable = ~(NV_DEVICE_V0_DISABLE_MMIO | - NV_DEVICE_V0_DISABLE_VBIOS | - NV_DEVICE_V0_DISABLE_CORE | - NV_DEVICE_V0_DISABLE_IDENTIFY), - .debug0 = ~((1ULL << NVDEV_SUBDEV_TIMER) | - (1ULL << NVDEV_ENGINE_PM)), - }, sizeof(struct nv_device_v0), &device); - nvif_client_ref(NULL, &client); + ret = u_device(NULL, argv[0], "error", true, true, + (1ULL << NVDEV_SUBDEV_TIMER) | + (1ULL << NVDEV_ENGINE_PM), + 0x00000000, &device); if (ret) return ret; diff --git a/bin/nv_rdfuc.c b/bin/nv_rdfuc.c deleted file mode 100644 index 3a422a847..000000000 --- a/bin/nv_rdfuc.c +++ /dev/null @@ -1,72 +0,0 @@ -#include <stdlib.h> -#include <limits.h> -#include <unistd.h> - -#include <nvif/client.h> -#include <nvif/device.h> -#include <nvif/class.h> - -int -main(int argc, char **argv) -{ - const char *drv = "lib"; - const char *cfg = NULL; - const char *dbg = "error"; - u64 dev = ~0ULL; - struct nvif_client *client; - struct nvif_device *device; - u32 fucbase = ~0; - int segment = -1; - int ret, c, i; - - while ((c = getopt(argc, argv, "-a:b:cd")) != -1) { - switch (c) { - case 'a': dev = strtoull(optarg, NULL, 0); break; - case 'b': drv = optarg; break; - case 'c': - segment = 0; - break; - case 'd': - segment = 1; - break; - case 1: - fucbase = strtol(optarg, NULL, 0); - break; - } - } - - if (fucbase == ~0 || segment < 0 || segment > 1) - return 1; - - ret = nvif_client_new(drv, argv[0], dev, cfg, dbg, &client); - if (ret) - return ret; - - ret = nvif_device_new(nvif_object(client), 0x00000000, NV_DEVICE, - &(struct nv_device_v0) { - .device = ~0ULL, - .disable = ~NV_DEVICE_V0_DISABLE_MMIO, - .debug0 = 0, - }, sizeof(struct nv_device_v0), &device); - nvif_client_ref(NULL, &client); - if (ret) - return ret; - - if (segment == 0) { - u32 size = (nvif_rd32(device, fucbase + 0x0108) & 0x1ff) << 8; - nvif_wr32(device, fucbase + 0x0180, 0x02000000); - for (i = 0; i < size; i += 4) { - if (!(i & 0xff)) - nvif_wr32(device, fucbase + 0x0188, i >> 8); - printf("0x%08x\n", nvif_rd32(device, fucbase + 0x0184)); - } - } else { - u32 size = (nvif_rd32(device, fucbase + 0x0108) & 0x3fe00) >> 1; - nvif_wr32(device, fucbase + 0x01c0, 0x02000000); - for (i = 0; i < size; i += 4) - printf("0x%08x\n", nvif_rd32(device, fucbase + 0x01c4)); - } - - nvif_device_ref(NULL, &device); - return 0; -} diff --git a/bin/nv_rdfunc.h b/bin/nv_rdfunc.h index 4668bf497..c9c2aea22 100644 --- a/bin/nv_rdfunc.h +++ b/bin/nv_rdfunc.h @@ -6,23 +6,16 @@ #include <nvif/device.h> #include <nvif/class.h> -#ifndef ENABLE -#define ENABLE NV_DEVICE_V0_DISABLE_MMIO -#endif -#ifndef DEBUG0 -#define DEBUG0 0ULL +#ifndef DETECT +#define DETECT false #endif +#include "util.h" + int main(int argc, char **argv) { - const char *drv = "lib"; - const char *cfg = NULL; - const char *dbg = "fatal"; - u64 dev = ~0ULL; - struct nvif_client *client; struct nvif_device *device; - struct nv_device_v0 args = {}; char *rstr = NULL; enum { NORMAL, @@ -38,12 +31,8 @@ main(int argc, char **argv) int ndata = 0; int ret, c; - while ((c = getopt(argc, argv, "-a:b:c:d:qrw")) != -1) { + while ((c = getopt(argc, argv, "-qrw"U_GETOPT)) != -1) { switch (c) { - case 'a': dev = strtoull(optarg, NULL, 0); break; - case 'b': drv = optarg; break; - case 'c': cfg = optarg; break; - case 'd': dbg = optarg; break; case 'q': mode = QUIET; break; case 'r': mode = RATES; break; case 'w': mode = WATCH; break; @@ -52,20 +41,15 @@ main(int argc, char **argv) return 1; rstr = optarg; break; + default: + if (!u_option(c)) + return 1; + break; } } - ret = nvif_client_new(drv, argv[0], dev, cfg, dbg, &client); - if (ret) - return ret; - - args.device = ~0ULL; - args.disable = ~ENABLE; - args.debug0 = ~DEBUG0; - - ret = nvif_device_new(nvif_object(client), 0x00000000, NV_DEVICE, - &args, sizeof(args), &device); - nvif_client_ref(NULL, &client); + ret = u_device("lib", argv[0], "fatal", DETECT, true, 0, + 0x00000000, &device); if (ret) return ret; diff --git a/bin/nv_rffunc.h b/bin/nv_rffunc.h index 350059b84..4bc0e4a41 100644 --- a/bin/nv_rffunc.h +++ b/bin/nv_rffunc.h @@ -35,5 +35,5 @@ nv_rfb(struct nvif_device *device, u64 offset) } #define READ(o) nv_rfb(device, (o)) -#define ENABLE (NV_DEVICE_V0_DISABLE_MMIO | NV_DEVICE_V0_DISABLE_IDENTIFY) +#define DETECT true #include "nv_rdfunc.h" diff --git a/bin/nv_rifunc.h b/bin/nv_rifunc.h index b1ffcfb6d..245a4833d 100644 --- a/bin/nv_rifunc.h +++ b/bin/nv_rifunc.h @@ -42,5 +42,5 @@ nv_rfb(struct nvif_device *device, u64 offset) } #define READ(o) nv_rfb(device, (o)) -#define ENABLE (NV_DEVICE_V0_DISABLE_MMIO | NV_DEVICE_V0_DISABLE_IDENTIFY) +#define DETECT true #include "nv_rdfunc.h" diff --git a/bin/nv_rsfunc.h b/bin/nv_rsfunc.h index e5cff49e1..2a36cd128 100644 --- a/bin/nv_rsfunc.h +++ b/bin/nv_rsfunc.h @@ -20,5 +20,5 @@ nv_rsys(struct nvif_device *device, u64 addr) } #define READ(o) nv_rsys(device, (o)) -#define ENABLE (NV_DEVICE_V0_DISABLE_MMIO | NV_DEVICE_V0_DISABLE_IDENTIFY) +#define DETECT true #include "nv_rdfunc.h" diff --git a/bin/nv_rvfunc.h b/bin/nv_rvfunc.h index cb63f374f..ffb97dff8 100644 --- a/bin/nv_rvfunc.h +++ b/bin/nv_rvfunc.h @@ -20,5 +20,5 @@ nv_rvram(struct nvif_device *device, u64 addr) } #define READ(o) nv_rvram(device, (o)) -#define ENABLE (NV_DEVICE_V0_DISABLE_MMIO | NV_DEVICE_V0_DISABLE_IDENTIFY) +#define DETECT true #include "nv_rdfunc.h" diff --git a/bin/nv_wffunc.h b/bin/nv_wffunc.h index dcb8fe50d..6efa67e2f 100644 --- a/bin/nv_wffunc.h +++ b/bin/nv_wffunc.h @@ -35,5 +35,5 @@ nv_wfb(struct nvif_device *device, u64 offset, CAST data) } #define WRITE(o,v) nv_wfb(device, (o), (v)) -#define ENABLE (NV_DEVICE_V0_DISABLE_MMIO | NV_DEVICE_V0_DISABLE_IDENTIFY) +#define DETECT true #include "nv_wrfunc.h" diff --git a/bin/nv_wifunc.h b/bin/nv_wifunc.h index eea6a23de..0525b8423 100644 --- a/bin/nv_wifunc.h +++ b/bin/nv_wifunc.h @@ -42,5 +42,5 @@ nv_wfb(struct nvif_device *device, u64 offset, CAST data) } #define WRITE(o,v) nv_wfb(device, (o), (v)) -#define ENABLE (NV_DEVICE_V0_DISABLE_MMIO | NV_DEVICE_V0_DISABLE_IDENTIFY) +#define DETECT true #include "nv_wrfunc.h" diff --git a/bin/nv_wrfunc.h b/bin/nv_wrfunc.h index fb39c460b..cea140443 100644 --- a/bin/nv_wrfunc.h +++ b/bin/nv_wrfunc.h @@ -6,34 +6,23 @@ #include <nvif/device.h> #include <nvif/class.h> -#ifndef ENABLE -#define ENABLE NV_DEVICE_V0_DISABLE_MMIO -#endif -#ifndef DEBUG0 -#define DEBUG0 0ULL +#ifndef DETECT +#define DETECT false #endif +#include "util.h" + int MAIN(int argc, char **argv) { - const char *drv = "lib"; - const char *cfg = NULL; - const char *dbg = "fatal"; - u64 dev = ~0ULL; - struct nvif_client *client; struct nvif_device *device; - struct nv_device_v0 args = {}; char *rstr = NULL; char *vstr = NULL; int quiet = 0; int ret, c; - while ((c = getopt(argc, argv, "-a:b:c:d:q")) != -1) { + while ((c = getopt(argc, argv, "-q"U_GETOPT)) != -1) { switch (c) { - case 'a': dev = strtoull(optarg, NULL, 0); break; - case 'b': drv = optarg; break; - case 'c': cfg = optarg; break; - case 'd': dbg = optarg; break; case 'q': quiet = 1; break; @@ -46,20 +35,15 @@ MAIN(int argc, char **argv) rstr = optarg; } break; + default: + if (!u_option(c)) + return 1; + break; } } - ret = nvif_client_new(drv, argv[0], dev, cfg, dbg, &client); - if (ret) - return ret; - - args.device = ~0ULL; - args.disable = ~ENABLE; - args.debug0 = ~DEBUG0; - - ret = nvif_device_new(nvif_object(client), 0, NV_DEVICE, - &args, sizeof(args), &device); - nvif_client_ref(NULL, &client); + ret = u_device("lib", argv[0], "fatal", DETECT, true, 0ULL, + 0x00000000, &device); if (ret) return ret; diff --git a/bin/nv_wsfunc.h b/bin/nv_wsfunc.h index 85b2d2500..909fd70cf 100644 --- a/bin/nv_wsfunc.h +++ b/bin/nv_wsfunc.h @@ -18,5 +18,5 @@ nv_wsys(struct nvif_device *device, u64 addr, CAST data) } #define WRITE(o,v) nv_wsys(device, (o), (v)) -#define ENABLE (NV_DEVICE_V0_DISABLE_MMIO | NV_DEVICE_V0_DISABLE_IDENTIFY) +#define DETECT true #include "nv_wrfunc.h" diff --git a/bin/nv_wvfunc.h b/bin/nv_wvfunc.h index c11de8bed..5a169227e 100644 --- a/bin/nv_wvfunc.h +++ b/bin/nv_wvfunc.h @@ -18,5 +18,5 @@ nv_wvram(struct nvif_device *device, u64 addr, CAST data) } #define WRITE(o,v) nv_wvram(device, (o), (v)) -#define ENABLE (NV_DEVICE_V0_DISABLE_MMIO | NV_DEVICE_V0_DISABLE_IDENTIFY) +#define DETECT true #include "nv_wrfunc.h" 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 |