asic_devices.c 18 KB

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