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>
31 * struct ps3_device_id - HV bus device identifier from the system repository
32 * @bus_id: HV bus id, {1..} (zero invalid)
33 * @dev_id: HV device id, {0..}
36 struct ps3_device_id {
44 enum ps3_dma_page_size {
51 enum ps3_dma_region_type {
57 * struct ps3_dma_region - A per device dma state variables structure
58 * @did: The HV device id.
59 * @page_size: The ioc pagesize.
60 * @region_type: The HV region type.
61 * @bus_addr: The 'translated' bus address of the region.
62 * @len: The length in bytes of the region.
63 * @chunk_list: Opaque variable used by the ioc page manager.
66 struct ps3_dma_region {
67 struct ps3_device_id did;
68 enum ps3_dma_page_size page_size;
69 enum ps3_dma_region_type region_type;
70 unsigned long bus_addr;
74 struct list_head head;
79 * struct ps3_dma_region_init - Helper to initialize structure variables
81 * Helper to properly initialize variables prior to calling
82 * ps3_system_bus_device_register.
85 static inline void ps3_dma_region_init(struct ps3_dma_region *r,
86 const struct ps3_device_id* did, enum ps3_dma_page_size page_size,
87 enum ps3_dma_region_type region_type)
90 r->page_size = page_size;
91 r->region_type = region_type;
93 int ps3_dma_region_create(struct ps3_dma_region *r);
94 int ps3_dma_region_free(struct ps3_dma_region *r);
95 int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
96 unsigned long len, unsigned long *bus_addr);
97 int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
102 enum ps3_mmio_page_size {
108 * struct ps3_mmio_region - a per device mmio state variables structure
110 * Current systems can be supported with a single region per device.
113 struct ps3_mmio_region {
114 struct ps3_device_id did;
115 unsigned long bus_addr;
117 enum ps3_mmio_page_size page_size;
118 unsigned long lpar_addr;
122 * struct ps3_mmio_region_init - Helper to initialize structure variables
124 * Helper to properly initialize variables prior to calling
125 * ps3_system_bus_device_register.
128 static inline void ps3_mmio_region_init(struct ps3_mmio_region *r,
129 const struct ps3_device_id* did, unsigned long bus_addr,
130 unsigned long len, enum ps3_mmio_page_size page_size)
133 r->bus_addr = bus_addr;
135 r->page_size = page_size;
137 int ps3_mmio_region_create(struct ps3_mmio_region *r);
138 int ps3_free_mmio_region(struct ps3_mmio_region *r);
139 unsigned long ps3_mm_phys_to_lpar(unsigned long phys_addr);
141 /* inrerrupt routines */
143 int ps3_alloc_io_irq(unsigned int interrupt_id, unsigned int *virq);
144 int ps3_free_io_irq(unsigned int virq);
145 int ps3_alloc_event_irq(unsigned int *virq);
146 int ps3_free_event_irq(unsigned int virq);
147 int ps3_send_event_locally(unsigned int virq);
148 int ps3_connect_event_irq(const struct ps3_device_id *did,
149 unsigned int interrupt_id, unsigned int *virq);
150 int ps3_disconnect_event_irq(const struct ps3_device_id *did,
151 unsigned int interrupt_id, unsigned int virq);
152 int ps3_alloc_vuart_irq(void* virt_addr_bmp, unsigned int *virq);
153 int ps3_free_vuart_irq(unsigned int virq);
154 int ps3_alloc_spe_irq(unsigned long spe_id, unsigned int class,
156 int ps3_free_spe_irq(unsigned int virq);
158 /* lv1 result codes */
163 LV1_RESOURCE_SHORTAGE = -2,
164 LV1_NO_PRIVILEGE = -3,
165 LV1_DENIED_BY_POLICY = -4,
166 LV1_ACCESS_VIOLATION = -5,
168 LV1_DUPLICATE_ENTRY = -7,
169 LV1_TYPE_MISMATCH = -8,
172 LV1_WRONG_STATE = -11,
175 LV1_ALREADY_CONNECTED = -14,
176 LV1_UNSUPPORTED_PARAMETER_VALUE = -15,
177 LV1_CONDITION_NOT_SATISFIED = -16,
178 LV1_ILLEGAL_PARAMETER_VALUE = -17,
179 LV1_BAD_OPTION = -18,
180 LV1_IMPLEMENTATION_LIMITATION = -19,
181 LV1_NOT_IMPLEMENTED = -20,
182 LV1_INVALID_CLASS_ID = -21,
183 LV1_CONSTRAINT_NOT_SATISFIED = -22,
184 LV1_ALIGNMENT_ERROR = -23,
185 LV1_INTERNAL_ERROR = -32768,
188 static inline const char* ps3_result(int result)
193 return "LV1_SUCCESS (0)";
195 return "** unknown result ** (-1)";
196 case LV1_RESOURCE_SHORTAGE:
197 return "LV1_RESOURCE_SHORTAGE (-2)";
198 case LV1_NO_PRIVILEGE:
199 return "LV1_NO_PRIVILEGE (-3)";
200 case LV1_DENIED_BY_POLICY:
201 return "LV1_DENIED_BY_POLICY (-4)";
202 case LV1_ACCESS_VIOLATION:
203 return "LV1_ACCESS_VIOLATION (-5)";
205 return "LV1_NO_ENTRY (-6)";
206 case LV1_DUPLICATE_ENTRY:
207 return "LV1_DUPLICATE_ENTRY (-7)";
208 case LV1_TYPE_MISMATCH:
209 return "LV1_TYPE_MISMATCH (-8)";
211 return "LV1_BUSY (-9)";
213 return "LV1_EMPTY (-10)";
214 case LV1_WRONG_STATE:
215 return "LV1_WRONG_STATE (-11)";
217 return "** unknown result ** (-12)";
219 return "LV1_NO_MATCH (-13)";
220 case LV1_ALREADY_CONNECTED:
221 return "LV1_ALREADY_CONNECTED (-14)";
222 case LV1_UNSUPPORTED_PARAMETER_VALUE:
223 return "LV1_UNSUPPORTED_PARAMETER_VALUE (-15)";
224 case LV1_CONDITION_NOT_SATISFIED:
225 return "LV1_CONDITION_NOT_SATISFIED (-16)";
226 case LV1_ILLEGAL_PARAMETER_VALUE:
227 return "LV1_ILLEGAL_PARAMETER_VALUE (-17)";
229 return "LV1_BAD_OPTION (-18)";
230 case LV1_IMPLEMENTATION_LIMITATION:
231 return "LV1_IMPLEMENTATION_LIMITATION (-19)";
232 case LV1_NOT_IMPLEMENTED:
233 return "LV1_NOT_IMPLEMENTED (-20)";
234 case LV1_INVALID_CLASS_ID:
235 return "LV1_INVALID_CLASS_ID (-21)";
236 case LV1_CONSTRAINT_NOT_SATISFIED:
237 return "LV1_CONSTRAINT_NOT_SATISFIED (-22)";
238 case LV1_ALIGNMENT_ERROR:
239 return "LV1_ALIGNMENT_ERROR (-23)";
240 case LV1_INTERNAL_ERROR:
241 return "LV1_INTERNAL_ERROR (-32768)";
244 return "** unknown result **";
251 /* repository bus info */
255 PS3_BUS_TYPE_STORAGE = 5,
259 PS3_DEV_TYPE_STOR_DISK = TYPE_DISK, /* 0 */
260 PS3_DEV_TYPE_SB_GELIC = 3,
261 PS3_DEV_TYPE_SB_USB = 4,
262 PS3_DEV_TYPE_STOR_ROM = TYPE_ROM, /* 5 */
263 PS3_DEV_TYPE_SB_GPIO = 6,
264 PS3_DEV_TYPE_STOR_FLASH = TYPE_RBC, /* 14 */
267 int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
269 int ps3_repository_read_bus_id(unsigned int bus_index, unsigned int *bus_id);
270 int ps3_repository_read_bus_type(unsigned int bus_index,
271 enum ps3_bus_type *bus_type);
272 int ps3_repository_read_bus_num_dev(unsigned int bus_index,
273 unsigned int *num_dev);
275 /* repository bus device info */
277 enum ps3_interrupt_type {
278 PS3_INTERRUPT_TYPE_EVENT_PORT = 2,
279 PS3_INTERRUPT_TYPE_SB_OHCI = 3,
280 PS3_INTERRUPT_TYPE_SB_EHCI = 4,
281 PS3_INTERRUPT_TYPE_OTHER = 5,
285 PS3_REG_TYPE_SB_OHCI = 3,
286 PS3_REG_TYPE_SB_EHCI = 4,
287 PS3_REG_TYPE_SB_GPIO = 5,
290 int ps3_repository_read_dev_str(unsigned int bus_index,
291 unsigned int dev_index, const char *dev_str, u64 *value);
292 int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
293 unsigned int *dev_id);
294 int ps3_repository_read_dev_type(unsigned int bus_index,
295 unsigned int dev_index, enum ps3_dev_type *dev_type);
296 int ps3_repository_read_dev_intr(unsigned int bus_index,
297 unsigned int dev_index, unsigned int intr_index,
298 enum ps3_interrupt_type *intr_type, unsigned int *interrupt_id);
299 int ps3_repository_read_dev_reg_type(unsigned int bus_index,
300 unsigned int dev_index, unsigned int reg_index,
301 enum ps3_reg_type *reg_type);
302 int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
303 unsigned int dev_index, unsigned int reg_index, u64 *bus_addr,
305 int ps3_repository_read_dev_reg(unsigned int bus_index,
306 unsigned int dev_index, unsigned int reg_index,
307 enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len);
309 /* repository bus enumerators */
311 struct ps3_repository_device {
312 unsigned int bus_index;
313 unsigned int dev_index;
314 struct ps3_device_id did;
317 int ps3_repository_find_device(enum ps3_bus_type bus_type,
318 enum ps3_dev_type dev_type,
319 const struct ps3_repository_device *start_dev,
320 struct ps3_repository_device *dev);
321 static inline int ps3_repository_find_first_device(
322 enum ps3_bus_type bus_type, enum ps3_dev_type dev_type,
323 struct ps3_repository_device *dev)
325 return ps3_repository_find_device(bus_type, dev_type, NULL, dev);
327 int ps3_repository_find_interrupt(const struct ps3_repository_device *dev,
328 enum ps3_interrupt_type intr_type, unsigned int *interrupt_id);
329 int ps3_repository_find_reg(const struct ps3_repository_device *dev,
330 enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len);
332 /* repository block device info */
334 int ps3_repository_read_stor_dev_port(unsigned int bus_index,
335 unsigned int dev_index, u64 *port);
336 int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
337 unsigned int dev_index, u64 *blk_size);
338 int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
339 unsigned int dev_index, u64 *num_blocks);
340 int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
341 unsigned int dev_index, unsigned int *num_regions);
342 int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
343 unsigned int dev_index, unsigned int region_index,
344 unsigned int *region_id);
345 int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
346 unsigned int dev_index, unsigned int region_index, u64 *region_size);
347 int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
348 unsigned int dev_index, unsigned int region_index, u64 *region_start);
349 int ps3_repository_read_stor_dev_info(unsigned int bus_index,
350 unsigned int dev_index, u64 *port, u64 *blk_size,
351 u64 *num_blocks, unsigned int *num_regions);
352 int ps3_repository_read_stor_dev_region(unsigned int bus_index,
353 unsigned int dev_index, unsigned int region_index,
354 unsigned int *region_id, u64 *region_start, u64 *region_size);
356 /* repository pu and memory info */
358 int ps3_repository_read_num_pu(unsigned int *num_pu);
359 int ps3_repository_read_ppe_id(unsigned int *pu_index, unsigned int *ppe_id);
360 int ps3_repository_read_rm_base(unsigned int ppe_id, u64 *rm_base);
361 int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size);
362 int ps3_repository_read_region_total(u64 *region_total);
363 int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size,
366 /* repository pme info */
368 int ps3_repository_read_num_be(unsigned int *num_be);
369 int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id);
370 int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq);
371 int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq);
373 /* repository 'Other OS' area */
375 int ps3_repository_read_boot_dat_addr(u64 *lpar_addr);
376 int ps3_repository_read_boot_dat_size(unsigned int *size);
377 int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size);
379 /* repository spu info */
382 * enum spu_resource_type - Type of spu resource.
383 * @spu_resource_type_shared: Logical spu is shared with other partions.
384 * @spu_resource_type_exclusive: Logical spu is not shared with other partions.
386 * Returned by ps3_repository_read_spu_resource_id().
389 enum ps3_spu_resource_type {
390 PS3_SPU_RESOURCE_TYPE_SHARED = 0,
391 PS3_SPU_RESOURCE_TYPE_EXCLUSIVE = 0x8000000000000000UL,
394 int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved);
395 int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id);
396 int ps3_repository_read_spu_resource_id(unsigned int res_index,
397 enum ps3_spu_resource_type* resource_type, unsigned int *resource_id);
400 /* system bus routines */
403 PS3_MATCH_ID_EHCI = 1,
406 PS3_MATCH_ID_AV_SETTINGS,
407 PS3_MATCH_ID_SYSTEM_MANAGER,
411 * struct ps3_system_bus_device - a device on the system bus
414 struct ps3_system_bus_device {
415 enum ps3_match_id match_id;
416 struct ps3_device_id did;
417 unsigned int interrupt_id;
418 /* struct iommu_table *iommu_table; -- waiting for Ben's cleanups */
419 struct ps3_dma_region *d_region;
420 struct ps3_mmio_region *m_region;
425 * struct ps3_system_bus_driver - a driver for a device on the system bus
428 struct ps3_system_bus_driver {
429 enum ps3_match_id match_id;
430 struct device_driver core;
431 int (*probe)(struct ps3_system_bus_device *);
432 int (*remove)(struct ps3_system_bus_device *);
433 /* int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
434 /* int (*resume)(struct ps3_system_bus_device *); */
437 int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
438 int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
439 void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
440 static inline struct ps3_system_bus_driver *to_ps3_system_bus_driver(
441 struct device_driver *_drv)
443 return container_of(_drv, struct ps3_system_bus_driver, core);
445 static inline struct ps3_system_bus_device *to_ps3_system_bus_device(
448 return container_of(_dev, struct ps3_system_bus_device, core);
452 * ps3_system_bus_set_drvdata -
453 * @dev: device structure
457 static inline void ps3_system_bus_set_driver_data(
458 struct ps3_system_bus_device *dev, void *data)
460 dev->core.driver_data = data;
462 static inline void *ps3_system_bus_get_driver_data(
463 struct ps3_system_bus_device *dev)
465 return dev->core.driver_data;
468 /* These two need global scope for get_dma_ops(). */
470 extern struct bus_type ps3_system_bus_type;