blob: ac85d729f14fcd7d69425356d9b8ff4f812e036d [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/**
53 * struct ps3_device_id - HV bus device identifier from the system repository
54 * @bus_id: HV bus id, {1..} (zero invalid)
55 * @dev_id: HV device id, {0..}
56 */
57
58struct ps3_device_id {
59 unsigned int bus_id;
60 unsigned int dev_id;
61};
62
63
64/* dma routines */
65
66enum ps3_dma_page_size {
67 PS3_DMA_4K = 12U,
68 PS3_DMA_64K = 16U,
69 PS3_DMA_1M = 20U,
70 PS3_DMA_16M = 24U,
71};
72
73enum ps3_dma_region_type {
74 PS3_DMA_OTHER = 0,
75 PS3_DMA_INTERNAL = 2,
76};
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 * @chunk_list: Opaque variable used by the ioc page manager.
86 */
87
88struct ps3_dma_region {
89 struct ps3_device_id did;
90 enum ps3_dma_page_size page_size;
91 enum ps3_dma_region_type region_type;
92 unsigned long bus_addr;
93 unsigned long len;
94 struct {
95 spinlock_t lock;
96 struct list_head head;
97 } chunk_list;
98};
99
100/**
101 * struct ps3_dma_region_init - Helper to initialize structure variables
102 *
103 * Helper to properly initialize variables prior to calling
104 * ps3_system_bus_device_register.
105 */
106
107static inline void ps3_dma_region_init(struct ps3_dma_region *r,
108 const struct ps3_device_id* did, enum ps3_dma_page_size page_size,
109 enum ps3_dma_region_type region_type)
110{
111 r->did = *did;
112 r->page_size = page_size;
113 r->region_type = region_type;
114}
115int ps3_dma_region_create(struct ps3_dma_region *r);
116int ps3_dma_region_free(struct ps3_dma_region *r);
117int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
118 unsigned long len, unsigned long *bus_addr);
119int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
120 unsigned long len);
121
122/* mmio routines */
123
124enum ps3_mmio_page_size {
125 PS3_MMIO_4K = 12U,
126 PS3_MMIO_64K = 16U
127};
128
129/**
130 * struct ps3_mmio_region - a per device mmio state variables structure
131 *
132 * Current systems can be supported with a single region per device.
133 */
134
135struct ps3_mmio_region {
136 struct ps3_device_id did;
137 unsigned long bus_addr;
138 unsigned long len;
139 enum ps3_mmio_page_size page_size;
140 unsigned long lpar_addr;
141};
142
143/**
144 * struct ps3_mmio_region_init - Helper to initialize structure variables
145 *
146 * Helper to properly initialize variables prior to calling
147 * ps3_system_bus_device_register.
148 */
149
150static inline void ps3_mmio_region_init(struct ps3_mmio_region *r,
151 const struct ps3_device_id* did, unsigned long bus_addr,
152 unsigned long len, enum ps3_mmio_page_size page_size)
153{
154 r->did = *did;
155 r->bus_addr = bus_addr;
156 r->len = len;
157 r->page_size = page_size;
158}
159int ps3_mmio_region_create(struct ps3_mmio_region *r);
160int ps3_free_mmio_region(struct ps3_mmio_region *r);
161unsigned long ps3_mm_phys_to_lpar(unsigned long phys_addr);
162
163/* inrerrupt routines */
164
Geoff Levand861be322007-01-26 19:08:08 -0800165enum ps3_cpu_binding {
166 PS3_BINDING_CPU_ANY = -1,
167 PS3_BINDING_CPU_0 = 0,
168 PS3_BINDING_CPU_1 = 1,
169};
170
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000171int ps3_virq_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
Geoff Levand861be322007-01-26 19:08:08 -0800172 unsigned int *virq);
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000173int ps3_virq_destroy(unsigned int virq);
174int ps3_irq_plug_setup(enum ps3_cpu_binding cpu, unsigned long outlet,
175 unsigned int *virq);
176int ps3_irq_plug_destroy(unsigned int virq);
177int ps3_event_receive_port_setup(enum ps3_cpu_binding cpu, unsigned int *virq);
178int ps3_event_receive_port_destroy(unsigned int virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100179int ps3_send_event_locally(unsigned int virq);
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000180
181int ps3_io_irq_setup(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
182 unsigned int *virq);
183int ps3_io_irq_destroy(unsigned int virq);
184int ps3_vuart_irq_setup(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
185 unsigned int *virq);
186int ps3_vuart_irq_destroy(unsigned int virq);
187int ps3_spe_irq_setup(enum ps3_cpu_binding cpu, unsigned long spe_id,
188 unsigned int class, unsigned int *virq);
189int ps3_spe_irq_destroy(unsigned int virq);
190
191int ps3_sb_event_receive_port_setup(enum ps3_cpu_binding cpu,
Geoff Levand861be322007-01-26 19:08:08 -0800192 const struct ps3_device_id *did, unsigned int interrupt_id,
193 unsigned int *virq);
Geoff Levanddc4f60c2007-05-01 07:01:01 +1000194int ps3_sb_event_receive_port_destroy(const struct ps3_device_id *did,
Geoff Levandf58a9d12006-11-23 00:46:51 +0100195 unsigned int interrupt_id, unsigned int virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100196
197/* lv1 result codes */
198
199enum lv1_result {
200 LV1_SUCCESS = 0,
201 /* not used -1 */
202 LV1_RESOURCE_SHORTAGE = -2,
203 LV1_NO_PRIVILEGE = -3,
204 LV1_DENIED_BY_POLICY = -4,
205 LV1_ACCESS_VIOLATION = -5,
206 LV1_NO_ENTRY = -6,
207 LV1_DUPLICATE_ENTRY = -7,
208 LV1_TYPE_MISMATCH = -8,
209 LV1_BUSY = -9,
210 LV1_EMPTY = -10,
211 LV1_WRONG_STATE = -11,
212 /* not used -12 */
213 LV1_NO_MATCH = -13,
214 LV1_ALREADY_CONNECTED = -14,
215 LV1_UNSUPPORTED_PARAMETER_VALUE = -15,
216 LV1_CONDITION_NOT_SATISFIED = -16,
217 LV1_ILLEGAL_PARAMETER_VALUE = -17,
218 LV1_BAD_OPTION = -18,
219 LV1_IMPLEMENTATION_LIMITATION = -19,
220 LV1_NOT_IMPLEMENTED = -20,
221 LV1_INVALID_CLASS_ID = -21,
222 LV1_CONSTRAINT_NOT_SATISFIED = -22,
223 LV1_ALIGNMENT_ERROR = -23,
224 LV1_INTERNAL_ERROR = -32768,
225};
226
227static inline const char* ps3_result(int result)
228{
229#if defined(DEBUG)
230 switch (result) {
231 case LV1_SUCCESS:
232 return "LV1_SUCCESS (0)";
233 case -1:
234 return "** unknown result ** (-1)";
235 case LV1_RESOURCE_SHORTAGE:
236 return "LV1_RESOURCE_SHORTAGE (-2)";
237 case LV1_NO_PRIVILEGE:
238 return "LV1_NO_PRIVILEGE (-3)";
239 case LV1_DENIED_BY_POLICY:
240 return "LV1_DENIED_BY_POLICY (-4)";
241 case LV1_ACCESS_VIOLATION:
242 return "LV1_ACCESS_VIOLATION (-5)";
243 case LV1_NO_ENTRY:
244 return "LV1_NO_ENTRY (-6)";
245 case LV1_DUPLICATE_ENTRY:
246 return "LV1_DUPLICATE_ENTRY (-7)";
247 case LV1_TYPE_MISMATCH:
248 return "LV1_TYPE_MISMATCH (-8)";
249 case LV1_BUSY:
250 return "LV1_BUSY (-9)";
251 case LV1_EMPTY:
252 return "LV1_EMPTY (-10)";
253 case LV1_WRONG_STATE:
254 return "LV1_WRONG_STATE (-11)";
255 case -12:
256 return "** unknown result ** (-12)";
257 case LV1_NO_MATCH:
258 return "LV1_NO_MATCH (-13)";
259 case LV1_ALREADY_CONNECTED:
260 return "LV1_ALREADY_CONNECTED (-14)";
261 case LV1_UNSUPPORTED_PARAMETER_VALUE:
262 return "LV1_UNSUPPORTED_PARAMETER_VALUE (-15)";
263 case LV1_CONDITION_NOT_SATISFIED:
264 return "LV1_CONDITION_NOT_SATISFIED (-16)";
265 case LV1_ILLEGAL_PARAMETER_VALUE:
266 return "LV1_ILLEGAL_PARAMETER_VALUE (-17)";
267 case LV1_BAD_OPTION:
268 return "LV1_BAD_OPTION (-18)";
269 case LV1_IMPLEMENTATION_LIMITATION:
270 return "LV1_IMPLEMENTATION_LIMITATION (-19)";
271 case LV1_NOT_IMPLEMENTED:
272 return "LV1_NOT_IMPLEMENTED (-20)";
273 case LV1_INVALID_CLASS_ID:
274 return "LV1_INVALID_CLASS_ID (-21)";
275 case LV1_CONSTRAINT_NOT_SATISFIED:
276 return "LV1_CONSTRAINT_NOT_SATISFIED (-22)";
277 case LV1_ALIGNMENT_ERROR:
278 return "LV1_ALIGNMENT_ERROR (-23)";
279 case LV1_INTERNAL_ERROR:
280 return "LV1_INTERNAL_ERROR (-32768)";
281 default:
282 BUG();
283 return "** unknown result **";
284 };
285#else
286 return "";
287#endif
288}
289
Geoff Levanda3d4d642006-11-23 00:47:00 +0100290/* system bus routines */
291
292enum ps3_match_id {
293 PS3_MATCH_ID_EHCI = 1,
294 PS3_MATCH_ID_OHCI,
295 PS3_MATCH_ID_GELIC,
296 PS3_MATCH_ID_AV_SETTINGS,
297 PS3_MATCH_ID_SYSTEM_MANAGER,
298};
299
300/**
301 * struct ps3_system_bus_device - a device on the system bus
302 */
303
304struct ps3_system_bus_device {
305 enum ps3_match_id match_id;
306 struct ps3_device_id did;
307 unsigned int interrupt_id;
308/* struct iommu_table *iommu_table; -- waiting for Ben's cleanups */
309 struct ps3_dma_region *d_region;
310 struct ps3_mmio_region *m_region;
311 struct device core;
312};
313
314/**
315 * struct ps3_system_bus_driver - a driver for a device on the system bus
316 */
317
318struct ps3_system_bus_driver {
319 enum ps3_match_id match_id;
320 struct device_driver core;
321 int (*probe)(struct ps3_system_bus_device *);
322 int (*remove)(struct ps3_system_bus_device *);
323/* int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
324/* int (*resume)(struct ps3_system_bus_device *); */
325};
326
327int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
328int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
329void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
330static inline struct ps3_system_bus_driver *to_ps3_system_bus_driver(
331 struct device_driver *_drv)
332{
333 return container_of(_drv, struct ps3_system_bus_driver, core);
334}
335static inline struct ps3_system_bus_device *to_ps3_system_bus_device(
336 struct device *_dev)
337{
338 return container_of(_dev, struct ps3_system_bus_device, core);
339}
340
341/**
342 * ps3_system_bus_set_drvdata -
343 * @dev: device structure
344 * @data: Data to set
345 */
346
347static inline void ps3_system_bus_set_driver_data(
348 struct ps3_system_bus_device *dev, void *data)
349{
350 dev->core.driver_data = data;
351}
352static inline void *ps3_system_bus_get_driver_data(
353 struct ps3_system_bus_device *dev)
354{
355 return dev->core.driver_data;
356}
357
358/* These two need global scope for get_dma_ops(). */
359
360extern struct bus_type ps3_system_bus_type;
361
Geoff Levand97ec1672007-01-30 15:20:30 -0800362/* vuart routines */
363
Geoff Levand75c86e72007-02-13 17:37:28 -0800364struct ps3_vuart_port_priv;
Geoff Levand97ec1672007-01-30 15:20:30 -0800365
366/**
367 * struct ps3_vuart_port_device - a device on a vuart port
368 */
369
370struct ps3_vuart_port_device {
371 enum ps3_match_id match_id;
372 struct device core;
Geoff Levand75c86e72007-02-13 17:37:28 -0800373 struct ps3_vuart_port_priv* priv; /* private driver variables */
Geoff Levand97ec1672007-01-30 15:20:30 -0800374
Geoff Levand97ec1672007-01-30 15:20:30 -0800375};
376
377int ps3_vuart_port_device_register(struct ps3_vuart_port_device *dev);
378
Geoff Levandfde5efd2007-02-07 12:20:01 -0800379/* system manager */
380
Geoff Levand6e668372007-05-10 06:09:14 +1000381#ifdef CONFIG_PS3_SYS_MANAGER
Geoff Levandfde5efd2007-02-07 12:20:01 -0800382void ps3_sys_manager_restart(void);
383void ps3_sys_manager_power_off(void);
Geoff Levand6e668372007-05-10 06:09:14 +1000384#else
385static inline void ps3_sys_manager_restart(void) {}
386static inline void ps3_sys_manager_power_off(void) {}
387#endif
Geoff Levandfde5efd2007-02-07 12:20:01 -0800388
Geert Uytterhoevenfbdb3e5b2007-02-12 00:55:22 -0800389struct ps3_prealloc {
390 const char *name;
391 void *address;
392 unsigned long size;
393 unsigned long align;
394};
395
396extern struct ps3_prealloc ps3fb_videomemory;
397
Geoff Levandf58a9d12006-11-23 00:46:51 +0100398#endif