ps3.h 15 KB

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