diff options
author | Thierry Reding <treding@nvidia.com> | 2017-11-14 18:52:10 +0100 |
---|---|---|
committer | Thierry Reding <treding@nvidia.com> | 2018-05-02 17:29:39 +0200 |
commit | 93410e3d4f906ef4f4d77512c4aa70f87e94420d (patch) | |
tree | f1bebaefaae006763ea63b031da77efeb744b0d2 | |
parent | 248f843f0e36ca7875ad0a252af72d050f27b8c1 (diff) |
nouveau: Add noop test program
Signed-off-by: Thierry Reding <treding@nvidia.com>
-rw-r--r-- | tests/nouveau/Makefile.am | 4 | ||||
-rw-r--r-- | tests/nouveau/noop.c | 130 |
2 files changed, 132 insertions, 2 deletions
diff --git a/tests/nouveau/Makefile.am b/tests/nouveau/Makefile.am index 3c799a81..29a7d02e 100644 --- a/tests/nouveau/Makefile.am +++ b/tests/nouveau/Makefile.am @@ -10,7 +10,7 @@ LDADD = \ ../../libdrm.la \ -ldl -TESTS = threaded +TESTS = noop threaded -check_PROGRAMS = $(TESTS) +noinst_PROGRAMS = $(TESTS) diff --git a/tests/nouveau/noop.c b/tests/nouveau/noop.c new file mode 100644 index 00000000..6e0ad0de --- /dev/null +++ b/tests/nouveau/noop.c @@ -0,0 +1,130 @@ +#include <stdio.h> +#include <stdint.h> +#include <fcntl.h> + +#include "drm.h" +#include "nouveau/nouveau.h" +#include "nouveau/nvif/class.h" +#include "nouveau/nvif/cl0080.h" + +//#include "nv_object.xml.h" +#define GM200_3D_CLASS 0x0000b197 +#define NV01_SUBCHAN_OBJECT 0x00000000 +#define NV04_GRAPH_NOP 0x00000100 + +static inline void +PUSH_KICK(struct nouveau_pushbuf *push) +{ + nouveau_pushbuf_kick(push, push->channel); +} + +static inline void +PUSH_DATA(struct nouveau_pushbuf *push, uint32_t data) +{ + *push->cur++ = data; +} + +static inline uint32_t +NVC0_FIFO_PKHDR_SQ(int subc, int mthd, unsigned size) +{ + return 0x20000000 | (size << 16) | (subc << 13) | (mthd >> 2); +} + +static inline void +BEGIN_NVC0(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size) +{ + PUSH_DATA (push, NVC0_FIFO_PKHDR_SQ(subc, mthd, size)); +} + +#define SUBC_3D(m) 0, (m) + +int main(int argc, char **argv) +{ + struct nouveau_object *channel; + struct nouveau_client *client; + struct nouveau_object *eng3d; + struct nouveau_pushbuf *pb; + struct nouveau_device *dev; + struct nouveau_drm *drm; + int err, fd; + + fprintf(stderr, "nouveau_noop_test - The simplest possible GPU sanity test\n"); + + if (argc < 2) { + fprintf(stderr, "Usage: nouveau_noop_test <card file>\n"); + return 1; + } + + fd = open(argv[1], O_RDWR); + if (fd == -1) { + perror("open"); + return 1; + } + + err = nouveau_drm_new(fd, &drm); + if (err) { + fprintf(stderr, "nouveau_drm_new: %d\n", err); + return 1; + } + + fprintf(stderr, "Opened DRM node.\n"); + + err = nouveau_device_new(&drm->client, NV_DEVICE, + &(struct nv_device_v0) { + /* default device */ + .device = ~0ULL, + }, sizeof(struct nv_device_v0), &dev); + if (err) { + fprintf(stderr, "nouveau_device_new: %d\n", err); + return 1; + } + + fprintf(stderr, "Opened device.\n"); + + err = nouveau_object_new(&dev->object, 0, NOUVEAU_FIFO_CHANNEL_CLASS, + &(struct nvc0_fifo) { }, sizeof(struct nvc0_fifo), + &channel); + if (err) { + fprintf(stderr, "nouveau_object_new: %d\n", err); + return 1; + } + + fprintf(stderr, "Opened channel.\n"); + + err = nouveau_client_new(dev, &client); + if (err) { + fprintf(stderr, "nouveau_client_new: %d\n", err); + return 1; + } + + fprintf(stderr, "Opened client.\n"); + + err = nouveau_pushbuf_new(client, channel, 4, 512 * 1024, 1, &pb); + if (err) { + fprintf(stderr, "nouveau_pushbuf_new: %d\n", err); + return 1; + } + + fprintf(stderr, "Created push buffer.\n"); + + nouveau_pushbuf_space(pb, 8, 0, 0); + + err = nouveau_object_new(channel, 0xbeef003d, GM200_3D_CLASS, NULL, 0, &eng3d); + if (err) { + fprintf(stderr, "nouveau_object_new (eng3d): %d\n", err); + return 1; + } + + fprintf(stderr, "Opened 3D class object.\n"); + + BEGIN_NVC0(pb, SUBC_3D(NV01_SUBCHAN_OBJECT), 1); + PUSH_DATA (pb, GM200_3D_CLASS); + BEGIN_NVC0(pb, SUBC_3D(NV04_GRAPH_NOP), 1); + PUSH_DATA (pb, 0); + + PUSH_KICK (pb); + + fprintf(stderr, "Submitted pushbuffer.\n"); + + return 0; +} |