summaryrefslogtreecommitdiff
path: root/bin/nv_wrfunc.h
diff options
context:
space:
mode:
authorBen Skeggs <bskeggs@redhat.com>2012-05-22 10:59:14 +1000
committerBen Skeggs <bskeggs@redhat.com>2013-01-09 14:32:47 +1000
commit827ac5471ac6b03d7a74e8fe0805787b0b3c8364 (patch)
treec493524ff33dedb9f6aa54b51832b4947921f75b /bin/nv_wrfunc.h
downloadnouveau-827ac5471ac6b03d7a74e8fe0805787b0b3c8364.tar.gz
initial import of nouveau kernel module core, some simple tools, and drm
Ignore (or, if you're really keen, fix) any of the horrors that are part of the emulate-linux-on-libpciaccess (lib/) layer. When I started down this path I was only aiming to prototype the reworked driver core, and never actually intended on going quite this far with things, but it turns out that being able to develop and test the nouveau core from userspace is *very* useful. This tree is based on the code available as of Linux 3.8-rc2. Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'bin/nv_wrfunc.h')
-rw-r--r--bin/nv_wrfunc.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/bin/nv_wrfunc.h b/bin/nv_wrfunc.h
new file mode 100644
index 000000000..eae75c248
--- /dev/null
+++ b/bin/nv_wrfunc.h
@@ -0,0 +1,101 @@
+#include <stdlib.h>
+#include <limits.h>
+#include <unistd.h>
+
+#include <core/os.h>
+#include <core/object.h>
+#include <core/class.h>
+
+#ifndef ENABLE
+#define ENABLE NV_DEVICE_DISABLE_MMIO
+#endif
+#ifndef DEBUG0
+#define DEBUG0 0ULL
+#endif
+
+int
+MAIN(int argc, char **argv)
+{
+ struct nouveau_object *client;
+ struct nouveau_object *device;
+ struct nv_device_class args;
+ char *rstr = NULL;
+ char *vstr = NULL;
+ int quiet = 0;
+ int ret, c;
+
+ while ((c = getopt(argc, argv, "-q")) != -1) {
+ switch (c) {
+ case 'q':
+ quiet = 1;
+ break;
+ case 1:
+ if (rstr) {
+ if (vstr)
+ return 1;
+ vstr = optarg;
+ } else {
+ rstr = optarg;
+ }
+ break;
+ }
+ }
+
+ ret = os_client_new(NULL, "fatal", argc, argv, &client);
+ if (ret)
+ return ret;
+
+ args.device = ~0ULL;
+ args.disable = ~ENABLE;
+ args.debug0 = ~DEBUG0;
+
+ ret = nouveau_object_new(client, ~0, 0, 0x0080, &args, sizeof(args),
+ &device);
+ if (ret)
+ return ret;
+
+ while (rstr && *rstr != '\0') {
+ unsigned long cnt = 1;
+ unsigned long reg;
+ unsigned long val;
+
+ if ((reg = strtoul(rstr, &rstr, 0)) == ULONG_MAX)
+ return 1;
+
+ if (*rstr == '/') {
+ if ((cnt = strtoul(rstr + 1, &rstr, 0)) == ULONG_MAX)
+ return 1;
+ } else
+ if (*rstr == '+') {
+ if ((cnt = strtoul(rstr + 1, &rstr, 0)) == ULONG_MAX)
+ return 1;
+ cnt /= sizeof(CAST);
+ }
+
+ if (*rstr == '=') {
+ if ((val = strtoul(rstr + 1, &rstr, 0)) == ULONG_MAX)
+ return 1;
+ } else {
+ if (!vstr ||
+ (val = strtoul(vstr, NULL, 0)) == ULONG_MAX)
+ return 1;
+ }
+
+ switch (*rstr) {
+ case ',':
+ rstr++;
+ case '\0':
+ while (cnt--) {
+ if (!quiet)
+ printk(NAME" "FMTADDR" "FMTDATA"\n", reg, (CAST)val);
+ WRITE(reg, val);
+ reg += sizeof(CAST);
+ }
+ break;
+ default:
+ return 1;
+ }
+ }
+
+ return 0;
+}