blob: 04530b01cb159c7cf96f03dc308ff6e0e4bdc3f6 [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
Juan Castillo7f1f0622014-09-09 09:49:23 +010014static uintptr_t g_cci_base;
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000015static unsigned int g_max_master_id;
16static const int *g_cci_slave_if_map;
17
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +000018#if ENABLE_ASSERTIONS
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000019static int validate_cci_map(const int *map)
20{
21 unsigned int valid_cci_map = 0;
22 int slave_if_id;
23 int i;
24
25 /* Validate the map */
26 for (i = 0; i <= g_max_master_id; i++) {
27 slave_if_id = map[i];
28
29 if (slave_if_id < 0)
30 continue;
31
32 if (slave_if_id >= CCI_SLAVE_INTERFACE_COUNT) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010033 ERROR("Slave interface ID is invalid\n");
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000034 return 0;
35 }
36
37 if (valid_cci_map & (1 << slave_if_id)) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010038 ERROR("Multiple masters are assigned same slave interface ID\n");
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000039 return 0;
40 }
41 valid_cci_map |= 1 << slave_if_id;
42 }
43
44 if (!valid_cci_map) {
Antonio Nino Diaz3207e942017-04-06 14:46:38 +010045 ERROR("No master is assigned a valid slave interface\n");
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000046 return 0;
47 }
48
49 return 1;
50}
Antonio Nino Diaz3759e3f2017-03-22 15:48:51 +000051#endif /* ENABLE_ASSERTIONS */
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000052
Juan Castillo7f1f0622014-09-09 09:49:23 +010053void cci_init(uintptr_t cci_base,
Vikram Kanigiri40d468c2014-12-23 01:00:22 +000054 const int *map,
55 unsigned int num_cci_masters)
56{
57 assert(map);
58 assert(cci_base);
59
60 g_cci_base = cci_base;
61
62 /*
63 * Master Id's are assigned from zero, So in an array of size n
64 * the max master id is (n - 1).
65 */
66 g_max_master_id = num_cci_masters - 1;
67
68 assert(validate_cci_map(map));
69 g_cci_slave_if_map = map;
70}
71
72void cci_enable_snoop_dvm_reqs(unsigned int master_id)
73{
74 int slave_if_id;
75
76 assert(g_cci_base);
77 assert(master_id <= g_max_master_id);
78
79 slave_if_id = g_cci_slave_if_map[master_id];
80 assert((slave_if_id < CCI_SLAVE_INTERFACE_COUNT) && (slave_if_id >= 0));
81
82 /*
83 * Enable Snoops and DVM messages, no need for Read/Modify/Write as
84 * rest of bits are write ignore
85 */
86 mmio_write_32(g_cci_base +
87 SLAVE_IFACE_OFFSET(slave_if_id) +
88 SNOOP_CTRL_REG, DVM_EN_BIT | SNOOP_EN_BIT);
89
90 /* Wait for the dust to settle down */
91 while (mmio_read_32(g_cci_base + STATUS_REG) & CHANGE_PENDING_BIT)
92 ;
93}
94
95void cci_disable_snoop_dvm_reqs(unsigned int master_id)
96{
97 int slave_if_id;
98
99 assert(g_cci_base);
100 assert(master_id <= g_max_master_id);
101
102 slave_if_id = g_cci_slave_if_map[master_id];
103 assert((slave_if_id < CCI_SLAVE_INTERFACE_COUNT) && (slave_if_id >= 0));
104
105 /*
106 * Disable Snoops and DVM messages, no need for Read/Modify/Write as
107 * rest of bits are write ignore.
108 */
109 mmio_write_32(g_cci_base +
110 SLAVE_IFACE_OFFSET(slave_if_id) +
111 SNOOP_CTRL_REG, ~(DVM_EN_BIT | SNOOP_EN_BIT));
112
113 /* Wait for the dust to settle down */
114 while (mmio_read_32(g_cci_base + STATUS_REG) & CHANGE_PENDING_BIT)
115 ;
116}
117