blob: 2adfe1718bca31907d8ee0f286a7fc44eca21569 [file] [log] [blame]
Vikram Kanigiri40d468c2014-12-23 01:00:22 +00001/*
Jimmy Brissoned202072020-08-04 16:18:52 -05002 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
Vikram Kanigiri40d468c2014-12-23 01:00:22 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Vikram Kanigiri40d468c2014-12-23 01:00:22 +00005 */
6
Vikram Kanigiri40d468c2014-12-23 01:00:22 +00007#include <assert.h>
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +01008#include <stdbool.h>
Juan Castillo7f1f0622014-09-09 09:49:23 +01009#include <stdint.h>
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000010
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011#include <arch.h>
12#include <arch_helpers.h>
13#include <common/debug.h>
14#include <drivers/arm/cci.h>
15#include <lib/mmio.h>
16
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010017#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)
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010020
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
25
26#define CCI400_SLAVE_PORTS 5
27#define CCI500_SLAVE_PORTS 7
28#define CCI550_SLAVE_PORTS 7
29
30static uintptr_t cci_base;
31static const int *cci_slave_if_map;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000032
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +000033#if ENABLE_ASSERTIONS
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010034static unsigned int max_master_id;
35static int cci_num_slave_ports;
36
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010037static bool validate_cci_map(const int *map)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000038{
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010039 unsigned int valid_cci_map = 0U;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000040 int slave_if_id;
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010041 unsigned int i;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000042
43 /* Validate the map */
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010044 for (i = 0U; i <= max_master_id; i++) {
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000045 slave_if_id = map[i];
46
47 if (slave_if_id < 0)
48 continue;
49
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010050 if (slave_if_id >= cci_num_slave_ports) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010051 ERROR("Slave interface ID is invalid\n");
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010052 return false;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000053 }
54
Jimmy Brissoned202072020-08-04 16:18:52 -050055 if ((valid_cci_map & (1UL << slave_if_id)) != 0U) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010056 ERROR("Multiple masters are assigned same slave interface ID\n");
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010057 return false;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000058 }
Jimmy Brissoned202072020-08-04 16:18:52 -050059 valid_cci_map |= 1UL << slave_if_id;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000060 }
61
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010062 if (valid_cci_map == 0U) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010063 ERROR("No master is assigned a valid slave interface\n");
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010064 return false;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000065 }
66
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010067 return true;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000068}
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010069
70/*
71 * Read CCI part number from Peripheral ID registers
72 */
73static unsigned int read_cci_part_number(uintptr_t base)
74{
75 unsigned int part_lo, part_hi;
76
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;
79
80 return MAKE_CCI_PART_NUMBER(part_hi, part_lo);
81}
82
83/*
84 * Identify a CCI device, and return the number of slaves. Return -1 for an
85 * unidentified device.
86 */
87static int get_slave_ports(unsigned int part_num)
88{
Jonathan Wright39b42212018-03-13 15:24:29 +000089 int num_slave_ports = -1;
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010090
91 switch (part_num) {
92
Jonathan Wright39b42212018-03-13 15:24:29 +000093 case CCI400_PART_NUM:
94 num_slave_ports = CCI400_SLAVE_PORTS;
95 break;
96 case CCI500_PART_NUM:
97 num_slave_ports = CCI500_SLAVE_PORTS;
98 break;
99 case CCI550_PART_NUM:
100 num_slave_ports = CCI550_SLAVE_PORTS;
101 break;
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100102 default:
Jonathan Wright39b42212018-03-13 15:24:29 +0000103 /* Do nothing in default case */
104 break;
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100105 }
106
Jonathan Wright39b42212018-03-13 15:24:29 +0000107 return num_slave_ports;
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100108}
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +0000109#endif /* ENABLE_ASSERTIONS */
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000110
Daniel Boulby844b4872018-09-18 13:36:39 +0100111void __init cci_init(uintptr_t base, const int *map,
112 unsigned int num_cci_masters)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000113{
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100114 assert(map != NULL);
115 assert(base != 0U);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000116
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100117 cci_base = base;
118 cci_slave_if_map = map;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000119
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100120#if ENABLE_ASSERTIONS
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000121 /*
122 * Master Id's are assigned from zero, So in an array of size n
123 * the max master id is (n - 1).
124 */
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100125 max_master_id = num_cci_masters - 1U;
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100126 cci_num_slave_ports = get_slave_ports(read_cci_part_number(base));
127#endif
128 assert(cci_num_slave_ports >= 0);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000129
130 assert(validate_cci_map(map));
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000131}
132
133void cci_enable_snoop_dvm_reqs(unsigned int master_id)
134{
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100135 int slave_if_id = cci_slave_if_map[master_id];
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000136
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100137 assert(master_id <= max_master_id);
138 assert((slave_if_id < cci_num_slave_ports) && (slave_if_id >= 0));
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100139 assert(cci_base != 0U);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000140
141 /*
142 * Enable Snoops and DVM messages, no need for Read/Modify/Write as
143 * rest of bits are write ignore
144 */
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100145 mmio_write_32(cci_base +
146 SLAVE_IFACE_OFFSET(slave_if_id) + SNOOP_CTRL_REG,
147 DVM_EN_BIT | SNOOP_EN_BIT);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000148
Roberto Vargasbd7bcd82018-07-18 11:14:20 +0100149 /*
150 * Wait for the completion of the write to the Snoop Control Register
151 * before testing the change_pending bit
152 */
Roberto Vargase90f64a2018-08-13 14:17:43 +0100153 dsbish();
Roberto Vargasbd7bcd82018-07-18 11:14:20 +0100154
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000155 /* Wait for the dust to settle down */
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100156 while ((mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT) != 0U)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000157 ;
158}
159
160void cci_disable_snoop_dvm_reqs(unsigned int master_id)
161{
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100162 int slave_if_id = cci_slave_if_map[master_id];
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000163
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100164 assert(master_id <= max_master_id);
165 assert((slave_if_id < cci_num_slave_ports) && (slave_if_id >= 0));
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100166 assert(cci_base != 0U);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000167
168 /*
169 * Disable Snoops and DVM messages, no need for Read/Modify/Write as
170 * rest of bits are write ignore.
171 */
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100172 mmio_write_32(cci_base +
173 SLAVE_IFACE_OFFSET(slave_if_id) + SNOOP_CTRL_REG,
174 ~(DVM_EN_BIT | SNOOP_EN_BIT));
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000175
Roberto Vargasbd7bcd82018-07-18 11:14:20 +0100176 /*
177 * Wait for the completion of the write to the Snoop Control Register
178 * before testing the change_pending bit
179 */
Roberto Vargase90f64a2018-08-13 14:17:43 +0100180 dsbish();
Roberto Vargasbd7bcd82018-07-18 11:14:20 +0100181
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000182 /* Wait for the dust to settle down */
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100183 while ((mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT) != 0U)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000184 ;
185}
186