blob: 021f802161a693db8596de4bc3f3c898746502e3 [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
30/**
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..}
34 */
35
36struct ps3_device_id {
37 unsigned int bus_id;
38 unsigned int dev_id;
39};
40
41
42/* dma routines */
43
44enum ps3_dma_page_size {
45 PS3_DMA_4K = 12U,
46 PS3_DMA_64K = 16U,
47 PS3_DMA_1M = 20U,
48 PS3_DMA_16M = 24U,
49};
50
51enum ps3_dma_region_type {
52 PS3_DMA_OTHER = 0,
53 PS3_DMA_INTERNAL = 2,
54};
55
56/**
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.
64 */
65
66struct 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;
71 unsigned long len;
72 struct {
73 spinlock_t lock;
74 struct list_head head;
75 } chunk_list;
76};
77
78/**
79 * struct ps3_dma_region_init - Helper to initialize structure variables
80 *
81 * Helper to properly initialize variables prior to calling
82 * ps3_system_bus_device_register.
83 */
84
85static 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)
88{
89 r->did = *did;
90 r->page_size = page_size;
91 r->region_type = region_type;
92}
93int ps3_dma_region_create(struct ps3_dma_region *r);
94int ps3_dma_region_free(struct ps3_dma_region *r);
95int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr,
96 unsigned long len, unsigned long *bus_addr);
97int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr,
98 unsigned long len);
99
100/* mmio routines */
101
102enum ps3_mmio_page_size {
103 PS3_MMIO_4K = 12U,
104 PS3_MMIO_64K = 16U
105};
106
107/**
108 * struct ps3_mmio_region - a per device mmio state variables structure
109 *
110 * Current systems can be supported with a single region per device.
111 */
112
113struct ps3_mmio_region {
114 struct ps3_device_id did;
115 unsigned long bus_addr;
116 unsigned long len;
117 enum ps3_mmio_page_size page_size;
118 unsigned long lpar_addr;
119};
120
121/**
122 * struct ps3_mmio_region_init - Helper to initialize structure variables
123 *
124 * Helper to properly initialize variables prior to calling
125 * ps3_system_bus_device_register.
126 */
127
128static 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)
131{
132 r->did = *did;
133 r->bus_addr = bus_addr;
134 r->len = len;
135 r->page_size = page_size;
136}
137int ps3_mmio_region_create(struct ps3_mmio_region *r);
138int ps3_free_mmio_region(struct ps3_mmio_region *r);
139unsigned long ps3_mm_phys_to_lpar(unsigned long phys_addr);
140
141/* inrerrupt routines */
142
Geoff Levand861be322007-01-26 19:08:08 -0800143enum ps3_cpu_binding {
144 PS3_BINDING_CPU_ANY = -1,
145 PS3_BINDING_CPU_0 = 0,
146 PS3_BINDING_CPU_1 = 1,
147};
148
149int ps3_alloc_io_irq(enum ps3_cpu_binding cpu, unsigned int interrupt_id,
150 unsigned int *virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100151int ps3_free_io_irq(unsigned int virq);
Geoff Levand861be322007-01-26 19:08:08 -0800152int ps3_alloc_event_irq(enum ps3_cpu_binding cpu, unsigned int *virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100153int ps3_free_event_irq(unsigned int virq);
154int ps3_send_event_locally(unsigned int virq);
Geoff Levand861be322007-01-26 19:08:08 -0800155int ps3_connect_event_irq(enum ps3_cpu_binding cpu,
156 const struct ps3_device_id *did, unsigned int interrupt_id,
157 unsigned int *virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100158int ps3_disconnect_event_irq(const struct ps3_device_id *did,
159 unsigned int interrupt_id, unsigned int virq);
Geoff Levand861be322007-01-26 19:08:08 -0800160int ps3_alloc_vuart_irq(enum ps3_cpu_binding cpu, void* virt_addr_bmp,
Geoff Levandf58a9d12006-11-23 00:46:51 +0100161 unsigned int *virq);
Geoff Levand861be322007-01-26 19:08:08 -0800162int ps3_free_vuart_irq(unsigned int virq);
163int ps3_alloc_spe_irq(enum ps3_cpu_binding cpu, unsigned long spe_id,
164 unsigned int class, unsigned int *virq);
Geoff Levandf58a9d12006-11-23 00:46:51 +0100165int ps3_free_spe_irq(unsigned int virq);
166
167/* lv1 result codes */
168
169enum lv1_result {
170 LV1_SUCCESS = 0,
171 /* not used -1 */
172 LV1_RESOURCE_SHORTAGE = -2,
173 LV1_NO_PRIVILEGE = -3,
174 LV1_DENIED_BY_POLICY = -4,
175 LV1_ACCESS_VIOLATION = -5,
176 LV1_NO_ENTRY = -6,
177 LV1_DUPLICATE_ENTRY = -7,
178 LV1_TYPE_MISMATCH = -8,
179 LV1_BUSY = -9,
180 LV1_EMPTY = -10,
181 LV1_WRONG_STATE = -11,
182 /* not used -12 */
183 LV1_NO_MATCH = -13,
184 LV1_ALREADY_CONNECTED = -14,
185 LV1_UNSUPPORTED_PARAMETER_VALUE = -15,
186 LV1_CONDITION_NOT_SATISFIED = -16,
187 LV1_ILLEGAL_PARAMETER_VALUE = -17,
188 LV1_BAD_OPTION = -18,
189 LV1_IMPLEMENTATION_LIMITATION = -19,
190 LV1_NOT_IMPLEMENTED = -20,
191 LV1_INVALID_CLASS_ID = -21,
192 LV1_CONSTRAINT_NOT_SATISFIED = -22,
193 LV1_ALIGNMENT_ERROR = -23,
194 LV1_INTERNAL_ERROR = -32768,
195};
196
197static inline const char* ps3_result(int result)
198{
199#if defined(DEBUG)
200 switch (result) {
201 case LV1_SUCCESS:
202 return "LV1_SUCCESS (0)";
203 case -1:
204 return "** unknown result ** (-1)";
205 case LV1_RESOURCE_SHORTAGE:
206 return "LV1_RESOURCE_SHORTAGE (-2)";
207 case LV1_NO_PRIVILEGE:
208 return "LV1_NO_PRIVILEGE (-3)";
209 case LV1_DENIED_BY_POLICY:
210 return "LV1_DENIED_BY_POLICY (-4)";
211 case LV1_ACCESS_VIOLATION:
212 return "LV1_ACCESS_VIOLATION (-5)";
213 case LV1_NO_ENTRY:
214 return "LV1_NO_ENTRY (-6)";
215 case LV1_DUPLICATE_ENTRY:
216 return "LV1_DUPLICATE_ENTRY (-7)";
217 case LV1_TYPE_MISMATCH:
218 return "LV1_TYPE_MISMATCH (-8)";
219 case LV1_BUSY:
220 return "LV1_BUSY (-9)";
221 case LV1_EMPTY:
222 return "LV1_EMPTY (-10)";
223 case LV1_WRONG_STATE:
224 return "LV1_WRONG_STATE (-11)";
225 case -12:
226 return "** unknown result ** (-12)";
227 case LV1_NO_MATCH:
228 return "LV1_NO_MATCH (-13)";
229 case LV1_ALREADY_CONNECTED:
230 return "LV1_ALREADY_CONNECTED (-14)";
231 case LV1_UNSUPPORTED_PARAMETER_VALUE:
232 return "LV1_UNSUPPORTED_PARAMETER_VALUE (-15)";
233 case LV1_CONDITION_NOT_SATISFIED:
234 return "LV1_CONDITION_NOT_SATISFIED (-16)";
235 case LV1_ILLEGAL_PARAMETER_VALUE:
236 return "LV1_ILLEGAL_PARAMETER_VALUE (-17)";
237 case LV1_BAD_OPTION:
238 return "LV1_BAD_OPTION (-18)";
239 case LV1_IMPLEMENTATION_LIMITATION:
240 return "LV1_IMPLEMENTATION_LIMITATION (-19)";
241 case LV1_NOT_IMPLEMENTED:
242 return "LV1_NOT_IMPLEMENTED (-20)";
243 case LV1_INVALID_CLASS_ID:
244 return "LV1_INVALID_CLASS_ID (-21)";
245 case LV1_CONSTRAINT_NOT_SATISFIED:
246 return "LV1_CONSTRAINT_NOT_SATISFIED (-22)";
247 case LV1_ALIGNMENT_ERROR:
248 return "LV1_ALIGNMENT_ERROR (-23)";
249 case LV1_INTERNAL_ERROR:
250 return "LV1_INTERNAL_ERROR (-32768)";
251 default:
252 BUG();
253 return "** unknown result **";
254 };
255#else
256 return "";
257#endif
258}
259
Geoff Levand6e74b382006-11-23 00:46:55 +0100260/* repository bus info */
261
262enum ps3_bus_type {
263 PS3_BUS_TYPE_SB = 4,
264 PS3_BUS_TYPE_STORAGE = 5,
265};
266
267enum ps3_dev_type {
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800268 PS3_DEV_TYPE_STOR_DISK = TYPE_DISK, /* 0 */
Geoff Levand6e74b382006-11-23 00:46:55 +0100269 PS3_DEV_TYPE_SB_GELIC = 3,
270 PS3_DEV_TYPE_SB_USB = 4,
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800271 PS3_DEV_TYPE_STOR_ROM = TYPE_ROM, /* 5 */
Geoff Levand6e74b382006-11-23 00:46:55 +0100272 PS3_DEV_TYPE_SB_GPIO = 6,
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800273 PS3_DEV_TYPE_STOR_FLASH = TYPE_RBC, /* 14 */
Geoff Levand6e74b382006-11-23 00:46:55 +0100274};
275
276int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str,
277 u64 *value);
278int ps3_repository_read_bus_id(unsigned int bus_index, unsigned int *bus_id);
279int ps3_repository_read_bus_type(unsigned int bus_index,
280 enum ps3_bus_type *bus_type);
281int ps3_repository_read_bus_num_dev(unsigned int bus_index,
282 unsigned int *num_dev);
283
284/* repository bus device info */
285
286enum ps3_interrupt_type {
287 PS3_INTERRUPT_TYPE_EVENT_PORT = 2,
288 PS3_INTERRUPT_TYPE_SB_OHCI = 3,
289 PS3_INTERRUPT_TYPE_SB_EHCI = 4,
290 PS3_INTERRUPT_TYPE_OTHER = 5,
291};
292
Geoff Levandeebb81c2007-01-26 19:07:47 -0800293enum ps3_reg_type {
294 PS3_REG_TYPE_SB_OHCI = 3,
295 PS3_REG_TYPE_SB_EHCI = 4,
296 PS3_REG_TYPE_SB_GPIO = 5,
Geoff Levand6e74b382006-11-23 00:46:55 +0100297};
298
299int ps3_repository_read_dev_str(unsigned int bus_index,
300 unsigned int dev_index, const char *dev_str, u64 *value);
301int ps3_repository_read_dev_id(unsigned int bus_index, unsigned int dev_index,
302 unsigned int *dev_id);
303int ps3_repository_read_dev_type(unsigned int bus_index,
304 unsigned int dev_index, enum ps3_dev_type *dev_type);
305int ps3_repository_read_dev_intr(unsigned int bus_index,
306 unsigned int dev_index, unsigned int intr_index,
307 enum ps3_interrupt_type *intr_type, unsigned int *interrupt_id);
308int ps3_repository_read_dev_reg_type(unsigned int bus_index,
309 unsigned int dev_index, unsigned int reg_index,
Geoff Levandeebb81c2007-01-26 19:07:47 -0800310 enum ps3_reg_type *reg_type);
Geoff Levand6e74b382006-11-23 00:46:55 +0100311int ps3_repository_read_dev_reg_addr(unsigned int bus_index,
312 unsigned int dev_index, unsigned int reg_index, u64 *bus_addr,
313 u64 *len);
314int ps3_repository_read_dev_reg(unsigned int bus_index,
315 unsigned int dev_index, unsigned int reg_index,
Geoff Levandeebb81c2007-01-26 19:07:47 -0800316 enum ps3_reg_type *reg_type, u64 *bus_addr, u64 *len);
Geoff Levand6e74b382006-11-23 00:46:55 +0100317
318/* repository bus enumerators */
319
320struct ps3_repository_device {
321 unsigned int bus_index;
322 unsigned int dev_index;
323 struct ps3_device_id did;
324};
325
326int ps3_repository_find_device(enum ps3_bus_type bus_type,
327 enum ps3_dev_type dev_type,
328 const struct ps3_repository_device *start_dev,
329 struct ps3_repository_device *dev);
330static inline int ps3_repository_find_first_device(
331 enum ps3_bus_type bus_type, enum ps3_dev_type dev_type,
332 struct ps3_repository_device *dev)
333{
334 return ps3_repository_find_device(bus_type, dev_type, NULL, dev);
335}
336int ps3_repository_find_interrupt(const struct ps3_repository_device *dev,
337 enum ps3_interrupt_type intr_type, unsigned int *interrupt_id);
Geoff Levandeebb81c2007-01-26 19:07:47 -0800338int ps3_repository_find_reg(const struct ps3_repository_device *dev,
339 enum ps3_reg_type reg_type, u64 *bus_addr, u64 *len);
Geoff Levand6e74b382006-11-23 00:46:55 +0100340
341/* repository block device info */
342
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800343int ps3_repository_read_stor_dev_port(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100344 unsigned int dev_index, u64 *port);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800345int ps3_repository_read_stor_dev_blk_size(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100346 unsigned int dev_index, u64 *blk_size);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800347int ps3_repository_read_stor_dev_num_blocks(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100348 unsigned int dev_index, u64 *num_blocks);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800349int ps3_repository_read_stor_dev_num_regions(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100350 unsigned int dev_index, unsigned int *num_regions);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800351int ps3_repository_read_stor_dev_region_id(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100352 unsigned int dev_index, unsigned int region_index,
353 unsigned int *region_id);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800354int ps3_repository_read_stor_dev_region_size(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100355 unsigned int dev_index, unsigned int region_index, u64 *region_size);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800356int ps3_repository_read_stor_dev_region_start(unsigned int bus_index,
Geoff Levand6e74b382006-11-23 00:46:55 +0100357 unsigned int dev_index, unsigned int region_index, u64 *region_start);
Geert Uytterhoeven6c7be7d2007-01-26 19:07:51 -0800358int ps3_repository_read_stor_dev_info(unsigned int bus_index,
359 unsigned int dev_index, u64 *port, u64 *blk_size,
360 u64 *num_blocks, unsigned int *num_regions);
361int ps3_repository_read_stor_dev_region(unsigned int bus_index,
362 unsigned int dev_index, unsigned int region_index,
363 unsigned int *region_id, u64 *region_start, u64 *region_size);
Geoff Levand6e74b382006-11-23 00:46:55 +0100364
365/* repository pu and memory info */
366
367int ps3_repository_read_num_pu(unsigned int *num_pu);
368int ps3_repository_read_ppe_id(unsigned int *pu_index, unsigned int *ppe_id);
369int ps3_repository_read_rm_base(unsigned int ppe_id, u64 *rm_base);
370int ps3_repository_read_rm_size(unsigned int ppe_id, u64 *rm_size);
371int ps3_repository_read_region_total(u64 *region_total);
372int ps3_repository_read_mm_info(u64 *rm_base, u64 *rm_size,
373 u64 *region_total);
374
375/* repository pme info */
376
377int ps3_repository_read_num_be(unsigned int *num_be);
378int ps3_repository_read_be_node_id(unsigned int be_index, u64 *node_id);
379int ps3_repository_read_tb_freq(u64 node_id, u64 *tb_freq);
380int ps3_repository_read_be_tb_freq(unsigned int be_index, u64 *tb_freq);
381
382/* repository 'Other OS' area */
383
384int ps3_repository_read_boot_dat_addr(u64 *lpar_addr);
385int ps3_repository_read_boot_dat_size(unsigned int *size);
386int ps3_repository_read_boot_dat_info(u64 *lpar_addr, unsigned int *size);
387
388/* repository spu info */
389
390/**
391 * enum spu_resource_type - Type of spu resource.
392 * @spu_resource_type_shared: Logical spu is shared with other partions.
393 * @spu_resource_type_exclusive: Logical spu is not shared with other partions.
394 *
395 * Returned by ps3_repository_read_spu_resource_id().
396 */
397
398enum ps3_spu_resource_type {
399 PS3_SPU_RESOURCE_TYPE_SHARED = 0,
400 PS3_SPU_RESOURCE_TYPE_EXCLUSIVE = 0x8000000000000000UL,
401};
402
403int ps3_repository_read_num_spu_reserved(unsigned int *num_spu_reserved);
404int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id);
405int ps3_repository_read_spu_resource_id(unsigned int res_index,
406 enum ps3_spu_resource_type* resource_type, unsigned int *resource_id);
407
Geoff Levanda3d4d642006-11-23 00:47:00 +0100408
409/* system bus routines */
410
411enum ps3_match_id {
412 PS3_MATCH_ID_EHCI = 1,
413 PS3_MATCH_ID_OHCI,
414 PS3_MATCH_ID_GELIC,
415 PS3_MATCH_ID_AV_SETTINGS,
416 PS3_MATCH_ID_SYSTEM_MANAGER,
417};
418
419/**
420 * struct ps3_system_bus_device - a device on the system bus
421 */
422
423struct ps3_system_bus_device {
424 enum ps3_match_id match_id;
425 struct ps3_device_id did;
426 unsigned int interrupt_id;
427/* struct iommu_table *iommu_table; -- waiting for Ben's cleanups */
428 struct ps3_dma_region *d_region;
429 struct ps3_mmio_region *m_region;
430 struct device core;
431};
432
433/**
434 * struct ps3_system_bus_driver - a driver for a device on the system bus
435 */
436
437struct ps3_system_bus_driver {
438 enum ps3_match_id match_id;
439 struct device_driver core;
440 int (*probe)(struct ps3_system_bus_device *);
441 int (*remove)(struct ps3_system_bus_device *);
442/* int (*suspend)(struct ps3_system_bus_device *, pm_message_t); */
443/* int (*resume)(struct ps3_system_bus_device *); */
444};
445
446int ps3_system_bus_device_register(struct ps3_system_bus_device *dev);
447int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv);
448void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv);
449static inline struct ps3_system_bus_driver *to_ps3_system_bus_driver(
450 struct device_driver *_drv)
451{
452 return container_of(_drv, struct ps3_system_bus_driver, core);
453}
454static inline struct ps3_system_bus_device *to_ps3_system_bus_device(
455 struct device *_dev)
456{
457 return container_of(_dev, struct ps3_system_bus_device, core);
458}
459
460/**
461 * ps3_system_bus_set_drvdata -
462 * @dev: device structure
463 * @data: Data to set
464 */
465
466static inline void ps3_system_bus_set_driver_data(
467 struct ps3_system_bus_device *dev, void *data)
468{
469 dev->core.driver_data = data;
470}
471static inline void *ps3_system_bus_get_driver_data(
472 struct ps3_system_bus_device *dev)
473{
474 return dev->core.driver_data;
475}
476
477/* These two need global scope for get_dma_ops(). */
478
479extern struct bus_type ps3_system_bus_type;
480
Geoff Levandf58a9d12006-11-23 00:46:51 +0100481#endif