Taniya Das | 263b7d6 | 2012-09-11 09:55:26 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2012, The Linux Foundation. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/interrupt.h> |
| 14 | #include <linux/irq.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/cpu.h> |
| 19 | #include <linux/io.h> |
| 20 | #include <asm/cputype.h> |
| 21 | #include <asm/hardware/cache-l2x0.h> |
| 22 | |
| 23 | #define MODULE_NAME "pl310_erp" |
| 24 | |
| 25 | struct pl310_drv_data { |
| 26 | unsigned int irq; |
| 27 | unsigned int ecntr; |
| 28 | unsigned int parrt; |
| 29 | unsigned int parrd; |
| 30 | unsigned int errwd; |
| 31 | unsigned int errwt; |
| 32 | unsigned int errrt; |
| 33 | unsigned int errrd; |
| 34 | unsigned int slverr; |
| 35 | unsigned int decerr; |
| 36 | void __iomem *base; |
Taniya Das | bbceeda | 2012-10-31 12:50:59 +0530 | [diff] [blame] | 37 | unsigned int intr_mask_reg; |
Taniya Das | 263b7d6 | 2012-09-11 09:55:26 +0530 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | #define ECNTR BIT(0) |
| 41 | #define PARRT BIT(1) |
| 42 | #define PARRD BIT(2) |
| 43 | #define ERRWT BIT(3) |
| 44 | #define ERRWD BIT(4) |
| 45 | #define ERRRT BIT(5) |
| 46 | #define ERRRD BIT(6) |
| 47 | #define SLVERR BIT(7) |
| 48 | #define DECERR BIT(8) |
| 49 | |
| 50 | static irqreturn_t pl310_erp_irq(int irq, void *dev_id) |
| 51 | { |
| 52 | struct pl310_drv_data *p = platform_get_drvdata(dev_id); |
| 53 | uint16_t mask_int_stat, int_clear = 0, error = 0; |
| 54 | |
| 55 | mask_int_stat = readl_relaxed(p->base + L2X0_MASKED_INTR_STAT); |
| 56 | |
| 57 | if (mask_int_stat & ECNTR) { |
| 58 | pr_alert("Event Counter1/0 Overflow Increment error\n"); |
| 59 | p->ecntr++; |
| 60 | int_clear = mask_int_stat & ECNTR; |
| 61 | } |
| 62 | |
| 63 | if (mask_int_stat & PARRT) { |
| 64 | pr_alert("Read parity error on L2 Tag RAM\n"); |
| 65 | p->parrt++; |
| 66 | error = 1; |
| 67 | int_clear = mask_int_stat & PARRT; |
| 68 | } |
| 69 | |
| 70 | if (mask_int_stat & PARRD) { |
| 71 | pr_alert("Read parity error on L2 Tag RAM\n"); |
| 72 | p->parrd++; |
| 73 | error = 1; |
| 74 | int_clear = mask_int_stat & PARRD; |
| 75 | } |
| 76 | |
| 77 | if (mask_int_stat & ERRWT) { |
| 78 | pr_alert("Write error on L2 Tag RAM\n"); |
| 79 | p->errwt++; |
| 80 | int_clear = mask_int_stat & ERRWT; |
| 81 | } |
| 82 | |
| 83 | if (mask_int_stat & ERRWD) { |
| 84 | pr_alert("Write error on L2 Data RAM\n"); |
| 85 | p->errwd++; |
| 86 | int_clear = mask_int_stat & ERRWD; |
| 87 | } |
| 88 | |
| 89 | if (mask_int_stat & ERRRT) { |
| 90 | pr_alert("Read error on L2 Tag RAM\n"); |
| 91 | p->errrt++; |
| 92 | int_clear = mask_int_stat & ERRRT; |
| 93 | } |
| 94 | |
| 95 | if (mask_int_stat & ERRRD) { |
| 96 | pr_alert("Read error on L2 Data RAM\n"); |
| 97 | p->errrd++; |
| 98 | int_clear = mask_int_stat & ERRRD; |
| 99 | } |
| 100 | |
| 101 | if (mask_int_stat & DECERR) { |
| 102 | pr_alert("L2 master port decode error\n"); |
| 103 | p->decerr++; |
| 104 | int_clear = mask_int_stat & DECERR; |
| 105 | } |
| 106 | |
| 107 | if (mask_int_stat & SLVERR) { |
| 108 | pr_alert("L2 slave port error\n"); |
| 109 | p->slverr++; |
| 110 | int_clear = mask_int_stat & SLVERR; |
| 111 | } |
| 112 | |
| 113 | writel_relaxed(int_clear, p->base + L2X0_INTR_CLEAR); |
| 114 | |
| 115 | /* Make sure the interrupts are cleared */ |
| 116 | mb(); |
| 117 | |
| 118 | /* WARNING will be thrown whenever we receive any L2 interrupt. |
| 119 | * Other than parity on tag/data ram, irrespective of the bits |
| 120 | * set we will throw a warning. |
| 121 | */ |
| 122 | WARN_ON(!error); |
| 123 | |
| 124 | /* Panic in case we encounter parity error in TAG/DATA Ram */ |
| 125 | BUG_ON(error); |
| 126 | |
| 127 | return IRQ_HANDLED; |
| 128 | } |
| 129 | |
| 130 | static void pl310_mask_int(struct pl310_drv_data *p, bool enable) |
| 131 | { |
Taniya Das | bbceeda | 2012-10-31 12:50:59 +0530 | [diff] [blame] | 132 | /* L2CC register contents needs to be saved |
| 133 | * as it's power rail will be removed during suspend |
| 134 | */ |
Taniya Das | 263b7d6 | 2012-09-11 09:55:26 +0530 | [diff] [blame] | 135 | if (enable) |
Taniya Das | bbceeda | 2012-10-31 12:50:59 +0530 | [diff] [blame] | 136 | p->intr_mask_reg = 0x1FF; |
Taniya Das | 263b7d6 | 2012-09-11 09:55:26 +0530 | [diff] [blame] | 137 | else |
Taniya Das | bbceeda | 2012-10-31 12:50:59 +0530 | [diff] [blame] | 138 | p->intr_mask_reg = 0x0; |
Taniya Das | 263b7d6 | 2012-09-11 09:55:26 +0530 | [diff] [blame] | 139 | |
Taniya Das | bbceeda | 2012-10-31 12:50:59 +0530 | [diff] [blame] | 140 | writel_relaxed(p->intr_mask_reg, p->base + L2X0_INTR_MASK); |
Taniya Das | 263b7d6 | 2012-09-11 09:55:26 +0530 | [diff] [blame] | 141 | |
| 142 | /* Make sure Mask is updated */ |
| 143 | mb(); |
| 144 | |
Taniya Das | bbceeda | 2012-10-31 12:50:59 +0530 | [diff] [blame] | 145 | pr_debug("Mask interrupt 0%x\n", |
Taniya Das | 263b7d6 | 2012-09-11 09:55:26 +0530 | [diff] [blame] | 146 | readl_relaxed(p->base + L2X0_INTR_MASK)); |
| 147 | } |
| 148 | |
| 149 | static int pl310_erp_show(struct device *dev, struct device_attribute *attr, |
| 150 | char *buf) |
| 151 | { |
| 152 | struct pl310_drv_data *p = dev_get_drvdata(dev); |
| 153 | |
| 154 | return snprintf(buf, PAGE_SIZE, |
| 155 | "L2CC Interrupt Number:\t\t\t%d\n"\ |
| 156 | "Event Counter1/0 Overflow Increment:\t%u\n"\ |
| 157 | "Parity Error on L2 Tag RAM (Read):\t%u\n"\ |
| 158 | "Parity Error on L2 Data RAM (Read):\t%u\n"\ |
| 159 | "Error on L2 Tag RAM (Write):\t\t%u\n"\ |
| 160 | "Error on L2 Data RAM (Write):\t\t%u\n"\ |
| 161 | "Error on L2 Tag RAM (Read):\t\t%u\n"\ |
| 162 | "Error on L2 Data RAM (Read):\t\t%u\n"\ |
| 163 | "SLave Error from L3 Port:\t\t%u\n"\ |
| 164 | "Decode Error from L3 Port:\t\t%u\n", |
| 165 | p->irq, p->ecntr, p->parrt, p->parrd, p->errwt, p->errwd, |
| 166 | p->errrt, p->errrd, p->slverr, p->decerr); |
| 167 | } |
| 168 | |
| 169 | static DEVICE_ATTR(cache_erp, 0664, pl310_erp_show, NULL); |
| 170 | |
| 171 | static int __init pl310_create_sysfs(struct device *dev) |
| 172 | { |
| 173 | /* create a sysfs entry at |
| 174 | * /sys/devices/platform/pl310_erp/cache_erp |
| 175 | */ |
| 176 | return device_create_file(dev, &dev_attr_cache_erp); |
| 177 | } |
| 178 | |
| 179 | static int __devinit pl310_cache_erp_probe(struct platform_device *pdev) |
| 180 | { |
| 181 | struct resource *r; |
| 182 | struct pl310_drv_data *drv_data; |
| 183 | int ret; |
| 184 | |
| 185 | drv_data = devm_kzalloc(&pdev->dev, sizeof(struct pl310_drv_data), |
| 186 | GFP_KERNEL); |
| 187 | if (drv_data == NULL) { |
| 188 | dev_err(&pdev->dev, "cannot allocate memory\n"); |
| 189 | ret = -ENOMEM; |
| 190 | goto error; |
| 191 | } |
| 192 | |
| 193 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 194 | if (!r) { |
| 195 | dev_err(&pdev->dev, "No L2 base address\n"); |
| 196 | ret = -ENODEV; |
| 197 | goto error; |
| 198 | } |
| 199 | |
| 200 | if (!devm_request_mem_region(&pdev->dev, r->start, resource_size(r), |
| 201 | "erp")) { |
| 202 | ret = -EBUSY; |
| 203 | goto error; |
| 204 | } |
| 205 | |
| 206 | drv_data->base = devm_ioremap_nocache(&pdev->dev, r->start, |
| 207 | resource_size(r)); |
| 208 | if (!drv_data->base) { |
| 209 | dev_err(&pdev->dev, "errored to ioremap 0x%x\n", r->start); |
| 210 | ret = -ENOMEM; |
| 211 | goto error; |
| 212 | } |
| 213 | dev_dbg(&pdev->dev, "L2CC base 0x%p\n", drv_data->base); |
| 214 | |
| 215 | r = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "l2_irq"); |
| 216 | if (!r) { |
| 217 | dev_err(&pdev->dev, "No L2 IRQ resource\n"); |
| 218 | ret = -ENODEV; |
| 219 | goto error; |
| 220 | } |
| 221 | |
| 222 | drv_data->irq = r->start; |
| 223 | |
| 224 | ret = devm_request_irq(&pdev->dev, drv_data->irq, pl310_erp_irq, |
| 225 | IRQF_TRIGGER_RISING, "l2cc_intr", pdev); |
| 226 | if (ret) { |
| 227 | dev_err(&pdev->dev, "request irq for L2 interrupt failed\n"); |
| 228 | goto error; |
| 229 | } |
| 230 | |
| 231 | platform_set_drvdata(pdev, drv_data); |
| 232 | |
| 233 | pl310_mask_int(drv_data, true); |
| 234 | |
| 235 | ret = pl310_create_sysfs(&pdev->dev); |
| 236 | if (ret) { |
| 237 | dev_err(&pdev->dev, "Failed to create sysfs entry\n"); |
| 238 | goto sysfs_err; |
| 239 | } |
| 240 | |
| 241 | return 0; |
| 242 | |
| 243 | sysfs_err: |
| 244 | platform_set_drvdata(pdev, NULL); |
| 245 | pl310_mask_int(drv_data, false); |
| 246 | error: |
| 247 | return ret; |
| 248 | } |
| 249 | |
| 250 | static int __devexit pl310_cache_erp_remove(struct platform_device *pdev) |
| 251 | { |
| 252 | struct pl310_drv_data *p = platform_get_drvdata(pdev); |
| 253 | |
| 254 | pl310_mask_int(p, false); |
| 255 | |
| 256 | device_remove_file(&pdev->dev, &dev_attr_cache_erp); |
| 257 | |
| 258 | platform_set_drvdata(pdev, NULL); |
| 259 | |
| 260 | return 0; |
| 261 | } |
| 262 | |
Taniya Das | bbceeda | 2012-10-31 12:50:59 +0530 | [diff] [blame] | 263 | #ifdef CONFIG_PM |
| 264 | static int pl310_suspend(struct device *dev) |
| 265 | { |
| 266 | struct pl310_drv_data *p = dev_get_drvdata(dev); |
| 267 | |
| 268 | disable_irq(p->irq); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | static int pl310_resume_early(struct device *dev) |
| 274 | { |
| 275 | struct pl310_drv_data *p = dev_get_drvdata(dev); |
| 276 | |
| 277 | pl310_mask_int(p, true); |
| 278 | |
| 279 | enable_irq(p->irq); |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static const struct dev_pm_ops pl310_cache_pm_ops = { |
| 285 | .suspend = pl310_suspend, |
| 286 | .resume_early = pl310_resume_early, |
| 287 | }; |
| 288 | #endif |
| 289 | |
Taniya Das | 263b7d6 | 2012-09-11 09:55:26 +0530 | [diff] [blame] | 290 | static struct platform_driver pl310_cache_erp_driver = { |
| 291 | .probe = pl310_cache_erp_probe, |
| 292 | .remove = __devexit_p(pl310_cache_erp_remove), |
| 293 | .driver = { |
| 294 | .name = MODULE_NAME, |
| 295 | .owner = THIS_MODULE, |
Taniya Das | bbceeda | 2012-10-31 12:50:59 +0530 | [diff] [blame] | 296 | #ifdef CONFIG_PM |
| 297 | .pm = &pl310_cache_pm_ops, |
| 298 | #endif |
Taniya Das | 263b7d6 | 2012-09-11 09:55:26 +0530 | [diff] [blame] | 299 | }, |
| 300 | }; |
| 301 | |
| 302 | static int __init pl310_cache_erp_init(void) |
| 303 | { |
| 304 | return platform_driver_register(&pl310_cache_erp_driver); |
| 305 | } |
| 306 | module_init(pl310_cache_erp_init); |
| 307 | |
| 308 | static void __exit pl310_cache_erp_exit(void) |
| 309 | { |
| 310 | platform_driver_unregister(&pl310_cache_erp_driver); |
| 311 | } |
| 312 | module_exit(pl310_cache_erp_exit); |
| 313 | |
| 314 | MODULE_LICENSE("GPL v2"); |
| 315 | MODULE_DESCRIPTION("PL310 cache error reporting driver"); |