[POWERPC] ps3: get firmware version
[pandora-kernel.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/compiler.h> /* for __deprecated */
25 #include <linux/init.h>
26 #include <linux/types.h>
27 #include <linux/device.h>
28 #include <scsi/scsi.h>
29
30 union ps3_firmware_version {
31         u64 raw;
32         struct {
33                 u16 pad;
34                 u16 major;
35                 u16 minor;
36                 u16 rev;
37         };
38 };
39
40 int ps3_get_firmware_version(union ps3_firmware_version *v);
41
42 /**
43  * struct ps3_device_id - HV bus device identifier from the system repository
44  * @bus_id: HV bus id, {1..} (zero invalid)
45  * @dev_id: HV device id, {0..}
46  */
47
48 struct ps3_device_id {
49         unsigned int bus_id;
50         unsigned int dev_id;
51 };
52
53
54 /* dma routines */
55
56 enum ps3_dma_page_size {
57         PS3_DMA_4K = 12U,
58         PS3_DMA_64K = 16U,
59         PS3_DMA_1M = 20U,
60         PS3_DMA_16M = 24U,
61 };
62
63 enum ps3_dma_region_type {
64         PS3_DMA_OTHER = 0,
65         PS3_DMA_INTERNAL = 2,
66 };
67
68 /**
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.
75  * @chunk_list: Opaque variable used by the ioc page manager.
76  */
77
78 struct ps3_dma_region {
79         struct ps3_device_id did;
80         enum ps3_dma_page_size page_size;
81         enum ps3_dma_region_type region_type;
82         unsigned long bus_addr;
83         unsigned long len;
84         struct {
85                 spinlock_t lock;
86                 struct list_head head;
87         } chunk_list;
88 };
89
90 /**
91  * struct ps3_dma_region_init - Helper to initialize structure variables
92  *
93  * Helper to properly initialize variables prior to calling
94  * ps3_system_bus_device_register.
95  */
96
97 static inline void ps3_dma_region_init(struct ps3_dma_region *r,
98         const struct ps3_device_id* did, enum ps3_dma_page_size page_size,
99         enum ps3_dma_region_type region_type)
100 {
101         r->did = *did;
102         r->page_size = page_size;
103         r->region_type = region_type;
104 }
105 int ps3_dma_region_create(struct ps3_dma_region *r);
106 int ps3_dma_region_free(struct ps3_dma_region *r);
107 int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
108         unsigned long len, unsigned long *bus_addr);
109 int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
110         unsigned long len);
111
112 /* mmio routines */
113
114 enum ps3_mmio_page_size {
115         PS3_MMIO_4K = 12U,
116         PS3_MMIO_64K = 16U
117 };
118
119 /**
120  * struct ps3_mmio_region - a per device mmio state variables structure
121  *
122  * Current systems can be supported with a single region per device.
123  */
124
125 struct ps3_mmio_region {
126         struct ps3_device_id did;
127         unsigned long bus_addr;
128         unsigned long len;
129         enum ps3_mmio_page_size page_size;
130         unsigned long lpar_addr;
131 };
132
133 /**
134  * struct ps3_mmio_region_init - Helper to initialize structure variables
135  *
136  * Helper to properly initialize variables prior to calling
137  * ps3_system_bus_device_register.
138  */
139
140 static inline void ps3_mmio_region_init(struct ps3_mmio_region *r,
141         const struct ps3_device_id* did, unsigned long bus_addr,
142         unsigned long len, enum ps3_mmio_page_size page_size)
143 {
144         r->did = *did;
145         r->bus_addr = bus_addr;
146         r->len = len;
147         r->page_size = page_size;
148 }
149 int ps3_mmio_region_create(struct ps3_mmio_region *r);
150 int ps3_free_mmio_region(struct ps3_mmio_region *r);
151 unsigned long ps3_mm_phys_to_lpar(unsigned long phys_addr);
152
153 /* inrerrupt routines */
154
155 enum ps3_cpu_binding {
156         PS3_BINDING_CPU_ANY = -1,
157         PS3_BINDING_CPU_0 = 0,
158         PS3_BINDING_CPU_1 = 1,
159 };
160
161 int ps3_alloc_io_irq(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
162         unsigned int *virq);
163 int ps3_free_io_irq(unsigned int virq);
164 int ps3_alloc_event_irq(enum ps3_cpu_binding cpu, unsigned int *virq);
165 int ps3_free_event_irq(unsigned int virq);
166 int ps3_send_event_locally(unsigned int virq);
167 int ps3_connect_event_irq(enum ps3_cpu_binding cpu,
168         const struct ps3_device_id *did, unsigned int interrupt_id,
169         unsigned int *virq);
170 int ps3_disconnect_event_irq(const struct ps3_device_id *did,
171         unsigned int interrupt_id, unsigned int virq);
172 int ps3_alloc_vuart_irq(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
173         unsigned int *virq);
174 int ps3_free_vuart_irq(unsigned int virq);
175 int ps3_alloc_spe_irq(enum ps3_cpu_binding cpu, unsigned long spe_id,
176         unsigned int class, unsigned int *virq);
177 int ps3_free_spe_irq(unsigned int virq);
178 int ps3_alloc_irq(enum ps3_cpu_binding cpu, unsigned long outlet,
179         unsigned int *virq);
180 int ps3_free_irq(unsigned int virq);
181
182 /* lv1 result codes */
183
184 enum lv1_result {
185         LV1_SUCCESS                     = 0,
186         /* not used                       -1 */
187         LV1_RESOURCE_SHORTAGE           = -2,
188         LV1_NO_PRIVILEGE                = -3,
189         LV1_DENIED_BY_POLICY            = -4,
190         LV1_ACCESS_VIOLATION            = -5,
191         LV1_NO_ENTRY                    = -6,
192         LV1_DUPLICATE_ENTRY             = -7,
193         LV1_TYPE_MISMATCH               = -8,
194         LV1_BUSY                        = -9,
195         LV1_EMPTY                       = -10,
196         LV1_WRONG_STATE                 = -11,
197         /* not used                       -12 */
198         LV1_NO_MATCH                    = -13,
199         LV1_ALREADY_CONNECTED           = -14,
200         LV1_UNSUPPORTED_PARAMETER_VALUE = -15,
201         LV1_CONDITION_NOT_SATISFIED     = -16,
202         LV1_ILLEGAL_PARAMETER_VALUE     = -17,
203         LV1_BAD_OPTION                  = -18,
204         LV1_IMPLEMENTATION_LIMITATION   = -19,
205         LV1_NOT_IMPLEMENTED             = -20,
206         LV1_INVALID_CLASS_ID            = -21,
207         LV1_CONSTRAINT_NOT_SATISFIED    = -22,
208         LV1_ALIGNMENT_ERROR             = -23,
209         LV1_INTERNAL_ERROR              = -32768,
210 };
211
212 static inline const char* ps3_result(int result)
213 {
214 #if defined(DEBUG)
215         switch (result) {
216         case LV1_SUCCESS:
217                 return "LV1_SUCCESS (0)";
218         case -1:
219                 return "** unknown result ** (-1)";
220         case LV1_RESOURCE_SHORTAGE:
221                 return "LV1_RESOURCE_SHORTAGE (-2)";
222         case LV1_NO_PRIVILEGE:
223                 return "LV1_NO_PRIVILEGE (-3)";
224         case LV1_DENIED_BY_POLICY:
225                 return "LV1_DENIED_BY_POLICY (-4)";
226         case LV1_ACCESS_VIOLATION:
227                 return "LV1_ACCESS_VIOLATION (-5)";
228         case LV1_NO_ENTRY:
229                 return "LV1_NO_ENTRY (-6)";
230         case LV1_DUPLICATE_ENTRY:
231                 return "LV1_DUPLICATE_ENTRY (-7)";
232         case LV1_TYPE_MISMATCH:
233                 return "LV1_TYPE_MISMATCH (-8)";
234         case LV1_BUSY:
235                 return "LV1_BUSY (-9)";
236         case LV1_EMPTY:
237                 return "LV1_EMPTY (-10)";
238         case LV1_WRONG_STATE:
239                 return "LV1_WRONG_STATE (-11)";
240         case -12:
241                 return "** unknown result ** (-12)";
242         case LV1_NO_MATCH:
243                 return "LV1_NO_MATCH (-13)";
244         case LV1_ALREADY_CONNECTED:
245                 return "LV1_ALREADY_CONNECTED (-14)";
246         case LV1_UNSUPPORTED_PARAMETER_VALUE:
247                 return "LV1_UNSUPPORTED_PARAMETER_VALUE (-15)";
248         case LV1_CONDITION_NOT_SATISFIED:
249                 return "LV1_CONDITION_NOT_SATISFIED (-16)";
250         case LV1_ILLEGAL_PARAMETER_VALUE:
251                 return "LV1_ILLEGAL_PARAMETER_VALUE (-17)";
252         case LV1_BAD_OPTION:
253                 return "LV1_BAD_OPTION (-18)";
254         case LV1_IMPLEMENTATION_LIMITATION:
255                 return "LV1_IMPLEMENTATION_LIMITATION (-19)";
256         case LV1_NOT_IMPLEMENTED:
257                 return "LV1_NOT_IMPLEMENTED (-20)";
258         case LV1_INVALID_CLASS_ID:
259                 return "LV1_INVALID_CLASS_ID (-21)";
260         case LV1_CONSTRAINT_NOT_SATISFIED:
261                 return "LV1_CONSTRAINT_NOT_SATISFIED (-22)";
262         case LV1_ALIGNMENT_ERROR:
263                 return "LV1_ALIGNMENT_ERROR (-23)";
264         case LV1_INTERNAL_ERROR:
265                 return "LV1_INTERNAL_ERROR (-32768)";
266         default:
267                 BUG();
268                 return "** unknown result **";
269         };
270 #else
271         return "";
272 #endif
273 }
274
275 /* repository bus info */
276
277 enum ps3_bus_type {
278         PS3_BUS_TYPE_SB = 4,
279         PS3_BUS_TYPE_STORAGE = 5,
280 };
281
282 enum ps3_dev_type {
283         PS3_DEV_TYPE_STOR_DISK = TYPE_DISK,     /* 0 */
284         PS3_DEV_TYPE_SB_GELIC = 3,
285         PS3_DEV_TYPE_SB_USB = 4,
286         PS3_DEV_TYPE_STOR_ROM = TYPE_ROM,       /* 5 */
287         PS3_DEV_TYPE_SB_GPIO = 6,
288         PS3_DEV_TYPE_STOR_FLASH = TYPE_RBC,     /* 14 */
289 };
290
291 int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
292         u64 *value);
293 int ps3_repository_read_bus_id(unsigned int bus_index, unsigned int *bus_id);
294 int ps3_repository_read_bus_type(unsigned int bus_index,
295         enum ps3_bus_type *bus_type);
296 int ps3_repository_read_bus_num_dev(unsigned int bus_index,
297         unsigned int *num_dev);
298
299 /* repository bus device info */
300
301 enum ps3_interrupt_type {
302         PS3_INTERRUPT_TYPE_EVENT_PORT = 2,
303         PS3_INTERRUPT_TYPE_SB_OHCI = 3,
304         PS3_INTERRUPT_TYPE_SB_EHCI = 4,
305         PS3_INTERRUPT_TYPE_OTHER = 5,
306 };
307
308 enum ps3_reg_type {
309         PS3_REG_TYPE_SB_OHCI = 3,
310         PS3_REG_TYPE_SB_EHCI = 4,
311         PS3_REG_TYPE_SB_GPIO = 5,
312 };
313
314 int ps3_repository_read_dev_str(unsigned int bus_index,
315         unsigned int dev_index, const char *dev_str, u64 *value);
316 int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
317         unsigned int *dev_id);
318 int ps3_repository_read_dev_type(unsigned int bus_index,
319         unsigned int dev_index, enum ps3_dev_type *dev_type);
320 int ps3_repository_read_dev_intr(unsigned int bus_index,
321         unsigned int dev_index, unsigned int intr_index,
322         enum ps3_interrupt_type *intr_type, unsigned int *interrupt_id);
323 int ps3_repository_read_dev_reg_type(unsigned int bus_index,
324         unsigned int dev_index, unsigned int reg_index,
325         enum ps3_reg_type *reg_type);
326 int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
327         unsigned int dev_index, unsigned int reg_index, u64 *bus_addr,
328         u64 *len);
329 int ps3_repository_read_dev_reg(unsigned int bus_index,
330         unsigned int dev_index, unsigned int reg_index,
331         enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len);
332
333 /* repository bus enumerators */
334
335 struct ps3_repository_device {
336         unsigned int bus_index;
337         unsigned int dev_index;
338         struct ps3_device_id did;
339 };
340
341 int ps3_repository_find_device(enum ps3_bus_type bus_type,
342         enum ps3_dev_type dev_type,
343         const struct ps3_repository_device *start_dev,
344         struct ps3_repository_device *dev);
345 static inline int ps3_repository_find_first_device(
346         enum ps3_bus_type bus_type, enum ps3_dev_type dev_type,
347         struct ps3_repository_device *dev)
348 {
349         return ps3_repository_find_device(bus_type, dev_type, NULL, dev);
350 }
351 int ps3_repository_find_interrupt(const struct ps3_repository_device *dev,
352         enum ps3_interrupt_type intr_type, unsigned int *interrupt_id);
353 int ps3_repository_find_reg(const struct ps3_repository_device *dev,
354         enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len);
355
356 /* repository block device info */
357
358 int ps3_repository_read_stor_dev_port(unsigned int bus_index,
359         unsigned int dev_index, u64 *port);
360 int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
361         unsigned int dev_index, u64 *blk_size);
362 int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
363         unsigned int dev_index, u64 *num_blocks);
364 int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
365         unsigned int dev_index, unsigned int *num_regions);
366 int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
367         unsigned int dev_index, unsigned int region_index,
368         unsigned int *region_id);
369 int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
370         unsigned int dev_index, unsigned int region_index, u64 *region_size);
371 int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
372         unsigned int dev_index, unsigned int region_index, u64 *region_start);
373 int ps3_repository_read_stor_dev_info(unsigned int bus_index,
374         unsigned int dev_index, u64 *port, u64 *blk_size,
375         u64 *num_blocks, unsigned int *num_regions);
376 int ps3_repository_read_stor_dev_region(unsigned int bus_index,
377         unsigned int dev_index, unsigned int region_index,
378         unsigned int *region_id, u64 *region_start, u64 *region_size);
379
380 /* repository pu and memory info */
381
382 int ps3_repository_read_num_pu(unsigned int *num_pu);
383 int ps3_repository_read_ppe_id(unsigned int *pu_index, unsigned int *ppe_id);
384 int ps3_repository_read_rm_base(unsigned int ppe_id, u64 *rm_base);
385 int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size);
386 int ps3_repository_read_region_total(u64 *region_total);
387 int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size,
388         u64 *region_total);
389
390 /* repository pme info */
391
392 int ps3_repository_read_num_be(unsigned int *num_be);
393 int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id);
394 int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq);
395 int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq);
396
397 /* repository 'Other OS' area */
398
399 int ps3_repository_read_boot_dat_addr(u64 *lpar_addr);
400 int ps3_repository_read_boot_dat_size(unsigned int *size);
401 int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size);
402
403 /* repository spu info */
404
405 /**
406  * enum spu_resource_type - Type of spu resource.
407  * @spu_resource_type_shared: Logical spu is shared with other partions.
408  * @spu_resource_type_exclusive: Logical spu is not shared with other partions.
409  *
410  * Returned by ps3_repository_read_spu_resource_id().
411  */
412
413 enum ps3_spu_resource_type {
414         PS3_SPU_RESOURCE_TYPE_SHARED = 0,
415         PS3_SPU_RESOURCE_TYPE_EXCLUSIVE = 0x8000000000000000UL,
416 };
417
418 int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved);
419 int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id);
420 int ps3_repository_read_spu_resource_id(unsigned int res_index,
421         enum ps3_spu_resource_type* resource_type, unsigned int *resource_id);
422
423
424 /* system bus routines */
425
426 enum ps3_match_id {
427         PS3_MATCH_ID_EHCI = 1,
428         PS3_MATCH_ID_OHCI,
429         PS3_MATCH_ID_GELIC,
430         PS3_MATCH_ID_AV_SETTINGS,
431         PS3_MATCH_ID_SYSTEM_MANAGER,
432 };
433
434 /**
435  * struct ps3_system_bus_device - a device on the system bus
436  */
437
438 struct ps3_system_bus_device {
439         enum ps3_match_id match_id;
440         struct ps3_device_id did;
441         unsigned int interrupt_id;
442 /*      struct iommu_table *iommu_table; -- waiting for Ben's cleanups */
443         struct ps3_dma_region *d_region;
444         struct ps3_mmio_region *m_region;
445         struct device core;
446 };
447
448 /**
449  * struct ps3_system_bus_driver - a driver for a device on the system bus
450  */
451
452 struct ps3_system_bus_driver {
453         enum ps3_match_id match_id;
454         struct device_driver core;
455         int (*probe)(struct ps3_system_bus_device *);
456         int (*remove)(struct ps3_system_bus_device *);
457 /*      int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
458 /*      int (*resume)(struct ps3_system_bus_device *); */
459 };
460
461 int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
462 int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
463 void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
464 static inline struct ps3_system_bus_driver *to_ps3_system_bus_driver(
465         struct device_driver *_drv)
466 {
467         return container_of(_drv, struct ps3_system_bus_driver, core);
468 }
469 static inline struct ps3_system_bus_device *to_ps3_system_bus_device(
470         struct device *_dev)
471 {
472         return container_of(_dev, struct ps3_system_bus_device, core);
473 }
474
475 /**
476  * ps3_system_bus_set_drvdata -
477  * @dev: device structure
478  * @data: Data to set
479  */
480
481 static inline void ps3_system_bus_set_driver_data(
482         struct ps3_system_bus_device *dev, void *data)
483 {
484         dev->core.driver_data = data;
485 }
486 static inline void *ps3_system_bus_get_driver_data(
487         struct ps3_system_bus_device *dev)
488 {
489         return dev->core.driver_data;
490 }
491
492 /* These two need global scope for get_dma_ops(). */
493
494 extern struct bus_type ps3_system_bus_type;
495
496 #endif