asic_devices.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. struct register_map _asic_register_map;
  64. EXPORT_SYMBOL(_asic_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. case ASIC_CRONUS:
  300. case ASIC_CRONUSLITE:
  301. fs_update(0x0000, 0x11, 0x02, 0);
  302. bcm1_usb2_ctl = 0x803;
  303. break;
  304. case ASIC_CALLIOPE:
  305. fs_update(0x0000, 0x11, 0x02, 1);
  306. switch (platform_family) {
  307. case FAMILY_1500VZE:
  308. break;
  309. case FAMILY_1500VZF:
  310. usb_eye_configure(0x003c0000);
  311. break;
  312. default:
  313. usb_eye_configure(0x00300000);
  314. break;
  315. }
  316. bcm1_usb2_ctl = 0x803;
  317. break;
  318. default:
  319. pr_err("Unknown ASIC type: %d\n", asic);
  320. break;
  321. }
  322. /* turn on USB power */
  323. asic_write(0, usb2_strap);
  324. /* Enable all OHCI interrupts */
  325. asic_write(bcm1_usb2_ctl, usb2_control);
  326. /* USB2_STBUS_OBC store32/load32 */
  327. asic_write(3, usb2_stbus_obc);
  328. /* USB2_STBUS_MESS_SIZE 2 packets */
  329. asic_write(1, usb2_stbus_mess_size);
  330. /* USB2_STBUS_CHUNK_SIZE 2 packets */
  331. asic_write(1, usb2_stbus_chunk_size);
  332. usb_configured = true;
  333. }
  334. /*
  335. * Set up the USB EHCI interface
  336. */
  337. void platform_configure_usb_ehci()
  338. {
  339. platform_configure_usb();
  340. }
  341. /*
  342. * Set up the USB OHCI interface
  343. */
  344. void platform_configure_usb_ohci()
  345. {
  346. platform_configure_usb();
  347. }
  348. /*
  349. * Shut the USB EHCI interface down--currently a NOP
  350. */
  351. void platform_unconfigure_usb_ehci()
  352. {
  353. }
  354. /*
  355. * Shut the USB OHCI interface down--currently a NOP
  356. */
  357. void platform_unconfigure_usb_ohci()
  358. {
  359. }
  360. static void __init set_register_map(unsigned long phys_base,
  361. const struct register_map *map)
  362. {
  363. asic_phy_base = phys_base;
  364. _asic_register_map = *map;
  365. register_map_virtualize(&_asic_register_map);
  366. asic_base = (unsigned long)ioremap_nocache(phys_base, ASIC_IO_SIZE);
  367. }
  368. /**
  369. * configure_platform - configuration based on platform type.
  370. */
  371. void __init configure_platform(void)
  372. {
  373. platform_set_family();
  374. switch (platform_family) {
  375. case FAMILY_1500:
  376. case FAMILY_1500VZE:
  377. case FAMILY_1500VZF:
  378. platform_features = FFS_CAPABLE;
  379. asic = ASIC_CALLIOPE;
  380. set_register_map(CALLIOPE_IO_BASE, &calliope_register_map);
  381. if (platform_family == FAMILY_1500VZE) {
  382. gp_resources = non_dvr_vze_calliope_resources;
  383. pr_info("Platform: 1500/Vz Class E - "
  384. "CALLIOPE, NON_DVR_CAPABLE\n");
  385. } else if (platform_family == FAMILY_1500VZF) {
  386. gp_resources = non_dvr_vzf_calliope_resources;
  387. pr_info("Platform: 1500/Vz Class F - "
  388. "CALLIOPE, NON_DVR_CAPABLE\n");
  389. } else {
  390. gp_resources = non_dvr_calliope_resources;
  391. pr_info("Platform: 1500/RNG100 - CALLIOPE, "
  392. "NON_DVR_CAPABLE\n");
  393. }
  394. break;
  395. case FAMILY_4500:
  396. platform_features = FFS_CAPABLE | PCIE_CAPABLE |
  397. DISPLAY_CAPABLE;
  398. asic = ASIC_ZEUS;
  399. set_register_map(ZEUS_IO_BASE, &zeus_register_map);
  400. gp_resources = non_dvr_zeus_resources;
  401. pr_info("Platform: 4500 - ZEUS, NON_DVR_CAPABLE\n");
  402. break;
  403. case FAMILY_4600:
  404. {
  405. unsigned int chipversion = 0;
  406. /* The settop has PCIE but it isn't used, so don't advertise
  407. * it*/
  408. platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;
  409. /* ASIC version will determine if this is a real CronusLite or
  410. * Castrati(Cronus) */
  411. chipversion = asic_read(chipver3) << 24;
  412. chipversion |= asic_read(chipver2) << 16;
  413. chipversion |= asic_read(chipver1) << 8;
  414. chipversion |= asic_read(chipver0);
  415. if ((chipversion == CRONUS_10) || (chipversion == CRONUS_11))
  416. asic = ASIC_CRONUS;
  417. else
  418. asic = ASIC_CRONUSLITE;
  419. /* Cronus and Cronus Lite have the same register map */
  420. set_register_map(CRONUS_IO_BASE, &cronus_register_map);
  421. gp_resources = non_dvr_cronuslite_resources;
  422. pr_info("Platform: 4600 - %s, NON_DVR_CAPABLE, "
  423. "chipversion=0x%08X\n",
  424. (asic == ASIC_CRONUS) ? "CRONUS" : "CRONUS LITE",
  425. chipversion);
  426. break;
  427. }
  428. case FAMILY_4600VZA:
  429. platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;
  430. asic = ASIC_CRONUS;
  431. set_register_map(CRONUS_IO_BASE, &cronus_register_map);
  432. gp_resources = non_dvr_cronus_resources;
  433. pr_info("Platform: Vz Class A - CRONUS, NON_DVR_CAPABLE\n");
  434. break;
  435. case FAMILY_8500:
  436. case FAMILY_8500RNG:
  437. platform_features = DVR_CAPABLE | PCIE_CAPABLE |
  438. DISPLAY_CAPABLE;
  439. asic = ASIC_ZEUS;
  440. set_register_map(ZEUS_IO_BASE, &zeus_register_map);
  441. gp_resources = dvr_zeus_resources;
  442. pr_info("Platform: 8500/RNG200 - ZEUS, DVR_CAPABLE\n");
  443. break;
  444. case FAMILY_8600:
  445. case FAMILY_8600VZB:
  446. platform_features = DVR_CAPABLE | PCIE_CAPABLE |
  447. DISPLAY_CAPABLE;
  448. asic = ASIC_CRONUS;
  449. set_register_map(CRONUS_IO_BASE, &cronus_register_map);
  450. gp_resources = dvr_cronus_resources;
  451. pr_info("Platform: 8600/Vz Class B - CRONUS, "
  452. "DVR_CAPABLE\n");
  453. break;
  454. default:
  455. pr_crit("Platform: UNKNOWN PLATFORM\n");
  456. break;
  457. }
  458. switch (asic) {
  459. case ASIC_ZEUS:
  460. phys_to_bus_offset = 0x30000000;
  461. break;
  462. case ASIC_CALLIOPE:
  463. phys_to_bus_offset = 0x10000000;
  464. break;
  465. case ASIC_CRONUSLITE:
  466. /* Fall through */
  467. case ASIC_CRONUS:
  468. /*
  469. * TODO: We suppose 0x10000000 aliases into 0x20000000-
  470. * 0x2XXXXXXX. If 0x10000000 aliases into 0x60000000-
  471. * 0x6XXXXXXX, the offset should be 0x50000000, not 0x10000000.
  472. */
  473. phys_to_bus_offset = 0x10000000;
  474. break;
  475. default:
  476. phys_to_bus_offset = 0x00000000;
  477. break;
  478. }
  479. }
  480. /**
  481. * platform_devices_init - sets up USB device resourse.
  482. */
  483. static int __init platform_devices_init(void)
  484. {
  485. pr_notice("%s: ----- Initializing USB resources -----\n", __func__);
  486. asic_resource.start = asic_phy_base;
  487. asic_resource.end += asic_resource.start;
  488. ehci_resources[0].start = asic_reg_phys_addr(ehci_hcapbase);
  489. ehci_resources[0].end += ehci_resources[0].start;
  490. ohci_resources[0].start = asic_reg_phys_addr(ohci_hc_revision);
  491. ohci_resources[0].end += ohci_resources[0].start;
  492. set_io_port_base(0);
  493. platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
  494. return 0;
  495. }
  496. arch_initcall(platform_devices_init);
  497. /*
  498. *
  499. * BOOTMEM ALLOCATION
  500. *
  501. */
  502. /*
  503. * Allocates/reserves the Platform memory resources early in the boot process.
  504. * This ignores any resources that are designated IORESOURCE_IO
  505. */
  506. void __init platform_alloc_bootmem(void)
  507. {
  508. int i;
  509. int total = 0;
  510. /* Get persistent memory data from command line before allocating
  511. * resources. This need to happen before normal command line parsing
  512. * has been done */
  513. pmem_setup_resource();
  514. /* Loop through looking for resources that want a particular address */
  515. for (i = 0; gp_resources[i].flags != 0; i++) {
  516. int size = gp_resources[i].end - gp_resources[i].start + 1;
  517. if ((gp_resources[i].start != 0) &&
  518. ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {
  519. reserve_bootmem(bus_to_phys(gp_resources[i].start),
  520. size, 0);
  521. total += gp_resources[i].end -
  522. gp_resources[i].start + 1;
  523. pr_info("reserve resource %s at %08x (%u bytes)\n",
  524. gp_resources[i].name, gp_resources[i].start,
  525. gp_resources[i].end -
  526. gp_resources[i].start + 1);
  527. }
  528. }
  529. /* Loop through assigning addresses for those that are left */
  530. for (i = 0; gp_resources[i].flags != 0; i++) {
  531. int size = gp_resources[i].end - gp_resources[i].start + 1;
  532. if ((gp_resources[i].start == 0) &&
  533. ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {
  534. void *mem = alloc_bootmem_pages(size);
  535. if (mem == NULL)
  536. pr_err("Unable to allocate bootmem pages "
  537. "for %s\n", gp_resources[i].name);
  538. else {
  539. gp_resources[i].start =
  540. phys_to_bus(virt_to_phys(mem));
  541. gp_resources[i].end =
  542. gp_resources[i].start + size - 1;
  543. total += size;
  544. pr_info("allocate resource %s at %08x "
  545. "(%u bytes)\n",
  546. gp_resources[i].name,
  547. gp_resources[i].start, size);
  548. }
  549. }
  550. }
  551. pr_info("Total Platform driver memory allocation: 0x%08x\n", total);
  552. /* indicate resources that are platform I/O related */
  553. for (i = 0; gp_resources[i].flags != 0; i++) {
  554. if ((gp_resources[i].start != 0) &&
  555. ((gp_resources[i].flags & IORESOURCE_IO) != 0)) {
  556. pr_info("reserved platform resource %s at %08x\n",
  557. gp_resources[i].name, gp_resources[i].start);
  558. }
  559. }
  560. }
  561. /*
  562. *
  563. * PERSISTENT MEMORY (PMEM) CONFIGURATION
  564. *
  565. */
  566. static unsigned long pmemaddr __initdata;
  567. static int __init early_param_pmemaddr(char *p)
  568. {
  569. pmemaddr = (unsigned long)simple_strtoul(p, NULL, 0);
  570. return 0;
  571. }
  572. early_param("pmemaddr", early_param_pmemaddr);
  573. static long pmemlen __initdata;
  574. static int __init early_param_pmemlen(char *p)
  575. {
  576. /* TODO: we can use this code when and if the bootloader ever changes this */
  577. #if 0
  578. pmemlen = (unsigned long)simple_strtoul(p, NULL, 0);
  579. #else
  580. pmemlen = 0x20000;
  581. #endif
  582. return 0;
  583. }
  584. early_param("pmemlen", early_param_pmemlen);
  585. /*
  586. * Set up persistent memory. If we were given values, we patch the array of
  587. * resources. Otherwise, persistent memory may be allocated anywhere at all.
  588. */
  589. static void __init pmem_setup_resource(void)
  590. {
  591. struct resource *resource;
  592. resource = asic_resource_get("DiagPersistentMemory");
  593. if (resource && pmemaddr && pmemlen) {
  594. /* The address provided by bootloader is in kseg0. Convert to
  595. * a bus address. */
  596. resource->start = phys_to_bus(pmemaddr - 0x80000000);
  597. resource->end = resource->start + pmemlen - 1;
  598. pr_info("persistent memory: start=0x%x end=0x%x\n",
  599. resource->start, resource->end);
  600. }
  601. }
  602. /*
  603. *
  604. * RESOURCE ACCESS FUNCTIONS
  605. *
  606. */
  607. /**
  608. * asic_resource_get - retrieves parameters for a platform resource.
  609. * @name: string to match resource
  610. *
  611. * Returns a pointer to a struct resource corresponding to the given name.
  612. *
  613. * CANNOT BE NAMED platform_resource_get, which would be the obvious choice,
  614. * as this function name is already declared
  615. */
  616. struct resource *asic_resource_get(const char *name)
  617. {
  618. int i;
  619. for (i = 0; gp_resources[i].flags != 0; i++) {
  620. if (strcmp(gp_resources[i].name, name) == 0)
  621. return &gp_resources[i];
  622. }
  623. return NULL;
  624. }
  625. EXPORT_SYMBOL(asic_resource_get);
  626. /**
  627. * platform_release_memory - release pre-allocated memory
  628. * @ptr: pointer to memory to release
  629. * @size: size of resource
  630. *
  631. * This must only be called for memory allocated or reserved via the boot
  632. * memory allocator.
  633. */
  634. void platform_release_memory(void *ptr, int size)
  635. {
  636. unsigned long addr;
  637. unsigned long end;
  638. addr = ((unsigned long)ptr + (PAGE_SIZE - 1)) & PAGE_MASK;
  639. end = ((unsigned long)ptr + size) & PAGE_MASK;
  640. for (; addr < end; addr += PAGE_SIZE) {
  641. ClearPageReserved(virt_to_page(__va(addr)));
  642. init_page_count(virt_to_page(__va(addr)));
  643. free_page((unsigned long)__va(addr));
  644. }
  645. }
  646. EXPORT_SYMBOL(platform_release_memory);
  647. /*
  648. *
  649. * FEATURE AVAILABILITY FUNCTIONS
  650. *
  651. */
  652. int platform_supports_dvr(void)
  653. {
  654. return (platform_features & DVR_CAPABLE) != 0;
  655. }
  656. int platform_supports_ffs(void)
  657. {
  658. return (platform_features & FFS_CAPABLE) != 0;
  659. }
  660. int platform_supports_pcie(void)
  661. {
  662. return (platform_features & PCIE_CAPABLE) != 0;
  663. }
  664. int platform_supports_display(void)
  665. {
  666. return (platform_features & DISPLAY_CAPABLE) != 0;
  667. }