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