xref: /openbmc/qemu/tests/qtest/libqos/riscv-iommu.h (revision 40b44316)
1*40b44316SDaniel Henrique Barboza /*
2*40b44316SDaniel Henrique Barboza  * libqos driver riscv-iommu-pci framework
3*40b44316SDaniel Henrique Barboza  *
4*40b44316SDaniel Henrique Barboza  * Copyright (c) 2024 Ventana Micro Systems Inc.
5*40b44316SDaniel Henrique Barboza  *
6*40b44316SDaniel Henrique Barboza  * This work is licensed under the terms of the GNU GPL, version 2 or (at your
7*40b44316SDaniel Henrique Barboza  * option) any later version.  See the COPYING file in the top-level directory.
8*40b44316SDaniel Henrique Barboza  *
9*40b44316SDaniel Henrique Barboza  */
10*40b44316SDaniel Henrique Barboza 
11*40b44316SDaniel Henrique Barboza #ifndef TESTS_LIBQOS_RISCV_IOMMU_H
12*40b44316SDaniel Henrique Barboza #define TESTS_LIBQOS_RISCV_IOMMU_H
13*40b44316SDaniel Henrique Barboza 
14*40b44316SDaniel Henrique Barboza #include "qgraph.h"
15*40b44316SDaniel Henrique Barboza #include "pci.h"
16*40b44316SDaniel Henrique Barboza #include "qemu/bitops.h"
17*40b44316SDaniel Henrique Barboza 
18*40b44316SDaniel Henrique Barboza #ifndef GENMASK_ULL
19*40b44316SDaniel Henrique Barboza #define GENMASK_ULL(h, l) (((~0ULL) >> (63 - (h) + (l))) << (l))
20*40b44316SDaniel Henrique Barboza #endif
21*40b44316SDaniel Henrique Barboza 
22*40b44316SDaniel Henrique Barboza /*
23*40b44316SDaniel Henrique Barboza  * RISC-V IOMMU uses PCI_VENDOR_ID_REDHAT 0x1b36 and
24*40b44316SDaniel Henrique Barboza  * PCI_DEVICE_ID_REDHAT_RISCV_IOMMU 0x0014.
25*40b44316SDaniel Henrique Barboza  */
26*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PCI_VENDOR_ID       0x1b36
27*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PCI_DEVICE_ID       0x0014
28*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PCI_DEVICE_CLASS    0x0806
29*40b44316SDaniel Henrique Barboza 
30*40b44316SDaniel Henrique Barboza /* Common field positions */
31*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_QUEUE_ENABLE        BIT(0)
32*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_QUEUE_INTR_ENABLE   BIT(1)
33*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_QUEUE_MEM_FAULT     BIT(8)
34*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_QUEUE_ACTIVE        BIT(16)
35*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_QUEUE_BUSY          BIT(17)
36*40b44316SDaniel Henrique Barboza 
37*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_CAP             0x0000
38*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_CAP_VERSION         GENMASK_ULL(7, 0)
39*40b44316SDaniel Henrique Barboza 
40*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_DDTP            0x0010
41*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_DDTP_BUSY           BIT_ULL(4)
42*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_DDTP_MODE           GENMASK_ULL(3, 0)
43*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_DDTP_MODE_OFF       0
44*40b44316SDaniel Henrique Barboza 
45*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_CQCSR           0x0048
46*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_CQCSR_CQEN          RISCV_IOMMU_QUEUE_ENABLE
47*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_CQCSR_CIE           RISCV_IOMMU_QUEUE_INTR_ENABLE
48*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_CQCSR_CQON          RISCV_IOMMU_QUEUE_ACTIVE
49*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_CQCSR_BUSY          RISCV_IOMMU_QUEUE_BUSY
50*40b44316SDaniel Henrique Barboza 
51*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_FQCSR           0x004C
52*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_FQCSR_FQEN          RISCV_IOMMU_QUEUE_ENABLE
53*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_FQCSR_FIE           RISCV_IOMMU_QUEUE_INTR_ENABLE
54*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_FQCSR_FQON          RISCV_IOMMU_QUEUE_ACTIVE
55*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_FQCSR_BUSY          RISCV_IOMMU_QUEUE_BUSY
56*40b44316SDaniel Henrique Barboza 
57*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_PQCSR           0x0050
58*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PQCSR_PQEN          RISCV_IOMMU_QUEUE_ENABLE
59*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PQCSR_PIE           RISCV_IOMMU_QUEUE_INTR_ENABLE
60*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PQCSR_PQON          RISCV_IOMMU_QUEUE_ACTIVE
61*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_PQCSR_BUSY          RISCV_IOMMU_QUEUE_BUSY
62*40b44316SDaniel Henrique Barboza 
63*40b44316SDaniel Henrique Barboza #define RISCV_IOMMU_REG_IPSR            0x0054
64*40b44316SDaniel Henrique Barboza 
65*40b44316SDaniel Henrique Barboza typedef struct QRISCVIOMMU {
66*40b44316SDaniel Henrique Barboza     QOSGraphObject obj;
67*40b44316SDaniel Henrique Barboza     QPCIDevice dev;
68*40b44316SDaniel Henrique Barboza     QPCIBar reg_bar;
69*40b44316SDaniel Henrique Barboza } QRISCVIOMMU;
70*40b44316SDaniel Henrique Barboza 
71*40b44316SDaniel Henrique Barboza #endif
72