blob: a0a822afb2b0bd37233d076476ed7b79744c0bf3 [file] [log] [blame]
Amol Jadidb1edb32011-07-18 14:24:46 -07001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
Aparna Mallavarapu18de8f02014-06-16 20:03:31 +05305 * Copyright (c) 2009-2011,2014, The Linux Foundation. All rights reserved.
Amol Jadidb1edb32011-07-18 14:24:46 -07006 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google, Inc. nor the names of its contributors
17 * may be used to endorse or promote products derived from this
18 * software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include <reg.h>
Amol Jadidb1edb32011-07-18 14:24:46 -070035#include <arch/arm.h>
Amol Jadidb1edb32011-07-18 14:24:46 -070036#include <qgic.h>
37
Aparna Mallavarapu18de8f02014-06-16 20:03:31 +053038static uint8_t qgic_get_cpumask()
39{
40 uint32_t mask=0, i;
41
42 /* Fetch the CPU MASK from the SGI/PPI reg */
43 for (i=0; i < 32; i += 4) {
44 mask = readl(GIC_DIST_TARGET + i);
45 mask |= mask >> 16;
46 mask |= mask >> 8;
47 if (mask)
48 break;
49 }
Aparna Mallavarapu18de8f02014-06-16 20:03:31 +053050 return mask;
51}
52
Amol Jadidb1edb32011-07-18 14:24:46 -070053/* Intialize distributor */
Channagoud Kadabie240b702014-06-19 12:14:44 -070054void qgic_dist_init(void)
Amol Jadidb1edb32011-07-18 14:24:46 -070055{
56 uint32_t i;
57 uint32_t num_irq = 0;
Aparna Mallavarapu18de8f02014-06-16 20:03:31 +053058 uint32_t cpumask;
59
60 cpumask = qgic_get_cpumask();
Amol Jadidb1edb32011-07-18 14:24:46 -070061
62 cpumask |= cpumask << 8;
63 cpumask |= cpumask << 16;
64
65 /* Disabling GIC */
66 writel(0, GIC_DIST_CTRL);
67
68 /*
69 * Find out how many interrupts are supported.
70 */
71 num_irq = readl(GIC_DIST_CTR) & 0x1f;
72 num_irq = (num_irq + 1) * 32;
73
Amol Jadidb1edb32011-07-18 14:24:46 -070074 /* Set up interrupts for this CPU */
75 for (i = 32; i < num_irq; i += 4)
76 writel(cpumask, GIC_DIST_TARGET + i * 4 / 4);
77
Channagoud Kadabie240b702014-06-19 12:14:44 -070078 qgic_dist_config(num_irq);
Amol Jadidb1edb32011-07-18 14:24:46 -070079
Ajay Dudanib01e5062011-12-03 23:23:42 -080080 /*Enabling GIC */
Amol Jadidb1edb32011-07-18 14:24:46 -070081 writel(1, GIC_DIST_CTRL);
82}
83
84/* Intialize cpu specific controller */
Channagoud Kadabie240b702014-06-19 12:14:44 -070085void qgic_cpu_init(void)
Amol Jadidb1edb32011-07-18 14:24:46 -070086{
87 writel(0xf0, GIC_CPU_PRIMASK);
88 writel(1, GIC_CPU_CTRL);
89}
90
Channagoud Kadabie240b702014-06-19 12:14:44 -070091uint32_t qgic_read_iar()
Amol Jadidb1edb32011-07-18 14:24:46 -070092{
Channagoud Kadabie240b702014-06-19 12:14:44 -070093 return readl(GIC_CPU_INTACK);
Amol Jadidb1edb32011-07-18 14:24:46 -070094}
95
Channagoud Kadabie240b702014-06-19 12:14:44 -070096void qgic_write_eoi(uint32_t num)
Amol Jadidb1edb32011-07-18 14:24:46 -070097{
Amol Jadidb1edb32011-07-18 14:24:46 -070098 writel(num, GIC_CPU_EOI);
Sridhar Parasuram1ed164d2014-09-25 18:04:34 -070099}