diff options
Diffstat (limited to 'arch/sparc64/kernel/chmc.c')
-rw-r--r-- | arch/sparc64/kernel/chmc.c | 817 |
1 files changed, 619 insertions, 198 deletions
diff --git a/arch/sparc64/kernel/chmc.c b/arch/sparc64/kernel/chmc.c index 6d4f02e8a4cf..967b04886822 100644 --- a/arch/sparc64/kernel/chmc.c +++ b/arch/sparc64/kernel/chmc.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* memctrlr.c: Driver for UltraSPARC-III memory controller. | 1 | /* chmc.c: Driver for UltraSPARC-III memory controller. |
2 | * | 2 | * |
3 | * Copyright (C) 2001, 2007 David S. Miller (davem@davemloft.net) | 3 | * Copyright (C) 2001, 2007, 2008 David S. Miller (davem@davemloft.net) |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <linux/module.h> | 6 | #include <linux/module.h> |
@@ -13,45 +13,64 @@ | |||
13 | #include <linux/smp.h> | 13 | #include <linux/smp.h> |
14 | #include <linux/errno.h> | 14 | #include <linux/errno.h> |
15 | #include <linux/init.h> | 15 | #include <linux/init.h> |
16 | #include <linux/of.h> | ||
17 | #include <linux/of_device.h> | ||
16 | #include <asm/spitfire.h> | 18 | #include <asm/spitfire.h> |
17 | #include <asm/chmctrl.h> | 19 | #include <asm/chmctrl.h> |
18 | #include <asm/cpudata.h> | 20 | #include <asm/cpudata.h> |
19 | #include <asm/oplib.h> | 21 | #include <asm/oplib.h> |
20 | #include <asm/prom.h> | 22 | #include <asm/prom.h> |
23 | #include <asm/head.h> | ||
21 | #include <asm/io.h> | 24 | #include <asm/io.h> |
25 | #include <asm/memctrl.h> | ||
26 | |||
27 | #define DRV_MODULE_NAME "chmc" | ||
28 | #define PFX DRV_MODULE_NAME ": " | ||
29 | #define DRV_MODULE_VERSION "0.2" | ||
30 | |||
31 | MODULE_AUTHOR("David S. Miller (davem@davemloft.net)"); | ||
32 | MODULE_DESCRIPTION("UltraSPARC-III memory controller driver"); | ||
33 | MODULE_LICENSE("GPL"); | ||
34 | MODULE_VERSION(DRV_MODULE_VERSION); | ||
35 | |||
36 | static int mc_type; | ||
37 | #define MC_TYPE_SAFARI 1 | ||
38 | #define MC_TYPE_JBUS 2 | ||
39 | |||
40 | static dimm_printer_t us3mc_dimm_printer; | ||
22 | 41 | ||
23 | #define CHMCTRL_NDGRPS 2 | 42 | #define CHMCTRL_NDGRPS 2 |
24 | #define CHMCTRL_NDIMMS 4 | 43 | #define CHMCTRL_NDIMMS 4 |
25 | 44 | ||
26 | #define DIMMS_PER_MC (CHMCTRL_NDGRPS * CHMCTRL_NDIMMS) | 45 | #define CHMC_DIMMS_PER_MC (CHMCTRL_NDGRPS * CHMCTRL_NDIMMS) |
27 | 46 | ||
28 | /* OBP memory-layout property format. */ | 47 | /* OBP memory-layout property format. */ |
29 | struct obp_map { | 48 | struct chmc_obp_map { |
30 | unsigned char dimm_map[144]; | 49 | unsigned char dimm_map[144]; |
31 | unsigned char pin_map[576]; | 50 | unsigned char pin_map[576]; |
32 | }; | 51 | }; |
33 | 52 | ||
34 | #define DIMM_LABEL_SZ 8 | 53 | #define DIMM_LABEL_SZ 8 |
35 | 54 | ||
36 | struct obp_mem_layout { | 55 | struct chmc_obp_mem_layout { |
37 | /* One max 8-byte string label per DIMM. Usually | 56 | /* One max 8-byte string label per DIMM. Usually |
38 | * this matches the label on the motherboard where | 57 | * this matches the label on the motherboard where |
39 | * that DIMM resides. | 58 | * that DIMM resides. |
40 | */ | 59 | */ |
41 | char dimm_labels[DIMMS_PER_MC][DIMM_LABEL_SZ]; | 60 | char dimm_labels[CHMC_DIMMS_PER_MC][DIMM_LABEL_SZ]; |
42 | 61 | ||
43 | /* If symmetric use map[0], else it is | 62 | /* If symmetric use map[0], else it is |
44 | * asymmetric and map[1] should be used. | 63 | * asymmetric and map[1] should be used. |
45 | */ | 64 | */ |
46 | char symmetric; | 65 | char symmetric; |
47 | 66 | ||
48 | struct obp_map map[2]; | 67 | struct chmc_obp_map map[2]; |
49 | }; | 68 | }; |
50 | 69 | ||
51 | #define CHMCTRL_NBANKS 4 | 70 | #define CHMCTRL_NBANKS 4 |
52 | 71 | ||
53 | struct bank_info { | 72 | struct chmc_bank_info { |
54 | struct mctrl_info *mp; | 73 | struct chmc *p; |
55 | int bank_id; | 74 | int bank_id; |
56 | 75 | ||
57 | u64 raw_reg; | 76 | u64 raw_reg; |
@@ -65,28 +84,406 @@ struct bank_info { | |||
65 | unsigned long size; | 84 | unsigned long size; |
66 | }; | 85 | }; |
67 | 86 | ||
68 | struct mctrl_info { | 87 | struct chmc { |
69 | struct list_head list; | 88 | struct list_head list; |
70 | int portid; | 89 | int portid; |
90 | |||
91 | struct chmc_obp_mem_layout layout_prop; | ||
92 | int layout_size; | ||
93 | |||
94 | void __iomem *regs; | ||
71 | 95 | ||
72 | struct obp_mem_layout layout_prop; | 96 | u64 timing_control1; |
73 | int layout_size; | 97 | u64 timing_control2; |
98 | u64 timing_control3; | ||
99 | u64 timing_control4; | ||
100 | u64 memaddr_control; | ||
74 | 101 | ||
75 | void __iomem *regs; | 102 | struct chmc_bank_info logical_banks[CHMCTRL_NBANKS]; |
103 | }; | ||
104 | |||
105 | #define JBUSMC_REGS_SIZE 8 | ||
106 | |||
107 | #define JB_MC_REG1_DIMM2_BANK3 0x8000000000000000UL | ||
108 | #define JB_MC_REG1_DIMM1_BANK1 0x4000000000000000UL | ||
109 | #define JB_MC_REG1_DIMM2_BANK2 0x2000000000000000UL | ||
110 | #define JB_MC_REG1_DIMM1_BANK0 0x1000000000000000UL | ||
111 | #define JB_MC_REG1_XOR 0x0000010000000000UL | ||
112 | #define JB_MC_REG1_ADDR_GEN_2 0x000000e000000000UL | ||
113 | #define JB_MC_REG1_ADDR_GEN_2_SHIFT 37 | ||
114 | #define JB_MC_REG1_ADDR_GEN_1 0x0000001c00000000UL | ||
115 | #define JB_MC_REG1_ADDR_GEN_1_SHIFT 34 | ||
116 | #define JB_MC_REG1_INTERLEAVE 0x0000000001800000UL | ||
117 | #define JB_MC_REG1_INTERLEAVE_SHIFT 23 | ||
118 | #define JB_MC_REG1_DIMM2_PTYPE 0x0000000000200000UL | ||
119 | #define JB_MC_REG1_DIMM2_PTYPE_SHIFT 21 | ||
120 | #define JB_MC_REG1_DIMM1_PTYPE 0x0000000000100000UL | ||
121 | #define JB_MC_REG1_DIMM1_PTYPE_SHIFT 20 | ||
122 | |||
123 | #define PART_TYPE_X8 0 | ||
124 | #define PART_TYPE_X4 1 | ||
125 | |||
126 | #define INTERLEAVE_NONE 0 | ||
127 | #define INTERLEAVE_SAME 1 | ||
128 | #define INTERLEAVE_INTERNAL 2 | ||
129 | #define INTERLEAVE_BOTH 3 | ||
130 | |||
131 | #define ADDR_GEN_128MB 0 | ||
132 | #define ADDR_GEN_256MB 1 | ||
133 | #define ADDR_GEN_512MB 2 | ||
134 | #define ADDR_GEN_1GB 3 | ||
135 | |||
136 | #define JB_NUM_DIMM_GROUPS 2 | ||
137 | #define JB_NUM_DIMMS_PER_GROUP 2 | ||
138 | #define JB_NUM_DIMMS (JB_NUM_DIMM_GROUPS * JB_NUM_DIMMS_PER_GROUP) | ||
139 | |||
140 | struct jbusmc_obp_map { | ||
141 | unsigned char dimm_map[18]; | ||
142 | unsigned char pin_map[144]; | ||
143 | }; | ||
144 | |||
145 | struct jbusmc_obp_mem_layout { | ||
146 | /* One max 8-byte string label per DIMM. Usually | ||
147 | * this matches the label on the motherboard where | ||
148 | * that DIMM resides. | ||
149 | */ | ||
150 | char dimm_labels[JB_NUM_DIMMS][DIMM_LABEL_SZ]; | ||
151 | |||
152 | /* If symmetric use map[0], else it is | ||
153 | * asymmetric and map[1] should be used. | ||
154 | */ | ||
155 | char symmetric; | ||
156 | |||
157 | struct jbusmc_obp_map map; | ||
158 | |||
159 | char _pad; | ||
160 | }; | ||
76 | 161 | ||
77 | u64 timing_control1; | 162 | struct jbusmc_dimm_group { |
78 | u64 timing_control2; | 163 | struct jbusmc *controller; |
79 | u64 timing_control3; | 164 | int index; |
80 | u64 timing_control4; | 165 | u64 base_addr; |
81 | u64 memaddr_control; | 166 | u64 size; |
167 | }; | ||
82 | 168 | ||
83 | struct bank_info logical_banks[CHMCTRL_NBANKS]; | 169 | struct jbusmc { |
170 | void __iomem *regs; | ||
171 | u64 mc_reg_1; | ||
172 | u32 portid; | ||
173 | struct jbusmc_obp_mem_layout layout; | ||
174 | int layout_len; | ||
175 | int num_dimm_groups; | ||
176 | struct jbusmc_dimm_group dimm_groups[JB_NUM_DIMM_GROUPS]; | ||
177 | struct list_head list; | ||
84 | }; | 178 | }; |
85 | 179 | ||
180 | static DEFINE_SPINLOCK(mctrl_list_lock); | ||
86 | static LIST_HEAD(mctrl_list); | 181 | static LIST_HEAD(mctrl_list); |
87 | 182 | ||
183 | static void mc_list_add(struct list_head *list) | ||
184 | { | ||
185 | spin_lock(&mctrl_list_lock); | ||
186 | list_add(list, &mctrl_list); | ||
187 | spin_unlock(&mctrl_list_lock); | ||
188 | } | ||
189 | |||
190 | static void mc_list_del(struct list_head *list) | ||
191 | { | ||
192 | spin_lock(&mctrl_list_lock); | ||
193 | list_del_init(list); | ||
194 | spin_unlock(&mctrl_list_lock); | ||
195 | } | ||
196 | |||
197 | #define SYNDROME_MIN -1 | ||
198 | #define SYNDROME_MAX 144 | ||
199 | |||
200 | /* Covert syndrome code into the way the bits are positioned | ||
201 | * on the bus. | ||
202 | */ | ||
203 | static int syndrome_to_qword_code(int syndrome_code) | ||
204 | { | ||
205 | if (syndrome_code < 128) | ||
206 | syndrome_code += 16; | ||
207 | else if (syndrome_code < 128 + 9) | ||
208 | syndrome_code -= (128 - 7); | ||
209 | else if (syndrome_code < (128 + 9 + 3)) | ||
210 | syndrome_code -= (128 + 9 - 4); | ||
211 | else | ||
212 | syndrome_code -= (128 + 9 + 3); | ||
213 | return syndrome_code; | ||
214 | } | ||
215 | |||
216 | /* All this magic has to do with how a cache line comes over the wire | ||
217 | * on Safari and JBUS. A 64-bit line comes over in 1 or more quadword | ||
218 | * cycles, each of which transmit ECC/MTAG info as well as the actual | ||
219 | * data. | ||
220 | */ | ||
221 | #define L2_LINE_SIZE 64 | ||
222 | #define L2_LINE_ADDR_MSK (L2_LINE_SIZE - 1) | ||
223 | #define QW_PER_LINE 4 | ||
224 | #define QW_BYTES (L2_LINE_SIZE / QW_PER_LINE) | ||
225 | #define QW_BITS 144 | ||
226 | #define SAFARI_LAST_BIT (576 - 1) | ||
227 | #define JBUS_LAST_BIT (144 - 1) | ||
228 | |||
229 | static void get_pin_and_dimm_str(int syndrome_code, unsigned long paddr, | ||
230 | int *pin_p, char **dimm_str_p, void *_prop, | ||
231 | int base_dimm_offset) | ||
232 | { | ||
233 | int qword_code = syndrome_to_qword_code(syndrome_code); | ||
234 | int cache_line_offset; | ||
235 | int offset_inverse; | ||
236 | int dimm_map_index; | ||
237 | int map_val; | ||
238 | |||
239 | if (mc_type == MC_TYPE_JBUS) { | ||
240 | struct jbusmc_obp_mem_layout *p = _prop; | ||
241 | |||
242 | /* JBUS */ | ||
243 | cache_line_offset = qword_code; | ||
244 | offset_inverse = (JBUS_LAST_BIT - cache_line_offset); | ||
245 | dimm_map_index = offset_inverse / 8; | ||
246 | map_val = p->map.dimm_map[dimm_map_index]; | ||
247 | map_val = ((map_val >> ((7 - (offset_inverse & 7)))) & 1); | ||
248 | *dimm_str_p = p->dimm_labels[base_dimm_offset + map_val]; | ||
249 | *pin_p = p->map.pin_map[cache_line_offset]; | ||
250 | } else { | ||
251 | struct chmc_obp_mem_layout *p = _prop; | ||
252 | struct chmc_obp_map *mp; | ||
253 | int qword; | ||
254 | |||
255 | /* Safari */ | ||
256 | if (p->symmetric) | ||
257 | mp = &p->map[0]; | ||
258 | else | ||
259 | mp = &p->map[1]; | ||
260 | |||
261 | qword = (paddr & L2_LINE_ADDR_MSK) / QW_BYTES; | ||
262 | cache_line_offset = ((3 - qword) * QW_BITS) + qword_code; | ||
263 | offset_inverse = (SAFARI_LAST_BIT - cache_line_offset); | ||
264 | dimm_map_index = offset_inverse >> 2; | ||
265 | map_val = mp->dimm_map[dimm_map_index]; | ||
266 | map_val = ((map_val >> ((3 - (offset_inverse & 3)) << 1)) & 0x3); | ||
267 | *dimm_str_p = p->dimm_labels[base_dimm_offset + map_val]; | ||
268 | *pin_p = mp->pin_map[cache_line_offset]; | ||
269 | } | ||
270 | } | ||
271 | |||
272 | static struct jbusmc_dimm_group *jbusmc_find_dimm_group(unsigned long phys_addr) | ||
273 | { | ||
274 | struct jbusmc *p; | ||
275 | |||
276 | list_for_each_entry(p, &mctrl_list, list) { | ||
277 | int i; | ||
278 | |||
279 | for (i = 0; i < p->num_dimm_groups; i++) { | ||
280 | struct jbusmc_dimm_group *dp = &p->dimm_groups[i]; | ||
281 | |||
282 | if (phys_addr < dp->base_addr || | ||
283 | (dp->base_addr + dp->size) <= phys_addr) | ||
284 | continue; | ||
285 | |||
286 | return dp; | ||
287 | } | ||
288 | } | ||
289 | return NULL; | ||
290 | } | ||
291 | |||
292 | static int jbusmc_print_dimm(int syndrome_code, | ||
293 | unsigned long phys_addr, | ||
294 | char *buf, int buflen) | ||
295 | { | ||
296 | struct jbusmc_obp_mem_layout *prop; | ||
297 | struct jbusmc_dimm_group *dp; | ||
298 | struct jbusmc *p; | ||
299 | int first_dimm; | ||
300 | |||
301 | dp = jbusmc_find_dimm_group(phys_addr); | ||
302 | if (dp == NULL || | ||
303 | syndrome_code < SYNDROME_MIN || | ||
304 | syndrome_code > SYNDROME_MAX) { | ||
305 | buf[0] = '?'; | ||
306 | buf[1] = '?'; | ||
307 | buf[2] = '?'; | ||
308 | buf[3] = '\0'; | ||
309 | } | ||
310 | p = dp->controller; | ||
311 | prop = &p->layout; | ||
312 | |||
313 | first_dimm = dp->index * JB_NUM_DIMMS_PER_GROUP; | ||
314 | |||
315 | if (syndrome_code != SYNDROME_MIN) { | ||
316 | char *dimm_str; | ||
317 | int pin; | ||
318 | |||
319 | get_pin_and_dimm_str(syndrome_code, phys_addr, &pin, | ||
320 | &dimm_str, prop, first_dimm); | ||
321 | sprintf(buf, "%s, pin %3d", dimm_str, pin); | ||
322 | } else { | ||
323 | int dimm; | ||
324 | |||
325 | /* Multi-bit error, we just dump out all the | ||
326 | * dimm labels associated with this dimm group. | ||
327 | */ | ||
328 | for (dimm = 0; dimm < JB_NUM_DIMMS_PER_GROUP; dimm++) { | ||
329 | sprintf(buf, "%s ", | ||
330 | prop->dimm_labels[first_dimm + dimm]); | ||
331 | buf += strlen(buf); | ||
332 | } | ||
333 | } | ||
334 | |||
335 | return 0; | ||
336 | } | ||
337 | |||
338 | static u64 __devinit jbusmc_dimm_group_size(u64 base, | ||
339 | const struct linux_prom64_registers *mem_regs, | ||
340 | int num_mem_regs) | ||
341 | { | ||
342 | u64 max = base + (8UL * 1024 * 1024 * 1024); | ||
343 | u64 max_seen = base; | ||
344 | int i; | ||
345 | |||
346 | for (i = 0; i < num_mem_regs; i++) { | ||
347 | const struct linux_prom64_registers *ent; | ||
348 | u64 this_base; | ||
349 | u64 this_end; | ||
350 | |||
351 | ent = &mem_regs[i]; | ||
352 | this_base = ent->phys_addr; | ||
353 | this_end = this_base + ent->reg_size; | ||
354 | if (base < this_base || base >= this_end) | ||
355 | continue; | ||
356 | if (this_end > max) | ||
357 | this_end = max; | ||
358 | if (this_end > max_seen) | ||
359 | max_seen = this_end; | ||
360 | } | ||
361 | |||
362 | return max_seen - base; | ||
363 | } | ||
364 | |||
365 | static void __devinit jbusmc_construct_one_dimm_group(struct jbusmc *p, | ||
366 | unsigned long index, | ||
367 | const struct linux_prom64_registers *mem_regs, | ||
368 | int num_mem_regs) | ||
369 | { | ||
370 | struct jbusmc_dimm_group *dp = &p->dimm_groups[index]; | ||
371 | |||
372 | dp->controller = p; | ||
373 | dp->index = index; | ||
374 | |||
375 | dp->base_addr = (p->portid * (64UL * 1024 * 1024 * 1024)); | ||
376 | dp->base_addr += (index * (8UL * 1024 * 1024 * 1024)); | ||
377 | dp->size = jbusmc_dimm_group_size(dp->base_addr, mem_regs, num_mem_regs); | ||
378 | } | ||
379 | |||
380 | static void __devinit jbusmc_construct_dimm_groups(struct jbusmc *p, | ||
381 | const struct linux_prom64_registers *mem_regs, | ||
382 | int num_mem_regs) | ||
383 | { | ||
384 | if (p->mc_reg_1 & JB_MC_REG1_DIMM1_BANK0) { | ||
385 | jbusmc_construct_one_dimm_group(p, 0, mem_regs, num_mem_regs); | ||
386 | p->num_dimm_groups++; | ||
387 | } | ||
388 | if (p->mc_reg_1 & JB_MC_REG1_DIMM2_BANK2) { | ||
389 | jbusmc_construct_one_dimm_group(p, 1, mem_regs, num_mem_regs); | ||
390 | p->num_dimm_groups++; | ||
391 | } | ||
392 | } | ||
393 | |||
394 | static int __devinit jbusmc_probe(struct of_device *op, | ||
395 | const struct of_device_id *match) | ||
396 | { | ||
397 | const struct linux_prom64_registers *mem_regs; | ||
398 | struct device_node *mem_node; | ||
399 | int err, len, num_mem_regs; | ||
400 | struct jbusmc *p; | ||
401 | const u32 *prop; | ||
402 | const void *ml; | ||
403 | |||
404 | err = -ENODEV; | ||
405 | mem_node = of_find_node_by_path("/memory"); | ||
406 | if (!mem_node) { | ||
407 | printk(KERN_ERR PFX "Cannot find /memory node.\n"); | ||
408 | goto out; | ||
409 | } | ||
410 | mem_regs = of_get_property(mem_node, "reg", &len); | ||
411 | if (!mem_regs) { | ||
412 | printk(KERN_ERR PFX "Cannot get reg property of /memory node.\n"); | ||
413 | goto out; | ||
414 | } | ||
415 | num_mem_regs = len / sizeof(*mem_regs); | ||
416 | |||
417 | err = -ENOMEM; | ||
418 | p = kzalloc(sizeof(*p), GFP_KERNEL); | ||
419 | if (!p) { | ||
420 | printk(KERN_ERR PFX "Cannot allocate struct jbusmc.\n"); | ||
421 | goto out; | ||
422 | } | ||
423 | |||
424 | INIT_LIST_HEAD(&p->list); | ||
425 | |||
426 | err = -ENODEV; | ||
427 | prop = of_get_property(op->node, "portid", &len); | ||
428 | if (!prop || len != 4) { | ||
429 | printk(KERN_ERR PFX "Cannot find portid.\n"); | ||
430 | goto out_free; | ||
431 | } | ||
432 | |||
433 | p->portid = *prop; | ||
434 | |||
435 | prop = of_get_property(op->node, "memory-control-register-1", &len); | ||
436 | if (!prop || len != 8) { | ||
437 | printk(KERN_ERR PFX "Cannot get memory control register 1.\n"); | ||
438 | goto out_free; | ||
439 | } | ||
440 | |||
441 | p->mc_reg_1 = ((u64)prop[0] << 32) | (u64) prop[1]; | ||
442 | |||
443 | err = -ENOMEM; | ||
444 | p->regs = of_ioremap(&op->resource[0], 0, JBUSMC_REGS_SIZE, "jbusmc"); | ||
445 | if (!p->regs) { | ||
446 | printk(KERN_ERR PFX "Cannot map jbusmc regs.\n"); | ||
447 | goto out_free; | ||
448 | } | ||
449 | |||
450 | err = -ENODEV; | ||
451 | ml = of_get_property(op->node, "memory-layout", &p->layout_len); | ||
452 | if (!ml) { | ||
453 | printk(KERN_ERR PFX "Cannot get memory layout property.\n"); | ||
454 | goto out_iounmap; | ||
455 | } | ||
456 | if (p->layout_len > sizeof(p->layout)) { | ||
457 | printk(KERN_ERR PFX "Unexpected memory-layout size %d\n", | ||
458 | p->layout_len); | ||
459 | goto out_iounmap; | ||
460 | } | ||
461 | memcpy(&p->layout, ml, p->layout_len); | ||
462 | |||
463 | jbusmc_construct_dimm_groups(p, mem_regs, num_mem_regs); | ||
464 | |||
465 | mc_list_add(&p->list); | ||
466 | |||
467 | printk(KERN_INFO PFX "UltraSPARC-IIIi memory controller at %s\n", | ||
468 | op->node->full_name); | ||
469 | |||
470 | dev_set_drvdata(&op->dev, p); | ||
471 | |||
472 | err = 0; | ||
473 | |||
474 | out: | ||
475 | return err; | ||
476 | |||
477 | out_iounmap: | ||
478 | of_iounmap(&op->resource[0], p->regs, JBUSMC_REGS_SIZE); | ||
479 | |||
480 | out_free: | ||
481 | kfree(p); | ||
482 | goto out; | ||
483 | } | ||
484 | |||
88 | /* Does BANK decode PHYS_ADDR? */ | 485 | /* Does BANK decode PHYS_ADDR? */ |
89 | static int bank_match(struct bank_info *bp, unsigned long phys_addr) | 486 | static int chmc_bank_match(struct chmc_bank_info *bp, unsigned long phys_addr) |
90 | { | 487 | { |
91 | unsigned long upper_bits = (phys_addr & PA_UPPER_BITS) >> PA_UPPER_BITS_SHIFT; | 488 | unsigned long upper_bits = (phys_addr & PA_UPPER_BITS) >> PA_UPPER_BITS_SHIFT; |
92 | unsigned long lower_bits = (phys_addr & PA_LOWER_BITS) >> PA_LOWER_BITS_SHIFT; | 489 | unsigned long lower_bits = (phys_addr & PA_LOWER_BITS) >> PA_LOWER_BITS_SHIFT; |
@@ -118,25 +515,18 @@ static int bank_match(struct bank_info *bp, unsigned long phys_addr) | |||
118 | } | 515 | } |
119 | 516 | ||
120 | /* Given PHYS_ADDR, search memory controller banks for a match. */ | 517 | /* Given PHYS_ADDR, search memory controller banks for a match. */ |
121 | static struct bank_info *find_bank(unsigned long phys_addr) | 518 | static struct chmc_bank_info *chmc_find_bank(unsigned long phys_addr) |
122 | { | 519 | { |
123 | struct list_head *mctrl_head = &mctrl_list; | 520 | struct chmc *p; |
124 | struct list_head *mctrl_entry = mctrl_head->next; | ||
125 | 521 | ||
126 | for (;;) { | 522 | list_for_each_entry(p, &mctrl_list, list) { |
127 | struct mctrl_info *mp = | ||
128 | list_entry(mctrl_entry, struct mctrl_info, list); | ||
129 | int bank_no; | 523 | int bank_no; |
130 | 524 | ||
131 | if (mctrl_entry == mctrl_head) | ||
132 | break; | ||
133 | mctrl_entry = mctrl_entry->next; | ||
134 | |||
135 | for (bank_no = 0; bank_no < CHMCTRL_NBANKS; bank_no++) { | 525 | for (bank_no = 0; bank_no < CHMCTRL_NBANKS; bank_no++) { |
136 | struct bank_info *bp; | 526 | struct chmc_bank_info *bp; |
137 | 527 | ||
138 | bp = &mp->logical_banks[bank_no]; | 528 | bp = &p->logical_banks[bank_no]; |
139 | if (bank_match(bp, phys_addr)) | 529 | if (chmc_bank_match(bp, phys_addr)) |
140 | return bp; | 530 | return bp; |
141 | } | 531 | } |
142 | } | 532 | } |
@@ -145,17 +535,15 @@ static struct bank_info *find_bank(unsigned long phys_addr) | |||
145 | } | 535 | } |
146 | 536 | ||
147 | /* This is the main purpose of this driver. */ | 537 | /* This is the main purpose of this driver. */ |
148 | #define SYNDROME_MIN -1 | 538 | static int chmc_print_dimm(int syndrome_code, |
149 | #define SYNDROME_MAX 144 | 539 | unsigned long phys_addr, |
150 | int chmc_getunumber(int syndrome_code, | 540 | char *buf, int buflen) |
151 | unsigned long phys_addr, | ||
152 | char *buf, int buflen) | ||
153 | { | 541 | { |
154 | struct bank_info *bp; | 542 | struct chmc_bank_info *bp; |
155 | struct obp_mem_layout *prop; | 543 | struct chmc_obp_mem_layout *prop; |
156 | int bank_in_controller, first_dimm; | 544 | int bank_in_controller, first_dimm; |
157 | 545 | ||
158 | bp = find_bank(phys_addr); | 546 | bp = chmc_find_bank(phys_addr); |
159 | if (bp == NULL || | 547 | if (bp == NULL || |
160 | syndrome_code < SYNDROME_MIN || | 548 | syndrome_code < SYNDROME_MIN || |
161 | syndrome_code > SYNDROME_MAX) { | 549 | syndrome_code > SYNDROME_MAX) { |
@@ -166,60 +554,18 @@ int chmc_getunumber(int syndrome_code, | |||
166 | return 0; | 554 | return 0; |
167 | } | 555 | } |
168 | 556 | ||
169 | prop = &bp->mp->layout_prop; | 557 | prop = &bp->p->layout_prop; |
170 | bank_in_controller = bp->bank_id & (CHMCTRL_NBANKS - 1); | 558 | bank_in_controller = bp->bank_id & (CHMCTRL_NBANKS - 1); |
171 | first_dimm = (bank_in_controller & (CHMCTRL_NDGRPS - 1)); | 559 | first_dimm = (bank_in_controller & (CHMCTRL_NDGRPS - 1)); |
172 | first_dimm *= CHMCTRL_NDIMMS; | 560 | first_dimm *= CHMCTRL_NDIMMS; |
173 | 561 | ||
174 | if (syndrome_code != SYNDROME_MIN) { | 562 | if (syndrome_code != SYNDROME_MIN) { |
175 | struct obp_map *map; | 563 | char *dimm_str; |
176 | int qword, where_in_line, where, map_index, map_offset; | 564 | int pin; |
177 | unsigned int map_val; | ||
178 | 565 | ||
179 | /* Yaay, single bit error so we can figure out | 566 | get_pin_and_dimm_str(syndrome_code, phys_addr, &pin, |
180 | * the exact dimm. | 567 | &dimm_str, prop, first_dimm); |
181 | */ | 568 | sprintf(buf, "%s, pin %3d", dimm_str, pin); |
182 | if (prop->symmetric) | ||
183 | map = &prop->map[0]; | ||
184 | else | ||
185 | map = &prop->map[1]; | ||
186 | |||
187 | /* Covert syndrome code into the way the bits are | ||
188 | * positioned on the bus. | ||
189 | */ | ||
190 | if (syndrome_code < 144 - 16) | ||
191 | syndrome_code += 16; | ||
192 | else if (syndrome_code < 144) | ||
193 | syndrome_code -= (144 - 7); | ||
194 | else if (syndrome_code < (144 + 3)) | ||
195 | syndrome_code -= (144 + 3 - 4); | ||
196 | else | ||
197 | syndrome_code -= 144 + 3; | ||
198 | |||
199 | /* All this magic has to do with how a cache line | ||
200 | * comes over the wire on Safari. A 64-bit line | ||
201 | * comes over in 4 quadword cycles, each of which | ||
202 | * transmit ECC/MTAG info as well as the actual | ||
203 | * data. 144 bits per quadword, 576 total. | ||
204 | */ | ||
205 | #define LINE_SIZE 64 | ||
206 | #define LINE_ADDR_MSK (LINE_SIZE - 1) | ||
207 | #define QW_PER_LINE 4 | ||
208 | #define QW_BYTES (LINE_SIZE / QW_PER_LINE) | ||
209 | #define QW_BITS 144 | ||
210 | #define LAST_BIT (576 - 1) | ||
211 | |||
212 | qword = (phys_addr & LINE_ADDR_MSK) / QW_BYTES; | ||
213 | where_in_line = ((3 - qword) * QW_BITS) + syndrome_code; | ||
214 | where = (LAST_BIT - where_in_line); | ||
215 | map_index = where >> 2; | ||
216 | map_offset = where & 0x3; | ||
217 | map_val = map->dimm_map[map_index]; | ||
218 | map_val = ((map_val >> ((3 - map_offset) << 1)) & (2 - 1)); | ||
219 | |||
220 | sprintf(buf, "%s, pin %3d", | ||
221 | prop->dimm_labels[first_dimm + map_val], | ||
222 | map->pin_map[where_in_line]); | ||
223 | } else { | 569 | } else { |
224 | int dimm; | 570 | int dimm; |
225 | 571 | ||
@@ -240,7 +586,7 @@ int chmc_getunumber(int syndrome_code, | |||
240 | * the code is executing, you must use special ASI load/store else | 586 | * the code is executing, you must use special ASI load/store else |
241 | * you go through the global mapping. | 587 | * you go through the global mapping. |
242 | */ | 588 | */ |
243 | static u64 read_mcreg(struct mctrl_info *mp, unsigned long offset) | 589 | static u64 chmc_read_mcreg(struct chmc *p, unsigned long offset) |
244 | { | 590 | { |
245 | unsigned long ret, this_cpu; | 591 | unsigned long ret, this_cpu; |
246 | 592 | ||
@@ -248,14 +594,14 @@ static u64 read_mcreg(struct mctrl_info *mp, unsigned long offset) | |||
248 | 594 | ||
249 | this_cpu = real_hard_smp_processor_id(); | 595 | this_cpu = real_hard_smp_processor_id(); |
250 | 596 | ||
251 | if (mp->portid == this_cpu) { | 597 | if (p->portid == this_cpu) { |
252 | __asm__ __volatile__("ldxa [%1] %2, %0" | 598 | __asm__ __volatile__("ldxa [%1] %2, %0" |
253 | : "=r" (ret) | 599 | : "=r" (ret) |
254 | : "r" (offset), "i" (ASI_MCU_CTRL_REG)); | 600 | : "r" (offset), "i" (ASI_MCU_CTRL_REG)); |
255 | } else { | 601 | } else { |
256 | __asm__ __volatile__("ldxa [%1] %2, %0" | 602 | __asm__ __volatile__("ldxa [%1] %2, %0" |
257 | : "=r" (ret) | 603 | : "=r" (ret) |
258 | : "r" (mp->regs + offset), | 604 | : "r" (p->regs + offset), |
259 | "i" (ASI_PHYS_BYPASS_EC_E)); | 605 | "i" (ASI_PHYS_BYPASS_EC_E)); |
260 | } | 606 | } |
261 | 607 | ||
@@ -265,178 +611,253 @@ static u64 read_mcreg(struct mctrl_info *mp, unsigned long offset) | |||
265 | } | 611 | } |
266 | 612 | ||
267 | #if 0 /* currently unused */ | 613 | #if 0 /* currently unused */ |
268 | static void write_mcreg(struct mctrl_info *mp, unsigned long offset, u64 val) | 614 | static void chmc_write_mcreg(struct chmc *p, unsigned long offset, u64 val) |
269 | { | 615 | { |
270 | if (mp->portid == smp_processor_id()) { | 616 | if (p->portid == smp_processor_id()) { |
271 | __asm__ __volatile__("stxa %0, [%1] %2" | 617 | __asm__ __volatile__("stxa %0, [%1] %2" |
272 | : : "r" (val), | 618 | : : "r" (val), |
273 | "r" (offset), "i" (ASI_MCU_CTRL_REG)); | 619 | "r" (offset), "i" (ASI_MCU_CTRL_REG)); |
274 | } else { | 620 | } else { |
275 | __asm__ __volatile__("ldxa %0, [%1] %2" | 621 | __asm__ __volatile__("ldxa %0, [%1] %2" |
276 | : : "r" (val), | 622 | : : "r" (val), |
277 | "r" (mp->regs + offset), | 623 | "r" (p->regs + offset), |
278 | "i" (ASI_PHYS_BYPASS_EC_E)); | 624 | "i" (ASI_PHYS_BYPASS_EC_E)); |
279 | } | 625 | } |
280 | } | 626 | } |
281 | #endif | 627 | #endif |
282 | 628 | ||
283 | static void interpret_one_decode_reg(struct mctrl_info *mp, int which_bank, u64 val) | 629 | static void chmc_interpret_one_decode_reg(struct chmc *p, int which_bank, u64 val) |
284 | { | 630 | { |
285 | struct bank_info *p = &mp->logical_banks[which_bank]; | 631 | struct chmc_bank_info *bp = &p->logical_banks[which_bank]; |
286 | 632 | ||
287 | p->mp = mp; | 633 | bp->p = p; |
288 | p->bank_id = (CHMCTRL_NBANKS * mp->portid) + which_bank; | 634 | bp->bank_id = (CHMCTRL_NBANKS * p->portid) + which_bank; |
289 | p->raw_reg = val; | 635 | bp->raw_reg = val; |
290 | p->valid = (val & MEM_DECODE_VALID) >> MEM_DECODE_VALID_SHIFT; | 636 | bp->valid = (val & MEM_DECODE_VALID) >> MEM_DECODE_VALID_SHIFT; |
291 | p->uk = (val & MEM_DECODE_UK) >> MEM_DECODE_UK_SHIFT; | 637 | bp->uk = (val & MEM_DECODE_UK) >> MEM_DECODE_UK_SHIFT; |
292 | p->um = (val & MEM_DECODE_UM) >> MEM_DECODE_UM_SHIFT; | 638 | bp->um = (val & MEM_DECODE_UM) >> MEM_DECODE_UM_SHIFT; |
293 | p->lk = (val & MEM_DECODE_LK) >> MEM_DECODE_LK_SHIFT; | 639 | bp->lk = (val & MEM_DECODE_LK) >> MEM_DECODE_LK_SHIFT; |
294 | p->lm = (val & MEM_DECODE_LM) >> MEM_DECODE_LM_SHIFT; | 640 | bp->lm = (val & MEM_DECODE_LM) >> MEM_DECODE_LM_SHIFT; |
295 | 641 | ||
296 | p->base = (p->um); | 642 | bp->base = (bp->um); |
297 | p->base &= ~(p->uk); | 643 | bp->base &= ~(bp->uk); |
298 | p->base <<= PA_UPPER_BITS_SHIFT; | 644 | bp->base <<= PA_UPPER_BITS_SHIFT; |
299 | 645 | ||
300 | switch(p->lk) { | 646 | switch(bp->lk) { |
301 | case 0xf: | 647 | case 0xf: |
302 | default: | 648 | default: |
303 | p->interleave = 1; | 649 | bp->interleave = 1; |
304 | break; | 650 | break; |
305 | 651 | ||
306 | case 0xe: | 652 | case 0xe: |
307 | p->interleave = 2; | 653 | bp->interleave = 2; |
308 | break; | 654 | break; |
309 | 655 | ||
310 | case 0xc: | 656 | case 0xc: |
311 | p->interleave = 4; | 657 | bp->interleave = 4; |
312 | break; | 658 | break; |
313 | 659 | ||
314 | case 0x8: | 660 | case 0x8: |
315 | p->interleave = 8; | 661 | bp->interleave = 8; |
316 | break; | 662 | break; |
317 | 663 | ||
318 | case 0x0: | 664 | case 0x0: |
319 | p->interleave = 16; | 665 | bp->interleave = 16; |
320 | break; | 666 | break; |
321 | }; | 667 | }; |
322 | 668 | ||
323 | /* UK[10] is reserved, and UK[11] is not set for the SDRAM | 669 | /* UK[10] is reserved, and UK[11] is not set for the SDRAM |
324 | * bank size definition. | 670 | * bank size definition. |
325 | */ | 671 | */ |
326 | p->size = (((unsigned long)p->uk & | 672 | bp->size = (((unsigned long)bp->uk & |
327 | ((1UL << 10UL) - 1UL)) + 1UL) << PA_UPPER_BITS_SHIFT; | 673 | ((1UL << 10UL) - 1UL)) + 1UL) << PA_UPPER_BITS_SHIFT; |
328 | p->size /= p->interleave; | 674 | bp->size /= bp->interleave; |
329 | } | 675 | } |
330 | 676 | ||
331 | static void fetch_decode_regs(struct mctrl_info *mp) | 677 | static void chmc_fetch_decode_regs(struct chmc *p) |
332 | { | 678 | { |
333 | if (mp->layout_size == 0) | 679 | if (p->layout_size == 0) |
334 | return; | 680 | return; |
335 | 681 | ||
336 | interpret_one_decode_reg(mp, 0, | 682 | chmc_interpret_one_decode_reg(p, 0, |
337 | read_mcreg(mp, CHMCTRL_DECODE1)); | 683 | chmc_read_mcreg(p, CHMCTRL_DECODE1)); |
338 | interpret_one_decode_reg(mp, 1, | 684 | chmc_interpret_one_decode_reg(p, 1, |
339 | read_mcreg(mp, CHMCTRL_DECODE2)); | 685 | chmc_read_mcreg(p, CHMCTRL_DECODE2)); |
340 | interpret_one_decode_reg(mp, 2, | 686 | chmc_interpret_one_decode_reg(p, 2, |
341 | read_mcreg(mp, CHMCTRL_DECODE3)); | 687 | chmc_read_mcreg(p, CHMCTRL_DECODE3)); |
342 | interpret_one_decode_reg(mp, 3, | 688 | chmc_interpret_one_decode_reg(p, 3, |
343 | read_mcreg(mp, CHMCTRL_DECODE4)); | 689 | chmc_read_mcreg(p, CHMCTRL_DECODE4)); |
344 | } | 690 | } |
345 | 691 | ||
346 | static int init_one_mctrl(struct device_node *dp) | 692 | static int __devinit chmc_probe(struct of_device *op, |
693 | const struct of_device_id *match) | ||
347 | { | 694 | { |
348 | struct mctrl_info *mp = kzalloc(sizeof(*mp), GFP_KERNEL); | 695 | struct device_node *dp = op->node; |
349 | int portid = of_getintprop_default(dp, "portid", -1); | 696 | unsigned long ver; |
350 | const struct linux_prom64_registers *regs; | ||
351 | const void *pval; | 697 | const void *pval; |
352 | int len; | 698 | int len, portid; |
699 | struct chmc *p; | ||
700 | int err; | ||
701 | |||
702 | err = -ENODEV; | ||
703 | __asm__ ("rdpr %%ver, %0" : "=r" (ver)); | ||
704 | if ((ver >> 32UL) == __JALAPENO_ID || | ||
705 | (ver >> 32UL) == __SERRANO_ID) | ||
706 | goto out; | ||
353 | 707 | ||
354 | if (!mp) | 708 | portid = of_getintprop_default(dp, "portid", -1); |
355 | return -1; | ||
356 | if (portid == -1) | 709 | if (portid == -1) |
357 | goto fail; | 710 | goto out; |
358 | 711 | ||
359 | mp->portid = portid; | ||
360 | pval = of_get_property(dp, "memory-layout", &len); | 712 | pval = of_get_property(dp, "memory-layout", &len); |
361 | mp->layout_size = len; | 713 | if (pval && len > sizeof(p->layout_prop)) { |
362 | if (!pval) | 714 | printk(KERN_ERR PFX "Unexpected memory-layout property " |
363 | mp->layout_size = 0; | 715 | "size %d.\n", len); |
364 | else { | 716 | goto out; |
365 | if (mp->layout_size > sizeof(mp->layout_prop)) | ||
366 | goto fail; | ||
367 | memcpy(&mp->layout_prop, pval, len); | ||
368 | } | 717 | } |
369 | 718 | ||
370 | regs = of_get_property(dp, "reg", NULL); | 719 | err = -ENOMEM; |
371 | if (!regs || regs->reg_size != 0x48) | 720 | p = kzalloc(sizeof(*p), GFP_KERNEL); |
372 | goto fail; | 721 | if (!p) { |
722 | printk(KERN_ERR PFX "Could not allocate struct chmc.\n"); | ||
723 | goto out; | ||
724 | } | ||
373 | 725 | ||
374 | mp->regs = ioremap(regs->phys_addr, regs->reg_size); | 726 | p->portid = portid; |
375 | if (mp->regs == NULL) | 727 | p->layout_size = len; |
376 | goto fail; | 728 | if (!pval) |
729 | p->layout_size = 0; | ||
730 | else | ||
731 | memcpy(&p->layout_prop, pval, len); | ||
732 | |||
733 | p->regs = of_ioremap(&op->resource[0], 0, 0x48, "chmc"); | ||
734 | if (!p->regs) { | ||
735 | printk(KERN_ERR PFX "Could not map registers.\n"); | ||
736 | goto out_free; | ||
737 | } | ||
377 | 738 | ||
378 | if (mp->layout_size != 0UL) { | 739 | if (p->layout_size != 0UL) { |
379 | mp->timing_control1 = read_mcreg(mp, CHMCTRL_TCTRL1); | 740 | p->timing_control1 = chmc_read_mcreg(p, CHMCTRL_TCTRL1); |
380 | mp->timing_control2 = read_mcreg(mp, CHMCTRL_TCTRL2); | 741 | p->timing_control2 = chmc_read_mcreg(p, CHMCTRL_TCTRL2); |
381 | mp->timing_control3 = read_mcreg(mp, CHMCTRL_TCTRL3); | 742 | p->timing_control3 = chmc_read_mcreg(p, CHMCTRL_TCTRL3); |
382 | mp->timing_control4 = read_mcreg(mp, CHMCTRL_TCTRL4); | 743 | p->timing_control4 = chmc_read_mcreg(p, CHMCTRL_TCTRL4); |
383 | mp->memaddr_control = read_mcreg(mp, CHMCTRL_MACTRL); | 744 | p->memaddr_control = chmc_read_mcreg(p, CHMCTRL_MACTRL); |
384 | } | 745 | } |
385 | 746 | ||
386 | fetch_decode_regs(mp); | 747 | chmc_fetch_decode_regs(p); |
387 | 748 | ||
388 | list_add(&mp->list, &mctrl_list); | 749 | mc_list_add(&p->list); |
389 | 750 | ||
390 | /* Report the device. */ | 751 | printk(KERN_INFO PFX "UltraSPARC-III memory controller at %s [%s]\n", |
391 | printk(KERN_INFO "%s: US3 memory controller at %p [%s]\n", | ||
392 | dp->full_name, | 752 | dp->full_name, |
393 | mp->regs, (mp->layout_size ? "ACTIVE" : "INACTIVE")); | 753 | (p->layout_size ? "ACTIVE" : "INACTIVE")); |
394 | 754 | ||
395 | return 0; | 755 | dev_set_drvdata(&op->dev, p); |
756 | |||
757 | err = 0; | ||
758 | |||
759 | out: | ||
760 | return err; | ||
761 | |||
762 | out_free: | ||
763 | kfree(p); | ||
764 | goto out; | ||
765 | } | ||
396 | 766 | ||
397 | fail: | 767 | static int __devinit us3mc_probe(struct of_device *op, |
398 | if (mp) { | 768 | const struct of_device_id *match) |
399 | if (mp->regs != NULL) | 769 | { |
400 | iounmap(mp->regs); | 770 | if (mc_type == MC_TYPE_SAFARI) |
401 | kfree(mp); | 771 | return chmc_probe(op, match); |
772 | else if (mc_type == MC_TYPE_JBUS) | ||
773 | return jbusmc_probe(op, match); | ||
774 | return -ENODEV; | ||
775 | } | ||
776 | |||
777 | static void __devexit chmc_destroy(struct of_device *op, struct chmc *p) | ||
778 | { | ||
779 | list_del(&p->list); | ||
780 | of_iounmap(&op->resource[0], p->regs, 0x48); | ||
781 | kfree(p); | ||
782 | } | ||
783 | |||
784 | static void __devexit jbusmc_destroy(struct of_device *op, struct jbusmc *p) | ||
785 | { | ||
786 | mc_list_del(&p->list); | ||
787 | of_iounmap(&op->resource[0], p->regs, JBUSMC_REGS_SIZE); | ||
788 | kfree(p); | ||
789 | } | ||
790 | |||
791 | static int __devexit us3mc_remove(struct of_device *op) | ||
792 | { | ||
793 | void *p = dev_get_drvdata(&op->dev); | ||
794 | |||
795 | if (p) { | ||
796 | if (mc_type == MC_TYPE_SAFARI) | ||
797 | chmc_destroy(op, p); | ||
798 | else if (mc_type == MC_TYPE_JBUS) | ||
799 | jbusmc_destroy(op, p); | ||
402 | } | 800 | } |
403 | return -1; | 801 | return 0; |
802 | } | ||
803 | |||
804 | static const struct of_device_id us3mc_match[] = { | ||
805 | { | ||
806 | .name = "memory-controller", | ||
807 | }, | ||
808 | {}, | ||
809 | }; | ||
810 | MODULE_DEVICE_TABLE(of, us3mc_match); | ||
811 | |||
812 | static struct of_platform_driver us3mc_driver = { | ||
813 | .name = "us3mc", | ||
814 | .match_table = us3mc_match, | ||
815 | .probe = us3mc_probe, | ||
816 | .remove = __devexit_p(us3mc_remove), | ||
817 | }; | ||
818 | |||
819 | static inline bool us3mc_platform(void) | ||
820 | { | ||
821 | if (tlb_type == cheetah || tlb_type == cheetah_plus) | ||
822 | return true; | ||
823 | return false; | ||
404 | } | 824 | } |
405 | 825 | ||
406 | static int __init chmc_init(void) | 826 | static int __init us3mc_init(void) |
407 | { | 827 | { |
408 | struct device_node *dp; | 828 | unsigned long ver; |
829 | int ret; | ||
409 | 830 | ||
410 | /* This driver is only for cheetah platforms. */ | 831 | if (!us3mc_platform()) |
411 | if (tlb_type != cheetah && tlb_type != cheetah_plus) | ||
412 | return -ENODEV; | 832 | return -ENODEV; |
413 | 833 | ||
414 | for_each_node_by_name(dp, "memory-controller") | 834 | __asm__ ("rdpr %%ver, %0" : "=r" (ver)); |
415 | init_one_mctrl(dp); | 835 | if ((ver >> 32UL) == __JALAPENO_ID || |
836 | (ver >> 32UL) == __SERRANO_ID) { | ||
837 | mc_type = MC_TYPE_JBUS; | ||
838 | us3mc_dimm_printer = jbusmc_print_dimm; | ||
839 | } else { | ||
840 | mc_type = MC_TYPE_SAFARI; | ||
841 | us3mc_dimm_printer = chmc_print_dimm; | ||
842 | } | ||
416 | 843 | ||
417 | for_each_node_by_name(dp, "mc-us3") | 844 | ret = register_dimm_printer(us3mc_dimm_printer); |
418 | init_one_mctrl(dp); | ||
419 | 845 | ||
420 | return 0; | 846 | if (!ret) { |
847 | ret = of_register_driver(&us3mc_driver, &of_bus_type); | ||
848 | if (ret) | ||
849 | unregister_dimm_printer(us3mc_dimm_printer); | ||
850 | } | ||
851 | return ret; | ||
421 | } | 852 | } |
422 | 853 | ||
423 | static void __exit chmc_cleanup(void) | 854 | static void __exit us3mc_cleanup(void) |
424 | { | 855 | { |
425 | struct list_head *head = &mctrl_list; | 856 | if (us3mc_platform()) { |
426 | struct list_head *tmp = head->next; | 857 | unregister_dimm_printer(us3mc_dimm_printer); |
427 | 858 | of_unregister_driver(&us3mc_driver); | |
428 | for (;;) { | ||
429 | struct mctrl_info *p = | ||
430 | list_entry(tmp, struct mctrl_info, list); | ||
431 | if (tmp == head) | ||
432 | break; | ||
433 | tmp = tmp->next; | ||
434 | |||
435 | list_del(&p->list); | ||
436 | iounmap(p->regs); | ||
437 | kfree(p); | ||
438 | } | 859 | } |
439 | } | 860 | } |
440 | 861 | ||
441 | module_init(chmc_init); | 862 | module_init(us3mc_init); |
442 | module_exit(chmc_cleanup); | 863 | module_exit(us3mc_cleanup); |