hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/soc/rockchip/rockchip_amp.c
....@@ -15,6 +15,7 @@
1515 #include <linux/pm_runtime.h>
1616 #include <linux/rockchip/rockchip_sip.h>
1717 #include <soc/rockchip/rockchip_amp.h>
18
+#include <linux/irqchip/arm-gic-common.h>
1819
1920 #define RK_CPU_STATUS_OFF 0
2021 #define RK_CPU_STATUS_ON 1
....@@ -24,6 +25,7 @@
2425 #define GPIO_BANK_NUM 16
2526 #define GPIO_GROUP_PRIO_MAX 3
2627
28
+#define MAX_GIC_SPI_NUM (1020)
2729 #define AMP_GIC_DBG(fmt, arg...) do { if (0) { pr_warn(fmt, ##arg); } } while (0)
2830
2931 enum amp_cpu_ctrl_status {
....@@ -55,26 +57,27 @@
5557 struct amp_gpio_group_s {
5658 u32 bank_id;
5759 u32 prio;
58
- u32 irq_aff[AMP_AFF_MAX_CPU];
60
+ u64 irq_aff[AMP_AFF_MAX_CPU];
5961 u32 irq_id[AMP_AFF_MAX_CPU];
6062 u32 en[AMP_AFF_MAX_CPU];
6163 };
6264
6365 struct amp_irq_cfg_s {
66
+ u64 aff;
6467 u32 prio;
6568 u32 cpumask;
66
- u32 aff;
6769 int amp_flag;
68
-} irqs_cfg[1024];
70
+} irqs_cfg[MAX_GIC_SPI_NUM];
6971
7072 static struct amp_gic_ctrl_s {
73
+ enum gic_type gic_version;
74
+ u32 spis_num;
7175 struct {
7276 u32 aff;
7377 u32 cpumask;
7478 u32 flag;
7579 } aff_to_cpumask[AMP_AFF_MAX_CLUSTER][AMP_AFF_MAX_CPU];
76
- struct amp_irq_cfg_s irqs_cfg[1024];
77
- u32 validmask[1020 / 32 + 1];
80
+ struct amp_irq_cfg_s irqs_cfg[MAX_GIC_SPI_NUM];
7881 struct amp_gpio_group_s gpio_grp[GPIO_BANK_NUM][GPIO_GROUP_PRIO_MAX];
7982 u32 gpio_banks;
8083 } amp_ctrl;
....@@ -275,7 +278,12 @@
275278 return amp_ctrl.irqs_cfg[irq].cpumask;
276279 }
277280
278
-static u32 amp_get_cpumask_bit(u32 aff)
281
+int rockchip_amp_need_init_amp_irq(u32 irq)
282
+{
283
+ return amp_ctrl.irqs_cfg[irq].amp_flag;
284
+}
285
+
286
+static u32 amp_get_cpumask_bit(u64 aff)
279287 {
280288 u32 aff_cluster, aff_cpu;
281289
....@@ -285,18 +293,24 @@
285293 if (aff_cpu >= AMP_AFF_MAX_CPU || aff_cluster >= AMP_AFF_MAX_CLUSTER)
286294 return 0;
287295
288
- AMP_GIC_DBG("%s: aff:%d-%d: %x\n", __func__, aff_cluster, aff_cpu,
296
+ AMP_GIC_DBG(" %s: aff:%d-%d: %x\n", __func__, aff_cluster, aff_cpu,
289297 amp_ctrl.aff_to_cpumask[aff_cluster][aff_cpu].cpumask);
290298
291299 return amp_ctrl.aff_to_cpumask[aff_cluster][aff_cpu].cpumask;
300
+}
301
+
302
+u64 rockchip_amp_get_irq_aff(u32 irq)
303
+{
304
+ return amp_ctrl.irqs_cfg[irq].aff;
292305 }
293306
294307 static int gic_amp_get_gpio_prio_group_info(struct device_node *np,
295308 struct amp_gic_ctrl_s *amp_ctrl,
296309 int prio_id)
297310 {
298
- u32 gpio_bank, count0, count1, prio, irq_id, irq_aff;
299
- int i;
311
+ u32 gpio_bank, prio, irq_id;
312
+ u64 irq_aff;
313
+ int i, count0, count1;
300314 struct amp_gpio_group_s *gpio_grp;
301315 struct amp_irq_cfg_s *irqs_cfg;
302316
....@@ -320,7 +334,7 @@
320334 __func__, gpio_bank, prio_id, prio);
321335
322336 count0 = of_property_count_u32_elems(np, "girq-id");
323
- count1 = of_property_count_u32_elems(np, "girq-aff");
337
+ count1 = of_property_count_u64_elems(np, "girq-aff");
324338
325339 if (count0 != count1)
326340 return -EINVAL;
....@@ -330,7 +344,7 @@
330344 for (i = 0; i < count0; i++) {
331345 of_property_read_u32_index(np, "girq-id", i, &irq_id);
332346 gpio_grp->irq_id[i] = irq_id;
333
- of_property_read_u32_index(np, "girq-aff", i, &irq_aff);
347
+ of_property_read_u64_index(np, "girq-aff", i, &irq_aff);
334348
335349 gpio_grp->irq_aff[i] = irq_aff;
336350
....@@ -338,18 +352,24 @@
338352
339353 irqs_cfg = &amp_ctrl->irqs_cfg[irq_id];
340354
341
- AMP_GIC_DBG(" %s: group cpu-%d, irq-%d: prio-%x, aff-%x en-%d\n",
355
+ AMP_GIC_DBG(" %s: group cpu-%d, irq-%d: prio-%x, aff-%llx en-%d\n",
342356 __func__, i, gpio_grp->irq_id[i], gpio_grp->prio,
343357 gpio_grp->irq_aff[i], gpio_grp->en[i]);
344358
345359 if (gpio_grp->en[i]) {
346360 irqs_cfg->prio = gpio_grp->prio;
347361 irqs_cfg->aff = irq_aff;
348
- irqs_cfg->cpumask = amp_get_cpumask_bit(irq_aff);
362
+ if (amp_ctrl->gic_version == GIC_V2) {
363
+ irqs_cfg->cpumask = amp_get_cpumask_bit(irq_aff);
364
+ if (!irqs_cfg->cpumask) {
365
+ pr_err(" %s: get cpumask error\n", __func__);
366
+ return -EINVAL;
367
+ }
368
+ }
349369 irqs_cfg->amp_flag = 1;
350370 }
351371
352
- AMP_GIC_DBG(" %s: irqs_cfg prio-%x aff-%x cpumaks-%x en-%d\n",
372
+ AMP_GIC_DBG(" %s: prio-%x aff-%llx cpumaks-%x flag-%d\n",
353373 __func__, irqs_cfg->prio, irqs_cfg->aff,
354374 irqs_cfg->cpumask, irqs_cfg->amp_flag);
355375 }
....@@ -404,33 +424,37 @@
404424 {
405425 const struct property *prop;
406426 int count, i;
407
- u32 cluster, aff_cpu, aff, cpumask;
427
+ u32 cluster, aff_cpu;
428
+ u64 aff, cpumask;
408429
430
+ if (amp_ctrl->gic_version != GIC_V2)
431
+ return 0;
409432 prop = of_find_property(np, "amp-cpu-aff-maskbits", NULL);
433
+
410434 if (!prop)
411435 return -1;
412436
413437 if (!prop->value)
414438 return -1;
415439
416
- count = of_property_count_u32_elems(np, "amp-cpu-aff-maskbits");
440
+ count = of_property_count_u64_elems(np, "amp-cpu-aff-maskbits");
417441 if (count % 2)
418442 return -1;
419443
420444 for (i = 0; i < count / 2; i++) {
421
- of_property_read_u32_index(np, "amp-cpu-aff-maskbits",
445
+ of_property_read_u64_index(np, "amp-cpu-aff-maskbits",
422446 2 * i, &aff);
423447 cluster = MPIDR_AFFINITY_LEVEL(aff, 1);
424448 aff_cpu = MPIDR_AFFINITY_LEVEL(aff, 0);
425449 amp_ctrl->aff_to_cpumask[cluster][aff_cpu].aff = aff;
426450
427
- of_property_read_u32_index(np, "amp-cpu-aff-maskbits",
451
+ of_property_read_u64_index(np, "amp-cpu-aff-maskbits",
428452 2 * i + 1, &cpumask);
429453
430
- amp_ctrl->aff_to_cpumask[cluster][aff_cpu].cpumask = cpumask;
454
+ amp_ctrl->aff_to_cpumask[cluster][aff_cpu].cpumask = (u32)cpumask;
431455
432
- AMP_GIC_DBG("cpumask: %d-%d: aff-%d cpumask-%d\n",
433
- cluster, aff_cpu, aff, cpumask);
456
+ AMP_GIC_DBG("cpumask: %d-%d: aff-%llx cpumask-%d\n",
457
+ cluster, aff_cpu, aff, (u32)cpumask);
434458
435459 if (!cpumask)
436460 return -1;
....@@ -443,8 +467,9 @@
443467 struct amp_gic_ctrl_s *amp_ctrl)
444468 {
445469 const struct property *prop;
446
- int count, i;
447
- u32 irq, prio, aff;
470
+ u32 irq, i;
471
+ int count;
472
+ u64 aff, val, prio;
448473
449474 prop = of_find_property(np, "amp-irqs", NULL);
450475 if (!prop)
....@@ -453,30 +478,31 @@
453478 if (!prop->value)
454479 return;
455480
456
- count = of_property_count_u32_elems(np, "amp-irqs");
481
+ count = of_property_count_u64_elems(np, "amp-irqs");
457482
458
- if (count < 0 || count % 3)
483
+ if (count % 3)
459484 return;
460485
461486 for (i = 0; i < count / 3; i++) {
462
- of_property_read_u32_index(np, "amp-irqs", 3 * i, &irq);
463
-
464
- if (irq > 1020)
487
+ of_property_read_u64_index(np, "amp-irqs", 3 * i, &val);
488
+ irq = (u32)val;
489
+ if (irq > amp_ctrl->spis_num)
465490 break;
466491
467
- of_property_read_u32_index(np, "amp-irqs", 3 * i + 1, &prio);
468
- of_property_read_u32_index(np, "amp-irqs", 3 * i + 2, &aff);
492
+ of_property_read_u64_index(np, "amp-irqs", 3 * i + 1, &prio);
493
+ of_property_read_u64_index(np, "amp-irqs", 3 * i + 2, &aff);
469494
470
- AMP_GIC_DBG("%s: irq-%d aff-%d prio-%x\n",
495
+ AMP_GIC_DBG("%s: irq-%d aff-%llx prio-%llx\n",
471496 __func__, irq, aff, prio);
472497
473
- amp_ctrl->irqs_cfg[irq].prio = prio;
498
+ amp_ctrl->irqs_cfg[irq].prio = (u32)prio;
474499 amp_ctrl->irqs_cfg[irq].aff = aff;
475
- amp_ctrl->irqs_cfg[irq].cpumask = amp_get_cpumask_bit(aff);
476
-
477
- if (!amp_ctrl->irqs_cfg[irq].cpumask) {
478
- AMP_GIC_DBG("%s: get cpumask error\n", __func__);
479
- break;
500
+ if (amp_ctrl->gic_version == GIC_V2) {
501
+ amp_ctrl->irqs_cfg[irq].cpumask = amp_get_cpumask_bit(aff);
502
+ if (!amp_ctrl->irqs_cfg[irq].cpumask) {
503
+ pr_err("%s: get cpumask error\n", __func__);
504
+ break;
505
+ }
480506 }
481507
482508 if (!amp_ctrl->irqs_cfg[irq].aff &&
....@@ -485,16 +511,19 @@
485511
486512 amp_ctrl->irqs_cfg[irq].amp_flag = 1;
487513
488
- AMP_GIC_DBG("%s: irq-%d aff-%d cpumask-%d pri-%x\n",
514
+ AMP_GIC_DBG(" %s: irq-%d aff-%llx cpumask-%x pri-%x\n",
489515 __func__, irq, amp_ctrl->irqs_cfg[irq].aff,
490516 amp_ctrl->irqs_cfg[irq].cpumask,
491517 amp_ctrl->irqs_cfg[irq].prio);
492518 }
493519 }
494520
495
-void rockchip_amp_get_gic_info(void)
521
+void rockchip_amp_get_gic_info(u32 spis_num, enum gic_type gic_version)
496522 {
497523 struct device_node *np;
524
+
525
+ amp_ctrl.spis_num = spis_num;
526
+ amp_ctrl.gic_version = gic_version;
498527
499528 np = of_find_node_by_name(NULL, "rockchip-amp");
500529 if (!np)
....@@ -504,6 +533,7 @@
504533 pr_err("%s: get amp gic cpu mask error\n", __func__);
505534 goto exit;
506535 }
536
+
507537 gic_of_get_gpio_group(np, &amp_ctrl);
508538 amp_gic_get_irqs_config(np, &amp_ctrl);
509539