sparc64: Fix bootup regressions on some Kconfig combinations.
[linux/fpc-iii.git] / drivers / edac / amd8111_edac.c
blob2b63f7c2d6d217d91c32591d2329e448797b37b5
1 /*
2 * amd8111_edac.c, AMD8111 Hyper Transport chip EDAC kernel module
4 * Copyright (c) 2008 Wind River Systems, Inc.
6 * Authors: Cao Qingtao <qingtao.cao@windriver.com>
7 * Benjamin Walsh <benjamin.walsh@windriver.com>
8 * Hu Yongqi <yongqi.hu@windriver.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/interrupt.h>
27 #include <linux/bitops.h>
28 #include <linux/edac.h>
29 #include <linux/pci_ids.h>
30 #include <asm/io.h>
32 #include "edac_core.h"
33 #include "edac_module.h"
34 #include "amd8111_edac.h"
36 #define AMD8111_EDAC_REVISION " Ver: 1.0.0"
37 #define AMD8111_EDAC_MOD_STR "amd8111_edac"
39 #define PCI_DEVICE_ID_AMD_8111_PCI 0x7460
41 enum amd8111_edac_devs {
42 LPC_BRIDGE = 0,
45 enum amd8111_edac_pcis {
46 PCI_BRIDGE = 0,
49 /* Wrapper functions for accessing PCI configuration space */
50 static int edac_pci_read_dword(struct pci_dev *dev, int reg, u32 *val32)
52 int ret;
54 ret = pci_read_config_dword(dev, reg, val32);
55 if (ret != 0)
56 printk(KERN_ERR AMD8111_EDAC_MOD_STR
57 " PCI Access Read Error at 0x%x\n", reg);
59 return ret;
62 static void edac_pci_read_byte(struct pci_dev *dev, int reg, u8 *val8)
64 int ret;
66 ret = pci_read_config_byte(dev, reg, val8);
67 if (ret != 0)
68 printk(KERN_ERR AMD8111_EDAC_MOD_STR
69 " PCI Access Read Error at 0x%x\n", reg);
72 static void edac_pci_write_dword(struct pci_dev *dev, int reg, u32 val32)
74 int ret;
76 ret = pci_write_config_dword(dev, reg, val32);
77 if (ret != 0)
78 printk(KERN_ERR AMD8111_EDAC_MOD_STR
79 " PCI Access Write Error at 0x%x\n", reg);
82 static void edac_pci_write_byte(struct pci_dev *dev, int reg, u8 val8)
84 int ret;
86 ret = pci_write_config_byte(dev, reg, val8);
87 if (ret != 0)
88 printk(KERN_ERR AMD8111_EDAC_MOD_STR
89 " PCI Access Write Error at 0x%x\n", reg);
93 * device-specific methods for amd8111 PCI Bridge Controller
95 * Error Reporting and Handling for amd8111 chipset could be found
96 * in its datasheet 3.1.2 section, P37
98 static void amd8111_pci_bridge_init(struct amd8111_pci_info *pci_info)
100 u32 val32;
101 struct pci_dev *dev = pci_info->dev;
103 /* First clear error detection flags on the host interface */
105 /* Clear SSE/SMA/STA flags in the global status register*/
106 edac_pci_read_dword(dev, REG_PCI_STSCMD, &val32);
107 if (val32 & PCI_STSCMD_CLEAR_MASK)
108 edac_pci_write_dword(dev, REG_PCI_STSCMD, val32);
110 /* Clear CRC and Link Fail flags in HT Link Control reg */
111 edac_pci_read_dword(dev, REG_HT_LINK, &val32);
112 if (val32 & HT_LINK_CLEAR_MASK)
113 edac_pci_write_dword(dev, REG_HT_LINK, val32);
115 /* Second clear all fault on the secondary interface */
117 /* Clear error flags in the memory-base limit reg. */
118 edac_pci_read_dword(dev, REG_MEM_LIM, &val32);
119 if (val32 & MEM_LIMIT_CLEAR_MASK)
120 edac_pci_write_dword(dev, REG_MEM_LIM, val32);
122 /* Clear Discard Timer Expired flag in Interrupt/Bridge Control reg */
123 edac_pci_read_dword(dev, REG_PCI_INTBRG_CTRL, &val32);
124 if (val32 & PCI_INTBRG_CTRL_CLEAR_MASK)
125 edac_pci_write_dword(dev, REG_PCI_INTBRG_CTRL, val32);
127 /* Last enable error detections */
128 if (edac_op_state == EDAC_OPSTATE_POLL) {
129 /* Enable System Error reporting in global status register */
130 edac_pci_read_dword(dev, REG_PCI_STSCMD, &val32);
131 val32 |= PCI_STSCMD_SERREN;
132 edac_pci_write_dword(dev, REG_PCI_STSCMD, val32);
134 /* Enable CRC Sync flood packets to HyperTransport Link */
135 edac_pci_read_dword(dev, REG_HT_LINK, &val32);
136 val32 |= HT_LINK_CRCFEN;
137 edac_pci_write_dword(dev, REG_HT_LINK, val32);
139 /* Enable SSE reporting etc in Interrupt control reg */
140 edac_pci_read_dword(dev, REG_PCI_INTBRG_CTRL, &val32);
141 val32 |= PCI_INTBRG_CTRL_POLL_MASK;
142 edac_pci_write_dword(dev, REG_PCI_INTBRG_CTRL, val32);
146 static void amd8111_pci_bridge_exit(struct amd8111_pci_info *pci_info)
148 u32 val32;
149 struct pci_dev *dev = pci_info->dev;
151 if (edac_op_state == EDAC_OPSTATE_POLL) {
152 /* Disable System Error reporting */
153 edac_pci_read_dword(dev, REG_PCI_STSCMD, &val32);
154 val32 &= ~PCI_STSCMD_SERREN;
155 edac_pci_write_dword(dev, REG_PCI_STSCMD, val32);
157 /* Disable CRC flood packets */
158 edac_pci_read_dword(dev, REG_HT_LINK, &val32);
159 val32 &= ~HT_LINK_CRCFEN;
160 edac_pci_write_dword(dev, REG_HT_LINK, val32);
162 /* Disable DTSERREN/MARSP/SERREN in Interrupt Control reg */
163 edac_pci_read_dword(dev, REG_PCI_INTBRG_CTRL, &val32);
164 val32 &= ~PCI_INTBRG_CTRL_POLL_MASK;
165 edac_pci_write_dword(dev, REG_PCI_INTBRG_CTRL, val32);
169 static void amd8111_pci_bridge_check(struct edac_pci_ctl_info *edac_dev)
171 struct amd8111_pci_info *pci_info = edac_dev->pvt_info;
172 struct pci_dev *dev = pci_info->dev;
173 u32 val32;
175 /* Check out PCI Bridge Status and Command Register */
176 edac_pci_read_dword(dev, REG_PCI_STSCMD, &val32);
177 if (val32 & PCI_STSCMD_CLEAR_MASK) {
178 printk(KERN_INFO "Error(s) in PCI bridge status and command"
179 "register on device %s\n", pci_info->ctl_name);
180 printk(KERN_INFO "SSE: %d, RMA: %d, RTA: %d\n",
181 (val32 & PCI_STSCMD_SSE) != 0,
182 (val32 & PCI_STSCMD_RMA) != 0,
183 (val32 & PCI_STSCMD_RTA) != 0);
185 val32 |= PCI_STSCMD_CLEAR_MASK;
186 edac_pci_write_dword(dev, REG_PCI_STSCMD, val32);
188 edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
191 /* Check out HyperTransport Link Control Register */
192 edac_pci_read_dword(dev, REG_HT_LINK, &val32);
193 if (val32 & HT_LINK_LKFAIL) {
194 printk(KERN_INFO "Error(s) in hypertransport link control"
195 "register on device %s\n", pci_info->ctl_name);
196 printk(KERN_INFO "LKFAIL: %d\n",
197 (val32 & HT_LINK_LKFAIL) != 0);
199 val32 |= HT_LINK_LKFAIL;
200 edac_pci_write_dword(dev, REG_HT_LINK, val32);
202 edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
205 /* Check out PCI Interrupt and Bridge Control Register */
206 edac_pci_read_dword(dev, REG_PCI_INTBRG_CTRL, &val32);
207 if (val32 & PCI_INTBRG_CTRL_DTSTAT) {
208 printk(KERN_INFO "Error(s) in PCI interrupt and bridge control"
209 "register on device %s\n", pci_info->ctl_name);
210 printk(KERN_INFO "DTSTAT: %d\n",
211 (val32 & PCI_INTBRG_CTRL_DTSTAT) != 0);
213 val32 |= PCI_INTBRG_CTRL_DTSTAT;
214 edac_pci_write_dword(dev, REG_PCI_INTBRG_CTRL, val32);
216 edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
219 /* Check out PCI Bridge Memory Base-Limit Register */
220 edac_pci_read_dword(dev, REG_MEM_LIM, &val32);
221 if (val32 & MEM_LIMIT_CLEAR_MASK) {
222 printk(KERN_INFO
223 "Error(s) in mem limit register on %s device\n",
224 pci_info->ctl_name);
225 printk(KERN_INFO "DPE: %d, RSE: %d, RMA: %d\n"
226 "RTA: %d, STA: %d, MDPE: %d\n",
227 (val32 & MEM_LIMIT_DPE) != 0,
228 (val32 & MEM_LIMIT_RSE) != 0,
229 (val32 & MEM_LIMIT_RMA) != 0,
230 (val32 & MEM_LIMIT_RTA) != 0,
231 (val32 & MEM_LIMIT_STA) != 0,
232 (val32 & MEM_LIMIT_MDPE) != 0);
234 val32 |= MEM_LIMIT_CLEAR_MASK;
235 edac_pci_write_dword(dev, REG_MEM_LIM, val32);
237 edac_pci_handle_npe(edac_dev, edac_dev->ctl_name);
241 static struct resource *legacy_io_res;
242 static int at_compat_reg_broken;
243 #define LEGACY_NR_PORTS 1
245 /* device-specific methods for amd8111 LPC Bridge device */
246 static void amd8111_lpc_bridge_init(struct amd8111_dev_info *dev_info)
248 u8 val8;
249 struct pci_dev *dev = dev_info->dev;
251 /* First clear REG_AT_COMPAT[SERR, IOCHK] if necessary */
252 legacy_io_res = request_region(REG_AT_COMPAT, LEGACY_NR_PORTS,
253 AMD8111_EDAC_MOD_STR);
254 if (!legacy_io_res)
255 printk(KERN_INFO "%s: failed to request legacy I/O region "
256 "start %d, len %d\n", __func__,
257 REG_AT_COMPAT, LEGACY_NR_PORTS);
258 else {
259 val8 = __do_inb(REG_AT_COMPAT);
260 if (val8 == 0xff) { /* buggy port */
261 printk(KERN_INFO "%s: port %d is buggy, not supported"
262 " by hardware?\n", __func__, REG_AT_COMPAT);
263 at_compat_reg_broken = 1;
264 release_region(REG_AT_COMPAT, LEGACY_NR_PORTS);
265 legacy_io_res = NULL;
266 } else {
267 u8 out8 = 0;
268 if (val8 & AT_COMPAT_SERR)
269 out8 = AT_COMPAT_CLRSERR;
270 if (val8 & AT_COMPAT_IOCHK)
271 out8 |= AT_COMPAT_CLRIOCHK;
272 if (out8 > 0)
273 __do_outb(out8, REG_AT_COMPAT);
277 /* Second clear error flags on LPC bridge */
278 edac_pci_read_byte(dev, REG_IO_CTRL_1, &val8);
279 if (val8 & IO_CTRL_1_CLEAR_MASK)
280 edac_pci_write_byte(dev, REG_IO_CTRL_1, val8);
283 static void amd8111_lpc_bridge_exit(struct amd8111_dev_info *dev_info)
285 if (legacy_io_res)
286 release_region(REG_AT_COMPAT, LEGACY_NR_PORTS);
289 static void amd8111_lpc_bridge_check(struct edac_device_ctl_info *edac_dev)
291 struct amd8111_dev_info *dev_info = edac_dev->pvt_info;
292 struct pci_dev *dev = dev_info->dev;
293 u8 val8;
295 edac_pci_read_byte(dev, REG_IO_CTRL_1, &val8);
296 if (val8 & IO_CTRL_1_CLEAR_MASK) {
297 printk(KERN_INFO
298 "Error(s) in IO control register on %s device\n",
299 dev_info->ctl_name);
300 printk(KERN_INFO "LPC ERR: %d, PW2LPC: %d\n",
301 (val8 & IO_CTRL_1_LPC_ERR) != 0,
302 (val8 & IO_CTRL_1_PW2LPC) != 0);
304 val8 |= IO_CTRL_1_CLEAR_MASK;
305 edac_pci_write_byte(dev, REG_IO_CTRL_1, val8);
307 edac_device_handle_ue(edac_dev, 0, 0, edac_dev->ctl_name);
310 if (at_compat_reg_broken == 0) {
311 u8 out8 = 0;
312 val8 = __do_inb(REG_AT_COMPAT);
313 if (val8 & AT_COMPAT_SERR)
314 out8 = AT_COMPAT_CLRSERR;
315 if (val8 & AT_COMPAT_IOCHK)
316 out8 |= AT_COMPAT_CLRIOCHK;
317 if (out8 > 0) {
318 __do_outb(out8, REG_AT_COMPAT);
319 edac_device_handle_ue(edac_dev, 0, 0,
320 edac_dev->ctl_name);
325 /* General devices represented by edac_device_ctl_info */
326 static struct amd8111_dev_info amd8111_devices[] = {
327 [LPC_BRIDGE] = {
328 .err_dev = PCI_DEVICE_ID_AMD_8111_LPC,
329 .ctl_name = "lpc",
330 .init = amd8111_lpc_bridge_init,
331 .exit = amd8111_lpc_bridge_exit,
332 .check = amd8111_lpc_bridge_check,
334 {0},
337 /* PCI controllers represented by edac_pci_ctl_info */
338 static struct amd8111_pci_info amd8111_pcis[] = {
339 [PCI_BRIDGE] = {
340 .err_dev = PCI_DEVICE_ID_AMD_8111_PCI,
341 .ctl_name = "AMD8111_PCI_Controller",
342 .init = amd8111_pci_bridge_init,
343 .exit = amd8111_pci_bridge_exit,
344 .check = amd8111_pci_bridge_check,
346 {0},
349 static int amd8111_dev_probe(struct pci_dev *dev,
350 const struct pci_device_id *id)
352 struct amd8111_dev_info *dev_info = &amd8111_devices[id->driver_data];
353 int ret = -ENODEV;
355 dev_info->dev = pci_get_device(PCI_VENDOR_ID_AMD,
356 dev_info->err_dev, NULL);
358 if (!dev_info->dev) {
359 printk(KERN_ERR "EDAC device not found:"
360 "vendor %x, device %x, name %s\n",
361 PCI_VENDOR_ID_AMD, dev_info->err_dev,
362 dev_info->ctl_name);
363 goto err;
366 if (pci_enable_device(dev_info->dev)) {
367 printk(KERN_ERR "failed to enable:"
368 "vendor %x, device %x, name %s\n",
369 PCI_VENDOR_ID_AMD, dev_info->err_dev,
370 dev_info->ctl_name);
371 goto err_dev_put;
375 * we do not allocate extra private structure for
376 * edac_device_ctl_info, but make use of existing
377 * one instead.
379 dev_info->edac_idx = edac_device_alloc_index();
380 dev_info->edac_dev =
381 edac_device_alloc_ctl_info(0, dev_info->ctl_name, 1,
382 NULL, 0, 0,
383 NULL, 0, dev_info->edac_idx);
384 if (!dev_info->edac_dev) {
385 ret = -ENOMEM;
386 goto err_dev_put;
389 dev_info->edac_dev->pvt_info = dev_info;
390 dev_info->edac_dev->dev = &dev_info->dev->dev;
391 dev_info->edac_dev->mod_name = AMD8111_EDAC_MOD_STR;
392 dev_info->edac_dev->ctl_name = dev_info->ctl_name;
393 dev_info->edac_dev->dev_name = dev_name(&dev_info->dev->dev);
395 if (edac_op_state == EDAC_OPSTATE_POLL)
396 dev_info->edac_dev->edac_check = dev_info->check;
398 if (dev_info->init)
399 dev_info->init(dev_info);
401 if (edac_device_add_device(dev_info->edac_dev) > 0) {
402 printk(KERN_ERR "failed to add edac_dev for %s\n",
403 dev_info->ctl_name);
404 goto err_edac_free_ctl;
407 printk(KERN_INFO "added one edac_dev on AMD8111 "
408 "vendor %x, device %x, name %s\n",
409 PCI_VENDOR_ID_AMD, dev_info->err_dev,
410 dev_info->ctl_name);
412 return 0;
414 err_edac_free_ctl:
415 edac_device_free_ctl_info(dev_info->edac_dev);
416 err_dev_put:
417 pci_dev_put(dev_info->dev);
418 err:
419 return ret;
422 static void amd8111_dev_remove(struct pci_dev *dev)
424 struct amd8111_dev_info *dev_info;
426 for (dev_info = amd8111_devices; dev_info->err_dev; dev_info++)
427 if (dev_info->dev->device == dev->device)
428 break;
430 if (!dev_info->err_dev) /* should never happen */
431 return;
433 if (dev_info->edac_dev) {
434 edac_device_del_device(dev_info->edac_dev->dev);
435 edac_device_free_ctl_info(dev_info->edac_dev);
438 if (dev_info->exit)
439 dev_info->exit(dev_info);
441 pci_dev_put(dev_info->dev);
444 static int amd8111_pci_probe(struct pci_dev *dev,
445 const struct pci_device_id *id)
447 struct amd8111_pci_info *pci_info = &amd8111_pcis[id->driver_data];
448 int ret = -ENODEV;
450 pci_info->dev = pci_get_device(PCI_VENDOR_ID_AMD,
451 pci_info->err_dev, NULL);
453 if (!pci_info->dev) {
454 printk(KERN_ERR "EDAC device not found:"
455 "vendor %x, device %x, name %s\n",
456 PCI_VENDOR_ID_AMD, pci_info->err_dev,
457 pci_info->ctl_name);
458 goto err;
461 if (pci_enable_device(pci_info->dev)) {
462 printk(KERN_ERR "failed to enable:"
463 "vendor %x, device %x, name %s\n",
464 PCI_VENDOR_ID_AMD, pci_info->err_dev,
465 pci_info->ctl_name);
466 goto err_dev_put;
470 * we do not allocate extra private structure for
471 * edac_pci_ctl_info, but make use of existing
472 * one instead.
474 pci_info->edac_idx = edac_pci_alloc_index();
475 pci_info->edac_dev = edac_pci_alloc_ctl_info(0, pci_info->ctl_name);
476 if (!pci_info->edac_dev) {
477 ret = -ENOMEM;
478 goto err_dev_put;
481 pci_info->edac_dev->pvt_info = pci_info;
482 pci_info->edac_dev->dev = &pci_info->dev->dev;
483 pci_info->edac_dev->mod_name = AMD8111_EDAC_MOD_STR;
484 pci_info->edac_dev->ctl_name = pci_info->ctl_name;
485 pci_info->edac_dev->dev_name = dev_name(&pci_info->dev->dev);
487 if (edac_op_state == EDAC_OPSTATE_POLL)
488 pci_info->edac_dev->edac_check = pci_info->check;
490 if (pci_info->init)
491 pci_info->init(pci_info);
493 if (edac_pci_add_device(pci_info->edac_dev, pci_info->edac_idx) > 0) {
494 printk(KERN_ERR "failed to add edac_pci for %s\n",
495 pci_info->ctl_name);
496 goto err_edac_free_ctl;
499 printk(KERN_INFO "added one edac_pci on AMD8111 "
500 "vendor %x, device %x, name %s\n",
501 PCI_VENDOR_ID_AMD, pci_info->err_dev,
502 pci_info->ctl_name);
504 return 0;
506 err_edac_free_ctl:
507 edac_pci_free_ctl_info(pci_info->edac_dev);
508 err_dev_put:
509 pci_dev_put(pci_info->dev);
510 err:
511 return ret;
514 static void amd8111_pci_remove(struct pci_dev *dev)
516 struct amd8111_pci_info *pci_info;
518 for (pci_info = amd8111_pcis; pci_info->err_dev; pci_info++)
519 if (pci_info->dev->device == dev->device)
520 break;
522 if (!pci_info->err_dev) /* should never happen */
523 return;
525 if (pci_info->edac_dev) {
526 edac_pci_del_device(pci_info->edac_dev->dev);
527 edac_pci_free_ctl_info(pci_info->edac_dev);
530 if (pci_info->exit)
531 pci_info->exit(pci_info);
533 pci_dev_put(pci_info->dev);
536 /* PCI Device ID talbe for general EDAC device */
537 static const struct pci_device_id amd8111_edac_dev_tbl[] = {
539 PCI_VEND_DEV(AMD, 8111_LPC),
540 .subvendor = PCI_ANY_ID,
541 .subdevice = PCI_ANY_ID,
542 .class = 0,
543 .class_mask = 0,
544 .driver_data = LPC_BRIDGE,
548 } /* table is NULL-terminated */
550 MODULE_DEVICE_TABLE(pci, amd8111_edac_dev_tbl);
552 static struct pci_driver amd8111_edac_dev_driver = {
553 .name = "AMD8111_EDAC_DEV",
554 .probe = amd8111_dev_probe,
555 .remove = amd8111_dev_remove,
556 .id_table = amd8111_edac_dev_tbl,
559 /* PCI Device ID table for EDAC PCI controller */
560 static const struct pci_device_id amd8111_edac_pci_tbl[] = {
562 PCI_VEND_DEV(AMD, 8111_PCI),
563 .subvendor = PCI_ANY_ID,
564 .subdevice = PCI_ANY_ID,
565 .class = 0,
566 .class_mask = 0,
567 .driver_data = PCI_BRIDGE,
571 } /* table is NULL-terminated */
573 MODULE_DEVICE_TABLE(pci, amd8111_edac_pci_tbl);
575 static struct pci_driver amd8111_edac_pci_driver = {
576 .name = "AMD8111_EDAC_PCI",
577 .probe = amd8111_pci_probe,
578 .remove = amd8111_pci_remove,
579 .id_table = amd8111_edac_pci_tbl,
582 static int __init amd8111_edac_init(void)
584 int val;
586 printk(KERN_INFO "AMD8111 EDAC driver " AMD8111_EDAC_REVISION "\n");
587 printk(KERN_INFO "\t(c) 2008 Wind River Systems, Inc.\n");
589 /* Only POLL mode supported so far */
590 edac_op_state = EDAC_OPSTATE_POLL;
592 val = pci_register_driver(&amd8111_edac_dev_driver);
593 val |= pci_register_driver(&amd8111_edac_pci_driver);
595 return val;
598 static void __exit amd8111_edac_exit(void)
600 pci_unregister_driver(&amd8111_edac_pci_driver);
601 pci_unregister_driver(&amd8111_edac_dev_driver);
605 module_init(amd8111_edac_init);
606 module_exit(amd8111_edac_exit);
608 MODULE_LICENSE("GPL");
609 MODULE_AUTHOR("Cao Qingtao <qingtao.cao@windriver.com>\n");
610 MODULE_DESCRIPTION("AMD8111 HyperTransport I/O Hub EDAC kernel module");