+128
-29
drivers/irqchip/irq-gic-v3-its.c
+128
-29
drivers/irqchip/irq-gic-v3-its.c
···
416
416
{
417
417
struct its_cmd_block *cmd, *sync_cmd, *next_cmd;
418
418
struct its_collection *sync_col;
419
+
unsigned long flags;
419
420
420
-
raw_spin_lock(&its->lock);
421
+
raw_spin_lock_irqsave(&its->lock, flags);
421
422
422
423
cmd = its_allocate_entry(its);
423
424
if (!cmd) { /* We're soooooo screewed... */
424
425
pr_err_ratelimited("ITS can't allocate, dropping command\n");
425
-
raw_spin_unlock(&its->lock);
426
+
raw_spin_unlock_irqrestore(&its->lock, flags);
426
427
return;
427
428
}
428
429
sync_col = builder(cmd, desc);
···
443
442
444
443
post:
445
444
next_cmd = its_post_commands(its);
446
-
raw_spin_unlock(&its->lock);
445
+
raw_spin_unlock_irqrestore(&its->lock, flags);
447
446
448
447
its_wait_for_range_completion(its, cmd, next_cmd);
449
448
}
···
800
799
{
801
800
int err;
802
801
int i;
803
-
int psz = PAGE_SIZE;
802
+
int psz = SZ_64K;
804
803
u64 shr = GITS_BASER_InnerShareable;
805
804
806
805
for (i = 0; i < GITS_BASER_NR_REGS; i++) {
807
806
u64 val = readq_relaxed(its->base + GITS_BASER + i * 8);
808
807
u64 type = GITS_BASER_TYPE(val);
809
808
u64 entry_size = GITS_BASER_ENTRY_SIZE(val);
809
+
int order = get_order(psz);
810
+
int alloc_size;
810
811
u64 tmp;
811
812
void *base;
812
813
813
814
if (type == GITS_BASER_TYPE_NONE)
814
815
continue;
815
816
816
-
/* We're lazy and only allocate a single page for now */
817
-
base = (void *)get_zeroed_page(GFP_KERNEL);
817
+
/*
818
+
* Allocate as many entries as required to fit the
819
+
* range of device IDs that the ITS can grok... The ID
820
+
* space being incredibly sparse, this results in a
821
+
* massive waste of memory.
822
+
*
823
+
* For other tables, only allocate a single page.
824
+
*/
825
+
if (type == GITS_BASER_TYPE_DEVICE) {
826
+
u64 typer = readq_relaxed(its->base + GITS_TYPER);
827
+
u32 ids = GITS_TYPER_DEVBITS(typer);
828
+
829
+
order = get_order((1UL << ids) * entry_size);
830
+
if (order >= MAX_ORDER) {
831
+
order = MAX_ORDER - 1;
832
+
pr_warn("%s: Device Table too large, reduce its page order to %u\n",
833
+
its->msi_chip.of_node->full_name, order);
834
+
}
835
+
}
836
+
837
+
alloc_size = (1 << order) * PAGE_SIZE;
838
+
base = (void *)__get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
818
839
if (!base) {
819
840
err = -ENOMEM;
820
841
goto out_free;
···
864
841
break;
865
842
}
866
843
867
-
val |= (PAGE_SIZE / psz) - 1;
844
+
val |= (alloc_size / psz) - 1;
868
845
869
846
writeq_relaxed(val, its->base + GITS_BASER + i * 8);
870
847
tmp = readq_relaxed(its->base + GITS_BASER + i * 8);
···
905
882
}
906
883
907
884
pr_info("ITS: allocated %d %s @%lx (psz %dK, shr %d)\n",
908
-
(int)(PAGE_SIZE / entry_size),
885
+
(int)(alloc_size / entry_size),
909
886
its_base_type_string[type],
910
887
(unsigned long)virt_to_phys(base),
911
888
psz / SZ_1K, (int)shr >> GITS_BASER_SHAREABILITY_SHIFT);
···
1043
1020
static struct its_device *its_find_device(struct its_node *its, u32 dev_id)
1044
1021
{
1045
1022
struct its_device *its_dev = NULL, *tmp;
1023
+
unsigned long flags;
1046
1024
1047
-
raw_spin_lock(&its->lock);
1025
+
raw_spin_lock_irqsave(&its->lock, flags);
1048
1026
1049
1027
list_for_each_entry(tmp, &its->its_device_list, entry) {
1050
1028
if (tmp->device_id == dev_id) {
···
1054
1030
}
1055
1031
}
1056
1032
1057
-
raw_spin_unlock(&its->lock);
1033
+
raw_spin_unlock_irqrestore(&its->lock, flags);
1058
1034
1059
1035
return its_dev;
1060
1036
}
···
1064
1040
{
1065
1041
struct its_device *dev;
1066
1042
unsigned long *lpi_map;
1043
+
unsigned long flags;
1067
1044
void *itt;
1068
1045
int lpi_base;
1069
1046
int nr_lpis;
···
1081
1056
nr_ites = max(2UL, roundup_pow_of_two(nvecs));
1082
1057
sz = nr_ites * its->ite_size;
1083
1058
sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1;
1084
-
itt = kmalloc(sz, GFP_KERNEL);
1059
+
itt = kzalloc(sz, GFP_KERNEL);
1085
1060
lpi_map = its_lpi_alloc_chunks(nvecs, &lpi_base, &nr_lpis);
1086
1061
1087
1062
if (!dev || !itt || !lpi_map) {
···
1100
1075
dev->device_id = dev_id;
1101
1076
INIT_LIST_HEAD(&dev->entry);
1102
1077
1103
-
raw_spin_lock(&its->lock);
1078
+
raw_spin_lock_irqsave(&its->lock, flags);
1104
1079
list_add(&dev->entry, &its->its_device_list);
1105
-
raw_spin_unlock(&its->lock);
1080
+
raw_spin_unlock_irqrestore(&its->lock, flags);
1106
1081
1107
1082
/* Bind the device to the first possible CPU */
1108
1083
cpu = cpumask_first(cpu_online_mask);
···
1116
1091
1117
1092
static void its_free_device(struct its_device *its_dev)
1118
1093
{
1119
-
raw_spin_lock(&its_dev->its->lock);
1094
+
unsigned long flags;
1095
+
1096
+
raw_spin_lock_irqsave(&its_dev->its->lock, flags);
1120
1097
list_del(&its_dev->entry);
1121
-
raw_spin_unlock(&its_dev->its->lock);
1098
+
raw_spin_unlock_irqrestore(&its_dev->its->lock, flags);
1122
1099
kfree(its_dev->itt);
1123
1100
kfree(its_dev);
1124
1101
}
···
1139
1112
return 0;
1140
1113
}
1141
1114
1115
+
struct its_pci_alias {
1116
+
struct pci_dev *pdev;
1117
+
u32 dev_id;
1118
+
u32 count;
1119
+
};
1120
+
1121
+
static int its_pci_msi_vec_count(struct pci_dev *pdev)
1122
+
{
1123
+
int msi, msix;
1124
+
1125
+
msi = max(pci_msi_vec_count(pdev), 0);
1126
+
msix = max(pci_msix_vec_count(pdev), 0);
1127
+
1128
+
return max(msi, msix);
1129
+
}
1130
+
1131
+
static int its_get_pci_alias(struct pci_dev *pdev, u16 alias, void *data)
1132
+
{
1133
+
struct its_pci_alias *dev_alias = data;
1134
+
1135
+
dev_alias->dev_id = alias;
1136
+
if (pdev != dev_alias->pdev)
1137
+
dev_alias->count += its_pci_msi_vec_count(dev_alias->pdev);
1138
+
1139
+
return 0;
1140
+
}
1141
+
1142
1142
static int its_msi_prepare(struct irq_domain *domain, struct device *dev,
1143
1143
int nvec, msi_alloc_info_t *info)
1144
1144
{
1145
1145
struct pci_dev *pdev;
1146
1146
struct its_node *its;
1147
-
u32 dev_id;
1148
1147
struct its_device *its_dev;
1148
+
struct its_pci_alias dev_alias;
1149
1149
1150
1150
if (!dev_is_pci(dev))
1151
1151
return -EINVAL;
1152
1152
1153
1153
pdev = to_pci_dev(dev);
1154
-
dev_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
1154
+
dev_alias.pdev = pdev;
1155
+
dev_alias.count = nvec;
1156
+
1157
+
pci_for_each_dma_alias(pdev, its_get_pci_alias, &dev_alias);
1155
1158
its = domain->parent->host_data;
1156
1159
1157
-
its_dev = its_find_device(its, dev_id);
1158
-
if (WARN_ON(its_dev))
1159
-
return -EINVAL;
1160
+
its_dev = its_find_device(its, dev_alias.dev_id);
1161
+
if (its_dev) {
1162
+
/*
1163
+
* We already have seen this ID, probably through
1164
+
* another alias (PCI bridge of some sort). No need to
1165
+
* create the device.
1166
+
*/
1167
+
dev_dbg(dev, "Reusing ITT for devID %x\n", dev_alias.dev_id);
1168
+
goto out;
1169
+
}
1160
1170
1161
-
its_dev = its_create_device(its, dev_id, nvec);
1171
+
its_dev = its_create_device(its, dev_alias.dev_id, dev_alias.count);
1162
1172
if (!its_dev)
1163
1173
return -ENOMEM;
1164
1174
1165
-
dev_dbg(&pdev->dev, "ITT %d entries, %d bits\n", nvec, ilog2(nvec));
1166
-
1175
+
dev_dbg(&pdev->dev, "ITT %d entries, %d bits\n",
1176
+
dev_alias.count, ilog2(dev_alias.count));
1177
+
out:
1167
1178
info->scratchpad[0].ptr = its_dev;
1168
1179
info->scratchpad[1].ptr = dev;
1169
1180
return 0;
···
1320
1255
.deactivate = its_irq_domain_deactivate,
1321
1256
};
1322
1257
1258
+
static int its_force_quiescent(void __iomem *base)
1259
+
{
1260
+
u32 count = 1000000; /* 1s */
1261
+
u32 val;
1262
+
1263
+
val = readl_relaxed(base + GITS_CTLR);
1264
+
if (val & GITS_CTLR_QUIESCENT)
1265
+
return 0;
1266
+
1267
+
/* Disable the generation of all interrupts to this ITS */
1268
+
val &= ~GITS_CTLR_ENABLE;
1269
+
writel_relaxed(val, base + GITS_CTLR);
1270
+
1271
+
/* Poll GITS_CTLR and wait until ITS becomes quiescent */
1272
+
while (1) {
1273
+
val = readl_relaxed(base + GITS_CTLR);
1274
+
if (val & GITS_CTLR_QUIESCENT)
1275
+
return 0;
1276
+
1277
+
count--;
1278
+
if (!count)
1279
+
return -EBUSY;
1280
+
1281
+
cpu_relax();
1282
+
udelay(1);
1283
+
}
1284
+
}
1285
+
1323
1286
static int its_probe(struct device_node *node, struct irq_domain *parent)
1324
1287
{
1325
1288
struct resource res;
···
1373
1280
if (val != 0x30 && val != 0x40) {
1374
1281
pr_warn("%s: no ITS detected, giving up\n", node->full_name);
1375
1282
err = -ENODEV;
1283
+
goto out_unmap;
1284
+
}
1285
+
1286
+
err = its_force_quiescent(its_base);
1287
+
if (err) {
1288
+
pr_warn("%s: failed to quiesce, giving up\n",
1289
+
node->full_name);
1376
1290
goto out_unmap;
1377
1291
}
1378
1292
···
1423
1323
writeq_relaxed(baser, its->base + GITS_CBASER);
1424
1324
tmp = readq_relaxed(its->base + GITS_CBASER);
1425
1325
writeq_relaxed(0, its->base + GITS_CWRITER);
1426
-
writel_relaxed(1, its->base + GITS_CTLR);
1326
+
writel_relaxed(GITS_CTLR_ENABLE, its->base + GITS_CTLR);
1427
1327
1428
1328
if ((tmp ^ baser) & GITS_BASER_SHAREABILITY_MASK) {
1429
1329
pr_info("ITS: using cache flushing for cmd queue\n");
···
1482
1382
1483
1383
int its_cpu_init(void)
1484
1384
{
1485
-
if (!gic_rdists_supports_plpis()) {
1486
-
pr_info("CPU%d: LPIs not supported\n", smp_processor_id());
1487
-
return -ENXIO;
1488
-
}
1489
-
1490
1385
if (!list_empty(&its_nodes)) {
1386
+
if (!gic_rdists_supports_plpis()) {
1387
+
pr_info("CPU%d: LPIs not supported\n", smp_processor_id());
1388
+
return -ENXIO;
1389
+
}
1491
1390
its_cpu_init_lpis();
1492
1391
its_cpu_init_collection();
1493
1392
}
+1
-1
drivers/irqchip/irq-gic-v3.c
+1
-1
drivers/irqchip/irq-gic-v3.c
+12
-8
drivers/irqchip/irq-gic.c
+12
-8
drivers/irqchip/irq-gic.c
···
154
154
static void gic_mask_irq(struct irq_data *d)
155
155
{
156
156
u32 mask = 1 << (gic_irq(d) % 32);
157
+
unsigned long flags;
157
158
158
-
raw_spin_lock(&irq_controller_lock);
159
+
raw_spin_lock_irqsave(&irq_controller_lock, flags);
159
160
writel_relaxed(mask, gic_dist_base(d) + GIC_DIST_ENABLE_CLEAR + (gic_irq(d) / 32) * 4);
160
161
if (gic_arch_extn.irq_mask)
161
162
gic_arch_extn.irq_mask(d);
162
-
raw_spin_unlock(&irq_controller_lock);
163
+
raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
163
164
}
164
165
165
166
static void gic_unmask_irq(struct irq_data *d)
166
167
{
167
168
u32 mask = 1 << (gic_irq(d) % 32);
169
+
unsigned long flags;
168
170
169
-
raw_spin_lock(&irq_controller_lock);
171
+
raw_spin_lock_irqsave(&irq_controller_lock, flags);
170
172
if (gic_arch_extn.irq_unmask)
171
173
gic_arch_extn.irq_unmask(d);
172
174
writel_relaxed(mask, gic_dist_base(d) + GIC_DIST_ENABLE_SET + (gic_irq(d) / 32) * 4);
173
-
raw_spin_unlock(&irq_controller_lock);
175
+
raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
174
176
}
175
177
176
178
static void gic_eoi_irq(struct irq_data *d)
···
190
188
{
191
189
void __iomem *base = gic_dist_base(d);
192
190
unsigned int gicirq = gic_irq(d);
191
+
unsigned long flags;
193
192
int ret;
194
193
195
194
/* Interrupt configuration for SGIs can't be changed */
···
202
199
type != IRQ_TYPE_EDGE_RISING)
203
200
return -EINVAL;
204
201
205
-
raw_spin_lock(&irq_controller_lock);
202
+
raw_spin_lock_irqsave(&irq_controller_lock, flags);
206
203
207
204
if (gic_arch_extn.irq_set_type)
208
205
gic_arch_extn.irq_set_type(d, type);
209
206
210
207
ret = gic_configure_irq(gicirq, type, base, NULL);
211
208
212
-
raw_spin_unlock(&irq_controller_lock);
209
+
raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
213
210
214
211
return ret;
215
212
}
···
230
227
void __iomem *reg = gic_dist_base(d) + GIC_DIST_TARGET + (gic_irq(d) & ~3);
231
228
unsigned int cpu, shift = (gic_irq(d) % 4) * 8;
232
229
u32 val, mask, bit;
230
+
unsigned long flags;
233
231
234
232
if (!force)
235
233
cpu = cpumask_any_and(mask_val, cpu_online_mask);
···
240
236
if (cpu >= NR_GIC_CPU_IF || cpu >= nr_cpu_ids)
241
237
return -EINVAL;
242
238
243
-
raw_spin_lock(&irq_controller_lock);
239
+
raw_spin_lock_irqsave(&irq_controller_lock, flags);
244
240
mask = 0xff << shift;
245
241
bit = gic_cpu_map[cpu] << shift;
246
242
val = readl_relaxed(reg) & ~mask;
247
243
writel_relaxed(val | bit, reg);
248
-
raw_spin_unlock(&irq_controller_lock);
244
+
raw_spin_unlock_irqrestore(&irq_controller_lock, flags);
249
245
250
246
return IRQ_SET_MASK_OK;
251
247
}
+5
include/linux/irqchip/arm-gic-v3.h
+5
include/linux/irqchip/arm-gic-v3.h
···
166
166
167
167
#define GITS_TRANSLATER 0x10040
168
168
169
+
#define GITS_CTLR_ENABLE (1U << 0)
170
+
#define GITS_CTLR_QUIESCENT (1U << 31)
171
+
172
+
#define GITS_TYPER_DEVBITS_SHIFT 13
173
+
#define GITS_TYPER_DEVBITS(r) ((((r) >> GITS_TYPER_DEVBITS_SHIFT) & 0x1f) + 1)
169
174
#define GITS_TYPER_PTA (1UL << 19)
170
175
171
176
#define GITS_CBASER_VALID (1UL << 63)