blob: e15683840dc00e2438f97f75548301ba13600a29 [file] [log] [blame]
Vikram Kanigiri40d468c2014-12-23 01:00:22 +00001/*
Antonio Nino Diaz3207e942017-04-06 14:46:38 +01002 * Copyright (c) 2015-2017, 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>
8#include <assert.h>
9#include <cci.h>
10#include <debug.h>
11#include <mmio.h>
Juan Castillo7f1f0622014-09-09 09:49:23 +010012#include <stdint.h>
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000013
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010014#define MAKE_CCI_PART_NUMBER(hi, lo) ((hi << 8) | lo)
15#define CCI_PART_LO_MASK 0xff
16#define CCI_PART_HI_MASK 0xf
17
18/* CCI part number codes read from Peripheral ID registers 0 and 1 */
19#define CCI400_PART_NUM 0x420
20#define CCI500_PART_NUM 0x422
21#define CCI550_PART_NUM 0x423
22
23#define CCI400_SLAVE_PORTS 5
24#define CCI500_SLAVE_PORTS 7
25#define CCI550_SLAVE_PORTS 7
26
27static uintptr_t cci_base;
28static const int *cci_slave_if_map;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000029
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +000030#if ENABLE_ASSERTIONS
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010031static unsigned int max_master_id;
32static int cci_num_slave_ports;
33
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000034static int validate_cci_map(const int *map)
35{
36 unsigned int valid_cci_map = 0;
37 int slave_if_id;
38 int i;
39
40 /* Validate the map */
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010041 for (i = 0; i <= max_master_id; i++) {
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000042 slave_if_id = map[i];
43
44 if (slave_if_id < 0)
45 continue;
46
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010047 if (slave_if_id >= cci_num_slave_ports) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010048 ERROR("Slave interface ID is invalid\n");
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000049 return 0;
50 }
51
52 if (valid_cci_map & (1 << slave_if_id)) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010053 ERROR("Multiple masters are assigned same slave interface ID\n");
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000054 return 0;
55 }
56 valid_cci_map |= 1 << slave_if_id;
57 }
58
59 if (!valid_cci_map) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010060 ERROR("No master is assigned a valid slave interface\n");
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000061 return 0;
62 }
63
64 return 1;
65}
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +010066
67/*
68 * Read CCI part number from Peripheral ID registers
69 */
70static unsigned int read_cci_part_number(uintptr_t base)
71{
72 unsigned int part_lo, part_hi;
73
74 part_lo = mmio_read_32(base + PERIPHERAL_ID0) & CCI_PART_LO_MASK;
75 part_hi = mmio_read_32(base + PERIPHERAL_ID1) & CCI_PART_HI_MASK;
76
77 return MAKE_CCI_PART_NUMBER(part_hi, part_lo);
78}
79
80/*
81 * Identify a CCI device, and return the number of slaves. Return -1 for an
82 * unidentified device.
83 */
84static int get_slave_ports(unsigned int part_num)
85{
86 /* Macro to match CCI products */
87#define RET_ON_MATCH(product) \
88 case CCI ## product ## _PART_NUM: \
89 return CCI ## product ## _SLAVE_PORTS
90
91 switch (part_num) {
92
93 RET_ON_MATCH(400);
94 RET_ON_MATCH(500);
95 RET_ON_MATCH(550);
96
97 default:
98 return -1;
99 }
100
101#undef RET_ON_MATCH
102}
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +0000103#endif /* ENABLE_ASSERTIONS */
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000104
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100105void cci_init(uintptr_t base, const int *map, unsigned int num_cci_masters)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000106{
107 assert(map);
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100108 assert(base);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000109
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100110 cci_base = base;
111 cci_slave_if_map = map;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000112
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100113#if ENABLE_ASSERTIONS
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000114 /*
115 * Master Id's are assigned from zero, So in an array of size n
116 * the max master id is (n - 1).
117 */
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100118 max_master_id = num_cci_masters - 1;
119 cci_num_slave_ports = get_slave_ports(read_cci_part_number(base));
120#endif
121 assert(cci_num_slave_ports >= 0);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000122
123 assert(validate_cci_map(map));
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000124}
125
126void cci_enable_snoop_dvm_reqs(unsigned int master_id)
127{
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100128 int slave_if_id = cci_slave_if_map[master_id];
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000129
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100130 assert(master_id <= max_master_id);
131 assert((slave_if_id < cci_num_slave_ports) && (slave_if_id >= 0));
132 assert(cci_base);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000133
134 /*
135 * Enable Snoops and DVM messages, no need for Read/Modify/Write as
136 * rest of bits are write ignore
137 */
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100138 mmio_write_32(cci_base +
139 SLAVE_IFACE_OFFSET(slave_if_id) + SNOOP_CTRL_REG,
140 DVM_EN_BIT | SNOOP_EN_BIT);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000141
142 /* Wait for the dust to settle down */
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100143 while (mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000144 ;
145}
146
147void cci_disable_snoop_dvm_reqs(unsigned int master_id)
148{
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100149 int slave_if_id = cci_slave_if_map[master_id];
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000150
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100151 assert(master_id <= max_master_id);
152 assert((slave_if_id < cci_num_slave_ports) && (slave_if_id >= 0));
153 assert(cci_base);
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000154
155 /*
156 * Disable Snoops and DVM messages, no need for Read/Modify/Write as
157 * rest of bits are write ignore.
158 */
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100159 mmio_write_32(cci_base +
160 SLAVE_IFACE_OFFSET(slave_if_id) + SNOOP_CTRL_REG,
161 ~(DVM_EN_BIT | SNOOP_EN_BIT));
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000162
163 /* Wait for the dust to settle down */
Jeenu Viswambharanb36577a2017-07-19 17:07:00 +0100164 while (mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT)
Vikram Kanigiri40d468c2014-12-23 01:00:22 +0000165 ;
166}
167