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