Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 2 | /* |
Dipen Dudhat | 00c4294 | 2011-01-20 16:29:35 +0530 | [diff] [blame] | 3 | * Copyright 2008-2011 Freescale Semiconductor, Inc. |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 6 | #ifndef _FSL_LAW_H_ |
| 7 | #define _FSL_LAW_H_ |
| 8 | |
| 9 | #include <asm/io.h> |
Fabio Estevam | 1a03a7e | 2015-11-05 12:43:40 -0200 | [diff] [blame] | 10 | #include <linux/log2.h> |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 11 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 12 | #define LAW_EN 0x80000000 |
| 13 | |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 14 | #define SET_LAW_ENTRY(idx, a, sz, trgt) \ |
| 15 | { .index = idx, .addr = a, .size = sz, .trgt_id = trgt } |
| 16 | |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 17 | #define SET_LAW(a, sz, trgt) \ |
| 18 | { .index = -1, .addr = a, .size = sz, .trgt_id = trgt } |
| 19 | |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 20 | enum law_size { |
| 21 | LAW_SIZE_4K = 0xb, |
| 22 | LAW_SIZE_8K, |
| 23 | LAW_SIZE_16K, |
| 24 | LAW_SIZE_32K, |
| 25 | LAW_SIZE_64K, |
| 26 | LAW_SIZE_128K, |
| 27 | LAW_SIZE_256K, |
| 28 | LAW_SIZE_512K, |
| 29 | LAW_SIZE_1M, |
| 30 | LAW_SIZE_2M, |
| 31 | LAW_SIZE_4M, |
| 32 | LAW_SIZE_8M, |
| 33 | LAW_SIZE_16M, |
| 34 | LAW_SIZE_32M, |
| 35 | LAW_SIZE_64M, |
| 36 | LAW_SIZE_128M, |
| 37 | LAW_SIZE_256M, |
| 38 | LAW_SIZE_512M, |
| 39 | LAW_SIZE_1G, |
| 40 | LAW_SIZE_2G, |
| 41 | LAW_SIZE_4G, |
| 42 | LAW_SIZE_8G, |
| 43 | LAW_SIZE_16G, |
| 44 | LAW_SIZE_32G, |
| 45 | }; |
| 46 | |
Li Yang | 019b293 | 2009-12-09 14:26:08 +0800 | [diff] [blame] | 47 | #define law_size_bits(sz) (__ilog2_u64(sz) - 1) |
Becky Bruce | eb891f0 | 2010-06-17 11:37:23 -0500 | [diff] [blame] | 48 | #define lawar_size(x) (1ULL << ((x & 0x3f) + 1)) |
Li Yang | 019b293 | 2009-12-09 14:26:08 +0800 | [diff] [blame] | 49 | |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 50 | #ifdef CONFIG_FSL_CORENET |
| 51 | enum law_trgt_if { |
| 52 | LAW_TRGT_IF_PCIE_1 = 0x00, |
| 53 | LAW_TRGT_IF_PCIE_2 = 0x01, |
| 54 | LAW_TRGT_IF_PCIE_3 = 0x02, |
Kumar Gala | 74e78b6 | 2010-04-28 04:02:21 -0500 | [diff] [blame] | 55 | LAW_TRGT_IF_PCIE_4 = 0x03, |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 56 | LAW_TRGT_IF_RIO_1 = 0x08, |
| 57 | LAW_TRGT_IF_RIO_2 = 0x09, |
| 58 | |
| 59 | LAW_TRGT_IF_DDR_1 = 0x10, |
| 60 | LAW_TRGT_IF_DDR_2 = 0x11, /* 2nd controller */ |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 61 | LAW_TRGT_IF_DDR_3 = 0x12, |
| 62 | LAW_TRGT_IF_DDR_4 = 0x13, |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 63 | LAW_TRGT_IF_DDR_INTRLV = 0x14, |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 64 | LAW_TRGT_IF_DDR_INTLV_34 = 0x15, |
| 65 | LAW_TRGT_IF_DDR_INTLV_123 = 0x17, |
| 66 | LAW_TRGT_IF_DDR_INTLV_1234 = 0x16, |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 67 | LAW_TRGT_IF_BMAN = 0x18, |
| 68 | LAW_TRGT_IF_DCSR = 0x1d, |
Sandeep Singh | 4fb16a1 | 2014-06-05 18:49:57 +0530 | [diff] [blame] | 69 | LAW_TRGT_IF_CCSR = 0x1e, |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 70 | LAW_TRGT_IF_LBC = 0x1f, |
| 71 | LAW_TRGT_IF_QMAN = 0x3c, |
Shaveta Leekha | 43e0f7b | 2013-03-25 07:40:24 +0000 | [diff] [blame] | 72 | |
| 73 | LAW_TRGT_IF_MAPLE = 0x50, |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 74 | }; |
| 75 | #define LAW_TRGT_IF_DDR LAW_TRGT_IF_DDR_1 |
Prabhakar Kushwaha | 4fc2aac | 2012-08-15 06:24:15 +0000 | [diff] [blame] | 76 | #define LAW_TRGT_IF_IFC LAW_TRGT_IF_LBC |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 77 | #else |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 78 | enum law_trgt_if { |
| 79 | LAW_TRGT_IF_PCI = 0x00, |
| 80 | LAW_TRGT_IF_PCI_2 = 0x01, |
Pali Rohár | a8d9e6e | 2022-05-01 17:45:58 +0200 | [diff] [blame] | 81 | LAW_TRGT_IF_PCIE_1 = 0x02, |
York Sun | a80bdf7 | 2016-11-15 14:09:50 -0800 | [diff] [blame] | 82 | #if defined(CONFIG_ARCH_BSC9131) || defined(CONFIG_ARCH_BSC9132) |
Priyanka Jain | f81e8b2 | 2013-04-04 09:31:54 +0530 | [diff] [blame] | 83 | LAW_TRGT_IF_OCN_DSP = 0x03, |
| 84 | #else |
Tom Rini | e1ef708 | 2021-05-14 21:34:25 -0400 | [diff] [blame] | 85 | #if !defined(CONFIG_ARCH_P2020) |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 86 | LAW_TRGT_IF_PCIE_3 = 0x03, |
| 87 | #endif |
Priyanka Jain | f81e8b2 | 2013-04-04 09:31:54 +0530 | [diff] [blame] | 88 | #endif |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 89 | LAW_TRGT_IF_LBC = 0x04, |
| 90 | LAW_TRGT_IF_CCSR = 0x08, |
Priyanka Jain | f81e8b2 | 2013-04-04 09:31:54 +0530 | [diff] [blame] | 91 | LAW_TRGT_IF_DSP_CCSR = 0x09, |
Mingkai Hu | 1a25807 | 2013-07-04 17:30:36 +0800 | [diff] [blame] | 92 | LAW_TRGT_IF_PLATFORM_SRAM = 0x0a, |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 93 | LAW_TRGT_IF_DDR_INTRLV = 0x0b, |
| 94 | LAW_TRGT_IF_RIO = 0x0c, |
York Sun | a80bdf7 | 2016-11-15 14:09:50 -0800 | [diff] [blame] | 95 | #if defined(CONFIG_ARCH_BSC9132) |
Priyanka Jain | c73b903 | 2013-07-02 09:21:04 +0530 | [diff] [blame] | 96 | LAW_TRGT_IF_CLASS_DSP = 0x0d, |
| 97 | #else |
Li Yang | 019b293 | 2009-12-09 14:26:08 +0800 | [diff] [blame] | 98 | LAW_TRGT_IF_RIO_2 = 0x0d, |
Priyanka Jain | c73b903 | 2013-07-02 09:21:04 +0530 | [diff] [blame] | 99 | #endif |
Roy Zang | 1de20b0 | 2011-02-03 22:14:19 -0600 | [diff] [blame] | 100 | LAW_TRGT_IF_DPAA_SWP_SRAM = 0x0e, |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 101 | LAW_TRGT_IF_DDR = 0x0f, |
| 102 | LAW_TRGT_IF_DDR_2 = 0x16, /* 2nd controller */ |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 103 | /* place holder for 3-way and 4-way interleaving */ |
| 104 | LAW_TRGT_IF_DDR_3, |
| 105 | LAW_TRGT_IF_DDR_4, |
| 106 | LAW_TRGT_IF_DDR_INTLV_34, |
| 107 | LAW_TRGT_IF_DDR_INTLV_123, |
| 108 | LAW_TRGT_IF_DDR_INTLV_1234, |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 109 | }; |
| 110 | #define LAW_TRGT_IF_DDR_1 LAW_TRGT_IF_DDR |
| 111 | #define LAW_TRGT_IF_PCI_1 LAW_TRGT_IF_PCI |
| 112 | #define LAW_TRGT_IF_PCIX LAW_TRGT_IF_PCI |
| 113 | #define LAW_TRGT_IF_PCIE_2 LAW_TRGT_IF_PCI_2 |
Kumar Gala | 8975d7a | 2010-12-30 12:09:53 -0600 | [diff] [blame] | 114 | #define LAW_TRGT_IF_RIO_1 LAW_TRGT_IF_RIO |
Dipen Dudhat | 00c4294 | 2011-01-20 16:29:35 +0530 | [diff] [blame] | 115 | #define LAW_TRGT_IF_IFC LAW_TRGT_IF_LBC |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 116 | |
Tom Rini | e1ef708 | 2021-05-14 21:34:25 -0400 | [diff] [blame] | 117 | #if defined(CONFIG_ARCH_P2020) |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 118 | #define LAW_TRGT_IF_PCIE_3 LAW_TRGT_IF_PCI |
| 119 | #endif |
Kumar Gala | 65e6c32 | 2009-03-19 02:32:23 -0500 | [diff] [blame] | 120 | #endif /* CONFIG_FSL_CORENET */ |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 121 | |
| 122 | struct law_entry { |
| 123 | int index; |
| 124 | phys_addr_t addr; |
| 125 | enum law_size size; |
| 126 | enum law_trgt_if trgt_id; |
| 127 | }; |
| 128 | |
| 129 | extern void set_law(u8 idx, phys_addr_t addr, enum law_size sz, enum law_trgt_if id); |
Kumar Gala | 75639e0 | 2008-06-11 00:44:10 -0500 | [diff] [blame] | 130 | extern int set_next_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id); |
Kumar Gala | a9abb00 | 2008-06-10 16:16:02 -0500 | [diff] [blame] | 131 | extern int set_last_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id); |
Kumar Gala | 61ed053 | 2008-08-26 15:01:28 -0500 | [diff] [blame] | 132 | extern int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id); |
Pali Rohár | f40662d | 2024-06-06 18:33:23 +0200 | [diff] [blame] | 133 | extern struct law_entry find_law_by_addr_id(phys_addr_t addr, enum law_trgt_if id); |
| 134 | |
| 135 | static inline struct law_entry find_law(phys_addr_t addr) |
| 136 | { |
| 137 | return find_law_by_addr_id(addr, -1); |
| 138 | } |
| 139 | |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 140 | extern void disable_law(u8 idx); |
| 141 | extern void init_laws(void); |
Becky Bruce | 2a15f75 | 2008-01-23 16:31:05 -0600 | [diff] [blame] | 142 | extern void print_laws(void); |
Kumar Gala | 95fd2f6 | 2008-01-16 01:13:58 -0600 | [diff] [blame] | 143 | |
| 144 | /* define in board code */ |
| 145 | extern struct law_entry law_table[]; |
| 146 | extern int num_law_entries; |
| 147 | #endif |