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