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