fsl_pamu.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright (C) 2013 Freescale Semiconductor, Inc.
  16. *
  17. */
  18. #ifndef __FSL_PAMU_H
  19. #define __FSL_PAMU_H
  20. #include <linux/iommu.h>
  21. #include <asm/fsl_pamu_stash.h>
  22. /* Bit Field macros
  23. * v = bit field variable; m = mask, m##_SHIFT = shift, x = value to load
  24. */
  25. #define set_bf(v, m, x) (v = ((v) & ~(m)) | (((x) << m##_SHIFT) & (m)))
  26. #define get_bf(v, m) (((v) & (m)) >> m##_SHIFT)
  27. /* PAMU CCSR space */
  28. #define PAMU_PGC 0x00000000 /* Allows all peripheral accesses */
  29. #define PAMU_PE 0x40000000 /* enable PAMU */
  30. /* PAMU_OFFSET to the next pamu space in ccsr */
  31. #define PAMU_OFFSET 0x1000
  32. #define PAMU_MMAP_REGS_BASE 0
  33. struct pamu_mmap_regs {
  34. u32 ppbah;
  35. u32 ppbal;
  36. u32 pplah;
  37. u32 pplal;
  38. u32 spbah;
  39. u32 spbal;
  40. u32 splah;
  41. u32 splal;
  42. u32 obah;
  43. u32 obal;
  44. u32 olah;
  45. u32 olal;
  46. };
  47. /* PAMU Error Registers */
  48. #define PAMU_POES1 0x0040
  49. #define PAMU_POES2 0x0044
  50. #define PAMU_POEAH 0x0048
  51. #define PAMU_POEAL 0x004C
  52. #define PAMU_AVS1 0x0050
  53. #define PAMU_AVS1_AV 0x1
  54. #define PAMU_AVS1_OTV 0x6
  55. #define PAMU_AVS1_APV 0x78
  56. #define PAMU_AVS1_WAV 0x380
  57. #define PAMU_AVS1_LAV 0x1c00
  58. #define PAMU_AVS1_GCV 0x2000
  59. #define PAMU_AVS1_PDV 0x4000
  60. #define PAMU_AV_MASK (PAMU_AVS1_AV | PAMU_AVS1_OTV | PAMU_AVS1_APV | PAMU_AVS1_WAV \
  61. | PAMU_AVS1_LAV | PAMU_AVS1_GCV | PAMU_AVS1_PDV)
  62. #define PAMU_AVS1_LIODN_SHIFT 16
  63. #define PAMU_LAV_LIODN_NOT_IN_PPAACT 0x400
  64. #define PAMU_AVS2 0x0054
  65. #define PAMU_AVAH 0x0058
  66. #define PAMU_AVAL 0x005C
  67. #define PAMU_EECTL 0x0060
  68. #define PAMU_EEDIS 0x0064
  69. #define PAMU_EEINTEN 0x0068
  70. #define PAMU_EEDET 0x006C
  71. #define PAMU_EEATTR 0x0070
  72. #define PAMU_EEAHI 0x0074
  73. #define PAMU_EEALO 0x0078
  74. #define PAMU_EEDHI 0X007C
  75. #define PAMU_EEDLO 0x0080
  76. #define PAMU_EECC 0x0084
  77. #define PAMU_UDAD 0x0090
  78. /* PAMU Revision Registers */
  79. #define PAMU_PR1 0x0BF8
  80. #define PAMU_PR2 0x0BFC
  81. /* PAMU version mask */
  82. #define PAMU_PR1_MASK 0xffff
  83. /* PAMU Capabilities Registers */
  84. #define PAMU_PC1 0x0C00
  85. #define PAMU_PC2 0x0C04
  86. #define PAMU_PC3 0x0C08
  87. #define PAMU_PC4 0x0C0C
  88. /* PAMU Control Register */
  89. #define PAMU_PC 0x0C10
  90. /* PAMU control defs */
  91. #define PAMU_CONTROL 0x0C10
  92. #define PAMU_PC_PGC 0x80000000 /* PAMU gate closed bit */
  93. #define PAMU_PC_PE 0x40000000 /* PAMU enable bit */
  94. #define PAMU_PC_SPCC 0x00000010 /* sPAACE cache enable */
  95. #define PAMU_PC_PPCC 0x00000001 /* pPAACE cache enable */
  96. #define PAMU_PC_OCE 0x00001000 /* OMT cache enable */
  97. #define PAMU_PFA1 0x0C14
  98. #define PAMU_PFA2 0x0C18
  99. #define PAMU_PC2_MLIODN(X) ((X) >> 16)
  100. #define PAMU_PC3_MWCE(X) (((X) >> 21) & 0xf)
  101. /* PAMU Interrupt control and Status Register */
  102. #define PAMU_PICS 0x0C1C
  103. #define PAMU_ACCESS_VIOLATION_STAT 0x8
  104. #define PAMU_ACCESS_VIOLATION_ENABLE 0x4
  105. /* PAMU Debug Registers */
  106. #define PAMU_PD1 0x0F00
  107. #define PAMU_PD2 0x0F04
  108. #define PAMU_PD3 0x0F08
  109. #define PAMU_PD4 0x0F0C
  110. #define PAACE_AP_PERMS_DENIED 0x0
  111. #define PAACE_AP_PERMS_QUERY 0x1
  112. #define PAACE_AP_PERMS_UPDATE 0x2
  113. #define PAACE_AP_PERMS_ALL 0x3
  114. #define PAACE_DD_TO_HOST 0x0
  115. #define PAACE_DD_TO_IO 0x1
  116. #define PAACE_PT_PRIMARY 0x0
  117. #define PAACE_PT_SECONDARY 0x1
  118. #define PAACE_V_INVALID 0x0
  119. #define PAACE_V_VALID 0x1
  120. #define PAACE_MW_SUBWINDOWS 0x1
  121. #define PAACE_WSE_4K 0xB
  122. #define PAACE_WSE_8K 0xC
  123. #define PAACE_WSE_16K 0xD
  124. #define PAACE_WSE_32K 0xE
  125. #define PAACE_WSE_64K 0xF
  126. #define PAACE_WSE_128K 0x10
  127. #define PAACE_WSE_256K 0x11
  128. #define PAACE_WSE_512K 0x12
  129. #define PAACE_WSE_1M 0x13
  130. #define PAACE_WSE_2M 0x14
  131. #define PAACE_WSE_4M 0x15
  132. #define PAACE_WSE_8M 0x16
  133. #define PAACE_WSE_16M 0x17
  134. #define PAACE_WSE_32M 0x18
  135. #define PAACE_WSE_64M 0x19
  136. #define PAACE_WSE_128M 0x1A
  137. #define PAACE_WSE_256M 0x1B
  138. #define PAACE_WSE_512M 0x1C
  139. #define PAACE_WSE_1G 0x1D
  140. #define PAACE_WSE_2G 0x1E
  141. #define PAACE_WSE_4G 0x1F
  142. #define PAACE_DID_PCI_EXPRESS_1 0x00
  143. #define PAACE_DID_PCI_EXPRESS_2 0x01
  144. #define PAACE_DID_PCI_EXPRESS_3 0x02
  145. #define PAACE_DID_PCI_EXPRESS_4 0x03
  146. #define PAACE_DID_LOCAL_BUS 0x04
  147. #define PAACE_DID_SRIO 0x0C
  148. #define PAACE_DID_MEM_1 0x10
  149. #define PAACE_DID_MEM_2 0x11
  150. #define PAACE_DID_MEM_3 0x12
  151. #define PAACE_DID_MEM_4 0x13
  152. #define PAACE_DID_MEM_1_2 0x14
  153. #define PAACE_DID_MEM_3_4 0x15
  154. #define PAACE_DID_MEM_1_4 0x16
  155. #define PAACE_DID_BM_SW_PORTAL 0x18
  156. #define PAACE_DID_PAMU 0x1C
  157. #define PAACE_DID_CAAM 0x21
  158. #define PAACE_DID_QM_SW_PORTAL 0x3C
  159. #define PAACE_DID_CORE0_INST 0x80
  160. #define PAACE_DID_CORE0_DATA 0x81
  161. #define PAACE_DID_CORE1_INST 0x82
  162. #define PAACE_DID_CORE1_DATA 0x83
  163. #define PAACE_DID_CORE2_INST 0x84
  164. #define PAACE_DID_CORE2_DATA 0x85
  165. #define PAACE_DID_CORE3_INST 0x86
  166. #define PAACE_DID_CORE3_DATA 0x87
  167. #define PAACE_DID_CORE4_INST 0x88
  168. #define PAACE_DID_CORE4_DATA 0x89
  169. #define PAACE_DID_CORE5_INST 0x8A
  170. #define PAACE_DID_CORE5_DATA 0x8B
  171. #define PAACE_DID_CORE6_INST 0x8C
  172. #define PAACE_DID_CORE6_DATA 0x8D
  173. #define PAACE_DID_CORE7_INST 0x8E
  174. #define PAACE_DID_CORE7_DATA 0x8F
  175. #define PAACE_DID_BROADCAST 0xFF
  176. #define PAACE_ATM_NO_XLATE 0x00
  177. #define PAACE_ATM_WINDOW_XLATE 0x01
  178. #define PAACE_ATM_PAGE_XLATE 0x02
  179. #define PAACE_ATM_WIN_PG_XLATE (PAACE_ATM_WINDOW_XLATE | PAACE_ATM_PAGE_XLATE)
  180. #define PAACE_OTM_NO_XLATE 0x00
  181. #define PAACE_OTM_IMMEDIATE 0x01
  182. #define PAACE_OTM_INDEXED 0x02
  183. #define PAACE_OTM_RESERVED 0x03
  184. #define PAACE_M_COHERENCE_REQ 0x01
  185. #define PAACE_PID_0 0x0
  186. #define PAACE_PID_1 0x1
  187. #define PAACE_PID_2 0x2
  188. #define PAACE_PID_3 0x3
  189. #define PAACE_PID_4 0x4
  190. #define PAACE_PID_5 0x5
  191. #define PAACE_PID_6 0x6
  192. #define PAACE_PID_7 0x7
  193. #define PAACE_TCEF_FORMAT0_8B 0x00
  194. #define PAACE_TCEF_FORMAT1_RSVD 0x01
  195. /*
  196. * Hard coded value for the PAACT size to accommodate
  197. * maximum LIODN value generated by u-boot.
  198. */
  199. #define PAACE_NUMBER_ENTRIES 0x500
  200. /* Hard coded value for the SPAACT size */
  201. #define SPAACE_NUMBER_ENTRIES 0x800
  202. #define OME_NUMBER_ENTRIES 16
  203. /* PAACE Bit Field Defines */
  204. #define PPAACE_AF_WBAL 0xfffff000
  205. #define PPAACE_AF_WBAL_SHIFT 12
  206. #define PPAACE_AF_WSE 0x00000fc0
  207. #define PPAACE_AF_WSE_SHIFT 6
  208. #define PPAACE_AF_MW 0x00000020
  209. #define PPAACE_AF_MW_SHIFT 5
  210. #define SPAACE_AF_LIODN 0xffff0000
  211. #define SPAACE_AF_LIODN_SHIFT 16
  212. #define PAACE_AF_AP 0x00000018
  213. #define PAACE_AF_AP_SHIFT 3
  214. #define PAACE_AF_DD 0x00000004
  215. #define PAACE_AF_DD_SHIFT 2
  216. #define PAACE_AF_PT 0x00000002
  217. #define PAACE_AF_PT_SHIFT 1
  218. #define PAACE_AF_V 0x00000001
  219. #define PAACE_AF_V_SHIFT 0
  220. #define PAACE_DA_HOST_CR 0x80
  221. #define PAACE_DA_HOST_CR_SHIFT 7
  222. #define PAACE_IA_CID 0x00FF0000
  223. #define PAACE_IA_CID_SHIFT 16
  224. #define PAACE_IA_WCE 0x000000F0
  225. #define PAACE_IA_WCE_SHIFT 4
  226. #define PAACE_IA_ATM 0x0000000C
  227. #define PAACE_IA_ATM_SHIFT 2
  228. #define PAACE_IA_OTM 0x00000003
  229. #define PAACE_IA_OTM_SHIFT 0
  230. #define PAACE_WIN_TWBAL 0xfffff000
  231. #define PAACE_WIN_TWBAL_SHIFT 12
  232. #define PAACE_WIN_SWSE 0x00000fc0
  233. #define PAACE_WIN_SWSE_SHIFT 6
  234. /* PAMU Data Structures */
  235. /* primary / secondary paact structure */
  236. struct paace {
  237. /* PAACE Offset 0x00 */
  238. u32 wbah; /* only valid for Primary PAACE */
  239. u32 addr_bitfields; /* See P/S PAACE_AF_* */
  240. /* PAACE Offset 0x08 */
  241. /* Interpretation of first 32 bits dependent on DD above */
  242. union {
  243. struct {
  244. /* Destination ID, see PAACE_DID_* defines */
  245. u8 did;
  246. /* Partition ID */
  247. u8 pid;
  248. /* Snoop ID */
  249. u8 snpid;
  250. /* coherency_required : 1 reserved : 7 */
  251. u8 coherency_required; /* See PAACE_DA_* */
  252. } to_host;
  253. struct {
  254. /* Destination ID, see PAACE_DID_* defines */
  255. u8 did;
  256. u8 reserved1;
  257. u16 reserved2;
  258. } to_io;
  259. } domain_attr;
  260. /* Implementation attributes + window count + address & operation translation modes */
  261. u32 impl_attr; /* See PAACE_IA_* */
  262. /* PAACE Offset 0x10 */
  263. /* Translated window base address */
  264. u32 twbah;
  265. u32 win_bitfields; /* See PAACE_WIN_* */
  266. /* PAACE Offset 0x18 */
  267. /* first secondary paace entry */
  268. u32 fspi; /* only valid for Primary PAACE */
  269. union {
  270. struct {
  271. u8 ioea;
  272. u8 moea;
  273. u8 ioeb;
  274. u8 moeb;
  275. } immed_ot;
  276. struct {
  277. u16 reserved;
  278. u16 omi;
  279. } index_ot;
  280. } op_encode;
  281. /* PAACE Offsets 0x20-0x38 */
  282. u32 reserved[8]; /* not currently implemented */
  283. };
  284. /* OME : Operation mapping entry
  285. * MOE : Mapped Operation Encodings
  286. * The operation mapping table is table containing operation mapping entries (OME).
  287. * The index of a particular OME is programmed in the PAACE entry for translation
  288. * in bound I/O operations corresponding to an LIODN. The OMT is used for translation
  289. * specifically in case of the indexed translation mode. Each OME contains a 128
  290. * byte mapped operation encoding (MOE), where each byte represents an MOE.
  291. */
  292. #define NUM_MOE 128
  293. struct ome {
  294. u8 moe[NUM_MOE];
  295. } __packed;
  296. #define PAACT_SIZE (sizeof(struct paace) * PAACE_NUMBER_ENTRIES)
  297. #define SPAACT_SIZE (sizeof(struct paace) * SPAACE_NUMBER_ENTRIES)
  298. #define OMT_SIZE (sizeof(struct ome) * OME_NUMBER_ENTRIES)
  299. #define PAMU_PAGE_SHIFT 12
  300. #define PAMU_PAGE_SIZE 4096ULL
  301. #define IOE_READ 0x00
  302. #define IOE_READ_IDX 0x00
  303. #define IOE_WRITE 0x81
  304. #define IOE_WRITE_IDX 0x01
  305. #define IOE_EREAD0 0x82 /* Enhanced read type 0 */
  306. #define IOE_EREAD0_IDX 0x02 /* Enhanced read type 0 */
  307. #define IOE_EWRITE0 0x83 /* Enhanced write type 0 */
  308. #define IOE_EWRITE0_IDX 0x03 /* Enhanced write type 0 */
  309. #define IOE_DIRECT0 0x84 /* Directive type 0 */
  310. #define IOE_DIRECT0_IDX 0x04 /* Directive type 0 */
  311. #define IOE_EREAD1 0x85 /* Enhanced read type 1 */
  312. #define IOE_EREAD1_IDX 0x05 /* Enhanced read type 1 */
  313. #define IOE_EWRITE1 0x86 /* Enhanced write type 1 */
  314. #define IOE_EWRITE1_IDX 0x06 /* Enhanced write type 1 */
  315. #define IOE_DIRECT1 0x87 /* Directive type 1 */
  316. #define IOE_DIRECT1_IDX 0x07 /* Directive type 1 */
  317. #define IOE_RAC 0x8c /* Read with Atomic clear */
  318. #define IOE_RAC_IDX 0x0c /* Read with Atomic clear */
  319. #define IOE_RAS 0x8d /* Read with Atomic set */
  320. #define IOE_RAS_IDX 0x0d /* Read with Atomic set */
  321. #define IOE_RAD 0x8e /* Read with Atomic decrement */
  322. #define IOE_RAD_IDX 0x0e /* Read with Atomic decrement */
  323. #define IOE_RAI 0x8f /* Read with Atomic increment */
  324. #define IOE_RAI_IDX 0x0f /* Read with Atomic increment */
  325. #define EOE_READ 0x00
  326. #define EOE_WRITE 0x01
  327. #define EOE_RAC 0x0c /* Read with Atomic clear */
  328. #define EOE_RAS 0x0d /* Read with Atomic set */
  329. #define EOE_RAD 0x0e /* Read with Atomic decrement */
  330. #define EOE_RAI 0x0f /* Read with Atomic increment */
  331. #define EOE_LDEC 0x10 /* Load external cache */
  332. #define EOE_LDECL 0x11 /* Load external cache with stash lock */
  333. #define EOE_LDECPE 0x12 /* Load external cache with preferred exclusive */
  334. #define EOE_LDECPEL 0x13 /* Load external cache with preferred exclusive and lock */
  335. #define EOE_LDECFE 0x14 /* Load external cache with forced exclusive */
  336. #define EOE_LDECFEL 0x15 /* Load external cache with forced exclusive and lock */
  337. #define EOE_RSA 0x16 /* Read with stash allocate */
  338. #define EOE_RSAU 0x17 /* Read with stash allocate and unlock */
  339. #define EOE_READI 0x18 /* Read with invalidate */
  340. #define EOE_RWNITC 0x19 /* Read with no intention to cache */
  341. #define EOE_WCI 0x1a /* Write cache inhibited */
  342. #define EOE_WWSA 0x1b /* Write with stash allocate */
  343. #define EOE_WWSAL 0x1c /* Write with stash allocate and lock */
  344. #define EOE_WWSAO 0x1d /* Write with stash allocate only */
  345. #define EOE_WWSAOL 0x1e /* Write with stash allocate only and lock */
  346. #define EOE_VALID 0x80
  347. /* Function prototypes */
  348. int pamu_domain_init(void);
  349. int pamu_enable_liodn(int liodn);
  350. int pamu_disable_liodn(int liodn);
  351. void pamu_free_subwins(int liodn);
  352. int pamu_config_ppaace(int liodn, phys_addr_t win_addr, phys_addr_t win_size,
  353. u32 omi, unsigned long rpn, u32 snoopid, uint32_t stashid,
  354. u32 subwin_cnt, int prot);
  355. int pamu_config_spaace(int liodn, u32 subwin_cnt, u32 subwin_addr,
  356. phys_addr_t subwin_size, u32 omi, unsigned long rpn,
  357. uint32_t snoopid, u32 stashid, int enable, int prot);
  358. u32 get_stash_id(u32 stash_dest_hint, u32 vcpu);
  359. void get_ome_index(u32 *omi_index, struct device *dev);
  360. int pamu_update_paace_stash(int liodn, u32 subwin, u32 value);
  361. int pamu_disable_spaace(int liodn, u32 subwin);
  362. u32 pamu_get_max_subwin_cnt(void);
  363. #endif /* __FSL_PAMU_H */