xref: /qemu/hw/arm/smmuv3-internal.h (revision 10a83cb9887eddb1b504ecf3b189159db949178e)
1*10a83cb9SPrem Mallappa /*
2*10a83cb9SPrem Mallappa  * ARM SMMUv3 support - Internal API
3*10a83cb9SPrem Mallappa  *
4*10a83cb9SPrem Mallappa  * Copyright (C) 2014-2016 Broadcom Corporation
5*10a83cb9SPrem Mallappa  * Copyright (c) 2017 Red Hat, Inc.
6*10a83cb9SPrem Mallappa  * Written by Prem Mallappa, Eric Auger
7*10a83cb9SPrem Mallappa  *
8*10a83cb9SPrem Mallappa  * This program is free software; you can redistribute it and/or modify
9*10a83cb9SPrem Mallappa  * it under the terms of the GNU General Public License version 2 as
10*10a83cb9SPrem Mallappa  * published by the Free Software Foundation.
11*10a83cb9SPrem Mallappa  *
12*10a83cb9SPrem Mallappa  * This program is distributed in the hope that it will be useful,
13*10a83cb9SPrem Mallappa  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14*10a83cb9SPrem Mallappa  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*10a83cb9SPrem Mallappa  * GNU General Public License for more details.
16*10a83cb9SPrem Mallappa  *
17*10a83cb9SPrem Mallappa  * You should have received a copy of the GNU General Public License along
18*10a83cb9SPrem Mallappa  * with this program; if not, see <http://www.gnu.org/licenses/>.
19*10a83cb9SPrem Mallappa  */
20*10a83cb9SPrem Mallappa 
21*10a83cb9SPrem Mallappa #ifndef HW_ARM_SMMU_V3_INTERNAL_H
22*10a83cb9SPrem Mallappa #define HW_ARM_SMMU_V3_INTERNAL_H
23*10a83cb9SPrem Mallappa 
24*10a83cb9SPrem Mallappa #include "hw/arm/smmu-common.h"
25*10a83cb9SPrem Mallappa 
26*10a83cb9SPrem Mallappa /* MMIO Registers */
27*10a83cb9SPrem Mallappa 
28*10a83cb9SPrem Mallappa REG32(IDR0,                0x0)
29*10a83cb9SPrem Mallappa     FIELD(IDR0, S1P,         1 , 1)
30*10a83cb9SPrem Mallappa     FIELD(IDR0, TTF,         2 , 2)
31*10a83cb9SPrem Mallappa     FIELD(IDR0, COHACC,      4 , 1)
32*10a83cb9SPrem Mallappa     FIELD(IDR0, ASID16,      12, 1)
33*10a83cb9SPrem Mallappa     FIELD(IDR0, TTENDIAN,    21, 2)
34*10a83cb9SPrem Mallappa     FIELD(IDR0, STALL_MODEL, 24, 2)
35*10a83cb9SPrem Mallappa     FIELD(IDR0, TERM_MODEL,  26, 1)
36*10a83cb9SPrem Mallappa     FIELD(IDR0, STLEVEL,     27, 2)
37*10a83cb9SPrem Mallappa 
38*10a83cb9SPrem Mallappa REG32(IDR1,                0x4)
39*10a83cb9SPrem Mallappa     FIELD(IDR1, SIDSIZE,      0 , 6)
40*10a83cb9SPrem Mallappa     FIELD(IDR1, EVENTQS,      16, 5)
41*10a83cb9SPrem Mallappa     FIELD(IDR1, CMDQS,        21, 5)
42*10a83cb9SPrem Mallappa 
43*10a83cb9SPrem Mallappa #define SMMU_IDR1_SIDSIZE 16
44*10a83cb9SPrem Mallappa #define SMMU_CMDQS   19
45*10a83cb9SPrem Mallappa #define SMMU_EVENTQS 19
46*10a83cb9SPrem Mallappa 
47*10a83cb9SPrem Mallappa REG32(IDR2,                0x8)
48*10a83cb9SPrem Mallappa REG32(IDR3,                0xc)
49*10a83cb9SPrem Mallappa REG32(IDR4,                0x10)
50*10a83cb9SPrem Mallappa REG32(IDR5,                0x14)
51*10a83cb9SPrem Mallappa      FIELD(IDR5, OAS,         0, 3);
52*10a83cb9SPrem Mallappa      FIELD(IDR5, GRAN4K,      4, 1);
53*10a83cb9SPrem Mallappa      FIELD(IDR5, GRAN16K,     5, 1);
54*10a83cb9SPrem Mallappa      FIELD(IDR5, GRAN64K,     6, 1);
55*10a83cb9SPrem Mallappa 
56*10a83cb9SPrem Mallappa #define SMMU_IDR5_OAS 4
57*10a83cb9SPrem Mallappa 
58*10a83cb9SPrem Mallappa REG32(IIDR,                0x1c)
59*10a83cb9SPrem Mallappa REG32(CR0,                 0x20)
60*10a83cb9SPrem Mallappa     FIELD(CR0, SMMU_ENABLE,   0, 1)
61*10a83cb9SPrem Mallappa     FIELD(CR0, EVENTQEN,      2, 1)
62*10a83cb9SPrem Mallappa     FIELD(CR0, CMDQEN,        3, 1)
63*10a83cb9SPrem Mallappa 
64*10a83cb9SPrem Mallappa REG32(CR0ACK,              0x24)
65*10a83cb9SPrem Mallappa REG32(CR1,                 0x28)
66*10a83cb9SPrem Mallappa REG32(CR2,                 0x2c)
67*10a83cb9SPrem Mallappa REG32(STATUSR,             0x40)
68*10a83cb9SPrem Mallappa REG32(IRQ_CTRL,            0x50)
69*10a83cb9SPrem Mallappa     FIELD(IRQ_CTRL, GERROR_IRQEN,        0, 1)
70*10a83cb9SPrem Mallappa     FIELD(IRQ_CTRL, PRI_IRQEN,           1, 1)
71*10a83cb9SPrem Mallappa     FIELD(IRQ_CTRL, EVENTQ_IRQEN,        2, 1)
72*10a83cb9SPrem Mallappa 
73*10a83cb9SPrem Mallappa REG32(IRQ_CTRL_ACK,        0x54)
74*10a83cb9SPrem Mallappa REG32(GERROR,              0x60)
75*10a83cb9SPrem Mallappa     FIELD(GERROR, CMDQ_ERR,           0, 1)
76*10a83cb9SPrem Mallappa     FIELD(GERROR, EVENTQ_ABT_ERR,     2, 1)
77*10a83cb9SPrem Mallappa     FIELD(GERROR, PRIQ_ABT_ERR,       3, 1)
78*10a83cb9SPrem Mallappa     FIELD(GERROR, MSI_CMDQ_ABT_ERR,   4, 1)
79*10a83cb9SPrem Mallappa     FIELD(GERROR, MSI_EVENTQ_ABT_ERR, 5, 1)
80*10a83cb9SPrem Mallappa     FIELD(GERROR, MSI_PRIQ_ABT_ERR,   6, 1)
81*10a83cb9SPrem Mallappa     FIELD(GERROR, MSI_GERROR_ABT_ERR, 7, 1)
82*10a83cb9SPrem Mallappa     FIELD(GERROR, MSI_SFM_ERR,        8, 1)
83*10a83cb9SPrem Mallappa 
84*10a83cb9SPrem Mallappa REG32(GERRORN,             0x64)
85*10a83cb9SPrem Mallappa 
86*10a83cb9SPrem Mallappa #define A_GERROR_IRQ_CFG0  0x68 /* 64b */
87*10a83cb9SPrem Mallappa REG32(GERROR_IRQ_CFG1, 0x70)
88*10a83cb9SPrem Mallappa REG32(GERROR_IRQ_CFG2, 0x74)
89*10a83cb9SPrem Mallappa 
90*10a83cb9SPrem Mallappa #define A_STRTAB_BASE      0x80 /* 64b */
91*10a83cb9SPrem Mallappa 
92*10a83cb9SPrem Mallappa #define SMMU_BASE_ADDR_MASK 0xffffffffffe0
93*10a83cb9SPrem Mallappa 
94*10a83cb9SPrem Mallappa REG32(STRTAB_BASE_CFG,     0x88)
95*10a83cb9SPrem Mallappa     FIELD(STRTAB_BASE_CFG, FMT,      16, 2)
96*10a83cb9SPrem Mallappa     FIELD(STRTAB_BASE_CFG, SPLIT,    6 , 5)
97*10a83cb9SPrem Mallappa     FIELD(STRTAB_BASE_CFG, LOG2SIZE, 0 , 6)
98*10a83cb9SPrem Mallappa 
99*10a83cb9SPrem Mallappa #define A_CMDQ_BASE        0x90 /* 64b */
100*10a83cb9SPrem Mallappa REG32(CMDQ_PROD,           0x98)
101*10a83cb9SPrem Mallappa REG32(CMDQ_CONS,           0x9c)
102*10a83cb9SPrem Mallappa     FIELD(CMDQ_CONS, ERR, 24, 7)
103*10a83cb9SPrem Mallappa 
104*10a83cb9SPrem Mallappa #define A_EVENTQ_BASE      0xa0 /* 64b */
105*10a83cb9SPrem Mallappa REG32(EVENTQ_PROD,         0xa8)
106*10a83cb9SPrem Mallappa REG32(EVENTQ_CONS,         0xac)
107*10a83cb9SPrem Mallappa 
108*10a83cb9SPrem Mallappa #define A_EVENTQ_IRQ_CFG0  0xb0 /* 64b */
109*10a83cb9SPrem Mallappa REG32(EVENTQ_IRQ_CFG1,     0xb8)
110*10a83cb9SPrem Mallappa REG32(EVENTQ_IRQ_CFG2,     0xbc)
111*10a83cb9SPrem Mallappa 
112*10a83cb9SPrem Mallappa #define A_IDREGS           0xfd0
113*10a83cb9SPrem Mallappa 
114*10a83cb9SPrem Mallappa static inline int smmu_enabled(SMMUv3State *s)
115*10a83cb9SPrem Mallappa {
116*10a83cb9SPrem Mallappa     return FIELD_EX32(s->cr[0], CR0, SMMU_ENABLE);
117*10a83cb9SPrem Mallappa }
118*10a83cb9SPrem Mallappa 
119*10a83cb9SPrem Mallappa /* Command Queue Entry */
120*10a83cb9SPrem Mallappa typedef struct Cmd {
121*10a83cb9SPrem Mallappa     uint32_t word[4];
122*10a83cb9SPrem Mallappa } Cmd;
123*10a83cb9SPrem Mallappa 
124*10a83cb9SPrem Mallappa /* Event Queue Entry */
125*10a83cb9SPrem Mallappa typedef struct Evt  {
126*10a83cb9SPrem Mallappa     uint32_t word[8];
127*10a83cb9SPrem Mallappa } Evt;
128*10a83cb9SPrem Mallappa 
129*10a83cb9SPrem Mallappa static inline uint32_t smmuv3_idreg(int regoffset)
130*10a83cb9SPrem Mallappa {
131*10a83cb9SPrem Mallappa     /*
132*10a83cb9SPrem Mallappa      * Return the value of the Primecell/Corelink ID registers at the
133*10a83cb9SPrem Mallappa      * specified offset from the first ID register.
134*10a83cb9SPrem Mallappa      * These value indicate an ARM implementation of MMU600 p1
135*10a83cb9SPrem Mallappa      */
136*10a83cb9SPrem Mallappa     static const uint8_t smmuv3_ids[] = {
137*10a83cb9SPrem Mallappa         0x04, 0, 0, 0, 0x84, 0xB4, 0xF0, 0x10, 0x0D, 0xF0, 0x05, 0xB1
138*10a83cb9SPrem Mallappa     };
139*10a83cb9SPrem Mallappa     return smmuv3_ids[regoffset / 4];
140*10a83cb9SPrem Mallappa }
141*10a83cb9SPrem Mallappa 
142*10a83cb9SPrem Mallappa #endif
143