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