asic_devices.c 18 KB

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