Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *
0004  * Copyright (C) 2013 Freescale Semiconductor, Inc.
0005  */
0006 
0007 #ifndef __FSL_PAMU_H
0008 #define __FSL_PAMU_H
0009 
0010 #include <linux/iommu.h>
0011 #include <linux/pci.h>
0012 
0013 #include <asm/fsl_pamu_stash.h>
0014 
0015 /* Bit Field macros
0016  *  v = bit field variable; m = mask, m##_SHIFT = shift, x = value to load
0017  */
0018 #define set_bf(v, m, x)     (v = ((v) & ~(m)) | (((x) << m##_SHIFT) & (m)))
0019 #define get_bf(v, m)        (((v) & (m)) >> m##_SHIFT)
0020 
0021 /* PAMU CCSR space */
0022 #define PAMU_PGC 0x00000000     /* Allows all peripheral accesses */
0023 #define PAMU_PE 0x40000000      /* enable PAMU                    */
0024 
0025 /* PAMU_OFFSET to the next pamu space in ccsr */
0026 #define PAMU_OFFSET 0x1000
0027 
0028 #define PAMU_MMAP_REGS_BASE 0
0029 
0030 struct pamu_mmap_regs {
0031     u32 ppbah;
0032     u32 ppbal;
0033     u32 pplah;
0034     u32 pplal;
0035     u32 spbah;
0036     u32 spbal;
0037     u32 splah;
0038     u32 splal;
0039     u32 obah;
0040     u32 obal;
0041     u32 olah;
0042     u32 olal;
0043 };
0044 
0045 /* PAMU Error Registers */
0046 #define PAMU_POES1 0x0040
0047 #define PAMU_POES2 0x0044
0048 #define PAMU_POEAH 0x0048
0049 #define PAMU_POEAL 0x004C
0050 #define PAMU_AVS1  0x0050
0051 #define PAMU_AVS1_AV    0x1
0052 #define PAMU_AVS1_OTV   0x6
0053 #define PAMU_AVS1_APV   0x78
0054 #define PAMU_AVS1_WAV   0x380
0055 #define PAMU_AVS1_LAV   0x1c00
0056 #define PAMU_AVS1_GCV   0x2000
0057 #define PAMU_AVS1_PDV   0x4000
0058 #define PAMU_AV_MASK    (PAMU_AVS1_AV | PAMU_AVS1_OTV | PAMU_AVS1_APV | PAMU_AVS1_WAV \
0059              | PAMU_AVS1_LAV | PAMU_AVS1_GCV | PAMU_AVS1_PDV)
0060 #define PAMU_AVS1_LIODN_SHIFT 16
0061 #define PAMU_LAV_LIODN_NOT_IN_PPAACT 0x400
0062 
0063 #define PAMU_AVS2  0x0054
0064 #define PAMU_AVAH  0x0058
0065 #define PAMU_AVAL  0x005C
0066 #define PAMU_EECTL 0x0060
0067 #define PAMU_EEDIS 0x0064
0068 #define PAMU_EEINTEN 0x0068
0069 #define PAMU_EEDET 0x006C
0070 #define PAMU_EEATTR 0x0070
0071 #define PAMU_EEAHI 0x0074
0072 #define PAMU_EEALO 0x0078
0073 #define PAMU_EEDHI 0X007C
0074 #define PAMU_EEDLO 0x0080
0075 #define PAMU_EECC  0x0084
0076 #define PAMU_UDAD  0x0090
0077 
0078 /* PAMU Revision Registers */
0079 #define PAMU_PR1 0x0BF8
0080 #define PAMU_PR2 0x0BFC
0081 
0082 /* PAMU version mask */
0083 #define PAMU_PR1_MASK 0xffff
0084 
0085 /* PAMU Capabilities Registers */
0086 #define PAMU_PC1 0x0C00
0087 #define PAMU_PC2 0x0C04
0088 #define PAMU_PC3 0x0C08
0089 #define PAMU_PC4 0x0C0C
0090 
0091 /* PAMU Control Register */
0092 #define PAMU_PC 0x0C10
0093 
0094 /* PAMU control defs */
0095 #define PAMU_CONTROL 0x0C10
0096 #define PAMU_PC_PGC 0x80000000  /* PAMU gate closed bit */
0097 #define PAMU_PC_PE   0x40000000 /* PAMU enable bit */
0098 #define PAMU_PC_SPCC 0x00000010 /* sPAACE cache enable */
0099 #define PAMU_PC_PPCC 0x00000001 /* pPAACE cache enable */
0100 #define PAMU_PC_OCE  0x00001000 /* OMT cache enable */
0101 
0102 #define PAMU_PFA1 0x0C14
0103 #define PAMU_PFA2 0x0C18
0104 
0105 #define PAMU_PC2_MLIODN(X) ((X) >> 16)
0106 #define PAMU_PC3_MWCE(X) (((X) >> 21) & 0xf)
0107 
0108 /* PAMU Interrupt control and Status Register */
0109 #define PAMU_PICS 0x0C1C
0110 #define PAMU_ACCESS_VIOLATION_STAT   0x8
0111 #define PAMU_ACCESS_VIOLATION_ENABLE 0x4
0112 
0113 /* PAMU Debug Registers */
0114 #define PAMU_PD1 0x0F00
0115 #define PAMU_PD2 0x0F04
0116 #define PAMU_PD3 0x0F08
0117 #define PAMU_PD4 0x0F0C
0118 
0119 #define PAACE_AP_PERMS_DENIED  0x0
0120 #define PAACE_AP_PERMS_QUERY   0x1
0121 #define PAACE_AP_PERMS_UPDATE  0x2
0122 #define PAACE_AP_PERMS_ALL     0x3
0123 
0124 #define PAACE_DD_TO_HOST       0x0
0125 #define PAACE_DD_TO_IO         0x1
0126 #define PAACE_PT_PRIMARY       0x0
0127 #define PAACE_PT_SECONDARY     0x1
0128 #define PAACE_V_INVALID        0x0
0129 #define PAACE_V_VALID          0x1
0130 #define PAACE_MW_SUBWINDOWS    0x1
0131 
0132 #define PAACE_WSE_4K           0xB
0133 #define PAACE_WSE_8K           0xC
0134 #define PAACE_WSE_16K          0xD
0135 #define PAACE_WSE_32K          0xE
0136 #define PAACE_WSE_64K          0xF
0137 #define PAACE_WSE_128K         0x10
0138 #define PAACE_WSE_256K         0x11
0139 #define PAACE_WSE_512K         0x12
0140 #define PAACE_WSE_1M           0x13
0141 #define PAACE_WSE_2M           0x14
0142 #define PAACE_WSE_4M           0x15
0143 #define PAACE_WSE_8M           0x16
0144 #define PAACE_WSE_16M          0x17
0145 #define PAACE_WSE_32M          0x18
0146 #define PAACE_WSE_64M          0x19
0147 #define PAACE_WSE_128M         0x1A
0148 #define PAACE_WSE_256M         0x1B
0149 #define PAACE_WSE_512M         0x1C
0150 #define PAACE_WSE_1G           0x1D
0151 #define PAACE_WSE_2G           0x1E
0152 #define PAACE_WSE_4G           0x1F
0153 
0154 #define PAACE_DID_PCI_EXPRESS_1 0x00
0155 #define PAACE_DID_PCI_EXPRESS_2 0x01
0156 #define PAACE_DID_PCI_EXPRESS_3 0x02
0157 #define PAACE_DID_PCI_EXPRESS_4 0x03
0158 #define PAACE_DID_LOCAL_BUS     0x04
0159 #define PAACE_DID_SRIO          0x0C
0160 #define PAACE_DID_MEM_1         0x10
0161 #define PAACE_DID_MEM_2         0x11
0162 #define PAACE_DID_MEM_3         0x12
0163 #define PAACE_DID_MEM_4         0x13
0164 #define PAACE_DID_MEM_1_2       0x14
0165 #define PAACE_DID_MEM_3_4       0x15
0166 #define PAACE_DID_MEM_1_4       0x16
0167 #define PAACE_DID_BM_SW_PORTAL  0x18
0168 #define PAACE_DID_PAMU          0x1C
0169 #define PAACE_DID_CAAM          0x21
0170 #define PAACE_DID_QM_SW_PORTAL  0x3C
0171 #define PAACE_DID_CORE0_INST    0x80
0172 #define PAACE_DID_CORE0_DATA    0x81
0173 #define PAACE_DID_CORE1_INST    0x82
0174 #define PAACE_DID_CORE1_DATA    0x83
0175 #define PAACE_DID_CORE2_INST    0x84
0176 #define PAACE_DID_CORE2_DATA    0x85
0177 #define PAACE_DID_CORE3_INST    0x86
0178 #define PAACE_DID_CORE3_DATA    0x87
0179 #define PAACE_DID_CORE4_INST    0x88
0180 #define PAACE_DID_CORE4_DATA    0x89
0181 #define PAACE_DID_CORE5_INST    0x8A
0182 #define PAACE_DID_CORE5_DATA    0x8B
0183 #define PAACE_DID_CORE6_INST    0x8C
0184 #define PAACE_DID_CORE6_DATA    0x8D
0185 #define PAACE_DID_CORE7_INST    0x8E
0186 #define PAACE_DID_CORE7_DATA    0x8F
0187 #define PAACE_DID_BROADCAST     0xFF
0188 
0189 #define PAACE_ATM_NO_XLATE      0x00
0190 #define PAACE_ATM_WINDOW_XLATE  0x01
0191 #define PAACE_ATM_PAGE_XLATE    0x02
0192 #define PAACE_ATM_WIN_PG_XLATE  (PAACE_ATM_WINDOW_XLATE | PAACE_ATM_PAGE_XLATE)
0193 #define PAACE_OTM_NO_XLATE      0x00
0194 #define PAACE_OTM_IMMEDIATE     0x01
0195 #define PAACE_OTM_INDEXED       0x02
0196 #define PAACE_OTM_RESERVED      0x03
0197 
0198 #define PAACE_M_COHERENCE_REQ   0x01
0199 
0200 #define PAACE_PID_0             0x0
0201 #define PAACE_PID_1             0x1
0202 #define PAACE_PID_2             0x2
0203 #define PAACE_PID_3             0x3
0204 #define PAACE_PID_4             0x4
0205 #define PAACE_PID_5             0x5
0206 #define PAACE_PID_6             0x6
0207 #define PAACE_PID_7             0x7
0208 
0209 #define PAACE_TCEF_FORMAT0_8B   0x00
0210 #define PAACE_TCEF_FORMAT1_RSVD 0x01
0211 /*
0212  * Hard coded value for the PAACT size to accommodate
0213  * maximum LIODN value generated by u-boot.
0214  */
0215 #define PAACE_NUMBER_ENTRIES    0x500
0216 /* Hard coded value for the SPAACT size */
0217 #define SPAACE_NUMBER_ENTRIES   0x800
0218 
0219 #define OME_NUMBER_ENTRIES      16
0220 
0221 /* PAACE Bit Field Defines */
0222 #define PPAACE_AF_WBAL          0xfffff000
0223 #define PPAACE_AF_WBAL_SHIFT        12
0224 #define PPAACE_AF_WSE           0x00000fc0
0225 #define PPAACE_AF_WSE_SHIFT     6
0226 #define PPAACE_AF_MW            0x00000020
0227 #define PPAACE_AF_MW_SHIFT      5
0228 
0229 #define SPAACE_AF_LIODN         0xffff0000
0230 #define SPAACE_AF_LIODN_SHIFT       16
0231 
0232 #define PAACE_AF_AP         0x00000018
0233 #define PAACE_AF_AP_SHIFT       3
0234 #define PAACE_AF_DD         0x00000004
0235 #define PAACE_AF_DD_SHIFT       2
0236 #define PAACE_AF_PT         0x00000002
0237 #define PAACE_AF_PT_SHIFT       1
0238 #define PAACE_AF_V          0x00000001
0239 #define PAACE_AF_V_SHIFT        0
0240 
0241 #define PAACE_DA_HOST_CR        0x80
0242 #define PAACE_DA_HOST_CR_SHIFT      7
0243 
0244 #define PAACE_IA_CID            0x00FF0000
0245 #define PAACE_IA_CID_SHIFT      16
0246 #define PAACE_IA_WCE            0x000000F0
0247 #define PAACE_IA_WCE_SHIFT      4
0248 #define PAACE_IA_ATM            0x0000000C
0249 #define PAACE_IA_ATM_SHIFT      2
0250 #define PAACE_IA_OTM            0x00000003
0251 #define PAACE_IA_OTM_SHIFT      0
0252 
0253 #define PAACE_WIN_TWBAL         0xfffff000
0254 #define PAACE_WIN_TWBAL_SHIFT       12
0255 #define PAACE_WIN_SWSE          0x00000fc0
0256 #define PAACE_WIN_SWSE_SHIFT        6
0257 
0258 /* PAMU Data Structures */
0259 /* primary / secondary paact structure */
0260 struct paace {
0261     /* PAACE Offset 0x00 */
0262     u32 wbah;               /* only valid for Primary PAACE */
0263     u32 addr_bitfields;     /* See P/S PAACE_AF_* */
0264 
0265     /* PAACE Offset 0x08 */
0266     /* Interpretation of first 32 bits dependent on DD above */
0267     union {
0268         struct {
0269             /* Destination ID, see PAACE_DID_* defines */
0270             u8 did;
0271             /* Partition ID */
0272             u8 pid;
0273             /* Snoop ID */
0274             u8 snpid;
0275             /* coherency_required : 1 reserved : 7 */
0276             u8 coherency_required; /* See PAACE_DA_* */
0277         } to_host;
0278         struct {
0279             /* Destination ID, see PAACE_DID_* defines */
0280             u8  did;
0281             u8  reserved1;
0282             u16 reserved2;
0283         } to_io;
0284     } domain_attr;
0285 
0286     /* Implementation attributes + window count + address & operation translation modes */
0287     u32 impl_attr;          /* See PAACE_IA_* */
0288 
0289     /* PAACE Offset 0x10 */
0290     /* Translated window base address */
0291     u32 twbah;
0292     u32 win_bitfields;          /* See PAACE_WIN_* */
0293 
0294     /* PAACE Offset 0x18 */
0295     /* first secondary paace entry */
0296     u32 fspi;               /* only valid for Primary PAACE */
0297     union {
0298         struct {
0299             u8 ioea;
0300             u8 moea;
0301             u8 ioeb;
0302             u8 moeb;
0303         } immed_ot;
0304         struct {
0305             u16 reserved;
0306             u16 omi;
0307         } index_ot;
0308     } op_encode;
0309 
0310     /* PAACE Offsets 0x20-0x38 */
0311     u32 reserved[8];            /* not currently implemented */
0312 };
0313 
0314 /* OME : Operation mapping entry
0315  * MOE : Mapped Operation Encodings
0316  * The operation mapping table is table containing operation mapping entries (OME).
0317  * The index of a particular OME is programmed in the PAACE entry for translation
0318  * in bound I/O operations corresponding to an LIODN. The OMT is used for translation
0319  * specifically in case of the indexed translation mode. Each OME contains a 128
0320  * byte mapped operation encoding (MOE), where each byte represents an MOE.
0321  */
0322 #define NUM_MOE 128
0323 struct ome {
0324     u8 moe[NUM_MOE];
0325 } __packed;
0326 
0327 #define PAACT_SIZE              (sizeof(struct paace) * PAACE_NUMBER_ENTRIES)
0328 #define SPAACT_SIZE              (sizeof(struct paace) * SPAACE_NUMBER_ENTRIES)
0329 #define OMT_SIZE                (sizeof(struct ome) * OME_NUMBER_ENTRIES)
0330 
0331 #define PAMU_PAGE_SHIFT 12
0332 #define PAMU_PAGE_SIZE  4096ULL
0333 
0334 #define IOE_READ        0x00
0335 #define IOE_READ_IDX    0x00
0336 #define IOE_WRITE       0x81
0337 #define IOE_WRITE_IDX   0x01
0338 #define IOE_EREAD0      0x82    /* Enhanced read type 0 */
0339 #define IOE_EREAD0_IDX  0x02    /* Enhanced read type 0 */
0340 #define IOE_EWRITE0     0x83    /* Enhanced write type 0 */
0341 #define IOE_EWRITE0_IDX 0x03    /* Enhanced write type 0 */
0342 #define IOE_DIRECT0     0x84    /* Directive type 0 */
0343 #define IOE_DIRECT0_IDX 0x04    /* Directive type 0 */
0344 #define IOE_EREAD1      0x85    /* Enhanced read type 1 */
0345 #define IOE_EREAD1_IDX  0x05    /* Enhanced read type 1 */
0346 #define IOE_EWRITE1     0x86    /* Enhanced write type 1 */
0347 #define IOE_EWRITE1_IDX 0x06    /* Enhanced write type 1 */
0348 #define IOE_DIRECT1     0x87    /* Directive type 1 */
0349 #define IOE_DIRECT1_IDX 0x07    /* Directive type 1 */
0350 #define IOE_RAC         0x8c    /* Read with Atomic clear */
0351 #define IOE_RAC_IDX     0x0c    /* Read with Atomic clear */
0352 #define IOE_RAS         0x8d    /* Read with Atomic set */
0353 #define IOE_RAS_IDX     0x0d    /* Read with Atomic set */
0354 #define IOE_RAD         0x8e    /* Read with Atomic decrement */
0355 #define IOE_RAD_IDX     0x0e    /* Read with Atomic decrement */
0356 #define IOE_RAI         0x8f    /* Read with Atomic increment */
0357 #define IOE_RAI_IDX     0x0f    /* Read with Atomic increment */
0358 
0359 #define EOE_READ        0x00
0360 #define EOE_WRITE       0x01
0361 #define EOE_RAC         0x0c    /* Read with Atomic clear */
0362 #define EOE_RAS         0x0d    /* Read with Atomic set */
0363 #define EOE_RAD         0x0e    /* Read with Atomic decrement */
0364 #define EOE_RAI         0x0f    /* Read with Atomic increment */
0365 #define EOE_LDEC        0x10    /* Load external cache */
0366 #define EOE_LDECL       0x11    /* Load external cache with stash lock */
0367 #define EOE_LDECPE      0x12    /* Load external cache with preferred exclusive */
0368 #define EOE_LDECPEL     0x13    /* Load external cache with preferred exclusive and lock */
0369 #define EOE_LDECFE      0x14    /* Load external cache with forced exclusive */
0370 #define EOE_LDECFEL     0x15    /* Load external cache with forced exclusive and lock */
0371 #define EOE_RSA         0x16    /* Read with stash allocate */
0372 #define EOE_RSAU        0x17    /* Read with stash allocate and unlock */
0373 #define EOE_READI       0x18    /* Read with invalidate */
0374 #define EOE_RWNITC      0x19    /* Read with no intention to cache */
0375 #define EOE_WCI         0x1a    /* Write cache inhibited */
0376 #define EOE_WWSA        0x1b    /* Write with stash allocate */
0377 #define EOE_WWSAL       0x1c    /* Write with stash allocate and lock */
0378 #define EOE_WWSAO       0x1d    /* Write with stash allocate only */
0379 #define EOE_WWSAOL      0x1e    /* Write with stash allocate only and lock */
0380 #define EOE_VALID       0x80
0381 
0382 /* Function prototypes */
0383 int pamu_domain_init(void);
0384 int pamu_enable_liodn(int liodn);
0385 int pamu_disable_liodn(int liodn);
0386 int pamu_config_ppaace(int liodn, u32 omi, uint32_t stashid, int prot);
0387 
0388 u32 get_stash_id(u32 stash_dest_hint, u32 vcpu);
0389 void get_ome_index(u32 *omi_index, struct device *dev);
0390 int  pamu_update_paace_stash(int liodn, u32 value);
0391 
0392 #endif  /* __FSL_PAMU_H */