aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/irqchip/irq-gic.c
diff options
context:
space:
mode:
authorJon Hunter <jonathanh@nvidia.com>2016-05-10 11:14:44 -0400
committerMarc Zyngier <marc.zyngier@arm.com>2016-05-11 05:12:44 -0400
commitf673b9b5cb5453fa14032d99edd55f49ac3980cc (patch)
tree63f057448656eee982adc533095a01adfc93dba4 /drivers/irqchip/irq-gic.c
parent6e5b5924d9a897062527b6fc9b06f31f7bfd5744 (diff)
irqchip/gic: Store GIC configuration parameters
Store the GIC configuration parameters in the GIC chip data structure. This will allow us to simplify the code by reducing the number of parameters passed between functions. Update the __gic_init_bases() function so that we only need to pass a pointer to the GIC chip data structure and no longer need to pass the GIC index in order to look-up the chip data. Signed-off-by: Jon Hunter <jonathanh@nvidia.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Diffstat (limited to 'drivers/irqchip/irq-gic.c')
-rw-r--r--drivers/irqchip/irq-gic.c114
1 files changed, 65 insertions, 49 deletions
diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
index d75aa1a8d6da..f4c14f9ca15b 100644
--- a/drivers/irqchip/irq-gic.c
+++ b/drivers/irqchip/irq-gic.c
@@ -72,6 +72,9 @@ struct gic_chip_data {
72 struct irq_chip chip; 72 struct irq_chip chip;
73 union gic_base dist_base; 73 union gic_base dist_base;
74 union gic_base cpu_base; 74 union gic_base cpu_base;
75 void __iomem *raw_dist_base;
76 void __iomem *raw_cpu_base;
77 u32 percpu_offset;
75#ifdef CONFIG_CPU_PM 78#ifdef CONFIG_CPU_PM
76 u32 saved_spi_enable[DIV_ROUND_UP(1020, 32)]; 79 u32 saved_spi_enable[DIV_ROUND_UP(1020, 32)];
77 u32 saved_spi_active[DIV_ROUND_UP(1020, 32)]; 80 u32 saved_spi_active[DIV_ROUND_UP(1020, 32)];
@@ -1026,38 +1029,36 @@ static const struct irq_domain_ops gic_irq_domain_ops = {
1026 .unmap = gic_irq_domain_unmap, 1029 .unmap = gic_irq_domain_unmap,
1027}; 1030};
1028 1031
1029static int __init __gic_init_bases(unsigned int gic_nr, int irq_start, 1032static int __init __gic_init_bases(struct gic_chip_data *gic, int irq_start,
1030 void __iomem *dist_base, void __iomem *cpu_base, 1033 struct fwnode_handle *handle)
1031 u32 percpu_offset, struct fwnode_handle *handle)
1032{ 1034{
1033 irq_hw_number_t hwirq_base; 1035 irq_hw_number_t hwirq_base;
1034 struct gic_chip_data *gic;
1035 int gic_irqs, irq_base, i, ret; 1036 int gic_irqs, irq_base, i, ret;
1036 1037
1037 BUG_ON(gic_nr >= CONFIG_ARM_GIC_MAX_NR); 1038 if (WARN_ON(!gic || gic->domain))
1039 return -EINVAL;
1038 1040
1039 gic_check_cpu_features(); 1041 gic_check_cpu_features();
1040 1042
1041 gic = &gic_data[gic_nr];
1042
1043 /* Initialize irq_chip */ 1043 /* Initialize irq_chip */
1044 gic->chip = gic_chip; 1044 gic->chip = gic_chip;
1045 1045
1046 if (static_key_true(&supports_deactivate) && gic_nr == 0) { 1046 if (static_key_true(&supports_deactivate) && gic == &gic_data[0]) {
1047 gic->chip.irq_mask = gic_eoimode1_mask_irq; 1047 gic->chip.irq_mask = gic_eoimode1_mask_irq;
1048 gic->chip.irq_eoi = gic_eoimode1_eoi_irq; 1048 gic->chip.irq_eoi = gic_eoimode1_eoi_irq;
1049 gic->chip.irq_set_vcpu_affinity = gic_irq_set_vcpu_affinity; 1049 gic->chip.irq_set_vcpu_affinity = gic_irq_set_vcpu_affinity;
1050 gic->chip.name = kasprintf(GFP_KERNEL, "GICv2"); 1050 gic->chip.name = kasprintf(GFP_KERNEL, "GICv2");
1051 } else { 1051 } else {
1052 gic->chip.name = kasprintf(GFP_KERNEL, "GIC-%d", gic_nr); 1052 gic->chip.name = kasprintf(GFP_KERNEL, "GIC-%d",
1053 (int)(gic - &gic_data[0]));
1053 } 1054 }
1054 1055
1055#ifdef CONFIG_SMP 1056#ifdef CONFIG_SMP
1056 if (gic_nr == 0) 1057 if (gic == &gic_data[0])
1057 gic->chip.irq_set_affinity = gic_set_affinity; 1058 gic->chip.irq_set_affinity = gic_set_affinity;
1058#endif 1059#endif
1059 1060
1060 if (IS_ENABLED(CONFIG_GIC_NON_BANKED) && percpu_offset) { 1061 if (IS_ENABLED(CONFIG_GIC_NON_BANKED) && gic->percpu_offset) {
1061 /* Frankein-GIC without banked registers... */ 1062 /* Frankein-GIC without banked registers... */
1062 unsigned int cpu; 1063 unsigned int cpu;
1063 1064
@@ -1072,19 +1073,21 @@ static int __init __gic_init_bases(unsigned int gic_nr, int irq_start,
1072 for_each_possible_cpu(cpu) { 1073 for_each_possible_cpu(cpu) {
1073 u32 mpidr = cpu_logical_map(cpu); 1074 u32 mpidr = cpu_logical_map(cpu);
1074 u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0); 1075 u32 core_id = MPIDR_AFFINITY_LEVEL(mpidr, 0);
1075 unsigned long offset = percpu_offset * core_id; 1076 unsigned long offset = gic->percpu_offset * core_id;
1076 *per_cpu_ptr(gic->dist_base.percpu_base, cpu) = dist_base + offset; 1077 *per_cpu_ptr(gic->dist_base.percpu_base, cpu) =
1077 *per_cpu_ptr(gic->cpu_base.percpu_base, cpu) = cpu_base + offset; 1078 gic->raw_dist_base + offset;
1079 *per_cpu_ptr(gic->cpu_base.percpu_base, cpu) =
1080 gic->raw_cpu_base + offset;
1078 } 1081 }
1079 1082
1080 gic_set_base_accessor(gic, gic_get_percpu_base); 1083 gic_set_base_accessor(gic, gic_get_percpu_base);
1081 } else { 1084 } else {
1082 /* Normal, sane GIC... */ 1085 /* Normal, sane GIC... */
1083 WARN(percpu_offset, 1086 WARN(gic->percpu_offset,
1084 "GIC_NON_BANKED not enabled, ignoring %08x offset!", 1087 "GIC_NON_BANKED not enabled, ignoring %08x offset!",
1085 percpu_offset); 1088 gic->percpu_offset);
1086 gic->dist_base.common_base = dist_base; 1089 gic->dist_base.common_base = gic->raw_dist_base;
1087 gic->cpu_base.common_base = cpu_base; 1090 gic->cpu_base.common_base = gic->raw_cpu_base;
1088 gic_set_base_accessor(gic, gic_get_common_base); 1091 gic_set_base_accessor(gic, gic_get_common_base);
1089 } 1092 }
1090 1093
@@ -1107,7 +1110,7 @@ static int __init __gic_init_bases(unsigned int gic_nr, int irq_start,
1107 * For primary GICs, skip over SGIs. 1110 * For primary GICs, skip over SGIs.
1108 * For secondary GICs, skip over PPIs, too. 1111 * For secondary GICs, skip over PPIs, too.
1109 */ 1112 */
1110 if (gic_nr == 0 && (irq_start & 31) > 0) { 1113 if (gic == &gic_data[0] && (irq_start & 31) > 0) {
1111 hwirq_base = 16; 1114 hwirq_base = 16;
1112 if (irq_start != -1) 1115 if (irq_start != -1)
1113 irq_start = (irq_start & ~31) + 16; 1116 irq_start = (irq_start & ~31) + 16;
@@ -1134,7 +1137,7 @@ static int __init __gic_init_bases(unsigned int gic_nr, int irq_start,
1134 goto error; 1137 goto error;
1135 } 1138 }
1136 1139
1137 if (gic_nr == 0) { 1140 if (gic == &gic_data[0]) {
1138 /* 1141 /*
1139 * Initialize the CPU interface map to all CPUs. 1142 * Initialize the CPU interface map to all CPUs.
1140 * It will be refined as each CPU probes its ID. 1143 * It will be refined as each CPU probes its ID.
@@ -1163,7 +1166,7 @@ static int __init __gic_init_bases(unsigned int gic_nr, int irq_start,
1163 return 0; 1166 return 0;
1164 1167
1165error: 1168error:
1166 if (IS_ENABLED(CONFIG_GIC_NON_BANKED) && percpu_offset) { 1169 if (IS_ENABLED(CONFIG_GIC_NON_BANKED) && gic->percpu_offset) {
1167 free_percpu(gic->dist_base.percpu_base); 1170 free_percpu(gic->dist_base.percpu_base);
1168 free_percpu(gic->cpu_base.percpu_base); 1171 free_percpu(gic->cpu_base.percpu_base);
1169 } 1172 }
@@ -1176,12 +1179,22 @@ error:
1176void __init gic_init(unsigned int gic_nr, int irq_start, 1179void __init gic_init(unsigned int gic_nr, int irq_start,
1177 void __iomem *dist_base, void __iomem *cpu_base) 1180 void __iomem *dist_base, void __iomem *cpu_base)
1178{ 1181{
1182 struct gic_chip_data *gic;
1183
1184 if (WARN_ON(gic_nr >= CONFIG_ARM_GIC_MAX_NR))
1185 return;
1186
1179 /* 1187 /*
1180 * Non-DT/ACPI systems won't run a hypervisor, so let's not 1188 * Non-DT/ACPI systems won't run a hypervisor, so let's not
1181 * bother with these... 1189 * bother with these...
1182 */ 1190 */
1183 static_key_slow_dec(&supports_deactivate); 1191 static_key_slow_dec(&supports_deactivate);
1184 __gic_init_bases(gic_nr, irq_start, dist_base, cpu_base, 0, NULL); 1192
1193 gic = &gic_data[gic_nr];
1194 gic->raw_dist_base = dist_base;
1195 gic->raw_cpu_base = cpu_base;
1196
1197 __gic_init_bases(gic, irq_start, NULL);
1185} 1198}
1186 1199
1187#ifdef CONFIG_OF 1200#ifdef CONFIG_OF
@@ -1228,21 +1241,24 @@ static bool gic_check_eoimode(struct device_node *node, void __iomem **base)
1228int __init 1241int __init
1229gic_of_init(struct device_node *node, struct device_node *parent) 1242gic_of_init(struct device_node *node, struct device_node *parent)
1230{ 1243{
1231 void __iomem *cpu_base; 1244 struct gic_chip_data *gic;
1232 void __iomem *dist_base;
1233 u32 percpu_offset;
1234 int irq, ret; 1245 int irq, ret;
1235 1246
1236 if (WARN_ON(!node)) 1247 if (WARN_ON(!node))
1237 return -ENODEV; 1248 return -ENODEV;
1238 1249
1239 dist_base = of_iomap(node, 0); 1250 if (WARN_ON(gic_cnt >= CONFIG_ARM_GIC_MAX_NR))
1240 if (WARN(!dist_base, "unable to map gic dist registers\n")) 1251 return -EINVAL;
1252
1253 gic = &gic_data[gic_cnt];
1254
1255 gic->raw_dist_base = of_iomap(node, 0);
1256 if (WARN(!gic->raw_dist_base, "unable to map gic dist registers\n"))
1241 return -ENOMEM; 1257 return -ENOMEM;
1242 1258
1243 cpu_base = of_iomap(node, 1); 1259 gic->raw_cpu_base = of_iomap(node, 1);
1244 if (WARN(!cpu_base, "unable to map gic cpu registers\n")) { 1260 if (WARN(!gic->raw_cpu_base, "unable to map gic cpu registers\n")) {
1245 iounmap(dist_base); 1261 iounmap(gic->raw_dist_base);
1246 return -ENOMEM; 1262 return -ENOMEM;
1247 } 1263 }
1248 1264
@@ -1250,17 +1266,16 @@ gic_of_init(struct device_node *node, struct device_node *parent)
1250 * Disable split EOI/Deactivate if either HYP is not available 1266 * Disable split EOI/Deactivate if either HYP is not available
1251 * or the CPU interface is too small. 1267 * or the CPU interface is too small.
1252 */ 1268 */
1253 if (gic_cnt == 0 && !gic_check_eoimode(node, &cpu_base)) 1269 if (gic_cnt == 0 && !gic_check_eoimode(node, &gic->raw_cpu_base))
1254 static_key_slow_dec(&supports_deactivate); 1270 static_key_slow_dec(&supports_deactivate);
1255 1271
1256 if (of_property_read_u32(node, "cpu-offset", &percpu_offset)) 1272 if (of_property_read_u32(node, "cpu-offset", &gic->percpu_offset))
1257 percpu_offset = 0; 1273 gic->percpu_offset = 0;
1258 1274
1259 ret = __gic_init_bases(gic_cnt, -1, dist_base, cpu_base, percpu_offset, 1275 ret = __gic_init_bases(gic, -1, &node->fwnode);
1260 &node->fwnode);
1261 if (ret) { 1276 if (ret) {
1262 iounmap(dist_base); 1277 iounmap(gic->raw_dist_base);
1263 iounmap(cpu_base); 1278 iounmap(gic->raw_cpu_base);
1264 return ret; 1279 return ret;
1265 } 1280 }
1266 1281
@@ -1350,8 +1365,8 @@ static int __init gic_v2_acpi_init(struct acpi_subtable_header *header,
1350 const unsigned long end) 1365 const unsigned long end)
1351{ 1366{
1352 struct acpi_madt_generic_distributor *dist; 1367 struct acpi_madt_generic_distributor *dist;
1353 void __iomem *cpu_base, *dist_base;
1354 struct fwnode_handle *domain_handle; 1368 struct fwnode_handle *domain_handle;
1369 struct gic_chip_data *gic = &gic_data[0];
1355 int count, ret; 1370 int count, ret;
1356 1371
1357 /* Collect CPU base addresses */ 1372 /* Collect CPU base addresses */
@@ -1362,17 +1377,18 @@ static int __init gic_v2_acpi_init(struct acpi_subtable_header *header,
1362 return -EINVAL; 1377 return -EINVAL;
1363 } 1378 }
1364 1379
1365 cpu_base = ioremap(cpu_phy_base, ACPI_GIC_CPU_IF_MEM_SIZE); 1380 gic->raw_cpu_base = ioremap(cpu_phy_base, ACPI_GIC_CPU_IF_MEM_SIZE);
1366 if (!cpu_base) { 1381 if (!gic->raw_cpu_base) {
1367 pr_err("Unable to map GICC registers\n"); 1382 pr_err("Unable to map GICC registers\n");
1368 return -ENOMEM; 1383 return -ENOMEM;
1369 } 1384 }
1370 1385
1371 dist = (struct acpi_madt_generic_distributor *)header; 1386 dist = (struct acpi_madt_generic_distributor *)header;
1372 dist_base = ioremap(dist->base_address, ACPI_GICV2_DIST_MEM_SIZE); 1387 gic->raw_dist_base = ioremap(dist->base_address,
1373 if (!dist_base) { 1388 ACPI_GICV2_DIST_MEM_SIZE);
1389 if (!gic->raw_dist_base) {
1374 pr_err("Unable to map GICD registers\n"); 1390 pr_err("Unable to map GICD registers\n");
1375 iounmap(cpu_base); 1391 iounmap(gic->raw_cpu_base);
1376 return -ENOMEM; 1392 return -ENOMEM;
1377 } 1393 }
1378 1394
@@ -1387,20 +1403,20 @@ static int __init gic_v2_acpi_init(struct acpi_subtable_header *header,
1387 /* 1403 /*
1388 * Initialize GIC instance zero (no multi-GIC support). 1404 * Initialize GIC instance zero (no multi-GIC support).
1389 */ 1405 */
1390 domain_handle = irq_domain_alloc_fwnode(dist_base); 1406 domain_handle = irq_domain_alloc_fwnode(gic->raw_dist_base);
1391 if (!domain_handle) { 1407 if (!domain_handle) {
1392 pr_err("Unable to allocate domain handle\n"); 1408 pr_err("Unable to allocate domain handle\n");
1393 iounmap(cpu_base); 1409 iounmap(gic->raw_cpu_base);
1394 iounmap(dist_base); 1410 iounmap(gic->raw_dist_base);
1395 return -ENOMEM; 1411 return -ENOMEM;
1396 } 1412 }
1397 1413
1398 ret = __gic_init_bases(0, -1, dist_base, cpu_base, 0, domain_handle); 1414 ret = __gic_init_bases(gic, -1, domain_handle);
1399 if (ret) { 1415 if (ret) {
1400 pr_err("Failed to initialise GIC\n"); 1416 pr_err("Failed to initialise GIC\n");
1401 irq_domain_free_fwnode(domain_handle); 1417 irq_domain_free_fwnode(domain_handle);
1402 iounmap(cpu_base); 1418 iounmap(gic->raw_cpu_base);
1403 iounmap(dist_base); 1419 iounmap(gic->raw_dist_base);
1404 return ret; 1420 return ret;
1405 } 1421 }
1406 1422