Skip to content

Commit 13ab844

Browse files
Thor Thayersuryasaimadhu
authored andcommitted
EDAC, altera: Add ECC Manager IRQ controller support
To better support child devices, the ECC manager needs to be implemented as an IRQ controller. Signed-off-by: Thor Thayer <[email protected]> Cc: [email protected] Cc: linux-edac <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Borislav Petkov <[email protected]>
1 parent 47d7800 commit 13ab844

File tree

2 files changed

+130
-42
lines changed

2 files changed

+130
-42
lines changed

drivers/edac/altera_edac.c

Lines changed: 127 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
#include <linux/edac.h>
2323
#include <linux/genalloc.h>
2424
#include <linux/interrupt.h>
25+
#include <linux/irqchip/chained_irq.h>
2526
#include <linux/kernel.h>
2627
#include <linux/mfd/syscon.h>
2728
#include <linux/of_address.h>
29+
#include <linux/of_irq.h>
2830
#include <linux/of_platform.h>
2931
#include <linux/platform_device.h>
3032
#include <linux/regmap.h>
@@ -882,22 +884,29 @@ static void ocram_free_mem(void *p, size_t size, void *other)
882884
gen_pool_free((struct gen_pool *)other, (u32)p, size);
883885
}
884886

885-
static irqreturn_t altr_edac_a10_ecc_irq(struct altr_edac_device_dev *dci,
886-
bool sberr)
887+
static irqreturn_t altr_edac_a10_ecc_irq(int irq, void *dev_id)
887888
{
889+
struct altr_edac_device_dev *dci = dev_id;
888890
void __iomem *base = dci->base;
889891

890-
if (sberr) {
892+
if (irq == dci->sb_irq) {
891893
writel(ALTR_A10_ECC_SERRPENA,
892894
base + ALTR_A10_ECC_INTSTAT_OFST);
893895
edac_device_handle_ce(dci->edac_dev, 0, 0, dci->edac_dev_name);
894-
} else {
896+
897+
return IRQ_HANDLED;
898+
} else if (irq == dci->db_irq) {
895899
writel(ALTR_A10_ECC_DERRPENA,
896900
base + ALTR_A10_ECC_INTSTAT_OFST);
897901
edac_device_handle_ue(dci->edac_dev, 0, 0, dci->edac_dev_name);
898902
panic("\nEDAC:ECC_DEVICE[Uncorrectable errors]\n");
903+
904+
return IRQ_HANDLED;
899905
}
900-
return IRQ_HANDLED;
906+
907+
WARN_ON(1);
908+
909+
return IRQ_NONE;
901910
}
902911

903912
const struct edac_device_prv_data ocramecc_data = {
@@ -988,22 +997,30 @@ static int altr_l2_check_deps(struct altr_edac_device_dev *device)
988997
return -ENODEV;
989998
}
990999

991-
static irqreturn_t altr_edac_a10_l2_irq(struct altr_edac_device_dev *dci,
992-
bool sberr)
1000+
static irqreturn_t altr_edac_a10_l2_irq(int irq, void *dev_id)
9931001
{
994-
if (sberr) {
1002+
struct altr_edac_device_dev *dci = dev_id;
1003+
1004+
if (irq == dci->sb_irq) {
9951005
regmap_write(dci->edac->ecc_mgr_map,
9961006
A10_SYSGMR_MPU_CLEAR_L2_ECC_OFST,
9971007
A10_SYSGMR_MPU_CLEAR_L2_ECC_SB);
9981008
edac_device_handle_ce(dci->edac_dev, 0, 0, dci->edac_dev_name);
999-
} else {
1009+
1010+
return IRQ_HANDLED;
1011+
} else if (irq == dci->db_irq) {
10001012
regmap_write(dci->edac->ecc_mgr_map,
10011013
A10_SYSGMR_MPU_CLEAR_L2_ECC_OFST,
10021014
A10_SYSGMR_MPU_CLEAR_L2_ECC_MB);
10031015
edac_device_handle_ue(dci->edac_dev, 0, 0, dci->edac_dev_name);
10041016
panic("\nEDAC:ECC_DEVICE[Uncorrectable errors]\n");
1017+
1018+
return IRQ_HANDLED;
10051019
}
1006-
return IRQ_HANDLED;
1020+
1021+
WARN_ON(1);
1022+
1023+
return IRQ_NONE;
10071024
}
10081025

10091026
const struct edac_device_prv_data l2ecc_data = {
@@ -1075,28 +1092,28 @@ static ssize_t altr_edac_a10_device_trig(struct file *file,
10751092
return count;
10761093
}
10771094

1078-
static irqreturn_t altr_edac_a10_irq_handler(int irq, void *dev_id)
1095+
static void altr_edac_a10_irq_handler(struct irq_desc *desc)
10791096
{
1080-
irqreturn_t rc = IRQ_NONE;
1081-
struct altr_arria10_edac *edac = dev_id;
1082-
struct altr_edac_device_dev *dci;
1083-
int irq_status;
1084-
bool sberr = (irq == edac->sb_irq) ? 1 : 0;
1085-
int sm_offset = sberr ? A10_SYSMGR_ECC_INTSTAT_SERR_OFST :
1086-
A10_SYSMGR_ECC_INTSTAT_DERR_OFST;
1097+
int dberr, bit, sm_offset, irq_status;
1098+
struct altr_arria10_edac *edac = irq_desc_get_handler_data(desc);
1099+
struct irq_chip *chip = irq_desc_get_chip(desc);
1100+
int irq = irq_desc_get_irq(desc);
1101+
1102+
dberr = (irq == edac->db_irq) ? 1 : 0;
1103+
sm_offset = dberr ? A10_SYSMGR_ECC_INTSTAT_DERR_OFST :
1104+
A10_SYSMGR_ECC_INTSTAT_SERR_OFST;
1105+
1106+
chained_irq_enter(chip, desc);
10871107

10881108
regmap_read(edac->ecc_mgr_map, sm_offset, &irq_status);
10891109

1090-
if ((irq != edac->sb_irq) && (irq != edac->db_irq)) {
1091-
WARN_ON(1);
1092-
} else {
1093-
list_for_each_entry(dci, &edac->a10_ecc_devices, next) {
1094-
if (irq_status & dci->data->irq_status_mask)
1095-
rc = dci->data->ecc_irq_handler(dci, sberr);
1096-
}
1110+
for_each_set_bit(bit, (unsigned long *)&irq_status, 32) {
1111+
irq = irq_linear_revmap(edac->domain, dberr * 32 + bit);
1112+
if (irq)
1113+
generic_handle_irq(irq);
10971114
}
10981115

1099-
return rc;
1116+
chained_irq_exit(chip, desc);
11001117
}
11011118

11021119
static int altr_edac_a10_device_add(struct altr_arria10_edac *edac,
@@ -1168,6 +1185,34 @@ static int altr_edac_a10_device_add(struct altr_arria10_edac *edac,
11681185
goto err_release_group1;
11691186
}
11701187

1188+
altdev->sb_irq = irq_of_parse_and_map(np, 0);
1189+
if (!altdev->sb_irq) {
1190+
edac_printk(KERN_ERR, EDAC_DEVICE, "Error allocating SBIRQ\n");
1191+
rc = -ENODEV;
1192+
goto err_release_group1;
1193+
}
1194+
rc = devm_request_irq(edac->dev, altdev->sb_irq,
1195+
prv->ecc_irq_handler,
1196+
IRQF_SHARED, ecc_name, altdev);
1197+
if (rc) {
1198+
edac_printk(KERN_ERR, EDAC_DEVICE, "No DBERR IRQ resource\n");
1199+
goto err_release_group1;
1200+
}
1201+
1202+
altdev->db_irq = irq_of_parse_and_map(np, 1);
1203+
if (!altdev->db_irq) {
1204+
edac_printk(KERN_ERR, EDAC_DEVICE, "Error allocating DBIRQ\n");
1205+
rc = -ENODEV;
1206+
goto err_release_group1;
1207+
}
1208+
rc = devm_request_irq(edac->dev, altdev->db_irq,
1209+
prv->ecc_irq_handler,
1210+
IRQF_SHARED, ecc_name, altdev);
1211+
if (rc) {
1212+
edac_printk(KERN_ERR, EDAC_DEVICE, "No DBERR IRQ resource\n");
1213+
goto err_release_group1;
1214+
}
1215+
11711216
rc = edac_device_add_device(dci);
11721217
if (rc) {
11731218
dev_err(edac->dev, "edac_device_add_device failed\n");
@@ -1186,19 +1231,50 @@ static int altr_edac_a10_device_add(struct altr_arria10_edac *edac,
11861231
err_release_group1:
11871232
edac_device_free_ctl_info(dci);
11881233
err_release_group:
1189-
edac_printk(KERN_ALERT, EDAC_DEVICE, "%s: %d\n", __func__, __LINE__);
11901234
devres_release_group(edac->dev, NULL);
11911235
edac_printk(KERN_ERR, EDAC_DEVICE,
11921236
"%s:Error setting up EDAC device: %d\n", ecc_name, rc);
11931237

11941238
return rc;
11951239
}
11961240

1241+
static void a10_eccmgr_irq_mask(struct irq_data *d)
1242+
{
1243+
struct altr_arria10_edac *edac = irq_data_get_irq_chip_data(d);
1244+
1245+
regmap_write(edac->ecc_mgr_map, A10_SYSMGR_ECC_INTMASK_SET_OFST,
1246+
BIT(d->hwirq));
1247+
}
1248+
1249+
static void a10_eccmgr_irq_unmask(struct irq_data *d)
1250+
{
1251+
struct altr_arria10_edac *edac = irq_data_get_irq_chip_data(d);
1252+
1253+
regmap_write(edac->ecc_mgr_map, A10_SYSMGR_ECC_INTMASK_CLR_OFST,
1254+
BIT(d->hwirq));
1255+
}
1256+
1257+
static int a10_eccmgr_irqdomain_map(struct irq_domain *d, unsigned int irq,
1258+
irq_hw_number_t hwirq)
1259+
{
1260+
struct altr_arria10_edac *edac = d->host_data;
1261+
1262+
irq_set_chip_and_handler(irq, &edac->irq_chip, handle_simple_irq);
1263+
irq_set_chip_data(irq, edac);
1264+
irq_set_noprobe(irq);
1265+
1266+
return 0;
1267+
}
1268+
1269+
struct irq_domain_ops a10_eccmgr_ic_ops = {
1270+
.map = a10_eccmgr_irqdomain_map,
1271+
.xlate = irq_domain_xlate_twocell,
1272+
};
1273+
11971274
static int altr_edac_a10_probe(struct platform_device *pdev)
11981275
{
11991276
struct altr_arria10_edac *edac;
12001277
struct device_node *child;
1201-
int rc;
12021278

12031279
edac = devm_kzalloc(&pdev->dev, sizeof(*edac), GFP_KERNEL);
12041280
if (!edac)
@@ -1216,23 +1292,34 @@ static int altr_edac_a10_probe(struct platform_device *pdev)
12161292
return PTR_ERR(edac->ecc_mgr_map);
12171293
}
12181294

1295+
edac->irq_chip.name = pdev->dev.of_node->name;
1296+
edac->irq_chip.irq_mask = a10_eccmgr_irq_mask;
1297+
edac->irq_chip.irq_unmask = a10_eccmgr_irq_unmask;
1298+
edac->domain = irq_domain_add_linear(pdev->dev.of_node, 64,
1299+
&a10_eccmgr_ic_ops, edac);
1300+
if (!edac->domain) {
1301+
dev_err(&pdev->dev, "Error adding IRQ domain\n");
1302+
return -ENOMEM;
1303+
}
1304+
12191305
edac->sb_irq = platform_get_irq(pdev, 0);
1220-
rc = devm_request_irq(&pdev->dev, edac->sb_irq,
1221-
altr_edac_a10_irq_handler,
1222-
IRQF_SHARED, dev_name(&pdev->dev), edac);
1223-
if (rc) {
1224-
edac_printk(KERN_ERR, EDAC_DEVICE, "No SBERR IRQ resource\n");
1225-
return rc;
1306+
if (edac->sb_irq < 0) {
1307+
dev_err(&pdev->dev, "No SBERR IRQ resource\n");
1308+
return edac->sb_irq;
12261309
}
12271310

1311+
irq_set_chained_handler_and_data(edac->sb_irq,
1312+
altr_edac_a10_irq_handler,
1313+
edac);
1314+
12281315
edac->db_irq = platform_get_irq(pdev, 1);
1229-
rc = devm_request_irq(&pdev->dev, edac->db_irq,
1230-
altr_edac_a10_irq_handler,
1231-
IRQF_SHARED, dev_name(&pdev->dev), edac);
1232-
if (rc) {
1233-
edac_printk(KERN_ERR, EDAC_DEVICE, "No DBERR IRQ resource\n");
1234-
return rc;
1316+
if (edac->db_irq < 0) {
1317+
dev_err(&pdev->dev, "No DBERR IRQ resource\n");
1318+
return edac->db_irq;
12351319
}
1320+
irq_set_chained_handler_and_data(edac->db_irq,
1321+
altr_edac_a10_irq_handler,
1322+
edac);
12361323

12371324
for_each_child_of_node(pdev->dev.of_node, child) {
12381325
if (!of_device_is_available(child))

drivers/edac/altera_edac.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,7 @@ struct edac_device_prv_data {
295295
int ce_set_mask;
296296
int ue_set_mask;
297297
int set_err_ofst;
298-
irqreturn_t (*ecc_irq_handler)(struct altr_edac_device_dev *dci,
299-
bool sb);
298+
irqreturn_t (*ecc_irq_handler)(int irq, void *dev_id);
300299
int trig_alloc_sz;
301300
const struct file_operations *inject_fops;
302301
};
@@ -320,6 +319,8 @@ struct altr_arria10_edac {
320319
struct regmap *ecc_mgr_map;
321320
int sb_irq;
322321
int db_irq;
322+
struct irq_domain *domain;
323+
struct irq_chip irq_chip;
323324
struct list_head a10_ecc_devices;
324325
};
325326

0 commit comments

Comments
 (0)