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>
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)
37 * 15:14 SERR enabled: x1=ue 1x=ce
39 * 12 diag: disabled, enabled
40 * 11:10 mode: dis, EC, ECC, ECC+scrub
41 * 9:8 status: x1=ue 1x=ce
46 #define AMD76X_DRAM_MODE_STATUS 0x58 /* DRAM Mode and status (32b)
48 * 31:26 clock disable 5 - 0
51 * 23 mode register service
52 * 22:21 suspend to RAM
53 * 20 burst refresh enable
56 * 17:16 cycles-per-refresh
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
65 * 15:7 chip-select mask
68 * 0 chip-select enable
71 struct amd76x_error_info
{
80 struct amd76x_dev_info
{
84 static const struct amd76x_dev_info amd76x_devs
[] = {
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
)
135 * Check for an uncorrectable error
137 if (info
->ecc_mode_status
& BIT(8)) {
141 row
= (info
->ecc_mode_status
>> 4) & 0xf;
142 edac_mc_handle_ue(mci
, mci
->csrows
[row
].first_page
, 0,
148 * Check for a correctable error
150 if (info
->ecc_mode_status
& BIT(9)) {
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
);
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
)
191 struct mem_ctl_info
*mci
= NULL
;
192 enum edac_type ems_modes
[] = {
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
);
212 debugf0("%s(): mci = %p\n", __func__
, mci
);
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
];
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
);
238 mba_base
= mba
& 0xff800000UL
;
239 mba_mask
= ((mba
& 0xff80) << 16) | 0x7fffffUL
;
240 pci_read_config_dword(mci
->pdev
, AMD76X_DRAM_MODE_STATUS
,
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__
);
259 /* get this far and it's successful */
260 debugf3("%s(): success\n", __func__
);
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
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
)
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,
305 PCI_VEND_DEV(AMD
, FE_GATE_700E
), PCI_ANY_ID
, PCI_ANY_ID
, 0, 0,
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");