ps3.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  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. union ps3_firmware_version {
  26. u64 raw;
  27. struct {
  28. u16 pad;
  29. u16 major;
  30. u16 minor;
  31. u16 rev;
  32. };
  33. };
  34. void ps3_get_firmware_version(union ps3_firmware_version *v);
  35. int ps3_compare_firmware_version(u16 major, u16 minor, u16 rev);
  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. /* dma routines */
  45. enum ps3_dma_page_size {
  46. PS3_DMA_4K = 12U,
  47. PS3_DMA_64K = 16U,
  48. PS3_DMA_1M = 20U,
  49. PS3_DMA_16M = 24U,
  50. };
  51. enum ps3_dma_region_type {
  52. PS3_DMA_OTHER = 0,
  53. PS3_DMA_INTERNAL = 2,
  54. };
  55. struct ps3_dma_region_ops;
  56. /**
  57. * struct ps3_dma_region - A per device dma state variables structure
  58. * @did: The HV device id.
  59. * @page_size: The ioc pagesize.
  60. * @region_type: The HV region type.
  61. * @bus_addr: The 'translated' bus address of the region.
  62. * @len: The length in bytes of the region.
  63. * @offset: The offset from the start of memory of the region.
  64. * @ioid: The IOID of the device who owns this region
  65. * @chunk_list: Opaque variable used by the ioc page manager.
  66. * @region_ops: struct ps3_dma_region_ops - dma region operations
  67. */
  68. struct ps3_dma_region {
  69. struct ps3_system_bus_device *dev;
  70. /* device variables */
  71. const struct ps3_dma_region_ops *region_ops;
  72. unsigned char ioid;
  73. enum ps3_dma_page_size page_size;
  74. enum ps3_dma_region_type region_type;
  75. unsigned long len;
  76. unsigned long offset;
  77. /* driver variables (set by ps3_dma_region_create) */
  78. unsigned long bus_addr;
  79. struct {
  80. spinlock_t lock;
  81. struct list_head head;
  82. } chunk_list;
  83. };
  84. struct ps3_dma_region_ops {
  85. int (*create)(struct ps3_dma_region *);
  86. int (*free)(struct ps3_dma_region *);
  87. int (*map)(struct ps3_dma_region *,
  88. unsigned long virt_addr,
  89. unsigned long len,
  90. unsigned long *bus_addr,
  91. u64 iopte_pp);
  92. int (*unmap)(struct ps3_dma_region *,
  93. unsigned long bus_addr,
  94. unsigned long len);
  95. };
  96. /**
  97. * struct ps3_dma_region_init - Helper to initialize structure variables
  98. *
  99. * Helper to properly initialize variables prior to calling
  100. * ps3_system_bus_device_register.
  101. */
  102. struct ps3_system_bus_device;
  103. int ps3_dma_region_init(struct ps3_system_bus_device *dev,
  104. struct ps3_dma_region *r, enum ps3_dma_page_size page_size,
  105. enum ps3_dma_region_type region_type, void *addr, unsigned long len);
  106. int ps3_dma_region_create(struct ps3_dma_region *r);
  107. int ps3_dma_region_free(struct ps3_dma_region *r);
  108. int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
  109. unsigned long len, unsigned long *bus_addr,
  110. u64 iopte_pp);
  111. int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
  112. unsigned long len);
  113. /* mmio routines */
  114. enum ps3_mmio_page_size {
  115. PS3_MMIO_4K = 12U,
  116. PS3_MMIO_64K = 16U
  117. };
  118. struct ps3_mmio_region_ops;
  119. /**
  120. * struct ps3_mmio_region - a per device mmio state variables structure
  121. *
  122. * Current systems can be supported with a single region per device.
  123. */
  124. struct ps3_mmio_region {
  125. struct ps3_system_bus_device *dev;
  126. const struct ps3_mmio_region_ops *mmio_ops;
  127. unsigned long bus_addr;
  128. unsigned long len;
  129. enum ps3_mmio_page_size page_size;
  130. unsigned long lpar_addr;
  131. };
  132. struct ps3_mmio_region_ops {
  133. int (*create)(struct ps3_mmio_region *);
  134. int (*free)(struct ps3_mmio_region *);
  135. };
  136. /**
  137. * struct ps3_mmio_region_init - Helper to initialize structure variables
  138. *
  139. * Helper to properly initialize variables prior to calling
  140. * ps3_system_bus_device_register.
  141. */
  142. int ps3_mmio_region_init(struct ps3_system_bus_device *dev,
  143. struct ps3_mmio_region *r, unsigned long bus_addr, unsigned long len,
  144. enum ps3_mmio_page_size page_size);
  145. int ps3_mmio_region_create(struct ps3_mmio_region *r);
  146. int ps3_free_mmio_region(struct ps3_mmio_region *r);
  147. unsigned long ps3_mm_phys_to_lpar(unsigned long phys_addr);
  148. /* inrerrupt routines */
  149. enum ps3_cpu_binding {
  150. PS3_BINDING_CPU_ANY = -1,
  151. PS3_BINDING_CPU_0 = 0,
  152. PS3_BINDING_CPU_1 = 1,
  153. };
  154. int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
  155. unsigned int *virq);
  156. int ps3_virq_destroy(unsigned int virq);
  157. int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
  158. unsigned int *virq);
  159. int ps3_irq_plug_destroy(unsigned int virq);
  160. int ps3_event_receive_port_setup(enum ps3_cpu_binding cpu, unsigned int *virq);
  161. int ps3_event_receive_port_destroy(unsigned int virq);
  162. int ps3_send_event_locally(unsigned int virq);
  163. int ps3_io_irq_setup(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
  164. unsigned int *virq);
  165. int ps3_io_irq_destroy(unsigned int virq);
  166. int ps3_vuart_irq_setup(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
  167. unsigned int *virq);
  168. int ps3_vuart_irq_destroy(unsigned int virq);
  169. int ps3_spe_irq_setup(enum ps3_cpu_binding cpu, unsigned long spe_id,
  170. unsigned int class, unsigned int *virq);
  171. int ps3_spe_irq_destroy(unsigned int virq);
  172. int ps3_sb_event_receive_port_setup(struct ps3_system_bus_device *dev,
  173. enum ps3_cpu_binding cpu, unsigned int *virq);
  174. int ps3_sb_event_receive_port_destroy(struct ps3_system_bus_device *dev,
  175. unsigned int virq);
  176. /* lv1 result codes */
  177. enum lv1_result {
  178. LV1_SUCCESS = 0,
  179. /* not used -1 */
  180. LV1_RESOURCE_SHORTAGE = -2,
  181. LV1_NO_PRIVILEGE = -3,
  182. LV1_DENIED_BY_POLICY = -4,
  183. LV1_ACCESS_VIOLATION = -5,
  184. LV1_NO_ENTRY = -6,
  185. LV1_DUPLICATE_ENTRY = -7,
  186. LV1_TYPE_MISMATCH = -8,
  187. LV1_BUSY = -9,
  188. LV1_EMPTY = -10,
  189. LV1_WRONG_STATE = -11,
  190. /* not used -12 */
  191. LV1_NO_MATCH = -13,
  192. LV1_ALREADY_CONNECTED = -14,
  193. LV1_UNSUPPORTED_PARAMETER_VALUE = -15,
  194. LV1_CONDITION_NOT_SATISFIED = -16,
  195. LV1_ILLEGAL_PARAMETER_VALUE = -17,
  196. LV1_BAD_OPTION = -18,
  197. LV1_IMPLEMENTATION_LIMITATION = -19,
  198. LV1_NOT_IMPLEMENTED = -20,
  199. LV1_INVALID_CLASS_ID = -21,
  200. LV1_CONSTRAINT_NOT_SATISFIED = -22,
  201. LV1_ALIGNMENT_ERROR = -23,
  202. LV1_HARDWARE_ERROR = -24,
  203. LV1_INVALID_DATA_FORMAT = -25,
  204. LV1_INVALID_OPERATION = -26,
  205. LV1_INTERNAL_ERROR = -32768,
  206. };
  207. static inline const char* ps3_result(int result)
  208. {
  209. #if defined(DEBUG)
  210. switch (result) {
  211. case LV1_SUCCESS:
  212. return "LV1_SUCCESS (0)";
  213. case -1:
  214. return "** unknown result ** (-1)";
  215. case LV1_RESOURCE_SHORTAGE:
  216. return "LV1_RESOURCE_SHORTAGE (-2)";
  217. case LV1_NO_PRIVILEGE:
  218. return "LV1_NO_PRIVILEGE (-3)";
  219. case LV1_DENIED_BY_POLICY:
  220. return "LV1_DENIED_BY_POLICY (-4)";
  221. case LV1_ACCESS_VIOLATION:
  222. return "LV1_ACCESS_VIOLATION (-5)";
  223. case LV1_NO_ENTRY:
  224. return "LV1_NO_ENTRY (-6)";
  225. case LV1_DUPLICATE_ENTRY:
  226. return "LV1_DUPLICATE_ENTRY (-7)";
  227. case LV1_TYPE_MISMATCH:
  228. return "LV1_TYPE_MISMATCH (-8)";
  229. case LV1_BUSY:
  230. return "LV1_BUSY (-9)";
  231. case LV1_EMPTY:
  232. return "LV1_EMPTY (-10)";
  233. case LV1_WRONG_STATE:
  234. return "LV1_WRONG_STATE (-11)";
  235. case -12:
  236. return "** unknown result ** (-12)";
  237. case LV1_NO_MATCH:
  238. return "LV1_NO_MATCH (-13)";
  239. case LV1_ALREADY_CONNECTED:
  240. return "LV1_ALREADY_CONNECTED (-14)";
  241. case LV1_UNSUPPORTED_PARAMETER_VALUE:
  242. return "LV1_UNSUPPORTED_PARAMETER_VALUE (-15)";
  243. case LV1_CONDITION_NOT_SATISFIED:
  244. return "LV1_CONDITION_NOT_SATISFIED (-16)";
  245. case LV1_ILLEGAL_PARAMETER_VALUE:
  246. return "LV1_ILLEGAL_PARAMETER_VALUE (-17)";
  247. case LV1_BAD_OPTION:
  248. return "LV1_BAD_OPTION (-18)";
  249. case LV1_IMPLEMENTATION_LIMITATION:
  250. return "LV1_IMPLEMENTATION_LIMITATION (-19)";
  251. case LV1_NOT_IMPLEMENTED:
  252. return "LV1_NOT_IMPLEMENTED (-20)";
  253. case LV1_INVALID_CLASS_ID:
  254. return "LV1_INVALID_CLASS_ID (-21)";
  255. case LV1_CONSTRAINT_NOT_SATISFIED:
  256. return "LV1_CONSTRAINT_NOT_SATISFIED (-22)";
  257. case LV1_ALIGNMENT_ERROR:
  258. return "LV1_ALIGNMENT_ERROR (-23)";
  259. case LV1_HARDWARE_ERROR:
  260. return "LV1_HARDWARE_ERROR (-24)";
  261. case LV1_INVALID_DATA_FORMAT:
  262. return "LV1_INVALID_DATA_FORMAT (-25)";
  263. case LV1_INVALID_OPERATION:
  264. return "LV1_INVALID_OPERATION (-26)";
  265. case LV1_INTERNAL_ERROR:
  266. return "LV1_INTERNAL_ERROR (-32768)";
  267. default:
  268. BUG();
  269. return "** unknown result **";
  270. };
  271. #else
  272. return "";
  273. #endif
  274. }
  275. /* system bus routines */
  276. enum ps3_match_id {
  277. PS3_MATCH_ID_EHCI = 1,
  278. PS3_MATCH_ID_OHCI = 2,
  279. PS3_MATCH_ID_GELIC = 3,
  280. PS3_MATCH_ID_AV_SETTINGS = 4,
  281. PS3_MATCH_ID_SYSTEM_MANAGER = 5,
  282. PS3_MATCH_ID_STOR_DISK = 6,
  283. PS3_MATCH_ID_STOR_ROM = 7,
  284. PS3_MATCH_ID_STOR_FLASH = 8,
  285. PS3_MATCH_ID_SOUND = 9,
  286. PS3_MATCH_ID_GRAPHICS = 10,
  287. };
  288. #define PS3_MODULE_ALIAS_EHCI "ps3:1"
  289. #define PS3_MODULE_ALIAS_OHCI "ps3:2"
  290. #define PS3_MODULE_ALIAS_GELIC "ps3:3"
  291. #define PS3_MODULE_ALIAS_AV_SETTINGS "ps3:4"
  292. #define PS3_MODULE_ALIAS_SYSTEM_MANAGER "ps3:5"
  293. #define PS3_MODULE_ALIAS_STOR_DISK "ps3:6"
  294. #define PS3_MODULE_ALIAS_STOR_ROM "ps3:7"
  295. #define PS3_MODULE_ALIAS_STOR_FLASH "ps3:8"
  296. #define PS3_MODULE_ALIAS_SOUND "ps3:9"
  297. #define PS3_MODULE_ALIAS_GRAPHICS "ps3:10"
  298. enum ps3_system_bus_device_type {
  299. PS3_DEVICE_TYPE_IOC0 = 1,
  300. PS3_DEVICE_TYPE_SB,
  301. PS3_DEVICE_TYPE_VUART,
  302. };
  303. /**
  304. * struct ps3_system_bus_device - a device on the system bus
  305. */
  306. struct ps3_system_bus_device {
  307. enum ps3_match_id match_id;
  308. enum ps3_system_bus_device_type dev_type;
  309. unsigned int bus_id; /* SB */
  310. unsigned int dev_id; /* SB */
  311. unsigned int interrupt_id; /* SB */
  312. struct ps3_dma_region *d_region; /* SB, IOC0 */
  313. struct ps3_mmio_region *m_region; /* SB, IOC0*/
  314. unsigned int port_number; /* VUART */
  315. /* struct iommu_table *iommu_table; -- waiting for BenH's cleanups */
  316. struct device core;
  317. void *driver_priv; /* private driver variables */
  318. };
  319. int ps3_open_hv_device(struct ps3_system_bus_device *dev);
  320. int ps3_close_hv_device(struct ps3_system_bus_device *dev);
  321. /**
  322. * struct ps3_system_bus_driver - a driver for a device on the system bus
  323. */
  324. struct ps3_system_bus_driver {
  325. enum ps3_match_id match_id;
  326. struct device_driver core;
  327. int (*probe)(struct ps3_system_bus_device *);
  328. int (*remove)(struct ps3_system_bus_device *);
  329. int (*shutdown)(struct ps3_system_bus_device *);
  330. /* int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
  331. /* int (*resume)(struct ps3_system_bus_device *); */
  332. };
  333. int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
  334. int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
  335. void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
  336. static inline struct ps3_system_bus_driver *ps3_drv_to_system_bus_drv(
  337. struct device_driver *_drv)
  338. {
  339. return container_of(_drv, struct ps3_system_bus_driver, core);
  340. }
  341. static inline struct ps3_system_bus_device *ps3_dev_to_system_bus_dev(
  342. struct device *_dev)
  343. {
  344. return container_of(_dev, struct ps3_system_bus_device, core);
  345. }
  346. static inline struct ps3_system_bus_driver *
  347. ps3_system_bus_dev_to_system_bus_drv(struct ps3_system_bus_device *_dev)
  348. {
  349. BUG_ON(!_dev);
  350. BUG_ON(!_dev->core.driver);
  351. return ps3_drv_to_system_bus_drv(_dev->core.driver);
  352. }
  353. /**
  354. * ps3_system_bus_set_drvdata -
  355. * @dev: device structure
  356. * @data: Data to set
  357. */
  358. static inline void ps3_system_bus_set_driver_data(
  359. struct ps3_system_bus_device *dev, void *data)
  360. {
  361. dev->core.driver_data = data;
  362. }
  363. static inline void *ps3_system_bus_get_driver_data(
  364. struct ps3_system_bus_device *dev)
  365. {
  366. return dev->core.driver_data;
  367. }
  368. /* These two need global scope for get_dma_ops(). */
  369. extern struct bus_type ps3_system_bus_type;
  370. /* system manager */
  371. struct ps3_sys_manager_ops {
  372. struct ps3_system_bus_device *dev;
  373. void (*power_off)(struct ps3_system_bus_device *dev);
  374. void (*restart)(struct ps3_system_bus_device *dev);
  375. };
  376. void ps3_sys_manager_register_ops(const struct ps3_sys_manager_ops *ops);
  377. void ps3_sys_manager_power_off(void);
  378. void ps3_sys_manager_restart(void);
  379. struct ps3_prealloc {
  380. const char *name;
  381. void *address;
  382. unsigned long size;
  383. unsigned long align;
  384. };
  385. extern struct ps3_prealloc ps3fb_videomemory;
  386. extern struct ps3_prealloc ps3flash_bounce_buffer;
  387. #endif