blob: 91245d46caa6f88b1a3cc3a2d98bc88cd4297dda [file] [log] [blame]
Vikram Kanigiri40d468c2014-12-23 01:00:22 +00001/*
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +01002 * Copyright (c) 2015-2018, 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
7#include <arch.h>
Roberto Vargasbd7bcd82018-07-18 11:14:20 +01008#include <arch_helpers.h>
Vikram Kanigiri40d468c2014-12-23 01:00:22 +00009#include <assert.h>
10#include <cci.h>
11#include <debug.h>
12#include <mmio.h>
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010013#include <stdbool.h>
Juan Castillo7f1f0622014-09-09 09:49:23 +010014#include <stdint.h>
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000015
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010016#define MAKE_CCI_PART_NUMBER(hi, lo) (((hi) << 8) | (lo))
17#define CCI_PART_LO_MASK U(0xff)
18#define CCI_PART_HI_MASK U(0xf)
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010019
20/* CCI part number codes read from Peripheral ID registers 0 and 1 */
21#define CCI400_PART_NUM 0x420
22#define CCI500_PART_NUM 0x422
23#define CCI550_PART_NUM 0x423
24
25#define CCI400_SLAVE_PORTS 5
26#define CCI500_SLAVE_PORTS 7
27#define CCI550_SLAVE_PORTS 7
28
29static uintptr_t cci_base;
30static const int *cci_slave_if_map;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000031
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +000032#if ENABLE_ASSERTIONS
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010033static unsigned int max_master_id;
34static int cci_num_slave_ports;
35
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010036static bool validate_cci_map(const int *map)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000037{
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010038 unsigned int valid_cci_map = 0U;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000039 int slave_if_id;
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010040 unsigned int i;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000041
42 /* Validate the map */
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010043 for (i = 0U; i <= max_master_id; i++) {
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000044 slave_if_id = map[i];
45
46 if (slave_if_id < 0)
47 continue;
48
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010049 if (slave_if_id >= cci_num_slave_ports) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010050 ERROR("Slave interface ID is invalid\n");
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010051 return false;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000052 }
53
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010054 if ((valid_cci_map & (1U << slave_if_id)) != 0U) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010055 ERROR("Multiple masters are assigned same slave interface ID\n");
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010056 return false;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000057 }
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010058 valid_cci_map |= 1U << slave_if_id;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000059 }
60
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010061 if (valid_cci_map == 0U) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010062 ERROR("No master is assigned a valid slave interface\n");
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010063 return false;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000064 }
65
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +010066 return true;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000067}
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010068
69/*
70 * Read CCI part number from Peripheral ID registers
71 */
72static unsigned int read_cci_part_number(uintptr_t base)
73{
74 unsigned int part_lo, part_hi;
75
76 part_lo = mmio_read_32(base + PERIPHERAL_ID0) & CCI_PART_LO_MASK;
77 part_hi = mmio_read_32(base + PERIPHERAL_ID1) & CCI_PART_HI_MASK;
78
79 return MAKE_CCI_PART_NUMBER(part_hi, part_lo);
80}
81
82/*
83 * Identify a CCI device, and return the number of slaves. Return -1 for an
84 * unidentified device.
85 */
86static int get_slave_ports(unsigned int part_num)
87{
Jonathan Wright39b42212018-03-13 15:24:29 +000088 int num_slave_ports = -1;
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010089
90 switch (part_num) {
91
Jonathan Wright39b42212018-03-13 15:24:29 +000092 case CCI400_PART_NUM:
93 num_slave_ports = CCI400_SLAVE_PORTS;
94 break;
95 case CCI500_PART_NUM:
96 num_slave_ports = CCI500_SLAVE_PORTS;
97 break;
98 case CCI550_PART_NUM:
99 num_slave_ports = CCI550_SLAVE_PORTS;
100 break;
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100101 default:
Jonathan Wright39b42212018-03-13 15:24:29 +0000102 /* Do nothing in default case */
103 break;
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100104 }
105
Jonathan Wright39b42212018-03-13 15:24:29 +0000106 return num_slave_ports;
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100107}
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +0000108#endif /* ENABLE_ASSERTIONS */
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000109
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100110void cci_init(uintptr_t base, const int *map, unsigned int num_cci_masters)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000111{
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100112 assert(map != NULL);
113 assert(base != 0U);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000114
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100115 cci_base = base;
116 cci_slave_if_map = map;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000117
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100118#if ENABLE_ASSERTIONS
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000119 /*
120 * Master Id's are assigned from zero, So in an array of size n
121 * the max master id is (n - 1).
122 */
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100123 max_master_id = num_cci_masters - 1U;
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100124 cci_num_slave_ports = get_slave_ports(read_cci_part_number(base));
125#endif
126 assert(cci_num_slave_ports >= 0);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000127
128 assert(validate_cci_map(map));
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000129}
130
131void cci_enable_snoop_dvm_reqs(unsigned int master_id)
132{
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100133 int slave_if_id = cci_slave_if_map[master_id];
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000134
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100135 assert(master_id <= max_master_id);
136 assert((slave_if_id < cci_num_slave_ports) && (slave_if_id >= 0));
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100137 assert(cci_base != 0U);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000138
139 /*
140 * Enable Snoops and DVM messages, no need for Read/Modify/Write as
141 * rest of bits are write ignore
142 */
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100143 mmio_write_32(cci_base +
144 SLAVE_IFACE_OFFSET(slave_if_id) + SNOOP_CTRL_REG,
145 DVM_EN_BIT | SNOOP_EN_BIT);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000146
Roberto Vargasbd7bcd82018-07-18 11:14:20 +0100147 /*
148 * Wait for the completion of the write to the Snoop Control Register
149 * before testing the change_pending bit
150 */
Roberto Vargase90f64a2018-08-13 14:17:43 +0100151 dsbish();
Roberto Vargasbd7bcd82018-07-18 11:14:20 +0100152
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000153 /* Wait for the dust to settle down */
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100154 while ((mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT) != 0U)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000155 ;
156}
157
158void cci_disable_snoop_dvm_reqs(unsigned int master_id)
159{
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100160 int slave_if_id = cci_slave_if_map[master_id];
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000161
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100162 assert(master_id <= max_master_id);
163 assert((slave_if_id < cci_num_slave_ports) && (slave_if_id >= 0));
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100164 assert(cci_base != 0U);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000165
166 /*
167 * Disable Snoops and DVM messages, no need for Read/Modify/Write as
168 * rest of bits are write ignore.
169 */
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100170 mmio_write_32(cci_base +
171 SLAVE_IFACE_OFFSET(slave_if_id) + SNOOP_CTRL_REG,
172 ~(DVM_EN_BIT | SNOOP_EN_BIT));
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000173
Roberto Vargasbd7bcd82018-07-18 11:14:20 +0100174 /*
175 * Wait for the completion of the write to the Snoop Control Register
176 * before testing the change_pending bit
177 */
Roberto Vargase90f64a2018-08-13 14:17:43 +0100178 dsbish();
Roberto Vargasbd7bcd82018-07-18 11:14:20 +0100179
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000180 /* Wait for the dust to settle down */
Antonio Nino Diaz8c09ab52018-08-23 10:19:23 +0100181 while ((mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT) != 0U)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000182 ;
183}
184