ps3.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /*
  2. * PS3 platform declarations.
  3. *
  4. * Copyright (C) 2006 Sony Computer Entertainment Inc.
  5. * Copyright 2006 Sony Corp.
  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; version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #if !defined(_ASM_POWERPC_PS3_H)
  21. #define _ASM_POWERPC_PS3_H
  22. #include <linux/init.h>
  23. #include <linux/types.h>
  24. #include <linux/device.h>
  25. #include <scsi/scsi.h>
  26. union ps3_firmware_version {
  27. u64 raw;
  28. struct {
  29. u16 pad;
  30. u16 major;
  31. u16 minor;
  32. u16 rev;
  33. };
  34. };
  35. int ps3_get_firmware_version(union ps3_firmware_version *v);
  36. /* 'Other OS' area */
  37. enum ps3_param_av_multi_out {
  38. PS3_PARAM_AV_MULTI_OUT_NTSC = 0,
  39. PS3_PARAM_AV_MULTI_OUT_PAL_RGB = 1,
  40. PS3_PARAM_AV_MULTI_OUT_PAL_YCBCR = 2,
  41. PS3_PARAM_AV_MULTI_OUT_SECAM = 3,
  42. };
  43. enum ps3_param_av_multi_out ps3_os_area_get_av_multi_out(void);
  44. /**
  45. * struct ps3_device_id - HV bus device identifier from the system repository
  46. * @bus_id: HV bus id, {1..} (zero invalid)
  47. * @dev_id: HV device id, {0..}
  48. */
  49. struct ps3_device_id {
  50. unsigned int bus_id;
  51. unsigned int dev_id;
  52. };
  53. /* dma routines */
  54. enum ps3_dma_page_size {
  55. PS3_DMA_4K = 12U,
  56. PS3_DMA_64K = 16U,
  57. PS3_DMA_1M = 20U,
  58. PS3_DMA_16M = 24U,
  59. };
  60. enum ps3_dma_region_type {
  61. PS3_DMA_OTHER = 0,
  62. PS3_DMA_INTERNAL = 2,
  63. };
  64. /**
  65. * struct ps3_dma_region - A per device dma state variables structure
  66. * @did: The HV device id.
  67. * @page_size: The ioc pagesize.
  68. * @region_type: The HV region type.
  69. * @bus_addr: The 'translated' bus address of the region.
  70. * @len: The length in bytes of the region.
  71. * @chunk_list: Opaque variable used by the ioc page manager.
  72. */
  73. struct ps3_dma_region {
  74. struct ps3_device_id did;
  75. enum ps3_dma_page_size page_size;
  76. enum ps3_dma_region_type region_type;
  77. unsigned long bus_addr;
  78. unsigned long len;
  79. struct {
  80. spinlock_t lock;
  81. struct list_head head;
  82. } chunk_list;
  83. };
  84. /**
  85. * struct ps3_dma_region_init - Helper to initialize structure variables
  86. *
  87. * Helper to properly initialize variables prior to calling
  88. * ps3_system_bus_device_register.
  89. */
  90. static inline void ps3_dma_region_init(struct ps3_dma_region *r,
  91. const struct ps3_device_id* did, enum ps3_dma_page_size page_size,
  92. enum ps3_dma_region_type region_type)
  93. {
  94. r->did = *did;
  95. r->page_size = page_size;
  96. r->region_type = region_type;
  97. }
  98. int ps3_dma_region_create(struct ps3_dma_region *r);
  99. int ps3_dma_region_free(struct ps3_dma_region *r);
  100. int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
  101. unsigned long len, unsigned long *bus_addr);
  102. int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
  103. unsigned long len);
  104. /* mmio routines */
  105. enum ps3_mmio_page_size {
  106. PS3_MMIO_4K = 12U,
  107. PS3_MMIO_64K = 16U
  108. };
  109. /**
  110. * struct ps3_mmio_region - a per device mmio state variables structure
  111. *
  112. * Current systems can be supported with a single region per device.
  113. */
  114. struct ps3_mmio_region {
  115. struct ps3_device_id did;
  116. unsigned long bus_addr;
  117. unsigned long len;
  118. enum ps3_mmio_page_size page_size;
  119. unsigned long lpar_addr;
  120. };
  121. /**
  122. * struct ps3_mmio_region_init - Helper to initialize structure variables
  123. *
  124. * Helper to properly initialize variables prior to calling
  125. * ps3_system_bus_device_register.
  126. */
  127. static inline void ps3_mmio_region_init(struct ps3_mmio_region *r,
  128. const struct ps3_device_id* did, unsigned long bus_addr,
  129. unsigned long len, enum ps3_mmio_page_size page_size)
  130. {
  131. r->did = *did;
  132. r->bus_addr = bus_addr;
  133. r->len = len;
  134. r->page_size = page_size;
  135. }
  136. int ps3_mmio_region_create(struct ps3_mmio_region *r);
  137. int ps3_free_mmio_region(struct ps3_mmio_region *r);
  138. unsigned long ps3_mm_phys_to_lpar(unsigned long phys_addr);
  139. /* inrerrupt routines */
  140. enum ps3_cpu_binding {
  141. PS3_BINDING_CPU_ANY = -1,
  142. PS3_BINDING_CPU_0 = 0,
  143. PS3_BINDING_CPU_1 = 1,
  144. };
  145. int ps3_alloc_io_irq(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
  146. unsigned int *virq);
  147. int ps3_free_io_irq(unsigned int virq);
  148. int ps3_alloc_event_irq(enum ps3_cpu_binding cpu, unsigned int *virq);
  149. int ps3_free_event_irq(unsigned int virq);
  150. int ps3_send_event_locally(unsigned int virq);
  151. int ps3_connect_event_irq(enum ps3_cpu_binding cpu,
  152. const struct ps3_device_id *did, unsigned int interrupt_id,
  153. unsigned int *virq);
  154. int ps3_disconnect_event_irq(const struct ps3_device_id *did,
  155. unsigned int interrupt_id, unsigned int virq);
  156. int ps3_alloc_vuart_irq(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
  157. unsigned int *virq);
  158. int ps3_free_vuart_irq(unsigned int virq);
  159. int ps3_alloc_spe_irq(enum ps3_cpu_binding cpu, unsigned long spe_id,
  160. unsigned int class, unsigned int *virq);
  161. int ps3_free_spe_irq(unsigned int virq);
  162. int ps3_alloc_irq(enum ps3_cpu_binding cpu, unsigned long outlet,
  163. unsigned int *virq);
  164. int ps3_free_irq(unsigned int virq);
  165. /* lv1 result codes */
  166. enum lv1_result {
  167. LV1_SUCCESS = 0,
  168. /* not used -1 */
  169. LV1_RESOURCE_SHORTAGE = -2,
  170. LV1_NO_PRIVILEGE = -3,
  171. LV1_DENIED_BY_POLICY = -4,
  172. LV1_ACCESS_VIOLATION = -5,
  173. LV1_NO_ENTRY = -6,
  174. LV1_DUPLICATE_ENTRY = -7,
  175. LV1_TYPE_MISMATCH = -8,
  176. LV1_BUSY = -9,
  177. LV1_EMPTY = -10,
  178. LV1_WRONG_STATE = -11,
  179. /* not used -12 */
  180. LV1_NO_MATCH = -13,
  181. LV1_ALREADY_CONNECTED = -14,
  182. LV1_UNSUPPORTED_PARAMETER_VALUE = -15,
  183. LV1_CONDITION_NOT_SATISFIED = -16,
  184. LV1_ILLEGAL_PARAMETER_VALUE = -17,
  185. LV1_BAD_OPTION = -18,
  186. LV1_IMPLEMENTATION_LIMITATION = -19,
  187. LV1_NOT_IMPLEMENTED = -20,
  188. LV1_INVALID_CLASS_ID = -21,
  189. LV1_CONSTRAINT_NOT_SATISFIED = -22,
  190. LV1_ALIGNMENT_ERROR = -23,
  191. LV1_INTERNAL_ERROR = -32768,
  192. };
  193. static inline const char* ps3_result(int result)
  194. {
  195. #if defined(DEBUG)
  196. switch (result) {
  197. case LV1_SUCCESS:
  198. return "LV1_SUCCESS (0)";
  199. case -1:
  200. return "** unknown result ** (-1)";
  201. case LV1_RESOURCE_SHORTAGE:
  202. return "LV1_RESOURCE_SHORTAGE (-2)";
  203. case LV1_NO_PRIVILEGE:
  204. return "LV1_NO_PRIVILEGE (-3)";
  205. case LV1_DENIED_BY_POLICY:
  206. return "LV1_DENIED_BY_POLICY (-4)";
  207. case LV1_ACCESS_VIOLATION:
  208. return "LV1_ACCESS_VIOLATION (-5)";
  209. case LV1_NO_ENTRY:
  210. return "LV1_NO_ENTRY (-6)";
  211. case LV1_DUPLICATE_ENTRY:
  212. return "LV1_DUPLICATE_ENTRY (-7)";
  213. case LV1_TYPE_MISMATCH:
  214. return "LV1_TYPE_MISMATCH (-8)";
  215. case LV1_BUSY:
  216. return "LV1_BUSY (-9)";
  217. case LV1_EMPTY:
  218. return "LV1_EMPTY (-10)";
  219. case LV1_WRONG_STATE:
  220. return "LV1_WRONG_STATE (-11)";
  221. case -12:
  222. return "** unknown result ** (-12)";
  223. case LV1_NO_MATCH:
  224. return "LV1_NO_MATCH (-13)";
  225. case LV1_ALREADY_CONNECTED:
  226. return "LV1_ALREADY_CONNECTED (-14)";
  227. case LV1_UNSUPPORTED_PARAMETER_VALUE:
  228. return "LV1_UNSUPPORTED_PARAMETER_VALUE (-15)";
  229. case LV1_CONDITION_NOT_SATISFIED:
  230. return "LV1_CONDITION_NOT_SATISFIED (-16)";
  231. case LV1_ILLEGAL_PARAMETER_VALUE:
  232. return "LV1_ILLEGAL_PARAMETER_VALUE (-17)";
  233. case LV1_BAD_OPTION:
  234. return "LV1_BAD_OPTION (-18)";
  235. case LV1_IMPLEMENTATION_LIMITATION:
  236. return "LV1_IMPLEMENTATION_LIMITATION (-19)";
  237. case LV1_NOT_IMPLEMENTED:
  238. return "LV1_NOT_IMPLEMENTED (-20)";
  239. case LV1_INVALID_CLASS_ID:
  240. return "LV1_INVALID_CLASS_ID (-21)";
  241. case LV1_CONSTRAINT_NOT_SATISFIED:
  242. return "LV1_CONSTRAINT_NOT_SATISFIED (-22)";
  243. case LV1_ALIGNMENT_ERROR:
  244. return "LV1_ALIGNMENT_ERROR (-23)";
  245. case LV1_INTERNAL_ERROR:
  246. return "LV1_INTERNAL_ERROR (-32768)";
  247. default:
  248. BUG();
  249. return "** unknown result **";
  250. };
  251. #else
  252. return "";
  253. #endif
  254. }
  255. /* repository bus info */
  256. enum ps3_bus_type {
  257. PS3_BUS_TYPE_SB = 4,
  258. PS3_BUS_TYPE_STORAGE = 5,
  259. };
  260. enum ps3_dev_type {
  261. PS3_DEV_TYPE_STOR_DISK = TYPE_DISK, /* 0 */
  262. PS3_DEV_TYPE_SB_GELIC = 3,
  263. PS3_DEV_TYPE_SB_USB = 4,
  264. PS3_DEV_TYPE_STOR_ROM = TYPE_ROM, /* 5 */
  265. PS3_DEV_TYPE_SB_GPIO = 6,
  266. PS3_DEV_TYPE_STOR_FLASH = TYPE_RBC, /* 14 */
  267. };
  268. int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
  269. u64 *value);
  270. int ps3_repository_read_bus_id(unsigned int bus_index, unsigned int *bus_id);
  271. int ps3_repository_read_bus_type(unsigned int bus_index,
  272. enum ps3_bus_type *bus_type);
  273. int ps3_repository_read_bus_num_dev(unsigned int bus_index,
  274. unsigned int *num_dev);
  275. /* repository bus device info */
  276. enum ps3_interrupt_type {
  277. PS3_INTERRUPT_TYPE_EVENT_PORT = 2,
  278. PS3_INTERRUPT_TYPE_SB_OHCI = 3,
  279. PS3_INTERRUPT_TYPE_SB_EHCI = 4,
  280. PS3_INTERRUPT_TYPE_OTHER = 5,
  281. };
  282. enum ps3_reg_type {
  283. PS3_REG_TYPE_SB_OHCI = 3,
  284. PS3_REG_TYPE_SB_EHCI = 4,
  285. PS3_REG_TYPE_SB_GPIO = 5,
  286. };
  287. int ps3_repository_read_dev_str(unsigned int bus_index,
  288. unsigned int dev_index, const char *dev_str, u64 *value);
  289. int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
  290. unsigned int *dev_id);
  291. int ps3_repository_read_dev_type(unsigned int bus_index,
  292. unsigned int dev_index, enum ps3_dev_type *dev_type);
  293. int ps3_repository_read_dev_intr(unsigned int bus_index,
  294. unsigned int dev_index, unsigned int intr_index,
  295. enum ps3_interrupt_type *intr_type, unsigned int *interrupt_id);
  296. int ps3_repository_read_dev_reg_type(unsigned int bus_index,
  297. unsigned int dev_index, unsigned int reg_index,
  298. enum ps3_reg_type *reg_type);
  299. int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
  300. unsigned int dev_index, unsigned int reg_index, u64 *bus_addr,
  301. u64 *len);
  302. int ps3_repository_read_dev_reg(unsigned int bus_index,
  303. unsigned int dev_index, unsigned int reg_index,
  304. enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len);
  305. /* repository bus enumerators */
  306. struct ps3_repository_device {
  307. unsigned int bus_index;
  308. unsigned int dev_index;
  309. struct ps3_device_id did;
  310. };
  311. int ps3_repository_find_device(enum ps3_bus_type bus_type,
  312. enum ps3_dev_type dev_type,
  313. const struct ps3_repository_device *start_dev,
  314. struct ps3_repository_device *dev);
  315. static inline int ps3_repository_find_first_device(
  316. enum ps3_bus_type bus_type, enum ps3_dev_type dev_type,
  317. struct ps3_repository_device *dev)
  318. {
  319. return ps3_repository_find_device(bus_type, dev_type, NULL, dev);
  320. }
  321. int ps3_repository_find_interrupt(const struct ps3_repository_device *dev,
  322. enum ps3_interrupt_type intr_type, unsigned int *interrupt_id);
  323. int ps3_repository_find_reg(const struct ps3_repository_device *dev,
  324. enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len);
  325. /* repository block device info */
  326. int ps3_repository_read_stor_dev_port(unsigned int bus_index,
  327. unsigned int dev_index, u64 *port);
  328. int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
  329. unsigned int dev_index, u64 *blk_size);
  330. int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
  331. unsigned int dev_index, u64 *num_blocks);
  332. int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
  333. unsigned int dev_index, unsigned int *num_regions);
  334. int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
  335. unsigned int dev_index, unsigned int region_index,
  336. unsigned int *region_id);
  337. int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
  338. unsigned int dev_index, unsigned int region_index, u64 *region_size);
  339. int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
  340. unsigned int dev_index, unsigned int region_index, u64 *region_start);
  341. int ps3_repository_read_stor_dev_info(unsigned int bus_index,
  342. unsigned int dev_index, u64 *port, u64 *blk_size,
  343. u64 *num_blocks, unsigned int *num_regions);
  344. int ps3_repository_read_stor_dev_region(unsigned int bus_index,
  345. unsigned int dev_index, unsigned int region_index,
  346. unsigned int *region_id, u64 *region_start, u64 *region_size);
  347. /* repository pu and memory info */
  348. int ps3_repository_read_num_pu(unsigned int *num_pu);
  349. int ps3_repository_read_ppe_id(unsigned int *pu_index, unsigned int *ppe_id);
  350. int ps3_repository_read_rm_base(unsigned int ppe_id, u64 *rm_base);
  351. int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size);
  352. int ps3_repository_read_region_total(u64 *region_total);
  353. int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size,
  354. u64 *region_total);
  355. /* repository pme info */
  356. int ps3_repository_read_num_be(unsigned int *num_be);
  357. int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id);
  358. int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq);
  359. int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq);
  360. /* repository 'Other OS' area */
  361. int ps3_repository_read_boot_dat_addr(u64 *lpar_addr);
  362. int ps3_repository_read_boot_dat_size(unsigned int *size);
  363. int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size);
  364. /* repository spu info */
  365. /**
  366. * enum spu_resource_type - Type of spu resource.
  367. * @spu_resource_type_shared: Logical spu is shared with other partions.
  368. * @spu_resource_type_exclusive: Logical spu is not shared with other partions.
  369. *
  370. * Returned by ps3_repository_read_spu_resource_id().
  371. */
  372. enum ps3_spu_resource_type {
  373. PS3_SPU_RESOURCE_TYPE_SHARED = 0,
  374. PS3_SPU_RESOURCE_TYPE_EXCLUSIVE = 0x8000000000000000UL,
  375. };
  376. int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved);
  377. int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id);
  378. int ps3_repository_read_spu_resource_id(unsigned int res_index,
  379. enum ps3_spu_resource_type* resource_type, unsigned int *resource_id);
  380. /* system bus routines */
  381. enum ps3_match_id {
  382. PS3_MATCH_ID_EHCI = 1,
  383. PS3_MATCH_ID_OHCI,
  384. PS3_MATCH_ID_GELIC,
  385. PS3_MATCH_ID_AV_SETTINGS,
  386. PS3_MATCH_ID_SYSTEM_MANAGER,
  387. };
  388. /**
  389. * struct ps3_system_bus_device - a device on the system bus
  390. */
  391. struct ps3_system_bus_device {
  392. enum ps3_match_id match_id;
  393. struct ps3_device_id did;
  394. unsigned int interrupt_id;
  395. /* struct iommu_table *iommu_table; -- waiting for Ben's cleanups */
  396. struct ps3_dma_region *d_region;
  397. struct ps3_mmio_region *m_region;
  398. struct device core;
  399. };
  400. /**
  401. * struct ps3_system_bus_driver - a driver for a device on the system bus
  402. */
  403. struct ps3_system_bus_driver {
  404. enum ps3_match_id match_id;
  405. struct device_driver core;
  406. int (*probe)(struct ps3_system_bus_device *);
  407. int (*remove)(struct ps3_system_bus_device *);
  408. /* int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
  409. /* int (*resume)(struct ps3_system_bus_device *); */
  410. };
  411. int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
  412. int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
  413. void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
  414. static inline struct ps3_system_bus_driver *to_ps3_system_bus_driver(
  415. struct device_driver *_drv)
  416. {
  417. return container_of(_drv, struct ps3_system_bus_driver, core);
  418. }
  419. static inline struct ps3_system_bus_device *to_ps3_system_bus_device(
  420. struct device *_dev)
  421. {
  422. return container_of(_dev, struct ps3_system_bus_device, core);
  423. }
  424. /**
  425. * ps3_system_bus_set_drvdata -
  426. * @dev: device structure
  427. * @data: Data to set
  428. */
  429. static inline void ps3_system_bus_set_driver_data(
  430. struct ps3_system_bus_device *dev, void *data)
  431. {
  432. dev->core.driver_data = data;
  433. }
  434. static inline void *ps3_system_bus_get_driver_data(
  435. struct ps3_system_bus_device *dev)
  436. {
  437. return dev->core.driver_data;
  438. }
  439. /* These two need global scope for get_dma_ops(). */
  440. extern struct bus_type ps3_system_bus_type;
  441. #endif