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