Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 1 | /* |
Jimmy Brisson | ed20207 | 2020-08-04 16:18:52 -0500 | [diff] [blame] | 2 | * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved. |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 7 | #include <assert.h> |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 8 | #include <stdbool.h> |
Juan Castillo | 7f1f062 | 2014-09-09 09:49:23 +0100 | [diff] [blame] | 9 | #include <stdint.h> |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 10 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #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 Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 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) |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 20 | |
| 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 | |
| 30 | static uintptr_t cci_base; |
| 31 | static const int *cci_slave_if_map; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 32 | |
Antonio Nino Diaz | 3759e3f | 2017-03-22 15:48:51 +0000 | [diff] [blame] | 33 | #if ENABLE_ASSERTIONS |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 34 | static unsigned int max_master_id; |
| 35 | static int cci_num_slave_ports; |
| 36 | |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 37 | static bool validate_cci_map(const int *map) |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 38 | { |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 39 | unsigned int valid_cci_map = 0U; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 40 | int slave_if_id; |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 41 | unsigned int i; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 42 | |
| 43 | /* Validate the map */ |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 44 | for (i = 0U; i <= max_master_id; i++) { |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 45 | slave_if_id = map[i]; |
| 46 | |
| 47 | if (slave_if_id < 0) |
| 48 | continue; |
| 49 | |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 50 | if (slave_if_id >= cci_num_slave_ports) { |
Antonio Nino Diaz | 3207e94 | 2017-04-06 14:46:38 +0100 | [diff] [blame] | 51 | ERROR("Slave interface ID is invalid\n"); |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 52 | return false; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Jimmy Brisson | ed20207 | 2020-08-04 16:18:52 -0500 | [diff] [blame] | 55 | if ((valid_cci_map & (1UL << slave_if_id)) != 0U) { |
Antonio Nino Diaz | 3207e94 | 2017-04-06 14:46:38 +0100 | [diff] [blame] | 56 | ERROR("Multiple masters are assigned same slave interface ID\n"); |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 57 | return false; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 58 | } |
Jimmy Brisson | ed20207 | 2020-08-04 16:18:52 -0500 | [diff] [blame] | 59 | valid_cci_map |= 1UL << slave_if_id; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 62 | if (valid_cci_map == 0U) { |
Antonio Nino Diaz | 3207e94 | 2017-04-06 14:46:38 +0100 | [diff] [blame] | 63 | ERROR("No master is assigned a valid slave interface\n"); |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 64 | return false; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 67 | return true; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 68 | } |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | * Read CCI part number from Peripheral ID registers |
| 72 | */ |
| 73 | static 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 | */ |
| 87 | static int get_slave_ports(unsigned int part_num) |
| 88 | { |
Jonathan Wright | 39b4221 | 2018-03-13 15:24:29 +0000 | [diff] [blame] | 89 | int num_slave_ports = -1; |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 90 | |
| 91 | switch (part_num) { |
| 92 | |
Jonathan Wright | 39b4221 | 2018-03-13 15:24:29 +0000 | [diff] [blame] | 93 | 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 Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 102 | default: |
Jonathan Wright | 39b4221 | 2018-03-13 15:24:29 +0000 | [diff] [blame] | 103 | /* Do nothing in default case */ |
| 104 | break; |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Jonathan Wright | 39b4221 | 2018-03-13 15:24:29 +0000 | [diff] [blame] | 107 | return num_slave_ports; |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 108 | } |
Antonio Nino Diaz | 3759e3f | 2017-03-22 15:48:51 +0000 | [diff] [blame] | 109 | #endif /* ENABLE_ASSERTIONS */ |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 110 | |
Daniel Boulby | 844b487 | 2018-09-18 13:36:39 +0100 | [diff] [blame] | 111 | void __init cci_init(uintptr_t base, const int *map, |
| 112 | unsigned int num_cci_masters) |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 113 | { |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 114 | assert(map != NULL); |
| 115 | assert(base != 0U); |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 116 | |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 117 | cci_base = base; |
| 118 | cci_slave_if_map = map; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 119 | |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 120 | #if ENABLE_ASSERTIONS |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 121 | /* |
| 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 Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 125 | max_master_id = num_cci_masters - 1U; |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 126 | cci_num_slave_ports = get_slave_ports(read_cci_part_number(base)); |
| 127 | #endif |
| 128 | assert(cci_num_slave_ports >= 0); |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 129 | |
| 130 | assert(validate_cci_map(map)); |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | void cci_enable_snoop_dvm_reqs(unsigned int master_id) |
| 134 | { |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 135 | int slave_if_id = cci_slave_if_map[master_id]; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 136 | |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 137 | assert(master_id <= max_master_id); |
| 138 | assert((slave_if_id < cci_num_slave_ports) && (slave_if_id >= 0)); |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 139 | assert(cci_base != 0U); |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 140 | |
| 141 | /* |
| 142 | * Enable Snoops and DVM messages, no need for Read/Modify/Write as |
| 143 | * rest of bits are write ignore |
| 144 | */ |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 145 | mmio_write_32(cci_base + |
| 146 | SLAVE_IFACE_OFFSET(slave_if_id) + SNOOP_CTRL_REG, |
| 147 | DVM_EN_BIT | SNOOP_EN_BIT); |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 148 | |
Roberto Vargas | bd7bcd8 | 2018-07-18 11:14:20 +0100 | [diff] [blame] | 149 | /* |
| 150 | * Wait for the completion of the write to the Snoop Control Register |
| 151 | * before testing the change_pending bit |
| 152 | */ |
Roberto Vargas | e90f64a | 2018-08-13 14:17:43 +0100 | [diff] [blame] | 153 | dsbish(); |
Roberto Vargas | bd7bcd8 | 2018-07-18 11:14:20 +0100 | [diff] [blame] | 154 | |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 155 | /* Wait for the dust to settle down */ |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 156 | while ((mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT) != 0U) |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 157 | ; |
| 158 | } |
| 159 | |
| 160 | void cci_disable_snoop_dvm_reqs(unsigned int master_id) |
| 161 | { |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 162 | int slave_if_id = cci_slave_if_map[master_id]; |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 163 | |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 164 | assert(master_id <= max_master_id); |
| 165 | assert((slave_if_id < cci_num_slave_ports) && (slave_if_id >= 0)); |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 166 | assert(cci_base != 0U); |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 167 | |
| 168 | /* |
| 169 | * Disable Snoops and DVM messages, no need for Read/Modify/Write as |
| 170 | * rest of bits are write ignore. |
| 171 | */ |
Jeenu Viswambharan | b36577a | 2017-07-19 17:07:00 +0100 | [diff] [blame] | 172 | mmio_write_32(cci_base + |
| 173 | SLAVE_IFACE_OFFSET(slave_if_id) + SNOOP_CTRL_REG, |
| 174 | ~(DVM_EN_BIT | SNOOP_EN_BIT)); |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 175 | |
Roberto Vargas | bd7bcd8 | 2018-07-18 11:14:20 +0100 | [diff] [blame] | 176 | /* |
| 177 | * Wait for the completion of the write to the Snoop Control Register |
| 178 | * before testing the change_pending bit |
| 179 | */ |
Roberto Vargas | e90f64a | 2018-08-13 14:17:43 +0100 | [diff] [blame] | 180 | dsbish(); |
Roberto Vargas | bd7bcd8 | 2018-07-18 11:14:20 +0100 | [diff] [blame] | 181 | |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 182 | /* Wait for the dust to settle down */ |
Antonio Nino Diaz | 8c09ab5 | 2018-08-23 10:19:23 +0100 | [diff] [blame] | 183 | while ((mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT) != 0U) |
Vikram Kanigiri | 40d468c | 2014-12-23 01:00:22 +0000 | [diff] [blame] | 184 | ; |
| 185 | } |
| 186 | |