ps3.h 14 KB

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