diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2019-09-04 08:20:30 -0400 |
---|---|---|
committer | Felipe Franciosi <felipe@nutanix.com> | 2019-09-05 16:45:35 +0100 |
commit | 73f280c124e69f9d8c46181208194a01d0f330d2 (patch) | |
tree | 5a4bd289facb17611e2c8bfeb5310fa677cee21d /samples | |
parent | 209c7c4daa3f8cdfe0070d4d5ccd602f56f43cb6 (diff) | |
download | libvfio-user-73f280c124e69f9d8c46181208194a01d0f330d2.zip libvfio-user-73f280c124e69f9d8c46181208194a01d0f330d2.tar.gz libvfio-user-73f280c124e69f9d8c46181208194a01d0f330d2.tar.bz2 |
introduce gpio sample
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/CMakeLists.txt | 3 | ||||
-rw-r--r-- | samples/gpio-pci-idio-16.c | 37 |
2 files changed, 40 insertions, 0 deletions
diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index d12a813..8a03c30 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -30,3 +30,6 @@ add_executable(test_read test_read.c) add_executable(test_mmap test_mmap.c) + +add_executable(gpio-pci-idio-16 gpio-pci-idio-16.c) +target_link_libraries(gpio-pci-idio-16 muser) diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c new file mode 100644 index 0000000..e16cae2 --- /dev/null +++ b/samples/gpio-pci-idio-16.c @@ -0,0 +1,37 @@ +/* gpio-pci-idio-16 */ + +#include <stdio.h> + +#include "../lib/muser.h" + +ssize_t +bar2_access(void *pvt, char * const buf, size_t count, loff_t offset, + const bool is_write) +{ + static char n; + + if (offset == 0 && !is_write) + buf[0] = n++ / 3; + + return count; +} + +int main(int argc, char **argv) +{ + lm_dev_info_t dev_info = { + .pci_info = { + .id = {.vid = 0x494F, .did = 0x0DC8 }, + .reg_info[LM_DEV_BAR2_REG_IDX] = { + .flags = LM_REG_FLAG_RW, + .size = 0x100, + .fn = &bar2_access + }, + .irq_count[LM_DEV_INTX_IRQ_IDX] = 1, + }, + .uuid = argv[1], + }; + + return lm_ctx_run(&dev_info); +} + +/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ |