Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/8xx: Use kmalloced data structure instead of global static

Use a kmalloced data structure to store interrupt controller internal
data instead of static global variables.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/c8f0866ee013113d5e28948943cf0586e49f5353.1649226186.git.christophe.leroy@csgroup.eu

authored by

Christophe Leroy and committed by
Michael Ellerman
5ad1aa00 e3ba31b7

+30 -18
+30 -18
arch/powerpc/platforms/8xx/cpm1-ic.c
··· 10 10 #include <linux/platform_device.h> 11 11 #include <asm/cpm1.h> 12 12 13 - static cpic8xx_t __iomem *cpic_reg; 14 - 15 - static struct irq_domain *cpm_pic_host; 13 + struct cpm_pic_data { 14 + cpic8xx_t __iomem *reg; 15 + struct irq_domain *host; 16 + }; 16 17 17 18 static void cpm_mask_irq(struct irq_data *d) 18 19 { 20 + struct cpm_pic_data *data = irq_data_get_irq_chip_data(d); 19 21 unsigned int cpm_vec = (unsigned int)irqd_to_hwirq(d); 20 22 21 - clrbits32(&cpic_reg->cpic_cimr, (1 << cpm_vec)); 23 + clrbits32(&data->reg->cpic_cimr, (1 << cpm_vec)); 22 24 } 23 25 24 26 static void cpm_unmask_irq(struct irq_data *d) 25 27 { 28 + struct cpm_pic_data *data = irq_data_get_irq_chip_data(d); 26 29 unsigned int cpm_vec = (unsigned int)irqd_to_hwirq(d); 27 30 28 - setbits32(&cpic_reg->cpic_cimr, (1 << cpm_vec)); 31 + setbits32(&data->reg->cpic_cimr, (1 << cpm_vec)); 29 32 } 30 33 31 34 static void cpm_end_irq(struct irq_data *d) 32 35 { 36 + struct cpm_pic_data *data = irq_data_get_irq_chip_data(d); 33 37 unsigned int cpm_vec = (unsigned int)irqd_to_hwirq(d); 34 38 35 - out_be32(&cpic_reg->cpic_cisr, (1 << cpm_vec)); 39 + out_be32(&data->reg->cpic_cisr, (1 << cpm_vec)); 36 40 } 37 41 38 42 static struct irq_chip cpm_pic = { ··· 46 42 .irq_eoi = cpm_end_irq, 47 43 }; 48 44 49 - static int cpm_get_irq(void) 45 + static int cpm_get_irq(struct irq_desc *desc) 50 46 { 47 + struct cpm_pic_data *data = irq_desc_get_handler_data(desc); 51 48 int cpm_vec; 52 49 53 50 /* 54 51 * Get the vector by setting the ACK bit and then reading 55 52 * the register. 56 53 */ 57 - out_be16(&cpic_reg->cpic_civr, 1); 58 - cpm_vec = in_be16(&cpic_reg->cpic_civr); 54 + out_be16(&data->reg->cpic_civr, 1); 55 + cpm_vec = in_be16(&data->reg->cpic_civr); 59 56 cpm_vec >>= 11; 60 57 61 - return irq_linear_revmap(cpm_pic_host, cpm_vec); 58 + return irq_linear_revmap(data->host, cpm_vec); 62 59 } 63 60 64 61 static void cpm_cascade(struct irq_desc *desc) 65 62 { 66 - generic_handle_irq(cpm_get_irq()); 63 + generic_handle_irq(cpm_get_irq(desc)); 67 64 } 68 65 69 66 static int cpm_pic_host_map(struct irq_domain *h, unsigned int virq, 70 67 irq_hw_number_t hw) 71 68 { 69 + irq_set_chip_data(virq, h->host_data); 72 70 irq_set_status_flags(virq, IRQ_LEVEL); 73 71 irq_set_chip_and_handler(virq, &cpm_pic, handle_fasteoi_irq); 74 72 return 0; ··· 85 79 struct device *dev = &pdev->dev; 86 80 struct resource *res; 87 81 int irq; 82 + struct cpm_pic_data *data; 88 83 89 84 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 90 85 if (!res) 91 86 return -ENODEV; 92 87 93 - cpic_reg = devm_ioremap(dev, res->start, resource_size(res)); 94 - if (!cpic_reg) 88 + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); 89 + if (!data) 90 + return -ENOMEM; 91 + 92 + data->reg = devm_ioremap(dev, res->start, resource_size(res)); 93 + if (!data->reg) 95 94 return -ENODEV; 96 95 97 96 irq = platform_get_irq(pdev, 0); ··· 104 93 return irq; 105 94 106 95 /* Initialize the CPM interrupt controller. */ 107 - out_be32(&cpic_reg->cpic_cicr, 96 + out_be32(&data->reg->cpic_cicr, 108 97 (CICR_SCD_SCC4 | CICR_SCC_SCC3 | CICR_SCB_SCC2 | CICR_SCA_SCC1) | 109 98 ((virq_to_hw(irq) / 2) << 13) | CICR_HP_MASK); 110 99 111 - out_be32(&cpic_reg->cpic_cimr, 0); 100 + out_be32(&data->reg->cpic_cimr, 0); 112 101 113 - cpm_pic_host = irq_domain_add_linear(dev->of_node, 64, &cpm_pic_host_ops, NULL); 114 - if (!cpm_pic_host) 102 + data->host = irq_domain_add_linear(dev->of_node, 64, &cpm_pic_host_ops, data); 103 + if (!data->host) 115 104 return -ENODEV; 116 105 106 + irq_set_handler_data(irq, data); 117 107 irq_set_chained_handler(irq, cpm_cascade); 118 108 119 - setbits32(&cpic_reg->cpic_cicr, CICR_IEN); 109 + setbits32(&data->reg->cpic_cicr, CICR_IEN); 120 110 121 111 return 0; 122 112 }