140b44316SDaniel Henrique Barboza /* 240b44316SDaniel Henrique Barboza * libqos driver riscv-iommu-pci framework 340b44316SDaniel Henrique Barboza * 440b44316SDaniel Henrique Barboza * Copyright (c) 2024 Ventana Micro Systems Inc. 540b44316SDaniel Henrique Barboza * 640b44316SDaniel Henrique Barboza * This work is licensed under the terms of the GNU GPL, version 2 or (at your 740b44316SDaniel Henrique Barboza * option) any later version. See the COPYING file in the top-level directory. 840b44316SDaniel Henrique Barboza * 940b44316SDaniel Henrique Barboza */ 1040b44316SDaniel Henrique Barboza 1140b44316SDaniel Henrique Barboza #ifndef TESTS_LIBQOS_RISCV_IOMMU_H 1240b44316SDaniel Henrique Barboza #define TESTS_LIBQOS_RISCV_IOMMU_H 1340b44316SDaniel Henrique Barboza 1440b44316SDaniel Henrique Barboza #include "qgraph.h" 1540b44316SDaniel Henrique Barboza #include "pci.h" 1640b44316SDaniel Henrique Barboza #include "qemu/bitops.h" 1740b44316SDaniel Henrique Barboza 1840b44316SDaniel Henrique Barboza #ifndef GENMASK_ULL 1940b44316SDaniel Henrique Barboza #define GENMASK_ULL(h, l) (((~0ULL) >> (63 - (h) + (l))) << (l)) 2040b44316SDaniel Henrique Barboza #endif 2140b44316SDaniel Henrique Barboza 2240b44316SDaniel Henrique Barboza /* 2340b44316SDaniel Henrique Barboza * RISC-V IOMMU uses PCI_VENDOR_ID_REDHAT 0x1b36 and 2440b44316SDaniel Henrique Barboza * PCI_DEVICE_ID_REDHAT_RISCV_IOMMU 0x0014. 2540b44316SDaniel Henrique Barboza */ 2640b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PCI_VENDOR_ID 0x1b36 2740b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PCI_DEVICE_ID 0x0014 2840b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PCI_DEVICE_CLASS 0x0806 2940b44316SDaniel Henrique Barboza 3040b44316SDaniel Henrique Barboza /* Common field positions */ 3140b44316SDaniel Henrique Barboza #define RISCV_IOMMU_QUEUE_ENABLE BIT(0) 3240b44316SDaniel Henrique Barboza #define RISCV_IOMMU_QUEUE_INTR_ENABLE BIT(1) 3340b44316SDaniel Henrique Barboza #define RISCV_IOMMU_QUEUE_MEM_FAULT BIT(8) 3440b44316SDaniel Henrique Barboza #define RISCV_IOMMU_QUEUE_ACTIVE BIT(16) 3540b44316SDaniel Henrique Barboza #define RISCV_IOMMU_QUEUE_BUSY BIT(17) 3640b44316SDaniel Henrique Barboza 3740b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_CAP 0x0000 3840b44316SDaniel Henrique Barboza #define RISCV_IOMMU_CAP_VERSION GENMASK_ULL(7, 0) 3940b44316SDaniel Henrique Barboza 4040b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_DDTP 0x0010 4140b44316SDaniel Henrique Barboza #define RISCV_IOMMU_DDTP_BUSY BIT_ULL(4) 4240b44316SDaniel Henrique Barboza #define RISCV_IOMMU_DDTP_MODE GENMASK_ULL(3, 0) 4340b44316SDaniel Henrique Barboza #define RISCV_IOMMU_DDTP_MODE_OFF 0 4440b44316SDaniel Henrique Barboza 4540b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_CQCSR 0x0048 4640b44316SDaniel Henrique Barboza #define RISCV_IOMMU_CQCSR_CQEN RISCV_IOMMU_QUEUE_ENABLE 4740b44316SDaniel Henrique Barboza #define RISCV_IOMMU_CQCSR_CIE RISCV_IOMMU_QUEUE_INTR_ENABLE 4840b44316SDaniel Henrique Barboza #define RISCV_IOMMU_CQCSR_CQON RISCV_IOMMU_QUEUE_ACTIVE 4940b44316SDaniel Henrique Barboza #define RISCV_IOMMU_CQCSR_BUSY RISCV_IOMMU_QUEUE_BUSY 5040b44316SDaniel Henrique Barboza 5140b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_FQCSR 0x004C 5240b44316SDaniel Henrique Barboza #define RISCV_IOMMU_FQCSR_FQEN RISCV_IOMMU_QUEUE_ENABLE 5340b44316SDaniel Henrique Barboza #define RISCV_IOMMU_FQCSR_FIE RISCV_IOMMU_QUEUE_INTR_ENABLE 5440b44316SDaniel Henrique Barboza #define RISCV_IOMMU_FQCSR_FQON RISCV_IOMMU_QUEUE_ACTIVE 5540b44316SDaniel Henrique Barboza #define RISCV_IOMMU_FQCSR_BUSY RISCV_IOMMU_QUEUE_BUSY 5640b44316SDaniel Henrique Barboza 5740b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_PQCSR 0x0050 5840b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PQCSR_PQEN RISCV_IOMMU_QUEUE_ENABLE 5940b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PQCSR_PIE RISCV_IOMMU_QUEUE_INTR_ENABLE 6040b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PQCSR_PQON RISCV_IOMMU_QUEUE_ACTIVE 6140b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PQCSR_BUSY RISCV_IOMMU_QUEUE_BUSY 6240b44316SDaniel Henrique Barboza 6340b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_IPSR 0x0054 6440b44316SDaniel Henrique Barboza 65*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_IVEC 0x02F8 66*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_IVEC_CIV GENMASK_ULL(3, 0) 67*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_IVEC_FIV GENMASK_ULL(7, 4) 68*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_IVEC_PMIV GENMASK_ULL(11, 8) 69*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_IVEC_PIV GENMASK_ULL(15, 12) 70*d4f7804bSDaniel Henrique Barboza 71*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_CQB 0x0018 72*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_CQB_PPN_START 10 73*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_CQB_PPN_LEN 44 74*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_CQB_LOG2SZ_START 0 75*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_CQB_LOG2SZ_LEN 5 76*d4f7804bSDaniel Henrique Barboza 77*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_CQT 0x0024 78*d4f7804bSDaniel Henrique Barboza 79*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_FQB 0x0028 80*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_FQB_PPN_START 10 81*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_FQB_PPN_LEN 44 82*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_FQB_LOG2SZ_START 0 83*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_FQB_LOG2SZ_LEN 5 84*d4f7804bSDaniel Henrique Barboza 85*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_FQT 0x0034 86*d4f7804bSDaniel Henrique Barboza 87*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_PQB 0x0038 88*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_PQB_PPN_START 10 89*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_PQB_PPN_LEN 44 90*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_PQB_LOG2SZ_START 0 91*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_PQB_LOG2SZ_LEN 5 92*d4f7804bSDaniel Henrique Barboza 93*d4f7804bSDaniel Henrique Barboza #define RISCV_IOMMU_REG_PQT 0x0044 94*d4f7804bSDaniel Henrique Barboza 9540b44316SDaniel Henrique Barboza typedef struct QRISCVIOMMU { 9640b44316SDaniel Henrique Barboza QOSGraphObject obj; 9740b44316SDaniel Henrique Barboza QPCIDevice dev; 9840b44316SDaniel Henrique Barboza QPCIBar reg_bar; 9940b44316SDaniel Henrique Barboza } QRISCVIOMMU; 10040b44316SDaniel Henrique Barboza 10140b44316SDaniel Henrique Barboza #endif 102