blob: f577a16c6728a1a34c363ccfefbc526e5c5f4894 [file] [log] [blame]
Geoff Levandf58a9d12006-11-23 00:46:51 +01001/*
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
Geoff Levandf58a9d12006-11-23 00:46:51 +010024#include <linux/init.h>
25#include <linux/types.h>
26#include <linux/device.h>
27
Geoff Levand66b44952007-01-26 19:08:21 -080028union ps3_firmware_version {
29 u64 raw;
30 struct {
31 u16 pad;
32 u16 major;
33 u16 minor;
34 u16 rev;
35 };
36};
37
Masakazu Mokuno13228102007-06-16 07:18:48 +100038void ps3_get_firmware_version(union ps3_firmware_version *v);
39int ps3_compare_firmware_version(u16 major, u16 minor, u16 rev);
Geoff Levand66b44952007-01-26 19:08:21 -080040
Geert Uytterhoeven098e2742007-01-26 19:08:24 -080041/* '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
Geoff Levandf58a9d12006-11-23 00:46:51 +010052/* dma routines */
53
54enum ps3_dma_page_size {
55 PS3_DMA_4K = 12U,
56 PS3_DMA_64K = 16U,
57 PS3_DMA_1M = 20U,
58 PS3_DMA_16M = 24U,
59};
60
61enum ps3_dma_region_type {
62 PS3_DMA_OTHER = 0,
63 PS3_DMA_INTERNAL = 2,
64};
65
Geoff Levand6bb5cf12007-06-16 07:52:02 +100066struct ps3_dma_region_ops;
67
Geoff Levandf58a9d12006-11-23 00:46:51 +010068/**
69 * struct ps3_dma_region - A per device dma state variables structure
70 * @did: The HV device id.
71 * @page_size: The ioc pagesize.
72 * @region_type: The HV region type.
73 * @bus_addr: The 'translated' bus address of the region.
74 * @len: The length in bytes of the region.
Geoff Levand6bb5cf12007-06-16 07:52:02 +100075 * @offset: The offset from the start of memory of the region.
76 * @ioid: The IOID of the device who owns this region
Geoff Levandf58a9d12006-11-23 00:46:51 +010077 * @chunk_list: Opaque variable used by the ioc page manager.
Geoff Levand6bb5cf12007-06-16 07:52:02 +100078 * @region_ops: struct ps3_dma_region_ops - dma region operations
Geoff Levandf58a9d12006-11-23 00:46:51 +010079 */
80
81struct ps3_dma_region {
Geoff Levand6bb5cf12007-06-16 07:52:02 +100082 struct ps3_system_bus_device *dev;
83 /* device variables */
84 const struct ps3_dma_region_ops *region_ops;
85 unsigned char ioid;
Geoff Levandf58a9d12006-11-23 00:46:51 +010086 enum ps3_dma_page_size page_size;
87 enum ps3_dma_region_type region_type;
Geoff Levandf58a9d12006-11-23 00:46:51 +010088 unsigned long len;
Geoff Levand6bb5cf12007-06-16 07:52:02 +100089 unsigned long offset;
90
91 /* driver variables (set by ps3_dma_region_create) */
92 unsigned long bus_addr;
Geoff Levandf58a9d12006-11-23 00:46:51 +010093 struct {
94 spinlock_t lock;
95 struct list_head head;
96 } chunk_list;
97};
98
Geoff Levand6bb5cf12007-06-16 07:52:02 +100099struct 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 unsigned long *bus_addr,
106 u64 iopte_pp);
107 int (*unmap)(struct ps3_dma_region *,
108 unsigned long bus_addr,
109 unsigned long len);
110};
Geoff Levandf58a9d12006-11-23 00:46:51 +0100111/**
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
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000118struct 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);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100123int 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,
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000126 unsigned long len, unsigned long *bus_addr,
127 u64 iopte_pp);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100128int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long 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
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000138struct ps3_mmio_region_ops;
Geoff Levandf58a9d12006-11-23 00:46:51 +0100139/**
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 {
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000146 struct ps3_system_bus_device *dev;
147 const struct ps3_mmio_region_ops *mmio_ops;
Geoff Levandf58a9d12006-11-23 00:46:51 +0100148 unsigned long bus_addr;
149 unsigned long len;
150 enum ps3_mmio_page_size page_size;
151 unsigned long lpar_addr;
152};
153
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000154struct ps3_mmio_region_ops {
155 int (*create)(struct ps3_mmio_region *);
156 int (*free)(struct ps3_mmio_region *);
157};
Geoff Levandf58a9d12006-11-23 00:46:51 +0100158/**
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
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000165int 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);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100168int 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
Geoff Levand861be322007-01-26 19:08:08 -0800174enum ps3_cpu_binding {
175 PS3_BINDING_CPU_ANY = -1,
176 PS3_BINDING_CPU_0 = 0,
177 PS3_BINDING_CPU_1 = 1,
178};
179
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000180int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
Geoff Levand861be322007-01-26 19:08:08 -0800181 unsigned int *virq);
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000182int ps3_virq_destroy(unsigned int virq);
183int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
184 unsigned int *virq);
185int ps3_irq_plug_destroy(unsigned int virq);
186int ps3_event_receive_port_setup(enum ps3_cpu_binding cpu, unsigned int *virq);
187int ps3_event_receive_port_destroy(unsigned int virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100188int ps3_send_event_locally(unsigned int virq);
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000189
190int ps3_io_irq_setup(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
191 unsigned int *virq);
192int ps3_io_irq_destroy(unsigned int virq);
193int ps3_vuart_irq_setup(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
194 unsigned int *virq);
195int ps3_vuart_irq_destroy(unsigned int virq);
196int ps3_spe_irq_setup(enum ps3_cpu_binding cpu, unsigned long spe_id,
197 unsigned int class, unsigned int *virq);
198int ps3_spe_irq_destroy(unsigned int virq);
199
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000200int ps3_sb_event_receive_port_setup(struct ps3_system_bus_device *dev,
201 enum ps3_cpu_binding cpu, unsigned int *virq);
202int ps3_sb_event_receive_port_destroy(struct ps3_system_bus_device *dev,
203 unsigned int virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100204
205/* lv1 result codes */
206
207enum 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,
Geert Uytterhoeven06462d92007-09-12 18:43:16 +1000232 LV1_HARDWARE_ERROR = -24,
233 LV1_INVALID_DATA_FORMAT = -25,
234 LV1_INVALID_OPERATION = -26,
Geoff Levandf58a9d12006-11-23 00:46:51 +0100235 LV1_INTERNAL_ERROR = -32768,
236};
237
238static inline const char* ps3_result(int result)
239{
240#if defined(DEBUG)
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)";
Geert Uytterhoeven06462d92007-09-12 18:43:16 +1000290 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)";
Geoff Levandf58a9d12006-11-23 00:46:51 +0100296 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
Geoff Levanda3d4d642006-11-23 00:47:00 +0100307/* system bus routines */
308
309enum ps3_match_id {
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000310 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_GRAPHICS = 10,
320};
321
322#define PS3_MODULE_ALIAS_EHCI "ps3:1"
323#define PS3_MODULE_ALIAS_OHCI "ps3:2"
324#define PS3_MODULE_ALIAS_GELIC "ps3:3"
325#define PS3_MODULE_ALIAS_AV_SETTINGS "ps3:4"
326#define PS3_MODULE_ALIAS_SYSTEM_MANAGER "ps3:5"
327#define PS3_MODULE_ALIAS_STOR_DISK "ps3:6"
328#define PS3_MODULE_ALIAS_STOR_ROM "ps3:7"
329#define PS3_MODULE_ALIAS_STOR_FLASH "ps3:8"
330#define PS3_MODULE_ALIAS_SOUND "ps3:9"
331#define PS3_MODULE_ALIAS_GRAPHICS "ps3:10"
332
333enum ps3_system_bus_device_type {
334 PS3_DEVICE_TYPE_IOC0 = 1,
335 PS3_DEVICE_TYPE_SB,
336 PS3_DEVICE_TYPE_VUART,
Geoff Levanda3d4d642006-11-23 00:47:00 +0100337};
338
339/**
340 * struct ps3_system_bus_device - a device on the system bus
341 */
342
343struct ps3_system_bus_device {
344 enum ps3_match_id match_id;
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000345 enum ps3_system_bus_device_type dev_type;
346
347 unsigned int bus_id; /* SB */
348 unsigned int dev_id; /* SB */
349 unsigned int interrupt_id; /* SB */
350 struct ps3_dma_region *d_region; /* SB, IOC0 */
351 struct ps3_mmio_region *m_region; /* SB, IOC0*/
352 unsigned int port_number; /* VUART */
353
354/* struct iommu_table *iommu_table; -- waiting for BenH's cleanups */
Geoff Levanda3d4d642006-11-23 00:47:00 +0100355 struct device core;
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000356 void *driver_priv; /* private driver variables */
Geoff Levanda3d4d642006-11-23 00:47:00 +0100357};
358
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000359int ps3_open_hv_device(struct ps3_system_bus_device *dev);
360int ps3_close_hv_device(struct ps3_system_bus_device *dev);
361
Geoff Levanda3d4d642006-11-23 00:47:00 +0100362/**
363 * struct ps3_system_bus_driver - a driver for a device on the system bus
364 */
365
366struct ps3_system_bus_driver {
367 enum ps3_match_id match_id;
368 struct device_driver core;
369 int (*probe)(struct ps3_system_bus_device *);
370 int (*remove)(struct ps3_system_bus_device *);
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000371 int (*shutdown)(struct ps3_system_bus_device *);
Geoff Levanda3d4d642006-11-23 00:47:00 +0100372/* int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
373/* int (*resume)(struct ps3_system_bus_device *); */
374};
375
376int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
377int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
378void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000379
380static inline struct ps3_system_bus_driver *ps3_drv_to_system_bus_drv(
Geoff Levanda3d4d642006-11-23 00:47:00 +0100381 struct device_driver *_drv)
382{
383 return container_of(_drv, struct ps3_system_bus_driver, core);
384}
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000385static inline struct ps3_system_bus_device *ps3_dev_to_system_bus_dev(
Geoff Levanda3d4d642006-11-23 00:47:00 +0100386 struct device *_dev)
387{
388 return container_of(_dev, struct ps3_system_bus_device, core);
389}
Geoff Levand6bb5cf12007-06-16 07:52:02 +1000390static inline struct ps3_system_bus_driver *
391 ps3_system_bus_dev_to_system_bus_drv(struct ps3_system_bus_device *_dev)
392{
393 BUG_ON(!_dev);
394 BUG_ON(!_dev->core.driver);
395 return ps3_drv_to_system_bus_drv(_dev->core.driver);
396}
Geoff Levanda3d4d642006-11-23 00:47:00 +0100397
398/**
399 * ps3_system_bus_set_drvdata -
400 * @dev: device structure
401 * @data: Data to set
402 */
403
404static inline void ps3_system_bus_set_driver_data(
405 struct ps3_system_bus_device *dev, void *data)
406{
407 dev->core.driver_data = data;
408}
409static inline void *ps3_system_bus_get_driver_data(
410 struct ps3_system_bus_device *dev)
411{
412 return dev->core.driver_data;
413}
414
415/* These two need global scope for get_dma_ops(). */
416
417extern struct bus_type ps3_system_bus_type;
418
Geoff Levandfde5efd2007-02-07 12:20:01 -0800419/* system manager */
420
Geoff Levand66c63b82007-06-16 08:03:54 +1000421struct ps3_sys_manager_ops {
422 struct ps3_system_bus_device *dev;
423 void (*power_off)(struct ps3_system_bus_device *dev);
424 void (*restart)(struct ps3_system_bus_device *dev);
425};
426
427void ps3_sys_manager_register_ops(const struct ps3_sys_manager_ops *ops);
Geoff Levandfde5efd2007-02-07 12:20:01 -0800428void ps3_sys_manager_power_off(void);
Geoff Levand66c63b82007-06-16 08:03:54 +1000429void ps3_sys_manager_restart(void);
Geoff Levandfde5efd2007-02-07 12:20:01 -0800430
Geert Uytterhoevenfbdb3e5b2007-02-12 00:55:22 -0800431struct ps3_prealloc {
432 const char *name;
433 void *address;
434 unsigned long size;
435 unsigned long align;
436};
437
438extern struct ps3_prealloc ps3fb_videomemory;
Geert Uytterhoeven32d73312007-06-22 00:14:20 +1000439extern struct ps3_prealloc ps3flash_bounce_buffer;
Geert Uytterhoevenfbdb3e5b2007-02-12 00:55:22 -0800440
Geoff Levand66c63b82007-06-16 08:03:54 +1000441
Geoff Levandf58a9d12006-11-23 00:46:51 +0100442#endif