2 * PS3 platform declarations.
4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006 Sony Corp.
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.
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.
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
21 #if !defined(_ASM_POWERPC_PS3_H)
22 #define _ASM_POWERPC_PS3_H
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>
30 union ps3_firmware_version {
40 int ps3_get_firmware_version(union ps3_firmware_version *v);
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..}
48 struct ps3_device_id {
56 enum ps3_dma_page_size {
63 enum ps3_dma_region_type {
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.
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;
86 struct list_head head;
91 * struct ps3_dma_region_init - Helper to initialize structure variables
93 * Helper to properly initialize variables prior to calling
94 * ps3_system_bus_device_register.
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)
102 r->page_size = page_size;
103 r->region_type = region_type;
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,
114 enum ps3_mmio_page_size {
120 * struct ps3_mmio_region - a per device mmio state variables structure
122 * Current systems can be supported with a single region per device.
125 struct ps3_mmio_region {
126 struct ps3_device_id did;
127 unsigned long bus_addr;
129 enum ps3_mmio_page_size page_size;
130 unsigned long lpar_addr;
134 * struct ps3_mmio_region_init - Helper to initialize structure variables
136 * Helper to properly initialize variables prior to calling
137 * ps3_system_bus_device_register.
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)
145 r->bus_addr = bus_addr;
147 r->page_size = page_size;
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);
153 /* inrerrupt routines */
155 enum ps3_cpu_binding {
156 PS3_BINDING_CPU_ANY = -1,
157 PS3_BINDING_CPU_0 = 0,
158 PS3_BINDING_CPU_1 = 1,
161 int ps3_alloc_io_irq(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
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,
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,
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,
180 int ps3_free_irq(unsigned int virq);
182 /* lv1 result codes */
187 LV1_RESOURCE_SHORTAGE = -2,
188 LV1_NO_PRIVILEGE = -3,
189 LV1_DENIED_BY_POLICY = -4,
190 LV1_ACCESS_VIOLATION = -5,
192 LV1_DUPLICATE_ENTRY = -7,
193 LV1_TYPE_MISMATCH = -8,
196 LV1_WRONG_STATE = -11,
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,
212 static inline const char* ps3_result(int result)
217 return "LV1_SUCCESS (0)";
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)";
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)";
235 return "LV1_BUSY (-9)";
237 return "LV1_EMPTY (-10)";
238 case LV1_WRONG_STATE:
239 return "LV1_WRONG_STATE (-11)";
241 return "** unknown result ** (-12)";
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)";
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)";
268 return "** unknown result **";
275 /* repository bus info */
279 PS3_BUS_TYPE_STORAGE = 5,
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 */
291 int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
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);
299 /* repository bus device info */
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,
309 PS3_REG_TYPE_SB_OHCI = 3,
310 PS3_REG_TYPE_SB_EHCI = 4,
311 PS3_REG_TYPE_SB_GPIO = 5,
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,
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);
333 /* repository bus enumerators */
335 struct ps3_repository_device {
336 unsigned int bus_index;
337 unsigned int dev_index;
338 struct ps3_device_id did;
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)
349 return ps3_repository_find_device(bus_type, dev_type, NULL, dev);
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);
356 /* repository block device info */
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);
380 /* repository pu and memory info */
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,
390 /* repository pme info */
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);
397 /* repository 'Other OS' area */
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);
403 /* repository spu info */
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.
410 * Returned by ps3_repository_read_spu_resource_id().
413 enum ps3_spu_resource_type {
414 PS3_SPU_RESOURCE_TYPE_SHARED = 0,
415 PS3_SPU_RESOURCE_TYPE_EXCLUSIVE = 0x8000000000000000UL,
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);
424 /* system bus routines */
427 PS3_MATCH_ID_EHCI = 1,
430 PS3_MATCH_ID_AV_SETTINGS,
431 PS3_MATCH_ID_SYSTEM_MANAGER,
435 * struct ps3_system_bus_device - a device on the system bus
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;
449 * struct ps3_system_bus_driver - a driver for a device on the system bus
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 *); */
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)
467 return container_of(_drv, struct ps3_system_bus_driver, core);
469 static inline struct ps3_system_bus_device *to_ps3_system_bus_device(
472 return container_of(_dev, struct ps3_system_bus_device, core);
476 * ps3_system_bus_set_drvdata -
477 * @dev: device structure
481 static inline void ps3_system_bus_set_driver_data(
482 struct ps3_system_bus_device *dev, void *data)
484 dev->core.driver_data = data;
486 static inline void *ps3_system_bus_get_driver_data(
487 struct ps3_system_bus_device *dev)
489 return dev->core.driver_data;
492 /* These two need global scope for get_dma_ops(). */
494 extern struct bus_type ps3_system_bus_type;