ps3.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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 "cell-pmu.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. void ps3_get_firmware_version(union ps3_firmware_version *v);
  36. int ps3_compare_firmware_version(u16 major, u16 minor, u16 rev);
  37. /* 'Other OS' area */
  38. enum ps3_param_av_multi_out {
  39. PS3_PARAM_AV_MULTI_OUT_NTSC = 0,
  40. PS3_PARAM_AV_MULTI_OUT_PAL_RGB = 1,
  41. PS3_PARAM_AV_MULTI_OUT_PAL_YCBCR = 2,
  42. PS3_PARAM_AV_MULTI_OUT_SECAM = 3,
  43. };
  44. enum ps3_param_av_multi_out ps3_os_area_get_av_multi_out(void);
  45. /* dma routines */
  46. enum ps3_dma_page_size {
  47. PS3_DMA_4K = 12U,
  48. PS3_DMA_64K = 16U,
  49. PS3_DMA_1M = 20U,
  50. PS3_DMA_16M = 24U,
  51. };
  52. enum ps3_dma_region_type {
  53. PS3_DMA_OTHER = 0,
  54. PS3_DMA_INTERNAL = 2,
  55. };
  56. struct ps3_dma_region_ops;
  57. /**
  58. * struct ps3_dma_region - A per device dma state variables structure
  59. * @did: The HV device id.
  60. * @page_size: The ioc pagesize.
  61. * @region_type: The HV region type.
  62. * @bus_addr: The 'translated' bus address of the region.
  63. * @len: The length in bytes of the region.
  64. * @offset: The offset from the start of memory of the region.
  65. * @ioid: The IOID of the device who owns this region
  66. * @chunk_list: Opaque variable used by the ioc page manager.
  67. * @region_ops: struct ps3_dma_region_ops - dma region operations
  68. */
  69. struct ps3_dma_region {
  70. struct ps3_system_bus_device *dev;
  71. /* device variables */
  72. const struct ps3_dma_region_ops *region_ops;
  73. unsigned char ioid;
  74. enum ps3_dma_page_size page_size;
  75. enum ps3_dma_region_type region_type;
  76. unsigned long len;
  77. unsigned long offset;
  78. /* driver variables (set by ps3_dma_region_create) */
  79. unsigned long bus_addr;
  80. struct {
  81. spinlock_t lock;
  82. struct list_head head;
  83. } chunk_list;
  84. };
  85. struct ps3_dma_region_ops {
  86. int (*create)(struct ps3_dma_region *);
  87. int (*free)(struct ps3_dma_region *);
  88. int (*map)(struct ps3_dma_region *,
  89. unsigned long virt_addr,
  90. unsigned long len,
  91. unsigned long *bus_addr,
  92. u64 iopte_pp);
  93. int (*unmap)(struct ps3_dma_region *,
  94. unsigned long bus_addr,
  95. unsigned long len);
  96. };
  97. /**
  98. * struct ps3_dma_region_init - Helper to initialize structure variables
  99. *
  100. * Helper to properly initialize variables prior to calling
  101. * ps3_system_bus_device_register.
  102. */
  103. struct ps3_system_bus_device;
  104. int ps3_dma_region_init(struct ps3_system_bus_device *dev,
  105. struct ps3_dma_region *r, enum ps3_dma_page_size page_size,
  106. enum ps3_dma_region_type region_type, void *addr, unsigned long len);
  107. int ps3_dma_region_create(struct ps3_dma_region *r);
  108. int ps3_dma_region_free(struct ps3_dma_region *r);
  109. int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
  110. unsigned long len, unsigned long *bus_addr,
  111. u64 iopte_pp);
  112. int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
  113. unsigned long len);
  114. /* mmio routines */
  115. enum ps3_mmio_page_size {
  116. PS3_MMIO_4K = 12U,
  117. PS3_MMIO_64K = 16U
  118. };
  119. struct ps3_mmio_region_ops;
  120. /**
  121. * struct ps3_mmio_region - a per device mmio state variables structure
  122. *
  123. * Current systems can be supported with a single region per device.
  124. */
  125. struct ps3_mmio_region {
  126. struct ps3_system_bus_device *dev;
  127. const struct ps3_mmio_region_ops *mmio_ops;
  128. unsigned long bus_addr;
  129. unsigned long len;
  130. enum ps3_mmio_page_size page_size;
  131. unsigned long lpar_addr;
  132. };
  133. struct ps3_mmio_region_ops {
  134. int (*create)(struct ps3_mmio_region *);
  135. int (*free)(struct ps3_mmio_region *);
  136. };
  137. /**
  138. * struct ps3_mmio_region_init - Helper to initialize structure variables
  139. *
  140. * Helper to properly initialize variables prior to calling
  141. * ps3_system_bus_device_register.
  142. */
  143. int ps3_mmio_region_init(struct ps3_system_bus_device *dev,
  144. struct ps3_mmio_region *r, unsigned long bus_addr, unsigned long len,
  145. enum ps3_mmio_page_size page_size);
  146. int ps3_mmio_region_create(struct ps3_mmio_region *r);
  147. int ps3_free_mmio_region(struct ps3_mmio_region *r);
  148. unsigned long ps3_mm_phys_to_lpar(unsigned long phys_addr);
  149. /* inrerrupt routines */
  150. enum ps3_cpu_binding {
  151. PS3_BINDING_CPU_ANY = -1,
  152. PS3_BINDING_CPU_0 = 0,
  153. PS3_BINDING_CPU_1 = 1,
  154. };
  155. int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
  156. unsigned int *virq);
  157. int ps3_irq_plug_destroy(unsigned int virq);
  158. int ps3_event_receive_port_setup(enum ps3_cpu_binding cpu, unsigned int *virq);
  159. int ps3_event_receive_port_destroy(unsigned int virq);
  160. int ps3_send_event_locally(unsigned int virq);
  161. int ps3_io_irq_setup(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
  162. unsigned int *virq);
  163. int ps3_io_irq_destroy(unsigned int virq);
  164. int ps3_vuart_irq_setup(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
  165. unsigned int *virq);
  166. int ps3_vuart_irq_destroy(unsigned int virq);
  167. int ps3_spe_irq_setup(enum ps3_cpu_binding cpu, unsigned long spe_id,
  168. unsigned int class, unsigned int *virq);
  169. int ps3_spe_irq_destroy(unsigned int virq);
  170. int ps3_sb_event_receive_port_setup(struct ps3_system_bus_device *dev,
  171. enum ps3_cpu_binding cpu, unsigned int *virq);
  172. int ps3_sb_event_receive_port_destroy(struct ps3_system_bus_device *dev,
  173. unsigned int virq);
  174. /* lv1 result codes */
  175. enum lv1_result {
  176. LV1_SUCCESS = 0,
  177. /* not used -1 */
  178. LV1_RESOURCE_SHORTAGE = -2,
  179. LV1_NO_PRIVILEGE = -3,
  180. LV1_DENIED_BY_POLICY = -4,
  181. LV1_ACCESS_VIOLATION = -5,
  182. LV1_NO_ENTRY = -6,
  183. LV1_DUPLICATE_ENTRY = -7,
  184. LV1_TYPE_MISMATCH = -8,
  185. LV1_BUSY = -9,
  186. LV1_EMPTY = -10,
  187. LV1_WRONG_STATE = -11,
  188. /* not used -12 */
  189. LV1_NO_MATCH = -13,
  190. LV1_ALREADY_CONNECTED = -14,
  191. LV1_UNSUPPORTED_PARAMETER_VALUE = -15,
  192. LV1_CONDITION_NOT_SATISFIED = -16,
  193. LV1_ILLEGAL_PARAMETER_VALUE = -17,
  194. LV1_BAD_OPTION = -18,
  195. LV1_IMPLEMENTATION_LIMITATION = -19,
  196. LV1_NOT_IMPLEMENTED = -20,
  197. LV1_INVALID_CLASS_ID = -21,
  198. LV1_CONSTRAINT_NOT_SATISFIED = -22,
  199. LV1_ALIGNMENT_ERROR = -23,
  200. LV1_HARDWARE_ERROR = -24,
  201. LV1_INVALID_DATA_FORMAT = -25,
  202. LV1_INVALID_OPERATION = -26,
  203. LV1_INTERNAL_ERROR = -32768,
  204. };
  205. static inline const char* ps3_result(int result)
  206. {
  207. #if defined(DEBUG)
  208. switch (result) {
  209. case LV1_SUCCESS:
  210. return "LV1_SUCCESS (0)";
  211. case -1:
  212. return "** unknown result ** (-1)";
  213. case LV1_RESOURCE_SHORTAGE:
  214. return "LV1_RESOURCE_SHORTAGE (-2)";
  215. case LV1_NO_PRIVILEGE:
  216. return "LV1_NO_PRIVILEGE (-3)";
  217. case LV1_DENIED_BY_POLICY:
  218. return "LV1_DENIED_BY_POLICY (-4)";
  219. case LV1_ACCESS_VIOLATION:
  220. return "LV1_ACCESS_VIOLATION (-5)";
  221. case LV1_NO_ENTRY:
  222. return "LV1_NO_ENTRY (-6)";
  223. case LV1_DUPLICATE_ENTRY:
  224. return "LV1_DUPLICATE_ENTRY (-7)";
  225. case LV1_TYPE_MISMATCH:
  226. return "LV1_TYPE_MISMATCH (-8)";
  227. case LV1_BUSY:
  228. return "LV1_BUSY (-9)";
  229. case LV1_EMPTY:
  230. return "LV1_EMPTY (-10)";
  231. case LV1_WRONG_STATE:
  232. return "LV1_WRONG_STATE (-11)";
  233. case -12:
  234. return "** unknown result ** (-12)";
  235. case LV1_NO_MATCH:
  236. return "LV1_NO_MATCH (-13)";
  237. case LV1_ALREADY_CONNECTED:
  238. return "LV1_ALREADY_CONNECTED (-14)";
  239. case LV1_UNSUPPORTED_PARAMETER_VALUE:
  240. return "LV1_UNSUPPORTED_PARAMETER_VALUE (-15)";
  241. case LV1_CONDITION_NOT_SATISFIED:
  242. return "LV1_CONDITION_NOT_SATISFIED (-16)";
  243. case LV1_ILLEGAL_PARAMETER_VALUE:
  244. return "LV1_ILLEGAL_PARAMETER_VALUE (-17)";
  245. case LV1_BAD_OPTION:
  246. return "LV1_BAD_OPTION (-18)";
  247. case LV1_IMPLEMENTATION_LIMITATION:
  248. return "LV1_IMPLEMENTATION_LIMITATION (-19)";
  249. case LV1_NOT_IMPLEMENTED:
  250. return "LV1_NOT_IMPLEMENTED (-20)";
  251. case LV1_INVALID_CLASS_ID:
  252. return "LV1_INVALID_CLASS_ID (-21)";
  253. case LV1_CONSTRAINT_NOT_SATISFIED:
  254. return "LV1_CONSTRAINT_NOT_SATISFIED (-22)";
  255. case LV1_ALIGNMENT_ERROR:
  256. return "LV1_ALIGNMENT_ERROR (-23)";
  257. case LV1_HARDWARE_ERROR:
  258. return "LV1_HARDWARE_ERROR (-24)";
  259. case LV1_INVALID_DATA_FORMAT:
  260. return "LV1_INVALID_DATA_FORMAT (-25)";
  261. case LV1_INVALID_OPERATION:
  262. return "LV1_INVALID_OPERATION (-26)";
  263. case LV1_INTERNAL_ERROR:
  264. return "LV1_INTERNAL_ERROR (-32768)";
  265. default:
  266. BUG();
  267. return "** unknown result **";
  268. };
  269. #else
  270. return "";
  271. #endif
  272. }
  273. /* system bus routines */
  274. enum ps3_match_id {
  275. PS3_MATCH_ID_EHCI = 1,
  276. PS3_MATCH_ID_OHCI = 2,
  277. PS3_MATCH_ID_GELIC = 3,
  278. PS3_MATCH_ID_AV_SETTINGS = 4,
  279. PS3_MATCH_ID_SYSTEM_MANAGER = 5,
  280. PS3_MATCH_ID_STOR_DISK = 6,
  281. PS3_MATCH_ID_STOR_ROM = 7,
  282. PS3_MATCH_ID_STOR_FLASH = 8,
  283. PS3_MATCH_ID_SOUND = 9,
  284. PS3_MATCH_ID_GRAPHICS = 10,
  285. PS3_MATCH_ID_LPM = 11,
  286. };
  287. #define PS3_MODULE_ALIAS_EHCI "ps3:1"
  288. #define PS3_MODULE_ALIAS_OHCI "ps3:2"
  289. #define PS3_MODULE_ALIAS_GELIC "ps3:3"
  290. #define PS3_MODULE_ALIAS_AV_SETTINGS "ps3:4"
  291. #define PS3_MODULE_ALIAS_SYSTEM_MANAGER "ps3:5"
  292. #define PS3_MODULE_ALIAS_STOR_DISK "ps3:6"
  293. #define PS3_MODULE_ALIAS_STOR_ROM "ps3:7"
  294. #define PS3_MODULE_ALIAS_STOR_FLASH "ps3:8"
  295. #define PS3_MODULE_ALIAS_SOUND "ps3:9"
  296. #define PS3_MODULE_ALIAS_GRAPHICS "ps3:10"
  297. #define PS3_MODULE_ALIAS_LPM "ps3:11"
  298. enum ps3_system_bus_device_type {
  299. PS3_DEVICE_TYPE_IOC0 = 1,
  300. PS3_DEVICE_TYPE_SB,
  301. PS3_DEVICE_TYPE_VUART,
  302. PS3_DEVICE_TYPE_LPM,
  303. };
  304. enum ps3_match_sub_id {
  305. /* for PS3_MATCH_ID_GRAPHICS */
  306. PS3_MATCH_SUB_ID_FB = 1,
  307. };
  308. /**
  309. * struct ps3_system_bus_device - a device on the system bus
  310. */
  311. struct ps3_system_bus_device {
  312. enum ps3_match_id match_id;
  313. enum ps3_match_sub_id match_sub_id;
  314. enum ps3_system_bus_device_type dev_type;
  315. u64 bus_id; /* SB */
  316. u64 dev_id; /* SB */
  317. unsigned int interrupt_id; /* SB */
  318. struct ps3_dma_region *d_region; /* SB, IOC0 */
  319. struct ps3_mmio_region *m_region; /* SB, IOC0*/
  320. unsigned int port_number; /* VUART */
  321. struct { /* LPM */
  322. u64 node_id;
  323. u64 pu_id;
  324. u64 rights;
  325. } lpm;
  326. /* struct iommu_table *iommu_table; -- waiting for BenH's cleanups */
  327. struct device core;
  328. void *driver_priv; /* private driver variables */
  329. };
  330. int ps3_open_hv_device(struct ps3_system_bus_device *dev);
  331. int ps3_close_hv_device(struct ps3_system_bus_device *dev);
  332. /**
  333. * struct ps3_system_bus_driver - a driver for a device on the system bus
  334. */
  335. struct ps3_system_bus_driver {
  336. enum ps3_match_id match_id;
  337. enum ps3_match_sub_id match_sub_id;
  338. struct device_driver core;
  339. int (*probe)(struct ps3_system_bus_device *);
  340. int (*remove)(struct ps3_system_bus_device *);
  341. int (*shutdown)(struct ps3_system_bus_device *);
  342. /* int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
  343. /* int (*resume)(struct ps3_system_bus_device *); */
  344. };
  345. int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
  346. int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
  347. void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
  348. static inline struct ps3_system_bus_driver *ps3_drv_to_system_bus_drv(
  349. struct device_driver *_drv)
  350. {
  351. return container_of(_drv, struct ps3_system_bus_driver, core);
  352. }
  353. static inline struct ps3_system_bus_device *ps3_dev_to_system_bus_dev(
  354. struct device *_dev)
  355. {
  356. return container_of(_dev, struct ps3_system_bus_device, core);
  357. }
  358. static inline struct ps3_system_bus_driver *
  359. ps3_system_bus_dev_to_system_bus_drv(struct ps3_system_bus_device *_dev)
  360. {
  361. BUG_ON(!_dev);
  362. BUG_ON(!_dev->core.driver);
  363. return ps3_drv_to_system_bus_drv(_dev->core.driver);
  364. }
  365. /**
  366. * ps3_system_bus_set_drvdata -
  367. * @dev: device structure
  368. * @data: Data to set
  369. */
  370. static inline void ps3_system_bus_set_driver_data(
  371. struct ps3_system_bus_device *dev, void *data)
  372. {
  373. dev->core.driver_data = data;
  374. }
  375. static inline void *ps3_system_bus_get_driver_data(
  376. struct ps3_system_bus_device *dev)
  377. {
  378. return dev->core.driver_data;
  379. }
  380. /* These two need global scope for get_dma_ops(). */
  381. extern struct bus_type ps3_system_bus_type;
  382. /* system manager */
  383. struct ps3_sys_manager_ops {
  384. struct ps3_system_bus_device *dev;
  385. void (*power_off)(struct ps3_system_bus_device *dev);
  386. void (*restart)(struct ps3_system_bus_device *dev);
  387. };
  388. void ps3_sys_manager_register_ops(const struct ps3_sys_manager_ops *ops);
  389. void __noreturn ps3_sys_manager_power_off(void);
  390. void __noreturn ps3_sys_manager_restart(void);
  391. void __noreturn ps3_sys_manager_halt(void);
  392. int ps3_sys_manager_get_wol(void);
  393. void ps3_sys_manager_set_wol(int state);
  394. struct ps3_prealloc {
  395. const char *name;
  396. void *address;
  397. unsigned long size;
  398. unsigned long align;
  399. };
  400. extern struct ps3_prealloc ps3fb_videomemory;
  401. extern struct ps3_prealloc ps3flash_bounce_buffer;
  402. /* logical performance monitor */
  403. /**
  404. * enum ps3_lpm_rights - Rigths granted by the system policy module.
  405. *
  406. * @PS3_LPM_RIGHTS_USE_LPM: The right to use the lpm.
  407. * @PS3_LPM_RIGHTS_USE_TB: The right to use the internal trace buffer.
  408. */
  409. enum ps3_lpm_rights {
  410. PS3_LPM_RIGHTS_USE_LPM = 0x001,
  411. PS3_LPM_RIGHTS_USE_TB = 0x100,
  412. };
  413. /**
  414. * enum ps3_lpm_tb_type - Type of trace buffer lv1 should use.
  415. *
  416. * @PS3_LPM_TB_TYPE_NONE: Do not use a trace buffer.
  417. * @PS3_LPM_RIGHTS_USE_TB: Use the lv1 internal trace buffer. Must have
  418. * rights @PS3_LPM_RIGHTS_USE_TB.
  419. */
  420. enum ps3_lpm_tb_type {
  421. PS3_LPM_TB_TYPE_NONE = 0,
  422. PS3_LPM_TB_TYPE_INTERNAL = 1,
  423. };
  424. int ps3_lpm_open(enum ps3_lpm_tb_type tb_type, void *tb_cache,
  425. u64 tb_cache_size);
  426. int ps3_lpm_close(void);
  427. int ps3_lpm_copy_tb(unsigned long offset, void *buf, unsigned long count,
  428. unsigned long *bytes_copied);
  429. int ps3_lpm_copy_tb_to_user(unsigned long offset, void __user *buf,
  430. unsigned long count, unsigned long *bytes_copied);
  431. void ps3_set_bookmark(u64 bookmark);
  432. void ps3_set_pm_bookmark(u64 tag, u64 incident, u64 th_id);
  433. int ps3_set_signal(u64 rtas_signal_group, u8 signal_bit, u16 sub_unit,
  434. u8 bus_word);
  435. u32 ps3_read_phys_ctr(u32 cpu, u32 phys_ctr);
  436. void ps3_write_phys_ctr(u32 cpu, u32 phys_ctr, u32 val);
  437. u32 ps3_read_ctr(u32 cpu, u32 ctr);
  438. void ps3_write_ctr(u32 cpu, u32 ctr, u32 val);
  439. u32 ps3_read_pm07_control(u32 cpu, u32 ctr);
  440. void ps3_write_pm07_control(u32 cpu, u32 ctr, u32 val);
  441. u32 ps3_read_pm(u32 cpu, enum pm_reg_name reg);
  442. void ps3_write_pm(u32 cpu, enum pm_reg_name reg, u32 val);
  443. u32 ps3_get_ctr_size(u32 cpu, u32 phys_ctr);
  444. void ps3_set_ctr_size(u32 cpu, u32 phys_ctr, u32 ctr_size);
  445. void ps3_enable_pm(u32 cpu);
  446. void ps3_disable_pm(u32 cpu);
  447. void ps3_enable_pm_interrupts(u32 cpu, u32 thread, u32 mask);
  448. void ps3_disable_pm_interrupts(u32 cpu);
  449. u32 ps3_get_and_clear_pm_interrupts(u32 cpu);
  450. void ps3_sync_irq(int node);
  451. u32 ps3_get_hw_thread_id(int cpu);
  452. u64 ps3_get_spe_id(void *arg);
  453. #endif