ps3.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. int ps3_get_firmware_version(union ps3_firmware_version *v);
  35. /* 'Other OS' area */
  36. enum ps3_param_av_multi_out {
  37. PS3_PARAM_AV_MULTI_OUT_NTSC = 0,
  38. PS3_PARAM_AV_MULTI_OUT_PAL_RGB = 1,
  39. PS3_PARAM_AV_MULTI_OUT_PAL_YCBCR = 2,
  40. PS3_PARAM_AV_MULTI_OUT_SECAM = 3,
  41. };
  42. enum ps3_param_av_multi_out ps3_os_area_get_av_multi_out(void);
  43. /**
  44. * struct ps3_device_id - HV bus device identifier from the system repository
  45. * @bus_id: HV bus id, {1..} (zero invalid)
  46. * @dev_id: HV device id, {0..}
  47. */
  48. struct ps3_device_id {
  49. unsigned int bus_id;
  50. unsigned int dev_id;
  51. };
  52. /* dma routines */
  53. enum ps3_dma_page_size {
  54. PS3_DMA_4K = 12U,
  55. PS3_DMA_64K = 16U,
  56. PS3_DMA_1M = 20U,
  57. PS3_DMA_16M = 24U,
  58. };
  59. enum ps3_dma_region_type {
  60. PS3_DMA_OTHER = 0,
  61. PS3_DMA_INTERNAL = 2,
  62. };
  63. /**
  64. * struct ps3_dma_region - A per device dma state variables structure
  65. * @did: The HV device id.
  66. * @page_size: The ioc pagesize.
  67. * @region_type: The HV region type.
  68. * @bus_addr: The 'translated' bus address of the region.
  69. * @len: The length in bytes of the region.
  70. * @chunk_list: Opaque variable used by the ioc page manager.
  71. */
  72. struct ps3_dma_region {
  73. struct ps3_device_id did;
  74. enum ps3_dma_page_size page_size;
  75. enum ps3_dma_region_type region_type;
  76. unsigned long bus_addr;
  77. unsigned long len;
  78. struct {
  79. spinlock_t lock;
  80. struct list_head head;
  81. } chunk_list;
  82. };
  83. /**
  84. * struct ps3_dma_region_init - Helper to initialize structure variables
  85. *
  86. * Helper to properly initialize variables prior to calling
  87. * ps3_system_bus_device_register.
  88. */
  89. static inline void ps3_dma_region_init(struct ps3_dma_region *r,
  90. const struct ps3_device_id* did, enum ps3_dma_page_size page_size,
  91. enum ps3_dma_region_type region_type)
  92. {
  93. r->did = *did;
  94. r->page_size = page_size;
  95. r->region_type = region_type;
  96. }
  97. int ps3_dma_region_create(struct ps3_dma_region *r);
  98. int ps3_dma_region_free(struct ps3_dma_region *r);
  99. int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
  100. unsigned long len, unsigned long *bus_addr);
  101. int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
  102. unsigned long len);
  103. /* mmio routines */
  104. enum ps3_mmio_page_size {
  105. PS3_MMIO_4K = 12U,
  106. PS3_MMIO_64K = 16U
  107. };
  108. /**
  109. * struct ps3_mmio_region - a per device mmio state variables structure
  110. *
  111. * Current systems can be supported with a single region per device.
  112. */
  113. struct ps3_mmio_region {
  114. struct ps3_device_id did;
  115. unsigned long bus_addr;
  116. unsigned long len;
  117. enum ps3_mmio_page_size page_size;
  118. unsigned long lpar_addr;
  119. };
  120. /**
  121. * struct ps3_mmio_region_init - Helper to initialize structure variables
  122. *
  123. * Helper to properly initialize variables prior to calling
  124. * ps3_system_bus_device_register.
  125. */
  126. static inline void ps3_mmio_region_init(struct ps3_mmio_region *r,
  127. const struct ps3_device_id* did, unsigned long bus_addr,
  128. unsigned long len, enum ps3_mmio_page_size page_size)
  129. {
  130. r->did = *did;
  131. r->bus_addr = bus_addr;
  132. r->len = len;
  133. r->page_size = page_size;
  134. }
  135. int ps3_mmio_region_create(struct ps3_mmio_region *r);
  136. int ps3_free_mmio_region(struct ps3_mmio_region *r);
  137. unsigned long ps3_mm_phys_to_lpar(unsigned long phys_addr);
  138. /* inrerrupt routines */
  139. enum ps3_cpu_binding {
  140. PS3_BINDING_CPU_ANY = -1,
  141. PS3_BINDING_CPU_0 = 0,
  142. PS3_BINDING_CPU_1 = 1,
  143. };
  144. int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
  145. unsigned int *virq);
  146. int ps3_virq_destroy(unsigned int virq);
  147. int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
  148. unsigned int *virq);
  149. int ps3_irq_plug_destroy(unsigned int virq);
  150. int ps3_event_receive_port_setup(enum ps3_cpu_binding cpu, unsigned int *virq);
  151. int ps3_event_receive_port_destroy(unsigned int virq);
  152. int ps3_send_event_locally(unsigned int virq);
  153. int ps3_io_irq_setup(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
  154. unsigned int *virq);
  155. int ps3_io_irq_destroy(unsigned int virq);
  156. int ps3_vuart_irq_setup(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
  157. unsigned int *virq);
  158. int ps3_vuart_irq_destroy(unsigned int virq);
  159. int ps3_spe_irq_setup(enum ps3_cpu_binding cpu, unsigned long spe_id,
  160. unsigned int class, unsigned int *virq);
  161. int ps3_spe_irq_destroy(unsigned int virq);
  162. int ps3_sb_event_receive_port_setup(enum ps3_cpu_binding cpu,
  163. const struct ps3_device_id *did, unsigned int interrupt_id,
  164. unsigned int *virq);
  165. int ps3_sb_event_receive_port_destroy(const struct ps3_device_id *did,
  166. unsigned int interrupt_id, unsigned int virq);
  167. /* lv1 result codes */
  168. enum lv1_result {
  169. LV1_SUCCESS = 0,
  170. /* not used -1 */
  171. LV1_RESOURCE_SHORTAGE = -2,
  172. LV1_NO_PRIVILEGE = -3,
  173. LV1_DENIED_BY_POLICY = -4,
  174. LV1_ACCESS_VIOLATION = -5,
  175. LV1_NO_ENTRY = -6,
  176. LV1_DUPLICATE_ENTRY = -7,
  177. LV1_TYPE_MISMATCH = -8,
  178. LV1_BUSY = -9,
  179. LV1_EMPTY = -10,
  180. LV1_WRONG_STATE = -11,
  181. /* not used -12 */
  182. LV1_NO_MATCH = -13,
  183. LV1_ALREADY_CONNECTED = -14,
  184. LV1_UNSUPPORTED_PARAMETER_VALUE = -15,
  185. LV1_CONDITION_NOT_SATISFIED = -16,
  186. LV1_ILLEGAL_PARAMETER_VALUE = -17,
  187. LV1_BAD_OPTION = -18,
  188. LV1_IMPLEMENTATION_LIMITATION = -19,
  189. LV1_NOT_IMPLEMENTED = -20,
  190. LV1_INVALID_CLASS_ID = -21,
  191. LV1_CONSTRAINT_NOT_SATISFIED = -22,
  192. LV1_ALIGNMENT_ERROR = -23,
  193. LV1_INTERNAL_ERROR = -32768,
  194. };
  195. static inline const char* ps3_result(int result)
  196. {
  197. #if defined(DEBUG)
  198. switch (result) {
  199. case LV1_SUCCESS:
  200. return "LV1_SUCCESS (0)";
  201. case -1:
  202. return "** unknown result ** (-1)";
  203. case LV1_RESOURCE_SHORTAGE:
  204. return "LV1_RESOURCE_SHORTAGE (-2)";
  205. case LV1_NO_PRIVILEGE:
  206. return "LV1_NO_PRIVILEGE (-3)";
  207. case LV1_DENIED_BY_POLICY:
  208. return "LV1_DENIED_BY_POLICY (-4)";
  209. case LV1_ACCESS_VIOLATION:
  210. return "LV1_ACCESS_VIOLATION (-5)";
  211. case LV1_NO_ENTRY:
  212. return "LV1_NO_ENTRY (-6)";
  213. case LV1_DUPLICATE_ENTRY:
  214. return "LV1_DUPLICATE_ENTRY (-7)";
  215. case LV1_TYPE_MISMATCH:
  216. return "LV1_TYPE_MISMATCH (-8)";
  217. case LV1_BUSY:
  218. return "LV1_BUSY (-9)";
  219. case LV1_EMPTY:
  220. return "LV1_EMPTY (-10)";
  221. case LV1_WRONG_STATE:
  222. return "LV1_WRONG_STATE (-11)";
  223. case -12:
  224. return "** unknown result ** (-12)";
  225. case LV1_NO_MATCH:
  226. return "LV1_NO_MATCH (-13)";
  227. case LV1_ALREADY_CONNECTED:
  228. return "LV1_ALREADY_CONNECTED (-14)";
  229. case LV1_UNSUPPORTED_PARAMETER_VALUE:
  230. return "LV1_UNSUPPORTED_PARAMETER_VALUE (-15)";
  231. case LV1_CONDITION_NOT_SATISFIED:
  232. return "LV1_CONDITION_NOT_SATISFIED (-16)";
  233. case LV1_ILLEGAL_PARAMETER_VALUE:
  234. return "LV1_ILLEGAL_PARAMETER_VALUE (-17)";
  235. case LV1_BAD_OPTION:
  236. return "LV1_BAD_OPTION (-18)";
  237. case LV1_IMPLEMENTATION_LIMITATION:
  238. return "LV1_IMPLEMENTATION_LIMITATION (-19)";
  239. case LV1_NOT_IMPLEMENTED:
  240. return "LV1_NOT_IMPLEMENTED (-20)";
  241. case LV1_INVALID_CLASS_ID:
  242. return "LV1_INVALID_CLASS_ID (-21)";
  243. case LV1_CONSTRAINT_NOT_SATISFIED:
  244. return "LV1_CONSTRAINT_NOT_SATISFIED (-22)";
  245. case LV1_ALIGNMENT_ERROR:
  246. return "LV1_ALIGNMENT_ERROR (-23)";
  247. case LV1_INTERNAL_ERROR:
  248. return "LV1_INTERNAL_ERROR (-32768)";
  249. default:
  250. BUG();
  251. return "** unknown result **";
  252. };
  253. #else
  254. return "";
  255. #endif
  256. }
  257. /* system bus routines */
  258. enum ps3_match_id {
  259. PS3_MATCH_ID_EHCI = 1,
  260. PS3_MATCH_ID_OHCI,
  261. PS3_MATCH_ID_GELIC,
  262. PS3_MATCH_ID_AV_SETTINGS,
  263. PS3_MATCH_ID_SYSTEM_MANAGER,
  264. };
  265. /**
  266. * struct ps3_system_bus_device - a device on the system bus
  267. */
  268. struct ps3_system_bus_device {
  269. enum ps3_match_id match_id;
  270. struct ps3_device_id did;
  271. unsigned int interrupt_id;
  272. /* struct iommu_table *iommu_table; -- waiting for Ben's cleanups */
  273. struct ps3_dma_region *d_region;
  274. struct ps3_mmio_region *m_region;
  275. struct device core;
  276. };
  277. /**
  278. * struct ps3_system_bus_driver - a driver for a device on the system bus
  279. */
  280. struct ps3_system_bus_driver {
  281. enum ps3_match_id match_id;
  282. struct device_driver core;
  283. int (*probe)(struct ps3_system_bus_device *);
  284. int (*remove)(struct ps3_system_bus_device *);
  285. /* int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
  286. /* int (*resume)(struct ps3_system_bus_device *); */
  287. };
  288. int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
  289. int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
  290. void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
  291. static inline struct ps3_system_bus_driver *to_ps3_system_bus_driver(
  292. struct device_driver *_drv)
  293. {
  294. return container_of(_drv, struct ps3_system_bus_driver, core);
  295. }
  296. static inline struct ps3_system_bus_device *to_ps3_system_bus_device(
  297. struct device *_dev)
  298. {
  299. return container_of(_dev, struct ps3_system_bus_device, core);
  300. }
  301. /**
  302. * ps3_system_bus_set_drvdata -
  303. * @dev: device structure
  304. * @data: Data to set
  305. */
  306. static inline void ps3_system_bus_set_driver_data(
  307. struct ps3_system_bus_device *dev, void *data)
  308. {
  309. dev->core.driver_data = data;
  310. }
  311. static inline void *ps3_system_bus_get_driver_data(
  312. struct ps3_system_bus_device *dev)
  313. {
  314. return dev->core.driver_data;
  315. }
  316. /* These two need global scope for get_dma_ops(). */
  317. extern struct bus_type ps3_system_bus_type;
  318. /* vuart routines */
  319. struct ps3_vuart_port_priv;
  320. /**
  321. * struct ps3_vuart_port_device - a device on a vuart port
  322. */
  323. struct ps3_vuart_port_device {
  324. enum ps3_match_id match_id;
  325. struct device core;
  326. struct ps3_vuart_port_priv* priv; /* private driver variables */
  327. };
  328. int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev);
  329. /* system manager */
  330. #ifdef CONFIG_PS3_SYS_MANAGER
  331. void ps3_sys_manager_restart(void);
  332. void ps3_sys_manager_power_off(void);
  333. #else
  334. static inline void ps3_sys_manager_restart(void) {}
  335. static inline void ps3_sys_manager_power_off(void) {}
  336. #endif
  337. struct ps3_prealloc {
  338. const char *name;
  339. void *address;
  340. unsigned long size;
  341. unsigned long align;
  342. };
  343. extern struct ps3_prealloc ps3fb_videomemory;
  344. #endif