2 * Page Deallocation Table (PDT) support
4 * The Page Deallocation Table (PDT) is maintained by firmware and holds a
5 * list of memory addresses in which memory errors were detected.
6 * The list contains both single-bit (correctable) and double-bit
7 * (uncorrectable) errors.
11 * possible future enhancements:
12 * - add userspace interface via procfs or sysfs to clear PDT
15 #include <linux/memblock.h>
16 #include <linux/seq_file.h>
17 #include <linux/kthread.h>
20 #include <asm/pdcpat.h>
21 #include <asm/sections.h>
22 #include <asm/pgtable.h>
24 enum pdt_access_type {
31 static enum pdt_access_type pdt_type;
33 /* PDT poll interval: 1 minute if errors, 5 minutes if everything OK. */
34 #define PDT_POLL_INTERVAL_DEFAULT (5*60*HZ)
35 #define PDT_POLL_INTERVAL_SHORT (1*60*HZ)
36 static unsigned long pdt_poll_interval = PDT_POLL_INTERVAL_DEFAULT;
38 /* global PDT status information */
39 static struct pdc_mem_retinfo pdt_status;
41 #define MAX_PDT_TABLE_SIZE PAGE_SIZE
42 #define MAX_PDT_ENTRIES (MAX_PDT_TABLE_SIZE / sizeof(unsigned long))
43 static unsigned long pdt_entry[MAX_PDT_ENTRIES] __page_aligned_bss;
46 * Constants for the pdt_entry format:
47 * A pdt_entry holds the physical address in bits 0-57, bits 58-61 are
48 * reserved, bit 62 is the perm bit and bit 63 is the error_type bit.
49 * The perm bit indicates whether the error have been verified as a permanent
50 * error (value of 1) or has not been verified, and may be transient (value
51 * of 0). The error_type bit indicates whether the error is a single bit error
52 * (value of 1) or a multiple bit error.
53 * On non-PAT machines phys_addr is encoded in bits 0-59 and error_type in bit
54 * 63. Those machines don't provide the perm bit.
57 #define PDT_ADDR_PHYS_MASK (pdt_type != PDT_PDC ? ~0x3f : ~0x0f)
58 #define PDT_ADDR_PERM_ERR (pdt_type != PDT_PDC ? 2UL : 0UL)
59 #define PDT_ADDR_SINGLE_ERR 1UL
61 /* report PDT entries via /proc/meminfo */
62 void arch_report_meminfo(struct seq_file *m)
64 if (pdt_type == PDT_NONE)
67 seq_printf(m, "PDT_max_entries: %7lu\n",
69 seq_printf(m, "PDT_cur_entries: %7lu\n",
70 pdt_status.pdt_entries);
73 static int get_info_pat_new(void)
75 struct pdc_pat_mem_retinfo pat_rinfo;
78 /* newer PAT machines like C8000 report info for all cells */
80 ret = pdc_pat_mem_pdt_info(&pat_rinfo);
84 pdt_status.pdt_size = pat_rinfo.max_pdt_entries;
85 pdt_status.pdt_entries = pat_rinfo.current_pdt_entries;
86 pdt_status.pdt_status = 0;
87 pdt_status.first_dbe_loc = pat_rinfo.first_dbe_loc;
88 pdt_status.good_mem = pat_rinfo.good_mem;
93 static int get_info_pat_cell(void)
95 struct pdc_pat_mem_cell_pdt_retinfo cell_rinfo;
98 /* older PAT machines like rp5470 report cell info only */
100 ret = pdc_pat_mem_pdt_cell_info(&cell_rinfo, parisc_cell_num);
104 pdt_status.pdt_size = cell_rinfo.max_pdt_entries;
105 pdt_status.pdt_entries = cell_rinfo.current_pdt_entries;
106 pdt_status.pdt_status = 0;
107 pdt_status.first_dbe_loc = cell_rinfo.first_dbe_loc;
108 pdt_status.good_mem = cell_rinfo.good_mem;
113 static void report_mem_err(unsigned long pde)
115 struct pdc_pat_mem_phys_mem_location loc;
119 addr = pde & PDT_ADDR_PHYS_MASK;
121 /* show DIMM slot description on PAT machines */
123 pdc_pat_mem_get_dimm_phys_location(&loc, addr);
124 sprintf(dimm_txt, "DIMM slot %02x, ", loc.dimm_slot);
128 pr_warn("PDT: BAD MEMORY at 0x%08lx, %s%s%s-bit error.\n",
130 pde & PDT_ADDR_PERM_ERR ? "permanent ":"",
131 pde & PDT_ADDR_SINGLE_ERR ? "single":"multi");
138 * Initialize kernel PDT structures, read initial PDT table from firmware,
139 * report all current PDT entries and mark bad memory with memblock_reserve()
140 * to avoid that the kernel will use broken memory areas.
143 void __init pdc_pdt_init(void)
146 unsigned long entries;
147 struct pdc_mem_read_pdt pdt_read_ret;
149 pdt_type = PDT_PAT_NEW;
150 ret = get_info_pat_new();
153 pdt_type = PDT_PAT_CELL;
154 ret = get_info_pat_cell();
159 /* non-PAT machines provide the standard PDC call */
160 ret = pdc_mem_pdt_info(&pdt_status);
165 pr_info("PDT: Firmware does not provide any page deallocation"
170 entries = pdt_status.pdt_entries;
171 if (WARN_ON(entries > MAX_PDT_ENTRIES))
172 entries = pdt_status.pdt_entries = MAX_PDT_ENTRIES;
174 pr_info("PDT: type %s, size %lu, entries %lu, status %lu, dbe_loc 0x%lx,"
175 " good_mem %lu MB\n",
176 pdt_type == PDT_PDC ? __stringify(PDT_PDC) :
177 pdt_type == PDT_PAT_CELL ? __stringify(PDT_PAT_CELL)
178 : __stringify(PDT_PAT_NEW),
179 pdt_status.pdt_size, pdt_status.pdt_entries,
180 pdt_status.pdt_status, pdt_status.first_dbe_loc,
181 pdt_status.good_mem / 1024 / 1024);
184 pr_info("PDT: Firmware reports all memory OK.\n");
188 if (pdt_status.first_dbe_loc &&
189 pdt_status.first_dbe_loc <= __pa((unsigned long)&_end))
190 pr_crit("CRITICAL: Bad memory inside kernel image memory area!\n");
192 pr_warn("PDT: Firmware reports %lu entries of faulty memory:\n",
195 if (pdt_type == PDT_PDC)
196 ret = pdc_mem_pdt_read_entries(&pdt_read_ret, pdt_entry);
199 struct pdc_pat_mem_read_pd_retinfo pat_pret;
201 if (pdt_type == PDT_PAT_CELL)
202 ret = pdc_pat_mem_read_cell_pdt(&pat_pret, pdt_entry,
205 ret = pdc_pat_mem_read_pd_pdt(&pat_pret, pdt_entry,
206 MAX_PDT_TABLE_SIZE, 0);
214 pr_warn("PDT: Get PDT entries failed with %d\n", ret);
218 for (i = 0; i < pdt_status.pdt_entries; i++) {
219 report_mem_err(pdt_entry[i]);
221 /* mark memory page bad */
222 memblock_reserve(pdt_entry[i] & PAGE_MASK, PAGE_SIZE);
228 * This is the PDT kernel thread main loop.
231 static int pdt_mainloop(void *unused)
233 struct pdc_mem_read_pdt pdt_read_ret;
234 struct pdc_pat_mem_read_pd_retinfo pat_pret __maybe_unused;
235 unsigned long old_num_entries;
236 unsigned long *bad_mem_ptr;
240 set_current_state(TASK_INTERRUPTIBLE);
242 old_num_entries = pdt_status.pdt_entries;
244 schedule_timeout(pdt_poll_interval);
245 if (kthread_should_stop())
248 /* Do we have new PDT entries? */
251 ret = get_info_pat_new();
254 ret = get_info_pat_cell();
257 ret = pdc_mem_pdt_info(&pdt_status);
262 pr_warn("PDT: unexpected failure %d\n", ret);
266 /* if no new PDT entries, just wait again */
267 num = pdt_status.pdt_entries - old_num_entries;
271 /* decrease poll interval in case we found memory errors */
272 if (pdt_status.pdt_entries &&
273 pdt_poll_interval == PDT_POLL_INTERVAL_DEFAULT)
274 pdt_poll_interval = PDT_POLL_INTERVAL_SHORT;
276 /* limit entries to get */
277 if (num > MAX_PDT_ENTRIES) {
278 num = MAX_PDT_ENTRIES;
279 pdt_status.pdt_entries = old_num_entries + num;
282 /* get new entries */
286 if (pdt_status.pdt_entries > MAX_PDT_ENTRIES) {
287 pr_crit("PDT: too many entries.\n");
290 ret = pdc_pat_mem_read_cell_pdt(&pat_pret, pdt_entry,
292 bad_mem_ptr = &pdt_entry[old_num_entries];
295 ret = pdc_pat_mem_read_pd_pdt(&pat_pret,
297 num * sizeof(unsigned long),
298 old_num_entries * sizeof(unsigned long));
299 bad_mem_ptr = &pdt_entry[0];
303 ret = pdc_mem_pdt_read_entries(&pdt_read_ret,
305 bad_mem_ptr = &pdt_entry[old_num_entries];
309 /* report and mark memory broken */
311 unsigned long pde = *bad_mem_ptr++;
315 #ifdef CONFIG_MEMORY_FAILURE
316 if ((pde & PDT_ADDR_PERM_ERR) ||
317 ((pde & PDT_ADDR_SINGLE_ERR) == 0))
318 memory_failure(pde >> PAGE_SHIFT, 0, 0);
321 pfn_to_page(pde >> PAGE_SHIFT), 0);
323 pr_crit("PDT: memory error at 0x%lx ignored.\n"
324 "Rebuild kernel with CONFIG_MEMORY_FAILURE=y "
325 "for real handling.\n",
326 pde & PDT_ADDR_PHYS_MASK);
336 static int __init pdt_initcall(void)
338 struct task_struct *kpdtd_task;
340 if (pdt_type == PDT_NONE)
343 kpdtd_task = kthread_create(pdt_mainloop, NULL, "kpdtd");
344 if (IS_ERR(kpdtd_task))
345 return PTR_ERR(kpdtd_task);
347 wake_up_process(kpdtd_task);
352 late_initcall(pdt_initcall);