Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Aparna Mallavarapu | 18de8f0 | 2014-06-16 20:03:31 +0530 | [diff] [blame] | 5 | * Copyright (c) 2009-2011,2014, The Linux Foundation. All rights reserved. |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 6 | * |
| 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 Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 35 | #include <arch/arm.h> |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 36 | #include <qgic.h> |
| 37 | |
Aparna Mallavarapu | 18de8f0 | 2014-06-16 20:03:31 +0530 | [diff] [blame] | 38 | static 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 Mallavarapu | 18de8f0 | 2014-06-16 20:03:31 +0530 | [diff] [blame] | 50 | return mask; |
| 51 | } |
| 52 | |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 53 | /* Intialize distributor */ |
Channagoud Kadabi | e240b70 | 2014-06-19 12:14:44 -0700 | [diff] [blame] | 54 | void qgic_dist_init(void) |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 55 | { |
| 56 | uint32_t i; |
| 57 | uint32_t num_irq = 0; |
Aparna Mallavarapu | 18de8f0 | 2014-06-16 20:03:31 +0530 | [diff] [blame] | 58 | uint32_t cpumask; |
| 59 | |
| 60 | cpumask = qgic_get_cpumask(); |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 61 | |
| 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 Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 74 | /* 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 Kadabi | e240b70 | 2014-06-19 12:14:44 -0700 | [diff] [blame] | 78 | qgic_dist_config(num_irq); |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 79 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 80 | /*Enabling GIC */ |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 81 | writel(1, GIC_DIST_CTRL); |
| 82 | } |
| 83 | |
| 84 | /* Intialize cpu specific controller */ |
Channagoud Kadabi | e240b70 | 2014-06-19 12:14:44 -0700 | [diff] [blame] | 85 | void qgic_cpu_init(void) |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 86 | { |
| 87 | writel(0xf0, GIC_CPU_PRIMASK); |
| 88 | writel(1, GIC_CPU_CTRL); |
| 89 | } |
| 90 | |
Channagoud Kadabi | e240b70 | 2014-06-19 12:14:44 -0700 | [diff] [blame] | 91 | uint32_t qgic_read_iar() |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 92 | { |
Channagoud Kadabi | e240b70 | 2014-06-19 12:14:44 -0700 | [diff] [blame] | 93 | return readl(GIC_CPU_INTACK); |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Channagoud Kadabi | e240b70 | 2014-06-19 12:14:44 -0700 | [diff] [blame] | 96 | void qgic_write_eoi(uint32_t num) |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 97 | { |
Amol Jadi | db1edb3 | 2011-07-18 14:24:46 -0700 | [diff] [blame] | 98 | writel(num, GIC_CPU_EOI); |
Sridhar Parasuram | 1ed164d | 2014-09-25 18:04:34 -0700 | [diff] [blame] | 99 | } |