blob: 888640df6f8133a7f39ad261f4b8507a67166b07 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Kumar Gala65e6c322009-03-19 02:32:23 -05002/*
Dipen Dudhat00c42942011-01-20 16:29:35 +05303 * Copyright 2008-2011 Freescale Semiconductor, Inc.
Kumar Gala65e6c322009-03-19 02:32:23 -05004 */
5
Kumar Gala95fd2f62008-01-16 01:13:58 -06006#ifndef _FSL_LAW_H_
7#define _FSL_LAW_H_
8
9#include <asm/io.h>
Fabio Estevam1a03a7e2015-11-05 12:43:40 -020010#include <linux/log2.h>
Kumar Gala95fd2f62008-01-16 01:13:58 -060011
Kumar Gala65e6c322009-03-19 02:32:23 -050012#define LAW_EN 0x80000000
13
Kumar Gala95fd2f62008-01-16 01:13:58 -060014#define SET_LAW_ENTRY(idx, a, sz, trgt) \
15 { .index = idx, .addr = a, .size = sz, .trgt_id = trgt }
16
Kumar Gala75639e02008-06-11 00:44:10 -050017#define SET_LAW(a, sz, trgt) \
18 { .index = -1, .addr = a, .size = sz, .trgt_id = trgt }
19
Kumar Gala95fd2f62008-01-16 01:13:58 -060020enum 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 Yang019b2932009-12-09 14:26:08 +080047#define law_size_bits(sz) (__ilog2_u64(sz) - 1)
Becky Bruceeb891f02010-06-17 11:37:23 -050048#define lawar_size(x) (1ULL << ((x & 0x3f) + 1))
Li Yang019b2932009-12-09 14:26:08 +080049
Kumar Gala65e6c322009-03-19 02:32:23 -050050#ifdef CONFIG_FSL_CORENET
51enum 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 Gala74e78b62010-04-28 04:02:21 -050055 LAW_TRGT_IF_PCIE_4 = 0x03,
Kumar Gala65e6c322009-03-19 02:32:23 -050056 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 Sune8dc17b2012-08-17 08:22:39 +000061 LAW_TRGT_IF_DDR_3 = 0x12,
62 LAW_TRGT_IF_DDR_4 = 0x13,
Kumar Gala65e6c322009-03-19 02:32:23 -050063 LAW_TRGT_IF_DDR_INTRLV = 0x14,
York Sune8dc17b2012-08-17 08:22:39 +000064 LAW_TRGT_IF_DDR_INTLV_34 = 0x15,
65 LAW_TRGT_IF_DDR_INTLV_123 = 0x17,
66 LAW_TRGT_IF_DDR_INTLV_1234 = 0x16,
Kumar Gala65e6c322009-03-19 02:32:23 -050067 LAW_TRGT_IF_BMAN = 0x18,
68 LAW_TRGT_IF_DCSR = 0x1d,
Sandeep Singh4fb16a12014-06-05 18:49:57 +053069 LAW_TRGT_IF_CCSR = 0x1e,
Kumar Gala65e6c322009-03-19 02:32:23 -050070 LAW_TRGT_IF_LBC = 0x1f,
71 LAW_TRGT_IF_QMAN = 0x3c,
Shaveta Leekha43e0f7b2013-03-25 07:40:24 +000072
73 LAW_TRGT_IF_MAPLE = 0x50,
Kumar Gala65e6c322009-03-19 02:32:23 -050074};
75#define LAW_TRGT_IF_DDR LAW_TRGT_IF_DDR_1
Prabhakar Kushwaha4fc2aac2012-08-15 06:24:15 +000076#define LAW_TRGT_IF_IFC LAW_TRGT_IF_LBC
Kumar Gala65e6c322009-03-19 02:32:23 -050077#else
Kumar Gala95fd2f62008-01-16 01:13:58 -060078enum law_trgt_if {
79 LAW_TRGT_IF_PCI = 0x00,
80 LAW_TRGT_IF_PCI_2 = 0x01,
York Sunefc30b62016-11-23 14:08:36 -080081#ifndef CONFIG_ARCH_MPC8641
Kumar Gala95fd2f62008-01-16 01:13:58 -060082 LAW_TRGT_IF_PCIE_1 = 0x02,
83#endif
York Suna80bdf72016-11-15 14:09:50 -080084#if defined(CONFIG_ARCH_BSC9131) || defined(CONFIG_ARCH_BSC9132)
Priyanka Jainf81e8b22013-04-04 09:31:54 +053085 LAW_TRGT_IF_OCN_DSP = 0x03,
86#else
York Sun4b08dd72016-11-18 11:08:43 -080087#if !defined(CONFIG_ARCH_MPC8572) && !defined(CONFIG_ARCH_P2020)
Kumar Gala95fd2f62008-01-16 01:13:58 -060088 LAW_TRGT_IF_PCIE_3 = 0x03,
89#endif
Priyanka Jainf81e8b22013-04-04 09:31:54 +053090#endif
Kumar Gala95fd2f62008-01-16 01:13:58 -060091 LAW_TRGT_IF_LBC = 0x04,
92 LAW_TRGT_IF_CCSR = 0x08,
Priyanka Jainf81e8b22013-04-04 09:31:54 +053093 LAW_TRGT_IF_DSP_CCSR = 0x09,
Mingkai Hu1a258072013-07-04 17:30:36 +080094 LAW_TRGT_IF_PLATFORM_SRAM = 0x0a,
Kumar Gala95fd2f62008-01-16 01:13:58 -060095 LAW_TRGT_IF_DDR_INTRLV = 0x0b,
96 LAW_TRGT_IF_RIO = 0x0c,
York Suna80bdf72016-11-15 14:09:50 -080097#if defined(CONFIG_ARCH_BSC9132)
Priyanka Jainc73b9032013-07-02 09:21:04 +053098 LAW_TRGT_IF_CLASS_DSP = 0x0d,
99#else
Li Yang019b2932009-12-09 14:26:08 +0800100 LAW_TRGT_IF_RIO_2 = 0x0d,
Priyanka Jainc73b9032013-07-02 09:21:04 +0530101#endif
Roy Zang1de20b02011-02-03 22:14:19 -0600102 LAW_TRGT_IF_DPAA_SWP_SRAM = 0x0e,
Kumar Gala95fd2f62008-01-16 01:13:58 -0600103 LAW_TRGT_IF_DDR = 0x0f,
104 LAW_TRGT_IF_DDR_2 = 0x16, /* 2nd controller */
York Sune8dc17b2012-08-17 08:22:39 +0000105 /* place holder for 3-way and 4-way interleaving */
106 LAW_TRGT_IF_DDR_3,
107 LAW_TRGT_IF_DDR_4,
108 LAW_TRGT_IF_DDR_INTLV_34,
109 LAW_TRGT_IF_DDR_INTLV_123,
110 LAW_TRGT_IF_DDR_INTLV_1234,
Kumar Gala95fd2f62008-01-16 01:13:58 -0600111};
112#define LAW_TRGT_IF_DDR_1 LAW_TRGT_IF_DDR
113#define LAW_TRGT_IF_PCI_1 LAW_TRGT_IF_PCI
114#define LAW_TRGT_IF_PCIX LAW_TRGT_IF_PCI
115#define LAW_TRGT_IF_PCIE_2 LAW_TRGT_IF_PCI_2
Kumar Gala8975d7a2010-12-30 12:09:53 -0600116#define LAW_TRGT_IF_RIO_1 LAW_TRGT_IF_RIO
Dipen Dudhat00c42942011-01-20 16:29:35 +0530117#define LAW_TRGT_IF_IFC LAW_TRGT_IF_LBC
Kumar Gala95fd2f62008-01-16 01:13:58 -0600118
York Sunefc30b62016-11-23 14:08:36 -0800119#ifdef CONFIG_ARCH_MPC8641
Kumar Gala95fd2f62008-01-16 01:13:58 -0600120#define LAW_TRGT_IF_PCIE_1 LAW_TRGT_IF_PCI
121#endif
122
York Sun4b08dd72016-11-18 11:08:43 -0800123#if defined(CONFIG_ARCH_MPC8572) || defined(CONFIG_ARCH_P2020)
Kumar Gala95fd2f62008-01-16 01:13:58 -0600124#define LAW_TRGT_IF_PCIE_3 LAW_TRGT_IF_PCI
125#endif
Kumar Gala65e6c322009-03-19 02:32:23 -0500126#endif /* CONFIG_FSL_CORENET */
Kumar Gala95fd2f62008-01-16 01:13:58 -0600127
128struct law_entry {
129 int index;
130 phys_addr_t addr;
131 enum law_size size;
132 enum law_trgt_if trgt_id;
133};
134
135extern void set_law(u8 idx, phys_addr_t addr, enum law_size sz, enum law_trgt_if id);
Kumar Gala75639e02008-06-11 00:44:10 -0500136extern int set_next_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id);
Kumar Galaa9abb002008-06-10 16:16:02 -0500137extern int set_last_law(phys_addr_t addr, enum law_size sz, enum law_trgt_if id);
Kumar Gala61ed0532008-08-26 15:01:28 -0500138extern int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id);
Kumar Gala65e6c322009-03-19 02:32:23 -0500139extern struct law_entry find_law(phys_addr_t addr);
Kumar Gala95fd2f62008-01-16 01:13:58 -0600140extern void disable_law(u8 idx);
141extern void init_laws(void);
Becky Bruce2a15f752008-01-23 16:31:05 -0600142extern void print_laws(void);
Kumar Gala95fd2f62008-01-16 01:13:58 -0600143
144/* define in board code */
145extern struct law_entry law_table[];
146extern int num_law_entries;
147#endif