2 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
12 #include <arch_helpers.h>
13 #include <common/debug.h>
14 #include <drivers/arm/cci.h>
17 #define MAKE_CCI_PART_NUMBER(hi, lo) (((hi) << 8) | (lo))
18 #define CCI_PART_LO_MASK U(0xff)
19 #define CCI_PART_HI_MASK U(0xf)
21 /* CCI part number codes read from Peripheral ID registers 0 and 1 */
22 #define CCI400_PART_NUM 0x420
23 #define CCI500_PART_NUM 0x422
24 #define CCI550_PART_NUM 0x423
26 #define CCI400_SLAVE_PORTS 5
27 #define CCI500_SLAVE_PORTS 7
28 #define CCI550_SLAVE_PORTS 7
30 static uintptr_t cci_base
;
31 static const int *cci_slave_if_map
;
34 static unsigned int max_master_id
;
35 static int cci_num_slave_ports
;
37 static bool validate_cci_map(const int *map
)
39 unsigned int valid_cci_map
= 0U;
43 /* Validate the map */
44 for (i
= 0U; i
<= max_master_id
; i
++) {
50 if (slave_if_id
>= cci_num_slave_ports
) {
51 ERROR("Slave interface ID is invalid\n");
55 if ((valid_cci_map
& (1U << slave_if_id
)) != 0U) {
56 ERROR("Multiple masters are assigned same slave interface ID\n");
59 valid_cci_map
|= 1U << slave_if_id
;
62 if (valid_cci_map
== 0U) {
63 ERROR("No master is assigned a valid slave interface\n");
71 * Read CCI part number from Peripheral ID registers
73 static unsigned int read_cci_part_number(uintptr_t base
)
75 unsigned int part_lo
, part_hi
;
77 part_lo
= mmio_read_32(base
+ PERIPHERAL_ID0
) & CCI_PART_LO_MASK
;
78 part_hi
= mmio_read_32(base
+ PERIPHERAL_ID1
) & CCI_PART_HI_MASK
;
80 return MAKE_CCI_PART_NUMBER(part_hi
, part_lo
);
84 * Identify a CCI device, and return the number of slaves. Return -1 for an
85 * unidentified device.
87 static int get_slave_ports(unsigned int part_num
)
89 int num_slave_ports
= -1;
94 num_slave_ports
= CCI400_SLAVE_PORTS
;
97 num_slave_ports
= CCI500_SLAVE_PORTS
;
100 num_slave_ports
= CCI550_SLAVE_PORTS
;
103 /* Do nothing in default case */
107 return num_slave_ports
;
109 #endif /* ENABLE_ASSERTIONS */
111 void __init
cci_init(uintptr_t base
, const int *map
,
112 unsigned int num_cci_masters
)
118 cci_slave_if_map
= map
;
120 #if ENABLE_ASSERTIONS
122 * Master Id's are assigned from zero, So in an array of size n
123 * the max master id is (n - 1).
125 max_master_id
= num_cci_masters
- 1U;
126 cci_num_slave_ports
= get_slave_ports(read_cci_part_number(base
));
128 assert(cci_num_slave_ports
>= 0);
130 assert(validate_cci_map(map
));
133 void cci_enable_snoop_dvm_reqs(unsigned int master_id
)
135 int slave_if_id
= cci_slave_if_map
[master_id
];
137 assert(master_id
<= max_master_id
);
138 assert((slave_if_id
< cci_num_slave_ports
) && (slave_if_id
>= 0));
139 assert(cci_base
!= 0U);
142 * Enable Snoops and DVM messages, no need for Read/Modify/Write as
143 * rest of bits are write ignore
145 mmio_write_32(cci_base
+
146 SLAVE_IFACE_OFFSET(slave_if_id
) + SNOOP_CTRL_REG
,
147 DVM_EN_BIT
| SNOOP_EN_BIT
);
150 * Wait for the completion of the write to the Snoop Control Register
151 * before testing the change_pending bit
155 /* Wait for the dust to settle down */
156 while ((mmio_read_32(cci_base
+ STATUS_REG
) & CHANGE_PENDING_BIT
) != 0U)
160 void cci_disable_snoop_dvm_reqs(unsigned int master_id
)
162 int slave_if_id
= cci_slave_if_map
[master_id
];
164 assert(master_id
<= max_master_id
);
165 assert((slave_if_id
< cci_num_slave_ports
) && (slave_if_id
>= 0));
166 assert(cci_base
!= 0U);
169 * Disable Snoops and DVM messages, no need for Read/Modify/Write as
170 * rest of bits are write ignore.
172 mmio_write_32(cci_base
+
173 SLAVE_IFACE_OFFSET(slave_if_id
) + SNOOP_CTRL_REG
,
174 ~(DVM_EN_BIT
| SNOOP_EN_BIT
));
177 * Wait for the completion of the write to the Snoop Control Register
178 * before testing the change_pending bit
182 /* Wait for the dust to settle down */
183 while ((mmio_read_32(cci_base
+ STATUS_REG
) & CHANGE_PENDING_BIT
) != 0U)