]>
Commit | Line | Data |
---|---|---|
a3a0f8c8 DV |
1 | /* |
2 | * ASIC Device List Intialization | |
3 | * | |
4 | * Description: Defines the platform resources for the SA settop. | |
5 | * | |
6 | * Copyright (C) 2005-2009 Scientific-Atlanta, Inc. | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
21 | * | |
22 | * Author: Ken Eppinett | |
23 | * David Schleef <ds@schleef.org> | |
24 | * | |
25 | * Description: Defines the platform resources for the SA settop. | |
26 | * | |
27 | * NOTE: The bootloader allocates persistent memory at an address which is | |
28 | * 16 MiB below the end of the highest address in KSEG0. All fixed | |
29 | * address memory reservations must avoid this region. | |
30 | */ | |
31 | ||
32 | #include <linux/device.h> | |
33 | #include <linux/kernel.h> | |
34 | #include <linux/init.h> | |
35 | #include <linux/resource.h> | |
36 | #include <linux/serial_reg.h> | |
37 | #include <linux/io.h> | |
38 | #include <linux/bootmem.h> | |
39 | #include <linux/mm.h> | |
40 | #include <linux/platform_device.h> | |
41 | #include <linux/module.h> | |
5a0e3ad6 | 42 | #include <linux/gfp.h> |
a3a0f8c8 DV |
43 | #include <asm/page.h> |
44 | #include <linux/swap.h> | |
45 | #include <linux/highmem.h> | |
46 | #include <linux/dma-mapping.h> | |
47 | ||
48 | #include <asm/mach-powertv/asic.h> | |
49 | #include <asm/mach-powertv/asic_regs.h> | |
50 | #include <asm/mach-powertv/interrupts.h> | |
51 | ||
52 | #ifdef CONFIG_BOOTLOADER_DRIVER | |
53 | #include <asm/mach-powertv/kbldr.h> | |
54 | #endif | |
55 | #include <asm/bootinfo.h> | |
56 | ||
57 | #define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0)) | |
58 | ||
59 | /* | |
60 | * Forward Prototypes | |
61 | */ | |
62 | static void pmem_setup_resource(void); | |
63 | ||
64 | /* | |
65 | * Global Variables | |
66 | */ | |
67 | enum asic_type asic; | |
68 | ||
69 | unsigned int platform_features; | |
70 | unsigned int platform_family; | |
59dfa2fc DV |
71 | struct register_map _asic_register_map; |
72 | EXPORT_SYMBOL(_asic_register_map); /* Exported for testing */ | |
a3a0f8c8 DV |
73 | unsigned long asic_phy_base; |
74 | unsigned long asic_base; | |
75 | EXPORT_SYMBOL(asic_base); /* Exported for testing */ | |
76 | struct resource *gp_resources; | |
77 | static bool usb_configured; | |
78 | ||
79 | /* | |
80 | * Don't recommend to use it directly, it is usually used by kernel internally. | |
81 | * Portable code should be using interfaces such as ioremp, dma_map_single, etc. | |
82 | */ | |
ca36c36b DV |
83 | unsigned long phys_to_dma_offset; |
84 | EXPORT_SYMBOL(phys_to_dma_offset); | |
a3a0f8c8 DV |
85 | |
86 | /* | |
87 | * | |
88 | * IO Resource Definition | |
89 | * | |
90 | */ | |
91 | ||
92 | struct resource asic_resource = { | |
93 | .name = "ASIC Resource", | |
94 | .start = 0, | |
95 | .end = ASIC_IO_SIZE, | |
96 | .flags = IORESOURCE_MEM, | |
97 | }; | |
98 | ||
99 | /* | |
100 | * | |
101 | * USB Host Resource Definition | |
102 | * | |
103 | */ | |
104 | ||
105 | static struct resource ehci_resources[] = { | |
106 | { | |
107 | .parent = &asic_resource, | |
108 | .start = 0, | |
109 | .end = 0xff, | |
110 | .flags = IORESOURCE_MEM, | |
111 | }, | |
112 | { | |
113 | .start = irq_usbehci, | |
114 | .end = irq_usbehci, | |
115 | .flags = IORESOURCE_IRQ, | |
116 | }, | |
117 | }; | |
118 | ||
119 | static u64 ehci_dmamask = DMA_BIT_MASK(32); | |
120 | ||
121 | static struct platform_device ehci_device = { | |
122 | .name = "powertv-ehci", | |
123 | .id = 0, | |
124 | .num_resources = 2, | |
125 | .resource = ehci_resources, | |
126 | .dev = { | |
127 | .dma_mask = &ehci_dmamask, | |
128 | .coherent_dma_mask = DMA_BIT_MASK(32), | |
129 | }, | |
130 | }; | |
131 | ||
132 | static struct resource ohci_resources[] = { | |
133 | { | |
134 | .parent = &asic_resource, | |
135 | .start = 0, | |
136 | .end = 0xff, | |
137 | .flags = IORESOURCE_MEM, | |
138 | }, | |
139 | { | |
140 | .start = irq_usbohci, | |
141 | .end = irq_usbohci, | |
142 | .flags = IORESOURCE_IRQ, | |
143 | }, | |
144 | }; | |
145 | ||
146 | static u64 ohci_dmamask = DMA_BIT_MASK(32); | |
147 | ||
148 | static struct platform_device ohci_device = { | |
149 | .name = "powertv-ohci", | |
150 | .id = 0, | |
151 | .num_resources = 2, | |
152 | .resource = ohci_resources, | |
153 | .dev = { | |
154 | .dma_mask = &ohci_dmamask, | |
155 | .coherent_dma_mask = DMA_BIT_MASK(32), | |
156 | }, | |
157 | }; | |
158 | ||
159 | static struct platform_device *platform_devices[] = { | |
160 | &ehci_device, | |
161 | &ohci_device, | |
162 | }; | |
163 | ||
164 | /* | |
165 | * | |
166 | * Platform Configuration and Device Initialization | |
167 | * | |
168 | */ | |
169 | static void __init fs_update(int pe, int md, int sdiv, int disable_div_by_3) | |
170 | { | |
171 | int en_prg, byp, pwr, nsb, val; | |
172 | int sout; | |
173 | ||
174 | sout = 1; | |
175 | en_prg = 1; | |
176 | byp = 0; | |
177 | nsb = 1; | |
178 | pwr = 1; | |
179 | ||
180 | val = ((sdiv << 29) | (md << 24) | (pe<<8) | (sout<<3) | (byp<<2) | | |
181 | (nsb<<1) | (disable_div_by_3<<5)); | |
182 | ||
183 | asic_write(val, usb_fs); | |
184 | asic_write(val | (en_prg<<4), usb_fs); | |
185 | asic_write(val | (en_prg<<4) | pwr, usb_fs); | |
186 | } | |
187 | ||
188 | /* | |
189 | * Allow override of bootloader-specified model | |
190 | */ | |
191 | static char __initdata cmdline[COMMAND_LINE_SIZE]; | |
192 | ||
193 | #define FORCEFAMILY_PARAM "forcefamily" | |
194 | ||
195 | static __init int check_forcefamily(unsigned char forced_family[2]) | |
196 | { | |
197 | const char *p; | |
198 | ||
199 | forced_family[0] = '\0'; | |
200 | forced_family[1] = '\0'; | |
201 | ||
202 | /* Check the command line for a forcefamily directive */ | |
203 | strncpy(cmdline, arcs_cmdline, COMMAND_LINE_SIZE - 1); | |
204 | p = strstr(cmdline, FORCEFAMILY_PARAM); | |
205 | if (p && (p != cmdline) && (*(p - 1) != ' ')) | |
206 | p = strstr(p, " " FORCEFAMILY_PARAM "="); | |
207 | ||
208 | if (p) { | |
209 | p += strlen(FORCEFAMILY_PARAM "="); | |
210 | ||
211 | if (*p == '\0' || *(p + 1) == '\0' || | |
212 | (*(p + 2) != '\0' && *(p + 2) != ' ')) | |
213 | pr_err(FORCEFAMILY_PARAM " must be exactly two " | |
214 | "characters long, ignoring value\n"); | |
215 | ||
216 | else { | |
217 | forced_family[0] = *p; | |
218 | forced_family[1] = *(p + 1); | |
219 | } | |
220 | } | |
221 | ||
222 | return 0; | |
223 | } | |
224 | ||
225 | /* | |
226 | * platform_set_family - determine major platform family type. | |
227 | * | |
228 | * Returns family type; -1 if none | |
229 | * Returns the family type; -1 if none | |
230 | * | |
231 | */ | |
232 | static __init noinline void platform_set_family(void) | |
233 | { | |
234 | #define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0)) | |
235 | ||
236 | unsigned char forced_family[2]; | |
237 | unsigned short bootldr_family; | |
238 | ||
239 | check_forcefamily(forced_family); | |
240 | ||
241 | if (forced_family[0] != '\0' && forced_family[1] != '\0') | |
242 | bootldr_family = BOOTLDRFAMILY(forced_family[0], | |
243 | forced_family[1]); | |
244 | else { | |
245 | ||
246 | #ifdef CONFIG_BOOTLOADER_DRIVER | |
247 | bootldr_family = (unsigned short) kbldr_GetSWFamily(); | |
248 | #else | |
249 | #if defined(CONFIG_BOOTLOADER_FAMILY) | |
250 | bootldr_family = (unsigned short) BOOTLDRFAMILY( | |
251 | CONFIG_BOOTLOADER_FAMILY[0], | |
252 | CONFIG_BOOTLOADER_FAMILY[1]); | |
253 | #else | |
254 | #error "Unknown Bootloader Family" | |
255 | #endif | |
256 | #endif | |
257 | } | |
258 | ||
259 | pr_info("Bootloader Family = 0x%04X\n", bootldr_family); | |
260 | ||
261 | switch (bootldr_family) { | |
262 | case BOOTLDRFAMILY('R', '1'): | |
263 | platform_family = FAMILY_1500; | |
264 | break; | |
265 | case BOOTLDRFAMILY('4', '4'): | |
266 | platform_family = FAMILY_4500; | |
267 | break; | |
268 | case BOOTLDRFAMILY('4', '6'): | |
269 | platform_family = FAMILY_4600; | |
270 | break; | |
271 | case BOOTLDRFAMILY('A', '1'): | |
272 | platform_family = FAMILY_4600VZA; | |
273 | break; | |
274 | case BOOTLDRFAMILY('8', '5'): | |
275 | platform_family = FAMILY_8500; | |
276 | break; | |
277 | case BOOTLDRFAMILY('R', '2'): | |
278 | platform_family = FAMILY_8500RNG; | |
279 | break; | |
280 | case BOOTLDRFAMILY('8', '6'): | |
281 | platform_family = FAMILY_8600; | |
282 | break; | |
283 | case BOOTLDRFAMILY('B', '1'): | |
284 | platform_family = FAMILY_8600VZB; | |
285 | break; | |
286 | case BOOTLDRFAMILY('E', '1'): | |
287 | platform_family = FAMILY_1500VZE; | |
288 | break; | |
289 | case BOOTLDRFAMILY('F', '1'): | |
290 | platform_family = FAMILY_1500VZF; | |
291 | break; | |
292 | default: | |
293 | platform_family = -1; | |
294 | } | |
295 | } | |
296 | ||
297 | unsigned int platform_get_family(void) | |
298 | { | |
299 | return platform_family; | |
300 | } | |
301 | EXPORT_SYMBOL(platform_get_family); | |
302 | ||
303 | /* | |
304 | * \brief usb_eye_configure() for optimizing the USB eye on Calliope. | |
305 | * | |
306 | * \param unsigned int value saved to the register. | |
307 | * | |
308 | * \return none | |
309 | * | |
310 | */ | |
311 | static void __init usb_eye_configure(unsigned int value) | |
312 | { | |
313 | asic_write(asic_read(crt_spare) | value, crt_spare); | |
314 | } | |
315 | ||
316 | /* | |
317 | * platform_get_asic - determine the ASIC type. | |
318 | * | |
319 | * \param none | |
320 | * | |
321 | * \return ASIC type; ASIC_UNKNOWN if none | |
322 | * | |
323 | */ | |
324 | enum asic_type platform_get_asic(void) | |
325 | { | |
326 | return asic; | |
327 | } | |
328 | EXPORT_SYMBOL(platform_get_asic); | |
329 | ||
330 | /* | |
331 | * platform_configure_usb - usb configuration based on platform type. | |
332 | * @bcm1_usb2_ctl: value for the BCM1_USB2_CTL register, which is | |
333 | * quirky | |
334 | */ | |
335 | static void __init platform_configure_usb(void) | |
336 | { | |
337 | u32 bcm1_usb2_ctl; | |
338 | ||
339 | if (usb_configured) | |
340 | return; | |
341 | ||
342 | switch (asic) { | |
343 | case ASIC_ZEUS: | |
a3a0f8c8 DV |
344 | case ASIC_CRONUS: |
345 | case ASIC_CRONUSLITE: | |
346 | fs_update(0x0000, 0x11, 0x02, 0); | |
347 | bcm1_usb2_ctl = 0x803; | |
348 | break; | |
349 | ||
350 | case ASIC_CALLIOPE: | |
351 | fs_update(0x0000, 0x11, 0x02, 1); | |
352 | ||
353 | switch (platform_family) { | |
354 | case FAMILY_1500VZE: | |
355 | break; | |
356 | ||
357 | case FAMILY_1500VZF: | |
358 | usb_eye_configure(0x003c0000); | |
359 | break; | |
360 | ||
361 | default: | |
362 | usb_eye_configure(0x00300000); | |
363 | break; | |
364 | } | |
365 | ||
366 | bcm1_usb2_ctl = 0x803; | |
367 | break; | |
368 | ||
369 | default: | |
370 | pr_err("Unknown ASIC type: %d\n", asic); | |
371 | break; | |
372 | } | |
373 | ||
374 | /* turn on USB power */ | |
375 | asic_write(0, usb2_strap); | |
376 | /* Enable all OHCI interrupts */ | |
377 | asic_write(bcm1_usb2_ctl, usb2_control); | |
378 | /* USB2_STBUS_OBC store32/load32 */ | |
379 | asic_write(3, usb2_stbus_obc); | |
380 | /* USB2_STBUS_MESS_SIZE 2 packets */ | |
381 | asic_write(1, usb2_stbus_mess_size); | |
382 | /* USB2_STBUS_CHUNK_SIZE 2 packets */ | |
383 | asic_write(1, usb2_stbus_chunk_size); | |
384 | ||
385 | usb_configured = true; | |
386 | } | |
387 | ||
388 | /* | |
389 | * Set up the USB EHCI interface | |
390 | */ | |
391 | void platform_configure_usb_ehci() | |
392 | { | |
393 | platform_configure_usb(); | |
394 | } | |
395 | ||
396 | /* | |
397 | * Set up the USB OHCI interface | |
398 | */ | |
399 | void platform_configure_usb_ohci() | |
400 | { | |
401 | platform_configure_usb(); | |
402 | } | |
403 | ||
404 | /* | |
405 | * Shut the USB EHCI interface down--currently a NOP | |
406 | */ | |
407 | void platform_unconfigure_usb_ehci() | |
408 | { | |
409 | } | |
410 | ||
411 | /* | |
412 | * Shut the USB OHCI interface down--currently a NOP | |
413 | */ | |
414 | void platform_unconfigure_usb_ohci() | |
415 | { | |
416 | } | |
417 | ||
59dfa2fc DV |
418 | static void __init set_register_map(unsigned long phys_base, |
419 | const struct register_map *map) | |
420 | { | |
421 | asic_phy_base = phys_base; | |
422 | _asic_register_map = *map; | |
423 | register_map_virtualize(&_asic_register_map); | |
424 | asic_base = (unsigned long)ioremap_nocache(phys_base, ASIC_IO_SIZE); | |
425 | } | |
426 | ||
a3a0f8c8 DV |
427 | /** |
428 | * configure_platform - configuration based on platform type. | |
429 | */ | |
430 | void __init configure_platform(void) | |
431 | { | |
432 | platform_set_family(); | |
433 | ||
434 | switch (platform_family) { | |
435 | case FAMILY_1500: | |
436 | case FAMILY_1500VZE: | |
437 | case FAMILY_1500VZF: | |
438 | platform_features = FFS_CAPABLE; | |
439 | asic = ASIC_CALLIOPE; | |
59dfa2fc | 440 | set_register_map(CALLIOPE_IO_BASE, &calliope_register_map); |
a3a0f8c8 DV |
441 | |
442 | if (platform_family == FAMILY_1500VZE) { | |
443 | gp_resources = non_dvr_vze_calliope_resources; | |
444 | pr_info("Platform: 1500/Vz Class E - " | |
445 | "CALLIOPE, NON_DVR_CAPABLE\n"); | |
446 | } else if (platform_family == FAMILY_1500VZF) { | |
447 | gp_resources = non_dvr_vzf_calliope_resources; | |
448 | pr_info("Platform: 1500/Vz Class F - " | |
449 | "CALLIOPE, NON_DVR_CAPABLE\n"); | |
450 | } else { | |
451 | gp_resources = non_dvr_calliope_resources; | |
452 | pr_info("Platform: 1500/RNG100 - CALLIOPE, " | |
453 | "NON_DVR_CAPABLE\n"); | |
454 | } | |
455 | break; | |
456 | ||
457 | case FAMILY_4500: | |
458 | platform_features = FFS_CAPABLE | PCIE_CAPABLE | | |
459 | DISPLAY_CAPABLE; | |
460 | asic = ASIC_ZEUS; | |
59dfa2fc | 461 | set_register_map(ZEUS_IO_BASE, &zeus_register_map); |
a3a0f8c8 DV |
462 | gp_resources = non_dvr_zeus_resources; |
463 | ||
464 | pr_info("Platform: 4500 - ZEUS, NON_DVR_CAPABLE\n"); | |
465 | break; | |
466 | ||
467 | case FAMILY_4600: | |
468 | { | |
469 | unsigned int chipversion = 0; | |
470 | ||
471 | /* The settop has PCIE but it isn't used, so don't advertise | |
472 | * it*/ | |
473 | platform_features = FFS_CAPABLE | DISPLAY_CAPABLE; | |
a3a0f8c8 | 474 | |
28d7d213 DV |
475 | /* Cronus and Cronus Lite have the same register map */ |
476 | set_register_map(CRONUS_IO_BASE, &cronus_register_map); | |
477 | ||
a3a0f8c8 DV |
478 | /* ASIC version will determine if this is a real CronusLite or |
479 | * Castrati(Cronus) */ | |
480 | chipversion = asic_read(chipver3) << 24; | |
481 | chipversion |= asic_read(chipver2) << 16; | |
482 | chipversion |= asic_read(chipver1) << 8; | |
483 | chipversion |= asic_read(chipver0); | |
484 | ||
485 | if ((chipversion == CRONUS_10) || (chipversion == CRONUS_11)) | |
486 | asic = ASIC_CRONUS; | |
487 | else | |
488 | asic = ASIC_CRONUSLITE; | |
489 | ||
59dfa2fc | 490 | gp_resources = non_dvr_cronuslite_resources; |
a3a0f8c8 DV |
491 | pr_info("Platform: 4600 - %s, NON_DVR_CAPABLE, " |
492 | "chipversion=0x%08X\n", | |
493 | (asic == ASIC_CRONUS) ? "CRONUS" : "CRONUS LITE", | |
494 | chipversion); | |
495 | break; | |
496 | } | |
497 | case FAMILY_4600VZA: | |
498 | platform_features = FFS_CAPABLE | DISPLAY_CAPABLE; | |
499 | asic = ASIC_CRONUS; | |
59dfa2fc | 500 | set_register_map(CRONUS_IO_BASE, &cronus_register_map); |
a3a0f8c8 DV |
501 | gp_resources = non_dvr_cronus_resources; |
502 | ||
503 | pr_info("Platform: Vz Class A - CRONUS, NON_DVR_CAPABLE\n"); | |
504 | break; | |
505 | ||
506 | case FAMILY_8500: | |
507 | case FAMILY_8500RNG: | |
508 | platform_features = DVR_CAPABLE | PCIE_CAPABLE | | |
509 | DISPLAY_CAPABLE; | |
510 | asic = ASIC_ZEUS; | |
59dfa2fc | 511 | set_register_map(ZEUS_IO_BASE, &zeus_register_map); |
a3a0f8c8 DV |
512 | gp_resources = dvr_zeus_resources; |
513 | ||
514 | pr_info("Platform: 8500/RNG200 - ZEUS, DVR_CAPABLE\n"); | |
515 | break; | |
516 | ||
517 | case FAMILY_8600: | |
518 | case FAMILY_8600VZB: | |
519 | platform_features = DVR_CAPABLE | PCIE_CAPABLE | | |
520 | DISPLAY_CAPABLE; | |
521 | asic = ASIC_CRONUS; | |
59dfa2fc | 522 | set_register_map(CRONUS_IO_BASE, &cronus_register_map); |
a3a0f8c8 DV |
523 | gp_resources = dvr_cronus_resources; |
524 | ||
525 | pr_info("Platform: 8600/Vz Class B - CRONUS, " | |
526 | "DVR_CAPABLE\n"); | |
527 | break; | |
528 | ||
529 | default: | |
530 | pr_crit("Platform: UNKNOWN PLATFORM\n"); | |
531 | break; | |
532 | } | |
533 | ||
534 | switch (asic) { | |
535 | case ASIC_ZEUS: | |
ca36c36b | 536 | phys_to_dma_offset = 0x30000000; |
a3a0f8c8 DV |
537 | break; |
538 | case ASIC_CALLIOPE: | |
ca36c36b | 539 | phys_to_dma_offset = 0x10000000; |
a3a0f8c8 DV |
540 | break; |
541 | case ASIC_CRONUSLITE: | |
542 | /* Fall through */ | |
543 | case ASIC_CRONUS: | |
544 | /* | |
545 | * TODO: We suppose 0x10000000 aliases into 0x20000000- | |
546 | * 0x2XXXXXXX. If 0x10000000 aliases into 0x60000000- | |
547 | * 0x6XXXXXXX, the offset should be 0x50000000, not 0x10000000. | |
548 | */ | |
ca36c36b | 549 | phys_to_dma_offset = 0x10000000; |
a3a0f8c8 DV |
550 | break; |
551 | default: | |
ca36c36b | 552 | phys_to_dma_offset = 0x00000000; |
a3a0f8c8 DV |
553 | break; |
554 | } | |
555 | } | |
556 | ||
557 | /** | |
558 | * platform_devices_init - sets up USB device resourse. | |
559 | */ | |
560 | static int __init platform_devices_init(void) | |
561 | { | |
562 | pr_notice("%s: ----- Initializing USB resources -----\n", __func__); | |
563 | ||
564 | asic_resource.start = asic_phy_base; | |
565 | asic_resource.end += asic_resource.start; | |
566 | ||
567 | ehci_resources[0].start = asic_reg_phys_addr(ehci_hcapbase); | |
568 | ehci_resources[0].end += ehci_resources[0].start; | |
569 | ||
570 | ohci_resources[0].start = asic_reg_phys_addr(ohci_hc_revision); | |
571 | ohci_resources[0].end += ohci_resources[0].start; | |
572 | ||
573 | set_io_port_base(0); | |
574 | ||
575 | platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices)); | |
576 | ||
577 | return 0; | |
578 | } | |
579 | ||
580 | arch_initcall(platform_devices_init); | |
581 | ||
582 | /* | |
583 | * | |
584 | * BOOTMEM ALLOCATION | |
585 | * | |
586 | */ | |
587 | /* | |
588 | * Allocates/reserves the Platform memory resources early in the boot process. | |
589 | * This ignores any resources that are designated IORESOURCE_IO | |
590 | */ | |
591 | void __init platform_alloc_bootmem(void) | |
592 | { | |
593 | int i; | |
594 | int total = 0; | |
595 | ||
596 | /* Get persistent memory data from command line before allocating | |
597 | * resources. This need to happen before normal command line parsing | |
598 | * has been done */ | |
599 | pmem_setup_resource(); | |
600 | ||
601 | /* Loop through looking for resources that want a particular address */ | |
602 | for (i = 0; gp_resources[i].flags != 0; i++) { | |
603 | int size = gp_resources[i].end - gp_resources[i].start + 1; | |
604 | if ((gp_resources[i].start != 0) && | |
605 | ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) { | |
ca36c36b | 606 | reserve_bootmem(dma_to_phys(gp_resources[i].start), |
a3a0f8c8 DV |
607 | size, 0); |
608 | total += gp_resources[i].end - | |
609 | gp_resources[i].start + 1; | |
610 | pr_info("reserve resource %s at %08x (%u bytes)\n", | |
611 | gp_resources[i].name, gp_resources[i].start, | |
612 | gp_resources[i].end - | |
613 | gp_resources[i].start + 1); | |
614 | } | |
615 | } | |
616 | ||
617 | /* Loop through assigning addresses for those that are left */ | |
618 | for (i = 0; gp_resources[i].flags != 0; i++) { | |
619 | int size = gp_resources[i].end - gp_resources[i].start + 1; | |
620 | if ((gp_resources[i].start == 0) && | |
621 | ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) { | |
622 | void *mem = alloc_bootmem_pages(size); | |
623 | ||
624 | if (mem == NULL) | |
625 | pr_err("Unable to allocate bootmem pages " | |
626 | "for %s\n", gp_resources[i].name); | |
627 | ||
628 | else { | |
629 | gp_resources[i].start = | |
ca36c36b | 630 | phys_to_dma(virt_to_phys(mem)); |
a3a0f8c8 DV |
631 | gp_resources[i].end = |
632 | gp_resources[i].start + size - 1; | |
633 | total += size; | |
634 | pr_info("allocate resource %s at %08x " | |
635 | "(%u bytes)\n", | |
636 | gp_resources[i].name, | |
637 | gp_resources[i].start, size); | |
638 | } | |
639 | } | |
640 | } | |
641 | ||
642 | pr_info("Total Platform driver memory allocation: 0x%08x\n", total); | |
643 | ||
644 | /* indicate resources that are platform I/O related */ | |
645 | for (i = 0; gp_resources[i].flags != 0; i++) { | |
646 | if ((gp_resources[i].start != 0) && | |
647 | ((gp_resources[i].flags & IORESOURCE_IO) != 0)) { | |
648 | pr_info("reserved platform resource %s at %08x\n", | |
649 | gp_resources[i].name, gp_resources[i].start); | |
650 | } | |
651 | } | |
652 | } | |
653 | ||
654 | /* | |
655 | * | |
656 | * PERSISTENT MEMORY (PMEM) CONFIGURATION | |
657 | * | |
658 | */ | |
659 | static unsigned long pmemaddr __initdata; | |
660 | ||
661 | static int __init early_param_pmemaddr(char *p) | |
662 | { | |
663 | pmemaddr = (unsigned long)simple_strtoul(p, NULL, 0); | |
664 | return 0; | |
665 | } | |
666 | early_param("pmemaddr", early_param_pmemaddr); | |
667 | ||
668 | static long pmemlen __initdata; | |
669 | ||
670 | static int __init early_param_pmemlen(char *p) | |
671 | { | |
672 | /* TODO: we can use this code when and if the bootloader ever changes this */ | |
673 | #if 0 | |
674 | pmemlen = (unsigned long)simple_strtoul(p, NULL, 0); | |
675 | #else | |
676 | pmemlen = 0x20000; | |
677 | #endif | |
678 | return 0; | |
679 | } | |
680 | early_param("pmemlen", early_param_pmemlen); | |
681 | ||
682 | /* | |
683 | * Set up persistent memory. If we were given values, we patch the array of | |
684 | * resources. Otherwise, persistent memory may be allocated anywhere at all. | |
685 | */ | |
686 | static void __init pmem_setup_resource(void) | |
687 | { | |
688 | struct resource *resource; | |
689 | resource = asic_resource_get("DiagPersistentMemory"); | |
690 | ||
691 | if (resource && pmemaddr && pmemlen) { | |
692 | /* The address provided by bootloader is in kseg0. Convert to | |
693 | * a bus address. */ | |
ca36c36b | 694 | resource->start = phys_to_dma(pmemaddr - 0x80000000); |
a3a0f8c8 DV |
695 | resource->end = resource->start + pmemlen - 1; |
696 | ||
697 | pr_info("persistent memory: start=0x%x end=0x%x\n", | |
698 | resource->start, resource->end); | |
699 | } | |
700 | } | |
701 | ||
702 | /* | |
703 | * | |
704 | * RESOURCE ACCESS FUNCTIONS | |
705 | * | |
706 | */ | |
707 | ||
708 | /** | |
709 | * asic_resource_get - retrieves parameters for a platform resource. | |
710 | * @name: string to match resource | |
711 | * | |
712 | * Returns a pointer to a struct resource corresponding to the given name. | |
713 | * | |
714 | * CANNOT BE NAMED platform_resource_get, which would be the obvious choice, | |
715 | * as this function name is already declared | |
716 | */ | |
717 | struct resource *asic_resource_get(const char *name) | |
718 | { | |
719 | int i; | |
720 | ||
721 | for (i = 0; gp_resources[i].flags != 0; i++) { | |
722 | if (strcmp(gp_resources[i].name, name) == 0) | |
723 | return &gp_resources[i]; | |
724 | } | |
725 | ||
726 | return NULL; | |
727 | } | |
728 | EXPORT_SYMBOL(asic_resource_get); | |
729 | ||
730 | /** | |
731 | * platform_release_memory - release pre-allocated memory | |
732 | * @ptr: pointer to memory to release | |
733 | * @size: size of resource | |
734 | * | |
735 | * This must only be called for memory allocated or reserved via the boot | |
736 | * memory allocator. | |
737 | */ | |
738 | void platform_release_memory(void *ptr, int size) | |
739 | { | |
740 | unsigned long addr; | |
741 | unsigned long end; | |
742 | ||
743 | addr = ((unsigned long)ptr + (PAGE_SIZE - 1)) & PAGE_MASK; | |
744 | end = ((unsigned long)ptr + size) & PAGE_MASK; | |
745 | ||
746 | for (; addr < end; addr += PAGE_SIZE) { | |
747 | ClearPageReserved(virt_to_page(__va(addr))); | |
748 | init_page_count(virt_to_page(__va(addr))); | |
749 | free_page((unsigned long)__va(addr)); | |
750 | } | |
751 | } | |
752 | EXPORT_SYMBOL(platform_release_memory); | |
753 | ||
754 | /* | |
755 | * | |
756 | * FEATURE AVAILABILITY FUNCTIONS | |
757 | * | |
758 | */ | |
759 | int platform_supports_dvr(void) | |
760 | { | |
761 | return (platform_features & DVR_CAPABLE) != 0; | |
762 | } | |
763 | ||
764 | int platform_supports_ffs(void) | |
765 | { | |
766 | return (platform_features & FFS_CAPABLE) != 0; | |
767 | } | |
768 | ||
769 | int platform_supports_pcie(void) | |
770 | { | |
771 | return (platform_features & PCIE_CAPABLE) != 0; | |
772 | } | |
773 | ||
774 | int platform_supports_display(void) | |
775 | { | |
776 | return (platform_features & DISPLAY_CAPABLE) != 0; | |
777 | } |