smmu_v3_defs.hh revision 14116:3868b8bdb52b
13457Sgblack@eecs.umich.edu/*
23457Sgblack@eecs.umich.edu * Copyright (c) 2013, 2018-2019 ARM Limited
33457Sgblack@eecs.umich.edu * All rights reserved
43457Sgblack@eecs.umich.edu *
53457Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
63457Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual
73457Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating
83457Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software
93457Sgblack@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
103457Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
113457Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
123457Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form.
133457Sgblack@eecs.umich.edu *
143457Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
153457Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
163457Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
173457Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
183457Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
193457Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
203457Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
213457Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
223457Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
233457Sgblack@eecs.umich.edu * this software without specific prior written permission.
243457Sgblack@eecs.umich.edu *
253457Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
263457Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
273457Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
283457Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
293457Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
303457Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3111793Sbrandon.potter@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3211793Sbrandon.potter@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
335569Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
345569Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
353457Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
365569Snate@binkert.org *
375569Snate@binkert.org * Authors: Stan Czerniawski
385569Snate@binkert.org */
395569Snate@binkert.org
405569Snate@binkert.org#ifndef __DEV_ARM_SMMU_V3_DEFS_HH__
415569Snate@binkert.org#define __DEV_ARM_SMMU_V3_DEFS_HH__
425569Snate@binkert.org
435569Snate@binkert.org#include <stdint.h>
445569Snate@binkert.org
455569Snate@binkert.org#include "base/bitunion.hh"
465569Snate@binkert.org
475569Snate@binkert.orgenum {
485569Snate@binkert.org    SMMU_SECURE_SZ = 0x184, // Secure regs are within page0
495569Snate@binkert.org    SMMU_PAGE_ZERO_SZ = 0x10000,
505569Snate@binkert.org    SMMU_PAGE_ONE_SZ = 0x10000,
515569Snate@binkert.org    SMMU_REG_SIZE = SMMU_PAGE_ONE_SZ + SMMU_PAGE_ZERO_SZ
525569Snate@binkert.org};
535569Snate@binkert.org
545569Snate@binkert.orgenum {
555569Snate@binkert.org    STE_CONFIG_ABORT        = 0x0,
565569Snate@binkert.org    STE_CONFIG_BYPASS       = 0x4,
575569Snate@binkert.org    STE_CONFIG_STAGE1_ONLY  = 0x5,
585569Snate@binkert.org    STE_CONFIG_STAGE2_ONLY  = 0x6,
595569Snate@binkert.org    STE_CONFIG_STAGE1_AND_2 = 0x7,
605569Snate@binkert.org};
615569Snate@binkert.org
625569Snate@binkert.orgenum {
635569Snate@binkert.org    STAGE1_CFG_1L     = 0x0,
645569Snate@binkert.org    STAGE1_CFG_2L_4K  = 0x1,
655569Snate@binkert.org    STAGE1_CFG_2L_64K = 0x2,
665569Snate@binkert.org};
675569Snate@binkert.org
685569Snate@binkert.orgenum {
695569Snate@binkert.org    ST_CFG_SPLIT_SHIFT = 6,
705569Snate@binkert.org    ST_CD_ADDR_SHIFT   = 6,
715569Snate@binkert.org    CD_TTB_SHIFT       = 4,
725569Snate@binkert.org    STE_S2TTB_SHIFT    = 4,
735569Snate@binkert.org};
745569Snate@binkert.org
755569Snate@binkert.orgenum {
765569Snate@binkert.org    TRANS_GRANULE_4K      = 0x0,
775569Snate@binkert.org    TRANS_GRANULE_64K     = 0x1,
785569Snate@binkert.org    TRANS_GRANULE_16K     = 0x2,
795569Snate@binkert.org    TRANS_GRANULE_INVALID = 0x3,
805569Snate@binkert.org};
815569Snate@binkert.org
825569Snate@binkert.orgenum {
835569Snate@binkert.org    ST_BASE_ADDR_MASK  = 0x0000ffffffffffe0ULL,
845569Snate@binkert.org    ST_CFG_SIZE_MASK   = 0x000000000000003fULL,
855569Snate@binkert.org    ST_CFG_SPLIT_MASK  = 0x00000000000007c0ULL,
865569Snate@binkert.org    ST_CFG_FMT_MASK    = 0x0000000000030000ULL,
875569Snate@binkert.org    ST_CFG_FMT_LINEAR  = 0x0000000000000000ULL,
885569Snate@binkert.org    ST_CFG_FMT_2LEVEL  = 0x0000000000010000ULL,
895569Snate@binkert.org    ST_L2_SPAN_MASK    = 0x000000000000001fULL,
905569Snate@binkert.org    ST_L2_ADDR_MASK    = 0x0000ffffffffffe0ULL,
915569Snate@binkert.org
925569Snate@binkert.org    VMT_BASE_ADDR_MASK = 0x0000ffffffffffe0ULL,
935569Snate@binkert.org    VMT_BASE_SIZE_MASK = 0x000000000000001fULL,
945569Snate@binkert.org
955569Snate@binkert.org    Q_BASE_ADDR_MASK   = 0x0000ffffffffffe0ULL,
965569Snate@binkert.org    Q_BASE_SIZE_MASK   = 0x000000000000001fULL,
975569Snate@binkert.org
985569Snate@binkert.org    E_BASE_ENABLE_MASK = 0x8000000000000000ULL,
995569Snate@binkert.org    E_BASE_ADDR_MASK   = 0x0000fffffffffffcULL,
1005569Snate@binkert.org};
1015569Snate@binkert.org
1025569Snate@binkert.orgunion SMMURegs
1035569Snate@binkert.org{
1045569Snate@binkert.org    uint8_t data[SMMU_REG_SIZE];
1055569Snate@binkert.org
1065569Snate@binkert.org    struct
1075569Snate@binkert.org    {
1085569Snate@binkert.org        uint32_t idr0;        // 0x0000
1095569Snate@binkert.org        uint32_t idr1;        // 0x0004
1105569Snate@binkert.org        uint32_t idr2;        // 0x0008
1115569Snate@binkert.org        uint32_t idr3;        // 0x000c
1125569Snate@binkert.org        uint32_t idr4;        // 0x0010
1135569Snate@binkert.org        uint32_t idr5;        // 0x0014
1145569Snate@binkert.org        uint32_t iidr;        // 0x0018
1155569Snate@binkert.org        uint32_t aidr;        // 0x001c
1165569Snate@binkert.org        uint32_t cr0;         // 0x0020
1175569Snate@binkert.org        uint32_t cr0ack;      // 0x0024
1185569Snate@binkert.org        uint32_t cr1;         // 0x0028
1195569Snate@binkert.org        uint32_t cr2;         // 0x002c
1205569Snate@binkert.org        uint32_t _pad1;       // 0x0030
1215569Snate@binkert.org        uint32_t _pad2;       // 0x0034
1225569Snate@binkert.org        uint32_t _pad3;       // 0x0038
1235569Snate@binkert.org        uint32_t _pad4;       // 0x003c
1245569Snate@binkert.org        uint32_t statusr;     // 0x0040
1255569Snate@binkert.org        uint32_t gbpa;        // 0x0044
1265569Snate@binkert.org        uint32_t agbpa;       // 0x0048
1275569Snate@binkert.org        uint32_t _pad5;       // 0x004c
1285569Snate@binkert.org        uint32_t irq_ctrl;    // 0x0050
1295569Snate@binkert.org        uint32_t irq_ctrlack; // 0x0054
1303457Sgblack@eecs.umich.edu        uint32_t _pad6;       // 0x0058
1315569Snate@binkert.org        uint32_t _pad7;       // 0x005c
1325569Snate@binkert.org
1335569Snate@binkert.org        uint32_t gerror;          // 0x0060
1343457Sgblack@eecs.umich.edu        uint32_t gerrorn;         // 0x0064
1355569Snate@binkert.org        uint64_t gerror_irq_cfg0; // 0x0068, 64 bit
1363457Sgblack@eecs.umich.edu        uint32_t gerror_irq_cfg1; // 0x0070
1375569Snate@binkert.org        uint32_t gerror_irq_cfg2; // 0x0074
1385569Snate@binkert.org        uint32_t _pad_1;          // 0x0078
1393457Sgblack@eecs.umich.edu        uint32_t _pad_2;          // 0x007c
1403457Sgblack@eecs.umich.edu
1415569Snate@binkert.org        uint64_t strtab_base;     // 0x0080, 64 bit
1425569Snate@binkert.org        uint32_t strtab_base_cfg; // 0x0088
143
144        uint64_t cmdq_base;       // 0x0090, 64 bit
145        uint32_t cmdq_prod;       // 0x0098
146        uint32_t cmdq_cons;       // 0x009c
147        uint64_t eventq_base;     // 0x00a0, 64 bit
148        uint32_t _pad8;           // 0x00a8
149        uint32_t _pad9;           // 0x00ac
150        uint64_t eventq_irq_cfg0; // 0x00b0, 64 bit
151        uint32_t eventq_irq_cfg1; // 0x00b8
152        uint32_t eventq_irq_cfg2; // 0x00bc
153        uint64_t priq_base;       // 0x00c0, 64 bit
154        uint32_t _pad10;          // 0x00c8
155        uint32_t _pad11;          // 0x00cc
156
157        uint64_t priq_irq_cfg0;   // 0x00d0
158        uint32_t priq_irq_cfg1;   // 0x00d8
159        uint32_t priq_irq_cfg2;   // 0x00dc
160
161        uint32_t _pad12[8];       // 0x00e0 - 0x0100
162        uint32_t gatos_ctrl;      // 0x0100
163        uint32_t _pad13;          // 0x0104
164        uint64_t gatos_sid;       // 0x0108
165        uint64_t gatos_addr;      // 0x0110
166        uint64_t gatos_par;       // 0x0118
167        uint32_t _pad14[24];      // 0x0120
168        uint32_t vatos_sel;       // 0x0180
169
170        uint32_t _pad15[8095];    // 0x184 - 0x7ffc
171
172        uint8_t  _secure_regs[SMMU_SECURE_SZ]; // 0x8000 - 0x8180
173
174        uint32_t _pad16[8095];    // 0x8184 - 0x10000
175
176        // Page 1
177        uint32_t _pad17[42];      // 0x10000
178        uint32_t eventq_prod;     // 0x100A8
179        uint32_t eventq_cons;     // 0x100AC
180
181        uint32_t _pad18[6];       // 0x100B0
182        uint32_t priq_prod;       // 0x100C8
183        uint32_t priq_cons;       // 0x100CC
184    };
185};
186
187struct StreamTableEntry
188{
189    BitUnion64(DWORD0)
190        Bitfield<0>       valid;
191        Bitfield<3, 1>    config;
192        Bitfield<5, 4>    s1fmt;
193        Bitfield<51, 6>   s1ctxptr;
194        Bitfield<63, 59>  s1cdmax;
195    EndBitUnion(DWORD0)
196    DWORD0 dw0;
197
198    BitUnion64(DWORD1)
199        Bitfield<1, 0>   s1dss;
200        Bitfield<3, 2>   s1cir;
201        Bitfield<5, 4>   s1cor;
202        Bitfield<7, 6>   s1csh;
203        Bitfield<8>      s2hwu59;
204        Bitfield<9>      s2hwu60;
205        Bitfield<10>     s2hwu61;
206        Bitfield<11>     s2hwu62;
207        Bitfield<12>     dre;
208        Bitfield<16, 13> cont;
209        Bitfield<17>     dcp;
210        Bitfield<18>     ppar;
211        Bitfield<19>     mev;
212        Bitfield<27>     s1stalld;
213        Bitfield<29, 28> eats;
214        Bitfield<31, 30> strw;
215        Bitfield<35, 32> memattr;
216        Bitfield<36>     mtcfg;
217        Bitfield<40, 37> alloccfg;
218        Bitfield<45, 44> shcfg;
219        Bitfield<47, 46> nscfg;
220        Bitfield<49, 48> privcfg;
221        Bitfield<51, 50> instcfg;
222    EndBitUnion(DWORD1)
223    DWORD1 dw1;
224
225    BitUnion64(DWORD2)
226        Bitfield<15, 0>  s2vmid;
227        Bitfield<37, 32> s2t0sz;
228        Bitfield<39, 38> s2sl0;
229        Bitfield<41, 40> s2ir0;
230        Bitfield<43, 42> s2or0;
231        Bitfield<45, 44> s2sh0;
232        Bitfield<47, 46> s2tg;
233        Bitfield<50, 48> s2ps;
234        Bitfield<51>     s2aa64;
235        Bitfield<52>     s2endi;
236        Bitfield<53>     s2affd;
237        Bitfield<54>     s2ptw;
238        Bitfield<55>     s2hd;
239        Bitfield<56>     s2ha;
240        Bitfield<57>     s2s;
241        Bitfield<58>     s2r;
242    EndBitUnion(DWORD2)
243    DWORD2 dw2;
244
245    BitUnion64(DWORD3)
246        Bitfield<51, 4> s2ttb;
247    EndBitUnion(DWORD3)
248    DWORD3 dw3;
249
250    uint64_t _pad[4];
251};
252
253struct ContextDescriptor
254{
255    BitUnion64(DWORD0)
256        Bitfield<5, 0>   t0sz;
257        Bitfield<7, 6>   tg0;
258        Bitfield<9, 8>   ir0;
259        Bitfield<11, 10> or0;
260        Bitfield<13, 12> sh0;
261        Bitfield<14>     epd0;
262        Bitfield<15>     endi;
263        Bitfield<21, 16> t1sz;
264        Bitfield<23, 22> tg1;
265        Bitfield<25, 24> ir1;
266        Bitfield<27, 26> or1;
267        Bitfield<29, 28> sh1;
268        Bitfield<30>     epd1;
269        Bitfield<31>     valid;
270        Bitfield<34, 32> ips;
271        Bitfield<35>     affd;
272        Bitfield<36>     wxn;
273        Bitfield<37>     uwxn;
274        Bitfield<39, 38> tbi;
275        Bitfield<40>     pan;
276        Bitfield<41>     aa64;
277        Bitfield<42>     hd;
278        Bitfield<43>     ha;
279        Bitfield<44>     s;
280        Bitfield<45>     r;
281        Bitfield<46>     a;
282        Bitfield<47>     aset;
283        Bitfield<63, 48> asid;
284    EndBitUnion(DWORD0)
285    DWORD0 dw0;
286
287    BitUnion64(DWORD1)
288        Bitfield<0>      nscfg0;
289        Bitfield<1>      had0;
290        Bitfield<51, 4>  ttb0;
291        Bitfield<60>     hwu0g59;
292        Bitfield<61>     hwu0g60;
293        Bitfield<62>     hwu0g61;
294        Bitfield<63>     hwu0g62;
295    EndBitUnion(DWORD1)
296    DWORD1 dw1;
297
298    BitUnion64(DWORD2)
299        Bitfield<0>      nscfg1;
300        Bitfield<1>      had1;
301        Bitfield<51, 4>  ttb1;
302        Bitfield<60>     hwu1g59;
303        Bitfield<61>     hwu1g60;
304        Bitfield<62>     hwu1g61;
305        Bitfield<63>     hwu1g62;
306    EndBitUnion(DWORD2)
307    DWORD2 dw2;
308
309    uint64_t mair;
310    uint64_t amair;
311    uint64_t _pad[3];
312};
313
314enum {
315    CR0_SMMUEN_MASK = 0x1,
316    CR0_PRIQEN_MASK = 0x2,
317    CR0_EVENTQEN_MASK = 0x4,
318    CR0_CMDQEN_MASK = 0x8,
319    CR0_ATSCHK_MASK = 0x10,
320    CR0_VMW_MASK = 0x1C0,
321};
322
323enum SMMUCommandType {
324    CMD_PRF_CONFIG     = 0x01,
325    CMD_PRF_ADDR       = 0x02,
326    CMD_CFGI_STE       = 0x03,
327    CMD_CFGI_STE_RANGE = 0x04,
328    CMD_CFGI_CD        = 0x05,
329    CMD_CFGI_CD_ALL    = 0x06,
330    CMD_TLBI_NH_ALL    = 0x10,
331    CMD_TLBI_NH_ASID   = 0x11,
332    CMD_TLBI_NH_VAA    = 0x13,
333    CMD_TLBI_NH_VA     = 0x12,
334    CMD_TLBI_EL3_ALL   = 0x18,
335    CMD_TLBI_EL3_VA    = 0x1A,
336    CMD_TLBI_EL2_ALL   = 0x20,
337    CMD_TLBI_EL2_ASID  = 0x21,
338    CMD_TLBI_EL2_VA    = 0x22,
339    CMD_TLBI_EL2_VAA   = 0x23,
340    CMD_TLBI_S2_IPA    = 0x2a,
341    CMD_TLBI_S12_VMALL = 0x28,
342    CMD_TLBI_NSNH_ALL  = 0x30,
343    CMD_ATC_INV        = 0x40,
344    CMD_PRI_RESP       = 0x41,
345    CMD_RESUME         = 0x44,
346    CMD_STALL_TERM     = 0x45,
347    CMD_SYNC           = 0x46,
348};
349
350struct SMMUCommand
351{
352    BitUnion64(DWORD0)
353        Bitfield<7, 0>   type;
354        Bitfield<10>     ssec;
355        Bitfield<11>     ssv;
356        Bitfield<31, 12> ssid;
357        Bitfield<47, 32> vmid;
358        Bitfield<63, 48> asid;
359        Bitfield<63, 32> sid;
360    EndBitUnion(DWORD0)
361    DWORD0 dw0;
362
363    BitUnion64(DWORD1)
364        Bitfield<0>      leaf;
365        Bitfield<4, 0>   size;
366        Bitfield<4, 0>   range;
367        Bitfield<63, 12> address;
368    EndBitUnion(DWORD1)
369    DWORD1 dw1;
370
371    uint64_t addr() const
372    {
373        uint64_t address = (uint64_t)(dw1.address) << 12;
374        return address;
375    }
376};
377
378enum SMMUEventTypes {
379    EVT_FAULT = 0x0001,
380};
381
382enum SMMUEventFlags {
383    EVF_WRITE = 0x0001,
384};
385
386struct SMMUEvent
387{
388    uint16_t type;
389    uint16_t stag;
390    uint32_t flags;
391    uint32_t streamId;
392    uint32_t substreamId;
393    uint64_t va;
394    uint64_t ipa;
395};
396
397enum {
398    SMMU_MAX_TRANS_ID = 64
399};
400
401#endif /* __DEV_ARM_SMMU_V3_DEFS_HH__ */
402