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