asic_devices.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. /*
  2. *
  3. * Description: Defines the platform resources for Gaia-based settops.
  4. *
  5. * Copyright (C) 2005-2009 Scientific-Atlanta, Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * NOTE: The bootloader allocates persistent memory at an address which is
  22. * 16 MiB below the end of the highest address in KSEG0. All fixed
  23. * address memory reservations must avoid this region.
  24. */
  25. #include <linux/device.h>
  26. #include <linux/kernel.h>
  27. #include <linux/init.h>
  28. #include <linux/resource.h>
  29. #include <linux/serial_reg.h>
  30. #include <linux/io.h>
  31. #include <linux/bootmem.h>
  32. #include <linux/mm.h>
  33. #include <linux/platform_device.h>
  34. #include <linux/module.h>
  35. #include <asm/page.h>
  36. #include <linux/swap.h>
  37. #include <linux/highmem.h>
  38. #include <linux/dma-mapping.h>
  39. #include <asm/mach-powertv/asic.h>
  40. #include <asm/mach-powertv/asic_regs.h>
  41. #include <asm/mach-powertv/interrupts.h>
  42. #ifdef CONFIG_BOOTLOADER_DRIVER
  43. #include <asm/mach-powertv/kbldr.h>
  44. #endif
  45. #include <asm/bootinfo.h>
  46. #define BOOTLDRFAMILY(byte1, byte0) (((byte1) << 8) | (byte0))
  47. /*
  48. * Forward Prototypes
  49. */
  50. static void pmem_setup_resource(void);
  51. /*
  52. * Global Variables
  53. */
  54. enum asic_type asic;
  55. unsigned int platform_features;
  56. unsigned int platform_family;
  57. struct register_map _asic_register_map;
  58. EXPORT_SYMBOL(_asic_register_map); /* Exported for testing */
  59. unsigned long asic_phy_base;
  60. unsigned long asic_base;
  61. EXPORT_SYMBOL(asic_base); /* Exported for testing */
  62. struct resource *gp_resources;
  63. /*
  64. * Don't recommend to use it directly, it is usually used by kernel internally.
  65. * Portable code should be using interfaces such as ioremp, dma_map_single, etc.
  66. */
  67. unsigned long phys_to_dma_offset;
  68. EXPORT_SYMBOL(phys_to_dma_offset);
  69. /*
  70. *
  71. * IO Resource Definition
  72. *
  73. */
  74. struct resource asic_resource = {
  75. .name = "ASIC Resource",
  76. .start = 0,
  77. .end = ASIC_IO_SIZE,
  78. .flags = IORESOURCE_MEM,
  79. };
  80. /*
  81. * Allow override of bootloader-specified model
  82. * Returns zero on success, a negative errno value on failure. This parameter
  83. * allows overriding of the bootloader-specified model.
  84. */
  85. static char __initdata cmdline[COMMAND_LINE_SIZE];
  86. #define FORCEFAMILY_PARAM "forcefamily"
  87. /*
  88. * check_forcefamily - check for, and parse, forcefamily command line parameter
  89. * @forced_family: Pointer to two-character array in which to store the
  90. * value of the forcedfamily parameter, if any.
  91. */
  92. static __init int check_forcefamily(unsigned char forced_family[2])
  93. {
  94. const char *p;
  95. forced_family[0] = '\0';
  96. forced_family[1] = '\0';
  97. /* Check the command line for a forcefamily directive */
  98. strncpy(cmdline, arcs_cmdline, COMMAND_LINE_SIZE - 1);
  99. p = strstr(cmdline, FORCEFAMILY_PARAM);
  100. if (p && (p != cmdline) && (*(p - 1) != ' '))
  101. p = strstr(p, " " FORCEFAMILY_PARAM "=");
  102. if (p) {
  103. p += strlen(FORCEFAMILY_PARAM "=");
  104. if (*p == '\0' || *(p + 1) == '\0' ||
  105. (*(p + 2) != '\0' && *(p + 2) != ' '))
  106. pr_err(FORCEFAMILY_PARAM " must be exactly two "
  107. "characters long, ignoring value\n");
  108. else {
  109. forced_family[0] = *p;
  110. forced_family[1] = *(p + 1);
  111. }
  112. }
  113. return 0;
  114. }
  115. /*
  116. * platform_set_family - determine major platform family type.
  117. *
  118. * Returns family type; -1 if none
  119. * Returns the family type; -1 if none
  120. *
  121. */
  122. static __init noinline void platform_set_family(void)
  123. {
  124. unsigned char forced_family[2];
  125. unsigned short bootldr_family;
  126. if (check_forcefamily(forced_family) == 0)
  127. bootldr_family = BOOTLDRFAMILY(forced_family[0],
  128. forced_family[1]);
  129. else {
  130. #ifdef CONFIG_BOOTLOADER_DRIVER
  131. bootldr_family = (unsigned short) kbldr_GetSWFamily();
  132. #else
  133. #if defined(CONFIG_BOOTLOADER_FAMILY)
  134. bootldr_family = (unsigned short) BOOTLDRFAMILY(
  135. CONFIG_BOOTLOADER_FAMILY[0],
  136. CONFIG_BOOTLOADER_FAMILY[1]);
  137. #else
  138. #error "Unknown Bootloader Family"
  139. #endif
  140. #endif
  141. }
  142. pr_info("Bootloader Family = 0x%04X\n", bootldr_family);
  143. switch (bootldr_family) {
  144. case BOOTLDRFAMILY('R', '1'):
  145. platform_family = FAMILY_1500;
  146. break;
  147. case BOOTLDRFAMILY('4', '4'):
  148. platform_family = FAMILY_4500;
  149. break;
  150. case BOOTLDRFAMILY('4', '6'):
  151. platform_family = FAMILY_4600;
  152. break;
  153. case BOOTLDRFAMILY('A', '1'):
  154. platform_family = FAMILY_4600VZA;
  155. break;
  156. case BOOTLDRFAMILY('8', '5'):
  157. platform_family = FAMILY_8500;
  158. break;
  159. case BOOTLDRFAMILY('R', '2'):
  160. platform_family = FAMILY_8500RNG;
  161. break;
  162. case BOOTLDRFAMILY('8', '6'):
  163. platform_family = FAMILY_8600;
  164. break;
  165. case BOOTLDRFAMILY('B', '1'):
  166. platform_family = FAMILY_8600VZB;
  167. break;
  168. case BOOTLDRFAMILY('E', '1'):
  169. platform_family = FAMILY_1500VZE;
  170. break;
  171. case BOOTLDRFAMILY('F', '1'):
  172. platform_family = FAMILY_1500VZF;
  173. break;
  174. case BOOTLDRFAMILY('8', '7'):
  175. platform_family = FAMILY_8700;
  176. break;
  177. default:
  178. platform_family = -1;
  179. }
  180. }
  181. unsigned int platform_get_family(void)
  182. {
  183. return platform_family;
  184. }
  185. EXPORT_SYMBOL(platform_get_family);
  186. /*
  187. * platform_get_asic - determine the ASIC type.
  188. *
  189. * Returns the ASIC type, or ASIC_UNKNOWN if unknown
  190. *
  191. */
  192. enum asic_type platform_get_asic(void)
  193. {
  194. return asic;
  195. }
  196. EXPORT_SYMBOL(platform_get_asic);
  197. /*
  198. * set_register_map - set ASIC register configuration
  199. * @phys_base: Physical address of the base of the ASIC registers
  200. * @map: Description of key ASIC registers
  201. */
  202. static void __init set_register_map(unsigned long phys_base,
  203. const struct register_map *map)
  204. {
  205. asic_phy_base = phys_base;
  206. _asic_register_map = *map;
  207. register_map_virtualize(&_asic_register_map);
  208. asic_base = (unsigned long)ioremap_nocache(phys_base, ASIC_IO_SIZE);
  209. }
  210. /**
  211. * configure_platform - configuration based on platform type.
  212. */
  213. void __init configure_platform(void)
  214. {
  215. platform_set_family();
  216. switch (platform_family) {
  217. case FAMILY_1500:
  218. case FAMILY_1500VZE:
  219. case FAMILY_1500VZF:
  220. platform_features = FFS_CAPABLE;
  221. asic = ASIC_CALLIOPE;
  222. set_register_map(CALLIOPE_IO_BASE, &calliope_register_map);
  223. if (platform_family == FAMILY_1500VZE) {
  224. gp_resources = non_dvr_vze_calliope_resources;
  225. pr_info("Platform: 1500/Vz Class E - "
  226. "CALLIOPE, NON_DVR_CAPABLE\n");
  227. } else if (platform_family == FAMILY_1500VZF) {
  228. gp_resources = non_dvr_vzf_calliope_resources;
  229. pr_info("Platform: 1500/Vz Class F - "
  230. "CALLIOPE, NON_DVR_CAPABLE\n");
  231. } else {
  232. gp_resources = non_dvr_calliope_resources;
  233. pr_info("Platform: 1500/RNG100 - CALLIOPE, "
  234. "NON_DVR_CAPABLE\n");
  235. }
  236. break;
  237. case FAMILY_4500:
  238. platform_features = FFS_CAPABLE | PCIE_CAPABLE |
  239. DISPLAY_CAPABLE;
  240. asic = ASIC_ZEUS;
  241. set_register_map(ZEUS_IO_BASE, &zeus_register_map);
  242. gp_resources = non_dvr_zeus_resources;
  243. pr_info("Platform: 4500 - ZEUS, NON_DVR_CAPABLE\n");
  244. break;
  245. case FAMILY_4600:
  246. {
  247. unsigned int chipversion = 0;
  248. /* The settop has PCIE but it isn't used, so don't advertise
  249. * it*/
  250. platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;
  251. /* Cronus and Cronus Lite have the same register map */
  252. set_register_map(CRONUS_IO_BASE, &cronus_register_map);
  253. /* ASIC version will determine if this is a real CronusLite or
  254. * Castrati(Cronus) */
  255. chipversion = asic_read(chipver3) << 24;
  256. chipversion |= asic_read(chipver2) << 16;
  257. chipversion |= asic_read(chipver1) << 8;
  258. chipversion |= asic_read(chipver0);
  259. if ((chipversion == CRONUS_10) || (chipversion == CRONUS_11))
  260. asic = ASIC_CRONUS;
  261. else
  262. asic = ASIC_CRONUSLITE;
  263. gp_resources = non_dvr_cronuslite_resources;
  264. pr_info("Platform: 4600 - %s, NON_DVR_CAPABLE, "
  265. "chipversion=0x%08X\n",
  266. (asic == ASIC_CRONUS) ? "CRONUS" : "CRONUS LITE",
  267. chipversion);
  268. break;
  269. }
  270. case FAMILY_4600VZA:
  271. platform_features = FFS_CAPABLE | DISPLAY_CAPABLE;
  272. asic = ASIC_CRONUS;
  273. set_register_map(CRONUS_IO_BASE, &cronus_register_map);
  274. gp_resources = non_dvr_cronus_resources;
  275. pr_info("Platform: Vz Class A - CRONUS, NON_DVR_CAPABLE\n");
  276. break;
  277. case FAMILY_8500:
  278. case FAMILY_8500RNG:
  279. platform_features = DVR_CAPABLE | PCIE_CAPABLE |
  280. DISPLAY_CAPABLE;
  281. asic = ASIC_ZEUS;
  282. set_register_map(ZEUS_IO_BASE, &zeus_register_map);
  283. gp_resources = dvr_zeus_resources;
  284. pr_info("Platform: 8500/RNG200 - ZEUS, DVR_CAPABLE\n");
  285. break;
  286. case FAMILY_8600:
  287. case FAMILY_8600VZB:
  288. platform_features = DVR_CAPABLE | PCIE_CAPABLE |
  289. DISPLAY_CAPABLE;
  290. asic = ASIC_CRONUS;
  291. set_register_map(CRONUS_IO_BASE, &cronus_register_map);
  292. gp_resources = dvr_cronus_resources;
  293. pr_info("Platform: 8600/Vz Class B - CRONUS, "
  294. "DVR_CAPABLE\n");
  295. break;
  296. case FAMILY_8700:
  297. platform_features = FFS_CAPABLE | PCIE_CAPABLE;
  298. asic = ASIC_GAIA;
  299. set_register_map(GAIA_IO_BASE, &gaia_register_map);
  300. gp_resources = dvr_gaia_resources;
  301. pr_info("Platform: 8700 - GAIA, DVR_CAPABLE\n");
  302. break;
  303. default:
  304. pr_crit("Platform: UNKNOWN PLATFORM\n");
  305. break;
  306. }
  307. switch (asic) {
  308. case ASIC_ZEUS:
  309. phys_to_dma_offset = 0x30000000;
  310. break;
  311. case ASIC_CALLIOPE:
  312. phys_to_dma_offset = 0x10000000;
  313. break;
  314. case ASIC_CRONUSLITE:
  315. /* Fall through */
  316. case ASIC_CRONUS:
  317. /*
  318. * TODO: We suppose 0x10000000 aliases into 0x20000000-
  319. * 0x2XXXXXXX. If 0x10000000 aliases into 0x60000000-
  320. * 0x6XXXXXXX, the offset should be 0x50000000, not 0x10000000.
  321. */
  322. phys_to_dma_offset = 0x10000000;
  323. break;
  324. default:
  325. phys_to_dma_offset = 0x00000000;
  326. break;
  327. }
  328. }
  329. /*
  330. * RESOURCE ALLOCATION
  331. *
  332. */
  333. /*
  334. * Allocates/reserves the Platform memory resources early in the boot process.
  335. * This ignores any resources that are designated IORESOURCE_IO
  336. */
  337. void __init platform_alloc_bootmem(void)
  338. {
  339. int i;
  340. int total = 0;
  341. /* Get persistent memory data from command line before allocating
  342. * resources. This need to happen before normal command line parsing
  343. * has been done */
  344. pmem_setup_resource();
  345. /* Loop through looking for resources that want a particular address */
  346. for (i = 0; gp_resources[i].flags != 0; i++) {
  347. int size = resource_size(&gp_resources[i]);
  348. if ((gp_resources[i].start != 0) &&
  349. ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {
  350. reserve_bootmem(dma_to_phys(gp_resources[i].start),
  351. size, 0);
  352. total += resource_size(&gp_resources[i]);
  353. pr_info("reserve resource %s at %08x (%u bytes)\n",
  354. gp_resources[i].name, gp_resources[i].start,
  355. resource_size(&gp_resources[i]));
  356. }
  357. }
  358. /* Loop through assigning addresses for those that are left */
  359. for (i = 0; gp_resources[i].flags != 0; i++) {
  360. int size = resource_size(&gp_resources[i]);
  361. if ((gp_resources[i].start == 0) &&
  362. ((gp_resources[i].flags & IORESOURCE_MEM) != 0)) {
  363. void *mem = alloc_bootmem_pages(size);
  364. if (mem == NULL)
  365. pr_err("Unable to allocate bootmem pages "
  366. "for %s\n", gp_resources[i].name);
  367. else {
  368. gp_resources[i].start =
  369. phys_to_dma(virt_to_phys(mem));
  370. gp_resources[i].end =
  371. gp_resources[i].start + size - 1;
  372. total += size;
  373. pr_info("allocate resource %s at %08x "
  374. "(%u bytes)\n",
  375. gp_resources[i].name,
  376. gp_resources[i].start, size);
  377. }
  378. }
  379. }
  380. pr_info("Total Platform driver memory allocation: 0x%08x\n", total);
  381. /* indicate resources that are platform I/O related */
  382. for (i = 0; gp_resources[i].flags != 0; i++) {
  383. if ((gp_resources[i].start != 0) &&
  384. ((gp_resources[i].flags & IORESOURCE_IO) != 0)) {
  385. pr_info("reserved platform resource %s at %08x\n",
  386. gp_resources[i].name, gp_resources[i].start);
  387. }
  388. }
  389. }
  390. /*
  391. *
  392. * PERSISTENT MEMORY (PMEM) CONFIGURATION
  393. *
  394. */
  395. static unsigned long pmemaddr __initdata;
  396. static int __init early_param_pmemaddr(char *p)
  397. {
  398. pmemaddr = (unsigned long)simple_strtoul(p, NULL, 0);
  399. return 0;
  400. }
  401. early_param("pmemaddr", early_param_pmemaddr);
  402. static long pmemlen __initdata;
  403. static int __init early_param_pmemlen(char *p)
  404. {
  405. /* TODO: we can use this code when and if the bootloader ever changes this */
  406. #if 0
  407. pmemlen = (unsigned long)simple_strtoul(p, NULL, 0);
  408. #else
  409. pmemlen = 0x20000;
  410. #endif
  411. return 0;
  412. }
  413. early_param("pmemlen", early_param_pmemlen);
  414. /*
  415. * Set up persistent memory. If we were given values, we patch the array of
  416. * resources. Otherwise, persistent memory may be allocated anywhere at all.
  417. */
  418. static void __init pmem_setup_resource(void)
  419. {
  420. struct resource *resource;
  421. resource = asic_resource_get("DiagPersistentMemory");
  422. if (resource && pmemaddr && pmemlen) {
  423. /* The address provided by bootloader is in kseg0. Convert to
  424. * a bus address. */
  425. resource->start = phys_to_dma(pmemaddr - 0x80000000);
  426. resource->end = resource->start + pmemlen - 1;
  427. pr_info("persistent memory: start=0x%x end=0x%x\n",
  428. resource->start, resource->end);
  429. }
  430. }
  431. /*
  432. *
  433. * RESOURCE ACCESS FUNCTIONS
  434. *
  435. */
  436. /**
  437. * asic_resource_get - retrieves parameters for a platform resource.
  438. * @name: string to match resource
  439. *
  440. * Returns a pointer to a struct resource corresponding to the given name.
  441. *
  442. * CANNOT BE NAMED platform_resource_get, which would be the obvious choice,
  443. * as this function name is already declared
  444. */
  445. struct resource *asic_resource_get(const char *name)
  446. {
  447. int i;
  448. for (i = 0; gp_resources[i].flags != 0; i++) {
  449. if (strcmp(gp_resources[i].name, name) == 0)
  450. return &gp_resources[i];
  451. }
  452. return NULL;
  453. }
  454. EXPORT_SYMBOL(asic_resource_get);
  455. /**
  456. * platform_release_memory - release pre-allocated memory
  457. * @ptr: pointer to memory to release
  458. * @size: size of resource
  459. *
  460. * This must only be called for memory allocated or reserved via the boot
  461. * memory allocator.
  462. */
  463. void platform_release_memory(void *ptr, int size)
  464. {
  465. unsigned long addr;
  466. unsigned long end;
  467. addr = ((unsigned long)ptr + (PAGE_SIZE - 1)) & PAGE_MASK;
  468. end = ((unsigned long)ptr + size) & PAGE_MASK;
  469. for (; addr < end; addr += PAGE_SIZE) {
  470. ClearPageReserved(virt_to_page(__va(addr)));
  471. init_page_count(virt_to_page(__va(addr)));
  472. free_page((unsigned long)__va(addr));
  473. }
  474. }
  475. EXPORT_SYMBOL(platform_release_memory);
  476. /*
  477. *
  478. * FEATURE AVAILABILITY FUNCTIONS
  479. *
  480. */
  481. int platform_supports_dvr(void)
  482. {
  483. return (platform_features & DVR_CAPABLE) != 0;
  484. }
  485. int platform_supports_ffs(void)
  486. {
  487. return (platform_features & FFS_CAPABLE) != 0;
  488. }
  489. int platform_supports_pcie(void)
  490. {
  491. return (platform_features & PCIE_CAPABLE) != 0;
  492. }
  493. int platform_supports_display(void)
  494. {
  495. return (platform_features & DISPLAY_CAPABLE) != 0;
  496. }