blob: d1ae87df7776bd4133511a00cbd117c6fe5902d7 [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
Geoff Levandf58a9d12006-11-23 00:46:51 +010042/**
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
48struct ps3_device_id {
49 unsigned int bus_id;
50 unsigned int dev_id;
51};
52
53
54/* dma routines */
55
56enum 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
63enum 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
78struct 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
97static 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}
105int ps3_dma_region_create(struct ps3_dma_region *r);
106int ps3_dma_region_free(struct ps3_dma_region *r);
107int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
108 unsigned long len, unsigned long *bus_addr);
109int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
110 unsigned long len);
111
112/* mmio routines */
113
114enum 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
125struct 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
140static 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}
149int ps3_mmio_region_create(struct ps3_mmio_region *r);
150int ps3_free_mmio_region(struct ps3_mmio_region *r);
151unsigned long ps3_mm_phys_to_lpar(unsigned long phys_addr);
152
153/* inrerrupt routines */
154
Geoff Levand861be322007-01-26 19:08:08 -0800155enum ps3_cpu_binding {
156 PS3_BINDING_CPU_ANY = -1,
157 PS3_BINDING_CPU_0 = 0,
158 PS3_BINDING_CPU_1 = 1,
159};
160
161int ps3_alloc_io_irq(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
162 unsigned int *virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100163int ps3_free_io_irq(unsigned int virq);
Geoff Levand861be322007-01-26 19:08:08 -0800164int ps3_alloc_event_irq(enum ps3_cpu_binding cpu, unsigned int *virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100165int ps3_free_event_irq(unsigned int virq);
166int ps3_send_event_locally(unsigned int virq);
Geoff Levand861be322007-01-26 19:08:08 -0800167int ps3_connect_event_irq(enum ps3_cpu_binding cpu,
168 const struct ps3_device_id *did, unsigned int interrupt_id,
169 unsigned int *virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100170int ps3_disconnect_event_irq(const struct ps3_device_id *did,
171 unsigned int interrupt_id, unsigned int virq);
Geoff Levand861be322007-01-26 19:08:08 -0800172int ps3_alloc_vuart_irq(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
Geoff Levandf58a9d12006-11-23 00:46:51 +0100173 unsigned int *virq);
Geoff Levand861be322007-01-26 19:08:08 -0800174int ps3_free_vuart_irq(unsigned int virq);
175int ps3_alloc_spe_irq(enum ps3_cpu_binding cpu, unsigned long spe_id,
176 unsigned int class, unsigned int *virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100177int ps3_free_spe_irq(unsigned int virq);
Geert Uytterhoevenb1eeb382007-01-26 19:08:12 -0800178int ps3_alloc_irq(enum ps3_cpu_binding cpu, unsigned long outlet,
179 unsigned int *virq);
180int ps3_free_irq(unsigned int virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100181
182/* lv1 result codes */
183
184enum 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
212static 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
Geoff Levand6e74b382006-11-23 00:46:55 +0100275/* repository bus info */
276
277enum ps3_bus_type {
278 PS3_BUS_TYPE_SB = 4,
279 PS3_BUS_TYPE_STORAGE = 5,
280};
281
282enum ps3_dev_type {
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800283 PS3_DEV_TYPE_STOR_DISK = TYPE_DISK, /* 0 */
Geoff Levand6e74b382006-11-23 00:46:55 +0100284 PS3_DEV_TYPE_SB_GELIC = 3,
285 PS3_DEV_TYPE_SB_USB = 4,
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800286 PS3_DEV_TYPE_STOR_ROM = TYPE_ROM, /* 5 */
Geoff Levand6e74b382006-11-23 00:46:55 +0100287 PS3_DEV_TYPE_SB_GPIO = 6,
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800288 PS3_DEV_TYPE_STOR_FLASH = TYPE_RBC, /* 14 */
Geoff Levand6e74b382006-11-23 00:46:55 +0100289};
290
291int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
292 u64 *value);
293int ps3_repository_read_bus_id(unsigned int bus_index, unsigned int *bus_id);
294int ps3_repository_read_bus_type(unsigned int bus_index,
295 enum ps3_bus_type *bus_type);
296int ps3_repository_read_bus_num_dev(unsigned int bus_index,
297 unsigned int *num_dev);
298
299/* repository bus device info */
300
301enum 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
Geoff Levandeebb81c2007-01-26 19:07:47 -0800308enum ps3_reg_type {
309 PS3_REG_TYPE_SB_OHCI = 3,
310 PS3_REG_TYPE_SB_EHCI = 4,
311 PS3_REG_TYPE_SB_GPIO = 5,
Geoff Levand6e74b382006-11-23 00:46:55 +0100312};
313
314int ps3_repository_read_dev_str(unsigned int bus_index,
315 unsigned int dev_index, const char *dev_str, u64 *value);
316int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
317 unsigned int *dev_id);
318int ps3_repository_read_dev_type(unsigned int bus_index,
319 unsigned int dev_index, enum ps3_dev_type *dev_type);
320int 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);
323int ps3_repository_read_dev_reg_type(unsigned int bus_index,
324 unsigned int dev_index, unsigned int reg_index,
Geoff Levandeebb81c2007-01-26 19:07:47 -0800325 enum ps3_reg_type *reg_type);
Geoff Levand6e74b382006-11-23 00:46:55 +0100326int 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);
329int ps3_repository_read_dev_reg(unsigned int bus_index,
330 unsigned int dev_index, unsigned int reg_index,
Geoff Levandeebb81c2007-01-26 19:07:47 -0800331 enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len);
Geoff Levand6e74b382006-11-23 00:46:55 +0100332
333/* repository bus enumerators */
334
335struct ps3_repository_device {
336 unsigned int bus_index;
337 unsigned int dev_index;
338 struct ps3_device_id did;
339};
340
341int 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);
345static 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}
351int ps3_repository_find_interrupt(const struct ps3_repository_device *dev,
352 enum ps3_interrupt_type intr_type, unsigned int *interrupt_id);
Geoff Levandeebb81c2007-01-26 19:07:47 -0800353int ps3_repository_find_reg(const struct ps3_repository_device *dev,
354 enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len);
Geoff Levand6e74b382006-11-23 00:46:55 +0100355
356/* repository block device info */
357
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800358int ps3_repository_read_stor_dev_port(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100359 unsigned int dev_index, u64 *port);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800360int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100361 unsigned int dev_index, u64 *blk_size);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800362int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100363 unsigned int dev_index, u64 *num_blocks);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800364int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100365 unsigned int dev_index, unsigned int *num_regions);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800366int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100367 unsigned int dev_index, unsigned int region_index,
368 unsigned int *region_id);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800369int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100370 unsigned int dev_index, unsigned int region_index, u64 *region_size);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800371int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100372 unsigned int dev_index, unsigned int region_index, u64 *region_start);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800373int 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);
376int 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);
Geoff Levand6e74b382006-11-23 00:46:55 +0100379
380/* repository pu and memory info */
381
382int ps3_repository_read_num_pu(unsigned int *num_pu);
383int ps3_repository_read_ppe_id(unsigned int *pu_index, unsigned int *ppe_id);
384int ps3_repository_read_rm_base(unsigned int ppe_id, u64 *rm_base);
385int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size);
386int ps3_repository_read_region_total(u64 *region_total);
387int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size,
388 u64 *region_total);
389
390/* repository pme info */
391
392int ps3_repository_read_num_be(unsigned int *num_be);
393int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id);
394int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq);
395int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq);
396
397/* repository 'Other OS' area */
398
399int ps3_repository_read_boot_dat_addr(u64 *lpar_addr);
400int ps3_repository_read_boot_dat_size(unsigned int *size);
401int 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
413enum ps3_spu_resource_type {
414 PS3_SPU_RESOURCE_TYPE_SHARED = 0,
415 PS3_SPU_RESOURCE_TYPE_EXCLUSIVE = 0x8000000000000000UL,
416};
417
418int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved);
419int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id);
420int ps3_repository_read_spu_resource_id(unsigned int res_index,
421 enum ps3_spu_resource_type* resource_type, unsigned int *resource_id);
422
Geoff Levanda3d4d642006-11-23 00:47:00 +0100423
424/* system bus routines */
425
426enum 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
438struct 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
452struct 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
461int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
462int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
463void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
464static 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}
469static 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
481static 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}
486static 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
494extern struct bus_type ps3_system_bus_type;
495
Geoff Levandf58a9d12006-11-23 00:46:51 +0100496#endif