diff options
-rw-r--r-- | README.md | 38 | ||||
-rw-r--r-- | samples/CMakeLists.txt | 3 | ||||
-rw-r--r-- | samples/gpio-pci-idio-16.c | 37 |
3 files changed, 77 insertions, 1 deletions
@@ -99,7 +99,7 @@ Running QEMU To pass the device to QEMU add the following options: - -device vfio-pci,sysfsdev=/sys/bus/mdev/devices/00000000-0000-0000-0000-000000000000 + -device vfio-pci,sysfsdev=/sys/bus/mdev/devices/<UUID> -object memory-backend-file,id=ram-node0,prealloc=yes,mem-path=mem,share=yes,size=1073741824 -numa node,nodeid=0,cpus=0,memdev=ram-node0 Guest RAM must be shared (share=yes) otherwise libmuser won't be able to do DMA @@ -108,6 +108,42 @@ accessed by libmuser must be allocate MAP_SHARED. Registering memory for DMA that has not been allocated with MAP_SHARED is ignored and any attempts to access that memory will result in an error. +Example +======= + +samples/gpio-pci-idio-16.c implements a tiny part of the PCI-IDIO-16 GPIO +(https://www.accesio.com/?p=/pci/pci_idio_16.html). In this sample it's a simple +device that toggles the input every 3 times it's read. + +Running gpio-pci-idio-16 +------------------------ + +First, follow the instructions to build and load muser. + +Then, start the gpio-pci-idio-16 device emulation: + + # echo 00000000-0000-0000-0000-000000000000 > /sys/class/muser/muser/mdev_supported_types/muser-1/create + # build/dbg/samples/gpio-pci-idio-16 00000000-0000-0000-0000-000000000000 + +Finally, start the VM adding the command line explained earlier and then +execute: + + # insmod gpio-pci-idio-16.ko + # cat /sys/class/gpio/gpiochip480/base > /sys/class/gpio/export + # for ((i=0;i<12;i++)); do cat /sys/class/gpio/OUT0/value; done + 0 + 0 + 0 + 1 + 1 + 1 + 0 + 0 + 0 + 1 + 1 + 1 + Future Work =========== 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: */ |