Remove obsolete #include <linux/config.h>
[linux-2.6/verdex.git] / drivers / edac / amd76x_edac.c
blob35599ed4bad5dfb824699f72bcaf22fa3c305829
1 /*
2 * AMD 76x Memory Controller kernel module
3 * (C) 2003 Linux Networx (http://lnxi.com)
4 * This file may be distributed under the terms of the
5 * GNU General Public License.
7 * Written by Thayne Harbaugh
8 * Based on work by Dan Hollis <goemon at anime dot net> and others.
9 * http://www.anime.net/~goemon/linux-ecc/
11 * $Id: edac_amd76x.c,v 1.4.2.5 2005/10/05 00:43:44 dsp_llnl Exp $
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/pci.h>
18 #include <linux/pci_ids.h>
19 #include <linux/slab.h>
20 #include "edac_mc.h"
22 #define amd76x_printk(level, fmt, arg...) \
23 edac_printk(level, "amd76x", fmt, ##arg)
25 #define amd76x_mc_printk(mci, level, fmt, arg...) \
26 edac_mc_chipset_printk(mci, level, "amd76x", fmt, ##arg)
28 #define AMD76X_NR_CSROWS 8
29 #define AMD76X_NR_CHANS 1
30 #define AMD76X_NR_DIMMS 4
32 /* AMD 76x register addresses - device 0 function 0 - PCI bridge */
34 #define AMD76X_ECC_MODE_STATUS 0x48 /* Mode and status of ECC (32b)
36 * 31:16 reserved
37 * 15:14 SERR enabled: x1=ue 1x=ce
38 * 13 reserved
39 * 12 diag: disabled, enabled
40 * 11:10 mode: dis, EC, ECC, ECC+scrub
41 * 9:8 status: x1=ue 1x=ce
42 * 7:4 UE cs row
43 * 3:0 CE cs row
46 #define AMD76X_DRAM_MODE_STATUS 0x58 /* DRAM Mode and status (32b)
48 * 31:26 clock disable 5 - 0
49 * 25 SDRAM init
50 * 24 reserved
51 * 23 mode register service
52 * 22:21 suspend to RAM
53 * 20 burst refresh enable
54 * 19 refresh disable
55 * 18 reserved
56 * 17:16 cycles-per-refresh
57 * 15:8 reserved
58 * 7:0 x4 mode enable 7 - 0
61 #define AMD76X_MEM_BASE_ADDR 0xC0 /* Memory base address (8 x 32b)
63 * 31:23 chip-select base
64 * 22:16 reserved
65 * 15:7 chip-select mask
66 * 6:3 reserved
67 * 2:1 address mode
68 * 0 chip-select enable
71 struct amd76x_error_info {
72 u32 ecc_mode_status;
75 enum amd76x_chips {
76 AMD761 = 0,
77 AMD762
80 struct amd76x_dev_info {
81 const char *ctl_name;
84 static const struct amd76x_dev_info amd76x_devs[] = {
85 [AMD761] = {
86 .ctl_name = "AMD761"
88 [AMD762] = {
89 .ctl_name = "AMD762"
93 /**
94 * amd76x_get_error_info - fetch error information
95 * @mci: Memory controller
96 * @info: Info to fill in
98 * Fetch and store the AMD76x ECC status. Clear pending status
99 * on the chip so that further errors will be reported
101 static void amd76x_get_error_info(struct mem_ctl_info *mci,
102 struct amd76x_error_info *info)
104 pci_read_config_dword(mci->pdev, AMD76X_ECC_MODE_STATUS,
105 &info->ecc_mode_status);
107 if (info->ecc_mode_status & BIT(8))
108 pci_write_bits32(mci->pdev, AMD76X_ECC_MODE_STATUS,
109 (u32) BIT(8), (u32) BIT(8));
111 if (info->ecc_mode_status & BIT(9))
112 pci_write_bits32(mci->pdev, AMD76X_ECC_MODE_STATUS,
113 (u32) BIT(9), (u32) BIT(9));
117 * amd76x_process_error_info - Error check
118 * @mci: Memory controller
119 * @info: Previously fetched information from chip
120 * @handle_errors: 1 if we should do recovery
122 * Process the chip state and decide if an error has occurred.
123 * A return of 1 indicates an error. Also if handle_errors is true
124 * then attempt to handle and clean up after the error
126 static int amd76x_process_error_info(struct mem_ctl_info *mci,
127 struct amd76x_error_info *info, int handle_errors)
129 int error_found;
130 u32 row;
132 error_found = 0;
135 * Check for an uncorrectable error
137 if (info->ecc_mode_status & BIT(8)) {
138 error_found = 1;
140 if (handle_errors) {
141 row = (info->ecc_mode_status >> 4) & 0xf;
142 edac_mc_handle_ue(mci, mci->csrows[row].first_page, 0,
143 row, mci->ctl_name);
148 * Check for a correctable error
150 if (info->ecc_mode_status & BIT(9)) {
151 error_found = 1;
153 if (handle_errors) {
154 row = info->ecc_mode_status & 0xf;
155 edac_mc_handle_ce(mci, mci->csrows[row].first_page, 0,
156 0, row, 0, mci->ctl_name);
160 return error_found;
164 * amd76x_check - Poll the controller
165 * @mci: Memory controller
167 * Called by the poll handlers this function reads the status
168 * from the controller and checks for errors.
170 static void amd76x_check(struct mem_ctl_info *mci)
172 struct amd76x_error_info info;
173 debugf3("%s()\n", __func__);
174 amd76x_get_error_info(mci, &info);
175 amd76x_process_error_info(mci, &info, 1);
179 * amd76x_probe1 - Perform set up for detected device
180 * @pdev; PCI device detected
181 * @dev_idx: Device type index
183 * We have found an AMD76x and now need to set up the memory
184 * controller status reporting. We configure and set up the
185 * memory controller reporting and claim the device.
187 static int amd76x_probe1(struct pci_dev *pdev, int dev_idx)
189 int rc = -ENODEV;
190 int index;
191 struct mem_ctl_info *mci = NULL;
192 enum edac_type ems_modes[] = {
193 EDAC_NONE,
194 EDAC_EC,
195 EDAC_SECDED,
196 EDAC_SECDED
198 u32 ems;
199 u32 ems_mode;
200 struct amd76x_error_info discard;
202 debugf0("%s()\n", __func__);
203 pci_read_config_dword(pdev, AMD76X_ECC_MODE_STATUS, &ems);
204 ems_mode = (ems >> 10) & 0x3;
205 mci = edac_mc_alloc(0, AMD76X_NR_CSROWS, AMD76X_NR_CHANS);
207 if (mci == NULL) {
208 rc = -ENOMEM;
209 goto fail;
212 debugf0("%s(): mci = %p\n", __func__, mci);
213 mci->pdev = pdev;
214 mci->mtype_cap = MEM_FLAG_RDDR;
215 mci->edac_ctl_cap = EDAC_FLAG_NONE | EDAC_FLAG_EC | EDAC_FLAG_SECDED;
216 mci->edac_cap = ems_mode ?
217 (EDAC_FLAG_EC | EDAC_FLAG_SECDED) : EDAC_FLAG_NONE;
218 mci->mod_name = EDAC_MOD_STR;
219 mci->mod_ver = "$Revision: 1.4.2.5 $";
220 mci->ctl_name = amd76x_devs[dev_idx].ctl_name;
221 mci->edac_check = amd76x_check;
222 mci->ctl_page_to_phys = NULL;
224 for (index = 0; index < mci->nr_csrows; index++) {
225 struct csrow_info *csrow = &mci->csrows[index];
226 u32 mba;
227 u32 mba_base;
228 u32 mba_mask;
229 u32 dms;
231 /* find the DRAM Chip Select Base address and mask */
232 pci_read_config_dword(mci->pdev,
233 AMD76X_MEM_BASE_ADDR + (index * 4), &mba);
235 if (!(mba & BIT(0)))
236 continue;
238 mba_base = mba & 0xff800000UL;
239 mba_mask = ((mba & 0xff80) << 16) | 0x7fffffUL;
240 pci_read_config_dword(mci->pdev, AMD76X_DRAM_MODE_STATUS,
241 &dms);
242 csrow->first_page = mba_base >> PAGE_SHIFT;
243 csrow->nr_pages = (mba_mask + 1) >> PAGE_SHIFT;
244 csrow->last_page = csrow->first_page + csrow->nr_pages - 1;
245 csrow->page_mask = mba_mask >> PAGE_SHIFT;
246 csrow->grain = csrow->nr_pages << PAGE_SHIFT;
247 csrow->mtype = MEM_RDDR;
248 csrow->dtype = ((dms >> index) & 0x1) ? DEV_X4 : DEV_UNKNOWN;
249 csrow->edac_mode = ems_modes[ems_mode];
252 amd76x_get_error_info(mci, &discard); /* clear counters */
254 if (edac_mc_add_mc(mci)) {
255 debugf3("%s(): failed edac_mc_add_mc()\n", __func__);
256 goto fail;
259 /* get this far and it's successful */
260 debugf3("%s(): success\n", __func__);
261 return 0;
263 fail:
264 if (mci != NULL)
265 edac_mc_free(mci);
266 return rc;
269 /* returns count (>= 0), or negative on error */
270 static int __devinit amd76x_init_one(struct pci_dev *pdev,
271 const struct pci_device_id *ent)
273 debugf0("%s()\n", __func__);
275 /* don't need to call pci_device_enable() */
276 return amd76x_probe1(pdev, ent->driver_data);
280 * amd76x_remove_one - driver shutdown
281 * @pdev: PCI device being handed back
283 * Called when the driver is unloaded. Find the matching mci
284 * structure for the device then delete the mci and free the
285 * resources.
287 static void __devexit amd76x_remove_one(struct pci_dev *pdev)
289 struct mem_ctl_info *mci;
291 debugf0("%s()\n", __func__);
293 if ((mci = edac_mc_del_mc(pdev)) == NULL)
294 return;
296 edac_mc_free(mci);
299 static const struct pci_device_id amd76x_pci_tbl[] __devinitdata = {
301 PCI_VEND_DEV(AMD, FE_GATE_700C), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
302 AMD762
305 PCI_VEND_DEV(AMD, FE_GATE_700E), PCI_ANY_ID, PCI_ANY_ID, 0, 0,
306 AMD761
310 } /* 0 terminated list. */
313 MODULE_DEVICE_TABLE(pci, amd76x_pci_tbl);
315 static struct pci_driver amd76x_driver = {
316 .name = EDAC_MOD_STR,
317 .probe = amd76x_init_one,
318 .remove = __devexit_p(amd76x_remove_one),
319 .id_table = amd76x_pci_tbl,
322 static int __init amd76x_init(void)
324 return pci_register_driver(&amd76x_driver);
327 static void __exit amd76x_exit(void)
329 pci_unregister_driver(&amd76x_driver);
332 module_init(amd76x_init);
333 module_exit(amd76x_exit);
335 MODULE_LICENSE("GPL");
336 MODULE_AUTHOR("Linux Networx (http://lnxi.com) Thayne Harbaugh");
337 MODULE_DESCRIPTION("MC support for AMD 76x memory controllers");