blob: 23dc0b890d0c763a8d367f7a4e24a65934cef29b [file] [log] [blame]
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +01001/*
2 * CCI cache coherent interconnect driver
3 *
4 * Copyright (C) 2013 ARM Ltd.
5 * Author: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
12 * kind, whether express or implied; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17#include <linux/arm-cci.h>
18#include <linux/io.h>
19#include <linux/module.h>
20#include <linux/of_address.h>
Punit Agrawalb91c8f22013-08-22 14:41:51 +010021#include <linux/of_platform.h>
22#include <linux/platform_device.h>
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +010023#include <linux/slab.h>
24
25#include <asm/cacheflush.h>
26#include <asm/smp_plat.h>
27
Robin Murphy3de6be72018-02-15 18:51:42 +000028/* Referenced read-only by the PMU driver; see drivers/perf/arm-cci.c */
29void __iomem *cci_ctrl_base;
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +000030static unsigned long cci_ctrl_phys;
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +010031
Suzuki K. Pouloseee8e5d52015-03-18 12:24:41 +000032#ifdef CONFIG_ARM_CCI400_PORT_CTRL
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +010033struct cci_nb_ports {
34 unsigned int nb_ace;
35 unsigned int nb_ace_lite;
36};
37
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +000038static const struct cci_nb_ports cci400_ports = {
39 .nb_ace = 2,
40 .nb_ace_lite = 3
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +010041};
42
Suzuki K. Pouloseee8e5d52015-03-18 12:24:41 +000043#define CCI400_PORTS_DATA (&cci400_ports)
44#else
45#define CCI400_PORTS_DATA (NULL)
46#endif
47
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +000048static const struct of_device_id arm_cci_matches[] = {
Suzuki K. Pouloseee8e5d52015-03-18 12:24:41 +000049#ifdef CONFIG_ARM_CCI400_COMMON
50 {.compatible = "arm,cci-400", .data = CCI400_PORTS_DATA },
51#endif
Suzuki K Poulose3d2e8702016-02-23 10:49:54 +000052#ifdef CONFIG_ARM_CCI5xx_PMU
Suzuki K. Poulosea95791e2015-05-26 10:53:15 +010053 { .compatible = "arm,cci-500", },
Suzuki K Poulosed7dd5fd2016-02-23 10:49:55 +000054 { .compatible = "arm,cci-550", },
Suzuki K. Poulosea95791e2015-05-26 10:53:15 +010055#endif
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +000056 {},
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +010057};
58
Suzuki K. Poulosef4d58932015-05-26 10:53:14 +010059#define DRIVER_NAME "ARM-CCI"
Punit Agrawalb91c8f22013-08-22 14:41:51 +010060
61static int cci_platform_probe(struct platform_device *pdev)
62{
63 if (!cci_probed())
64 return -ENODEV;
65
66 return of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
67}
68
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +000069static struct platform_driver cci_platform_driver = {
70 .driver = {
71 .name = DRIVER_NAME,
72 .of_match_table = arm_cci_matches,
73 },
74 .probe = cci_platform_probe,
75};
76
77static int __init cci_platform_init(void)
78{
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +000079 return platform_driver_register(&cci_platform_driver);
80}
81
Suzuki K. Pouloseee8e5d52015-03-18 12:24:41 +000082#ifdef CONFIG_ARM_CCI400_PORT_CTRL
Punit Agrawalb91c8f22013-08-22 14:41:51 +010083
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +000084#define CCI_PORT_CTRL 0x0
85#define CCI_CTRL_STATUS 0xc
86
87#define CCI_ENABLE_SNOOP_REQ 0x1
88#define CCI_ENABLE_DVM_REQ 0x2
89#define CCI_ENABLE_REQ (CCI_ENABLE_SNOOP_REQ | CCI_ENABLE_DVM_REQ)
90
91enum cci_ace_port_type {
92 ACE_INVALID_PORT = 0x0,
93 ACE_PORT,
94 ACE_LITE_PORT,
95};
96
97struct cci_ace_port {
98 void __iomem *base;
99 unsigned long phys;
100 enum cci_ace_port_type type;
101 struct device_node *dn;
102};
103
104static struct cci_ace_port *ports;
105static unsigned int nb_cci_ports;
106
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100107struct cpu_port {
108 u64 mpidr;
109 u32 port;
110};
Nicolas Pitre62158f82013-05-21 23:34:41 -0400111
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100112/*
113 * Use the port MSB as valid flag, shift can be made dynamic
114 * by computing number of bits required for port indexes.
115 * Code disabling CCI cpu ports runs with D-cache invalidated
116 * and SCTLR bit clear so data accesses must be kept to a minimum
117 * to improve performance; for now shift is left static to
118 * avoid one more data access while disabling the CCI port.
119 */
120#define PORT_VALID_SHIFT 31
121#define PORT_VALID (0x1 << PORT_VALID_SHIFT)
122
123static inline void init_cpu_port(struct cpu_port *port, u32 index, u64 mpidr)
124{
125 port->port = PORT_VALID | index;
126 port->mpidr = mpidr;
127}
128
129static inline bool cpu_port_is_valid(struct cpu_port *port)
130{
131 return !!(port->port & PORT_VALID);
132}
133
134static inline bool cpu_port_match(struct cpu_port *port, u64 mpidr)
135{
136 return port->mpidr == (mpidr & MPIDR_HWID_BITMASK);
137}
138
139static struct cpu_port cpu_port[NR_CPUS];
140
141/**
142 * __cci_ace_get_port - Function to retrieve the port index connected to
143 * a cpu or device.
144 *
145 * @dn: device node of the device to look-up
146 * @type: port type
147 *
148 * Return value:
149 * - CCI port index if success
150 * - -ENODEV if failure
151 */
152static int __cci_ace_get_port(struct device_node *dn, int type)
153{
154 int i;
155 bool ace_match;
156 struct device_node *cci_portn;
157
158 cci_portn = of_parse_phandle(dn, "cci-control-port", 0);
159 for (i = 0; i < nb_cci_ports; i++) {
160 ace_match = ports[i].type == type;
161 if (ace_match && cci_portn == ports[i].dn)
162 return i;
163 }
164 return -ENODEV;
165}
166
167int cci_ace_get_port(struct device_node *dn)
168{
169 return __cci_ace_get_port(dn, ACE_LITE_PORT);
170}
171EXPORT_SYMBOL_GPL(cci_ace_get_port);
172
Punit Agrawalb91c8f22013-08-22 14:41:51 +0100173static void cci_ace_init_ports(void)
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100174{
Sudeep KarkadaNagesha78b4d6e2013-06-17 14:51:48 +0100175 int port, cpu;
176 struct device_node *cpun;
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100177
178 /*
179 * Port index look-up speeds up the function disabling ports by CPU,
180 * since the logical to port index mapping is done once and does
181 * not change after system boot.
182 * The stashed index array is initialized for all possible CPUs
183 * at probe time.
184 */
Sudeep KarkadaNagesha78b4d6e2013-06-17 14:51:48 +0100185 for_each_possible_cpu(cpu) {
186 /* too early to use cpu->of_node */
187 cpun = of_get_cpu_node(cpu, NULL);
188
189 if (WARN(!cpun, "Missing cpu device node\n"))
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100190 continue;
191
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100192 port = __cci_ace_get_port(cpun, ACE_PORT);
193 if (port < 0)
194 continue;
195
196 init_cpu_port(&cpu_port[cpu], port, cpu_logical_map(cpu));
197 }
198
199 for_each_possible_cpu(cpu) {
200 WARN(!cpu_port_is_valid(&cpu_port[cpu]),
201 "CPU %u does not have an associated CCI port\n",
202 cpu);
203 }
204}
205/*
206 * Functions to enable/disable a CCI interconnect slave port
207 *
208 * They are called by low-level power management code to disable slave
209 * interfaces snoops and DVM broadcast.
210 * Since they may execute with cache data allocation disabled and
211 * after the caches have been cleaned and invalidated the functions provide
212 * no explicit locking since they may run with D-cache disabled, so normal
213 * cacheable kernel locks based on ldrex/strex may not work.
214 * Locking has to be provided by BSP implementations to ensure proper
215 * operations.
216 */
217
218/**
219 * cci_port_control() - function to control a CCI port
220 *
221 * @port: index of the port to setup
222 * @enable: if true enables the port, if false disables it
223 */
224static void notrace cci_port_control(unsigned int port, bool enable)
225{
226 void __iomem *base = ports[port].base;
227
228 writel_relaxed(enable ? CCI_ENABLE_REQ : 0, base + CCI_PORT_CTRL);
229 /*
230 * This function is called from power down procedures
231 * and must not execute any instruction that might
232 * cause the processor to be put in a quiescent state
233 * (eg wfi). Hence, cpu_relax() can not be added to this
234 * read loop to optimize power, since it might hide possibly
235 * disruptive operations.
236 */
237 while (readl_relaxed(cci_ctrl_base + CCI_CTRL_STATUS) & 0x1)
238 ;
239}
240
241/**
242 * cci_disable_port_by_cpu() - function to disable a CCI port by CPU
243 * reference
244 *
245 * @mpidr: mpidr of the CPU whose CCI port should be disabled
246 *
247 * Disabling a CCI port for a CPU implies disabling the CCI port
248 * controlling that CPU cluster. Code disabling CPU CCI ports
249 * must make sure that the CPU running the code is the last active CPU
250 * in the cluster ie all other CPUs are quiescent in a low power state.
251 *
252 * Return:
253 * 0 on success
254 * -ENODEV on port look-up failure
255 */
256int notrace cci_disable_port_by_cpu(u64 mpidr)
257{
258 int cpu;
259 bool is_valid;
260 for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
261 is_valid = cpu_port_is_valid(&cpu_port[cpu]);
262 if (is_valid && cpu_port_match(&cpu_port[cpu], mpidr)) {
263 cci_port_control(cpu_port[cpu].port, false);
264 return 0;
265 }
266 }
267 return -ENODEV;
268}
269EXPORT_SYMBOL_GPL(cci_disable_port_by_cpu);
270
271/**
Nicolas Pitre62158f82013-05-21 23:34:41 -0400272 * cci_enable_port_for_self() - enable a CCI port for calling CPU
273 *
274 * Enabling a CCI port for the calling CPU implies enabling the CCI
275 * port controlling that CPU's cluster. Caller must make sure that the
276 * CPU running the code is the first active CPU in the cluster and all
277 * other CPUs are quiescent in a low power state or waiting for this CPU
278 * to complete the CCI initialization.
279 *
280 * Because this is called when the MMU is still off and with no stack,
281 * the code must be position independent and ideally rely on callee
282 * clobbered registers only. To achieve this we must code this function
283 * entirely in assembler.
284 *
285 * On success this returns with the proper CCI port enabled. In case of
286 * any failure this never returns as the inability to enable the CCI is
287 * fatal and there is no possible recovery at this stage.
288 */
289asmlinkage void __naked cci_enable_port_for_self(void)
290{
291 asm volatile ("\n"
Arnd Bergmannf4902492013-06-03 15:15:36 +0200292" .arch armv7-a\n"
Nicolas Pitre62158f82013-05-21 23:34:41 -0400293" mrc p15, 0, r0, c0, c0, 5 @ get MPIDR value \n"
294" and r0, r0, #"__stringify(MPIDR_HWID_BITMASK)" \n"
295" adr r1, 5f \n"
296" ldr r2, [r1] \n"
297" add r1, r1, r2 @ &cpu_port \n"
298" add ip, r1, %[sizeof_cpu_port] \n"
299
300 /* Loop over the cpu_port array looking for a matching MPIDR */
301"1: ldr r2, [r1, %[offsetof_cpu_port_mpidr_lsb]] \n"
302" cmp r2, r0 @ compare MPIDR \n"
303" bne 2f \n"
304
305 /* Found a match, now test port validity */
306" ldr r3, [r1, %[offsetof_cpu_port_port]] \n"
307" tst r3, #"__stringify(PORT_VALID)" \n"
308" bne 3f \n"
309
310 /* no match, loop with the next cpu_port entry */
311"2: add r1, r1, %[sizeof_struct_cpu_port] \n"
312" cmp r1, ip @ done? \n"
313" blo 1b \n"
314
315 /* CCI port not found -- cheaply try to stall this CPU */
316"cci_port_not_found: \n"
317" wfi \n"
318" wfe \n"
319" b cci_port_not_found \n"
320
321 /* Use matched port index to look up the corresponding ports entry */
322"3: bic r3, r3, #"__stringify(PORT_VALID)" \n"
323" adr r0, 6f \n"
324" ldmia r0, {r1, r2} \n"
325" sub r1, r1, r0 @ virt - phys \n"
326" ldr r0, [r0, r2] @ *(&ports) \n"
327" mov r2, %[sizeof_struct_ace_port] \n"
328" mla r0, r2, r3, r0 @ &ports[index] \n"
329" sub r0, r0, r1 @ virt_to_phys() \n"
330
331 /* Enable the CCI port */
332" ldr r0, [r0, %[offsetof_port_phys]] \n"
Victor Kamenskyfdb07ae2013-10-15 21:50:34 -0700333" mov r3, %[cci_enable_req]\n"
Nicolas Pitre62158f82013-05-21 23:34:41 -0400334" str r3, [r0, #"__stringify(CCI_PORT_CTRL)"] \n"
335
336 /* poll the status reg for completion */
337" adr r1, 7f \n"
338" ldr r0, [r1] \n"
339" ldr r0, [r0, r1] @ cci_ctrl_base \n"
340"4: ldr r1, [r0, #"__stringify(CCI_CTRL_STATUS)"] \n"
Victor Kamenskyfdb07ae2013-10-15 21:50:34 -0700341" tst r1, %[cci_control_status_bits] \n"
Nicolas Pitre62158f82013-05-21 23:34:41 -0400342" bne 4b \n"
343
344" mov r0, #0 \n"
345" bx lr \n"
346
347" .align 2 \n"
348"5: .word cpu_port - . \n"
349"6: .word . \n"
350" .word ports - 6b \n"
351"7: .word cci_ctrl_phys - . \n"
352 : :
353 [sizeof_cpu_port] "i" (sizeof(cpu_port)),
Victor Kamenskyfdb07ae2013-10-15 21:50:34 -0700354 [cci_enable_req] "i" cpu_to_le32(CCI_ENABLE_REQ),
355 [cci_control_status_bits] "i" cpu_to_le32(1),
Nicolas Pitre62158f82013-05-21 23:34:41 -0400356#ifndef __ARMEB__
357 [offsetof_cpu_port_mpidr_lsb] "i" (offsetof(struct cpu_port, mpidr)),
358#else
359 [offsetof_cpu_port_mpidr_lsb] "i" (offsetof(struct cpu_port, mpidr)+4),
360#endif
361 [offsetof_cpu_port_port] "i" (offsetof(struct cpu_port, port)),
362 [sizeof_struct_cpu_port] "i" (sizeof(struct cpu_port)),
363 [sizeof_struct_ace_port] "i" (sizeof(struct cci_ace_port)),
364 [offsetof_port_phys] "i" (offsetof(struct cci_ace_port, phys)) );
365
366 unreachable();
367}
368
369/**
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100370 * __cci_control_port_by_device() - function to control a CCI port by device
371 * reference
372 *
373 * @dn: device node pointer of the device whose CCI port should be
374 * controlled
375 * @enable: if true enables the port, if false disables it
376 *
377 * Return:
378 * 0 on success
379 * -ENODEV on port look-up failure
380 */
381int notrace __cci_control_port_by_device(struct device_node *dn, bool enable)
382{
383 int port;
384
385 if (!dn)
386 return -ENODEV;
387
388 port = __cci_ace_get_port(dn, ACE_LITE_PORT);
Rob Herring9c0982d2017-07-18 16:42:51 -0500389 if (WARN_ONCE(port < 0, "node %pOF ACE lite port look-up failure\n",
390 dn))
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100391 return -ENODEV;
392 cci_port_control(port, enable);
393 return 0;
394}
395EXPORT_SYMBOL_GPL(__cci_control_port_by_device);
396
397/**
398 * __cci_control_port_by_index() - function to control a CCI port by port index
399 *
400 * @port: port index previously retrieved with cci_ace_get_port()
401 * @enable: if true enables the port, if false disables it
402 *
403 * Return:
404 * 0 on success
405 * -ENODEV on port index out of range
406 * -EPERM if operation carried out on an ACE PORT
407 */
408int notrace __cci_control_port_by_index(u32 port, bool enable)
409{
410 if (port >= nb_cci_ports || ports[port].type == ACE_INVALID_PORT)
411 return -ENODEV;
412 /*
413 * CCI control for ports connected to CPUS is extremely fragile
414 * and must be made to go through a specific and controlled
415 * interface (ie cci_disable_port_by_cpu(); control by general purpose
416 * indexing is therefore disabled for ACE ports.
417 */
418 if (ports[port].type == ACE_PORT)
419 return -EPERM;
420
421 cci_port_control(port, enable);
422 return 0;
423}
424EXPORT_SYMBOL_GPL(__cci_control_port_by_index);
425
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100426static const struct of_device_id arm_cci_ctrl_if_matches[] = {
427 {.compatible = "arm,cci-400-ctrl-if", },
428 {},
429};
430
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +0000431static int cci_probe_ports(struct device_node *np)
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100432{
433 struct cci_nb_ports const *cci_config;
434 int ret, i, nb_ace = 0, nb_ace_lite = 0;
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +0000435 struct device_node *cp;
Nicolas Pitre62158f82013-05-21 23:34:41 -0400436 struct resource res;
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100437 const char *match_str;
438 bool is_ace;
439
Abhilash Kesavan896ddd62015-01-10 08:41:35 +0530440
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100441 cci_config = of_match_node(arm_cci_matches, np)->data;
442 if (!cci_config)
443 return -ENODEV;
444
445 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
446
Lorenzo Pieralisi7c762032014-01-27 10:50:37 +0000447 ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100448 if (!ports)
449 return -ENOMEM;
450
Robin Murphy3ee5e822018-02-15 18:51:44 +0000451 for_each_available_child_of_node(np, cp) {
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100452 if (!of_match_node(arm_cci_ctrl_if_matches, cp))
453 continue;
454
455 i = nb_ace + nb_ace_lite;
456
457 if (i >= nb_cci_ports)
458 break;
459
460 if (of_property_read_string(cp, "interface-type",
461 &match_str)) {
Rob Herring9c0982d2017-07-18 16:42:51 -0500462 WARN(1, "node %pOF missing interface-type property\n",
463 cp);
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100464 continue;
465 }
466 is_ace = strcmp(match_str, "ace") == 0;
467 if (!is_ace && strcmp(match_str, "ace-lite")) {
Rob Herring9c0982d2017-07-18 16:42:51 -0500468 WARN(1, "node %pOF containing invalid interface-type property, skipping it\n",
469 cp);
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100470 continue;
471 }
472
Nicolas Pitre62158f82013-05-21 23:34:41 -0400473 ret = of_address_to_resource(cp, 0, &res);
474 if (!ret) {
475 ports[i].base = ioremap(res.start, resource_size(&res));
476 ports[i].phys = res.start;
477 }
478 if (ret || !ports[i].base) {
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100479 WARN(1, "unable to ioremap CCI port %d\n", i);
480 continue;
481 }
482
483 if (is_ace) {
484 if (WARN_ON(nb_ace >= cci_config->nb_ace))
485 continue;
486 ports[i].type = ACE_PORT;
487 ++nb_ace;
488 } else {
489 if (WARN_ON(nb_ace_lite >= cci_config->nb_ace_lite))
490 continue;
491 ports[i].type = ACE_LITE_PORT;
492 ++nb_ace_lite;
493 }
494 ports[i].dn = cp;
495 }
496
Lorenzo Pieralisi801f33b2016-09-23 14:09:07 +0100497 /*
498 * If there is no CCI port that is under kernel control
499 * return early and report probe status.
500 */
501 if (!nb_ace && !nb_ace_lite)
502 return -ENODEV;
503
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100504 /* initialize a stashed array of ACE ports to speed-up look-up */
505 cci_ace_init_ports();
506
507 /*
508 * Multi-cluster systems may need this data when non-coherent, during
509 * cluster power-up/power-down. Make sure it reaches main memory.
510 */
511 sync_cache_w(&cci_ctrl_base);
Nicolas Pitre62158f82013-05-21 23:34:41 -0400512 sync_cache_w(&cci_ctrl_phys);
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100513 sync_cache_w(&ports);
514 sync_cache_w(&cpu_port);
515 __sync_cache_range_w(ports, sizeof(*ports) * nb_cci_ports);
516 pr_info("ARM CCI driver probed\n");
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +0000517
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100518 return 0;
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +0000519}
Suzuki K. Pouloseee8e5d52015-03-18 12:24:41 +0000520#else /* !CONFIG_ARM_CCI400_PORT_CTRL */
521static inline int cci_probe_ports(struct device_node *np)
522{
523 return 0;
524}
525#endif /* CONFIG_ARM_CCI400_PORT_CTRL */
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100526
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +0000527static int cci_probe(void)
528{
529 int ret;
530 struct device_node *np;
531 struct resource res;
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100532
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +0000533 np = of_find_matching_node(NULL, arm_cci_matches);
Robin Murphy3ee5e822018-02-15 18:51:44 +0000534 if (!of_device_is_available(np))
Suzuki K. Poulosef6b9e832015-03-18 12:24:38 +0000535 return -ENODEV;
536
537 ret = of_address_to_resource(np, 0, &res);
538 if (!ret) {
539 cci_ctrl_base = ioremap(res.start, resource_size(&res));
540 cci_ctrl_phys = res.start;
541 }
542 if (ret || !cci_ctrl_base) {
543 WARN(1, "unable to ioremap CCI ctrl\n");
544 return -ENXIO;
545 }
546
547 return cci_probe_ports(np);
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100548}
549
550static int cci_init_status = -EAGAIN;
551static DEFINE_MUTEX(cci_probing);
552
Punit Agrawalb91c8f22013-08-22 14:41:51 +0100553static int cci_init(void)
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100554{
555 if (cci_init_status != -EAGAIN)
556 return cci_init_status;
557
558 mutex_lock(&cci_probing);
559 if (cci_init_status == -EAGAIN)
560 cci_init_status = cci_probe();
561 mutex_unlock(&cci_probing);
562 return cci_init_status;
563}
564
565/*
566 * To sort out early init calls ordering a helper function is provided to
567 * check if the CCI driver has beed initialized. Function check if the driver
568 * has been initialized, if not it calls the init function that probes
569 * the driver and updates the return value.
570 */
Punit Agrawalb91c8f22013-08-22 14:41:51 +0100571bool cci_probed(void)
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100572{
573 return cci_init() == 0;
574}
575EXPORT_SYMBOL_GPL(cci_probed);
576
577early_initcall(cci_init);
Punit Agrawalb91c8f22013-08-22 14:41:51 +0100578core_initcall(cci_platform_init);
Lorenzo Pieralisied69bdd2012-07-13 15:55:52 +0100579MODULE_LICENSE("GPL");
580MODULE_DESCRIPTION("ARM CCI support");