diff options
author | Geoff Levand <geoffrey.levand@am.sony.com> | 2007-06-15 17:52:02 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-06-28 05:16:38 -0400 |
commit | 6bb5cf1025414fe00b20f3bef56135849e4ed3b8 (patch) | |
tree | d8cc37288ce123dc790af37f99b7bcc7c9e1872d /arch/powerpc/platforms/ps3 | |
parent | 9263e85aa9e9d341ef238fffc040f586674d1709 (diff) |
[POWERPC] PS3: System-bus rework
Rework the PS3 system bus to unify device support.
- DMA region sizes must be a power of two
- storage bus DMA updates:
- Small fixes for the PS3 DMA core:
o fix alignment bug
o kill superfluous test
o indentation
o spelling
o export ps3_dma_region_{create,free}()
- ps3_dma_region_init():
o Add `addr' and `len' parameters, so you can create a DMA region that
does not cover all memory (use `NULL' and `0' to cover all memory).
This is needed because there are not sufficient IOMMU resources to have
all DMA regions cover all memory.
o Uninline
- Added remove and shutdown routines to all drivers.
- Added loadable module support to all drivers.
- Added HV calls for iopte management (needed by sound driver).
Signed-off-by: MOKUNO Masakazu <mokuno@sm.sony.co.jp>
Signed-off-by: Geert Uytterhoeven <Geert.Uytterhoeven@sonycom.com>
Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/platforms/ps3')
-rw-r--r-- | arch/powerpc/platforms/ps3/interrupt.c | 24 | ||||
-rw-r--r-- | arch/powerpc/platforms/ps3/mm.c | 622 | ||||
-rw-r--r-- | arch/powerpc/platforms/ps3/platform.h | 11 | ||||
-rw-r--r-- | arch/powerpc/platforms/ps3/system-bus.c | 533 |
4 files changed, 988 insertions, 202 deletions
diff --git a/arch/powerpc/platforms/ps3/interrupt.c b/arch/powerpc/platforms/ps3/interrupt.c index 462eacc55c97..51141dc06f91 100644 --- a/arch/powerpc/platforms/ps3/interrupt.c +++ b/arch/powerpc/platforms/ps3/interrupt.c | |||
@@ -400,17 +400,15 @@ int ps3_send_event_locally(unsigned int virq) | |||
400 | * ps3_sb_event_receive_port_setup - Setup a system bus event receive port. | 400 | * ps3_sb_event_receive_port_setup - Setup a system bus event receive port. |
401 | * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be | 401 | * @cpu: enum ps3_cpu_binding indicating the cpu the interrupt should be |
402 | * serviced on. | 402 | * serviced on. |
403 | * @did: The HV device identifier read from the system repository. | 403 | * @dev: The system bus device instance. |
404 | * @interrupt_id: The device interrupt id read from the system repository. | ||
405 | * @virq: The assigned Linux virq. | 404 | * @virq: The assigned Linux virq. |
406 | * | 405 | * |
407 | * An event irq represents a virtual device interrupt. The interrupt_id | 406 | * An event irq represents a virtual device interrupt. The interrupt_id |
408 | * coresponds to the software interrupt number. | 407 | * coresponds to the software interrupt number. |
409 | */ | 408 | */ |
410 | 409 | ||
411 | int ps3_sb_event_receive_port_setup(enum ps3_cpu_binding cpu, | 410 | int ps3_sb_event_receive_port_setup(struct ps3_system_bus_device *dev, |
412 | const struct ps3_device_id *did, unsigned int interrupt_id, | 411 | enum ps3_cpu_binding cpu, unsigned int *virq) |
413 | unsigned int *virq) | ||
414 | { | 412 | { |
415 | /* this should go in system-bus.c */ | 413 | /* this should go in system-bus.c */ |
416 | 414 | ||
@@ -421,8 +419,8 @@ int ps3_sb_event_receive_port_setup(enum ps3_cpu_binding cpu, | |||
421 | if (result) | 419 | if (result) |
422 | return result; | 420 | return result; |
423 | 421 | ||
424 | result = lv1_connect_interrupt_event_receive_port(did->bus_id, | 422 | result = lv1_connect_interrupt_event_receive_port(dev->bus_id, |
425 | did->dev_id, virq_to_hw(*virq), interrupt_id); | 423 | dev->dev_id, virq_to_hw(*virq), dev->interrupt_id); |
426 | 424 | ||
427 | if (result) { | 425 | if (result) { |
428 | pr_debug("%s:%d: lv1_connect_interrupt_event_receive_port" | 426 | pr_debug("%s:%d: lv1_connect_interrupt_event_receive_port" |
@@ -434,24 +432,24 @@ int ps3_sb_event_receive_port_setup(enum ps3_cpu_binding cpu, | |||
434 | } | 432 | } |
435 | 433 | ||
436 | pr_debug("%s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__, | 434 | pr_debug("%s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__, |
437 | interrupt_id, *virq); | 435 | dev->interrupt_id, *virq); |
438 | 436 | ||
439 | return 0; | 437 | return 0; |
440 | } | 438 | } |
441 | EXPORT_SYMBOL(ps3_sb_event_receive_port_setup); | 439 | EXPORT_SYMBOL(ps3_sb_event_receive_port_setup); |
442 | 440 | ||
443 | int ps3_sb_event_receive_port_destroy(const struct ps3_device_id *did, | 441 | int ps3_sb_event_receive_port_destroy(struct ps3_system_bus_device *dev, |
444 | unsigned int interrupt_id, unsigned int virq) | 442 | unsigned int virq) |
445 | { | 443 | { |
446 | /* this should go in system-bus.c */ | 444 | /* this should go in system-bus.c */ |
447 | 445 | ||
448 | int result; | 446 | int result; |
449 | 447 | ||
450 | pr_debug(" -> %s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__, | 448 | pr_debug(" -> %s:%d: interrupt_id %u, virq %u\n", __func__, __LINE__, |
451 | interrupt_id, virq); | 449 | dev->interrupt_id, virq); |
452 | 450 | ||
453 | result = lv1_disconnect_interrupt_event_receive_port(did->bus_id, | 451 | result = lv1_disconnect_interrupt_event_receive_port(dev->bus_id, |
454 | did->dev_id, virq_to_hw(virq), interrupt_id); | 452 | dev->dev_id, virq_to_hw(virq), dev->interrupt_id); |
455 | 453 | ||
456 | if (result) | 454 | if (result) |
457 | pr_debug("%s:%d: lv1_disconnect_interrupt_event_receive_port" | 455 | pr_debug("%s:%d: lv1_disconnect_interrupt_event_receive_port" |
diff --git a/arch/powerpc/platforms/ps3/mm.c b/arch/powerpc/platforms/ps3/mm.c index 39c200b34985..c49c5dcb9485 100644 --- a/arch/powerpc/platforms/ps3/mm.c +++ b/arch/powerpc/platforms/ps3/mm.c | |||
@@ -115,7 +115,8 @@ struct map { | |||
115 | }; | 115 | }; |
116 | 116 | ||
117 | #define debug_dump_map(x) _debug_dump_map(x, __func__, __LINE__) | 117 | #define debug_dump_map(x) _debug_dump_map(x, __func__, __LINE__) |
118 | static void _debug_dump_map(const struct map* m, const char* func, int line) | 118 | static void __maybe_unused _debug_dump_map(const struct map *m, |
119 | const char *func, int line) | ||
119 | { | 120 | { |
120 | DBG("%s:%d: map.total = %lxh\n", func, line, m->total); | 121 | DBG("%s:%d: map.total = %lxh\n", func, line, m->total); |
121 | DBG("%s:%d: map.rm.size = %lxh\n", func, line, m->rm.size); | 122 | DBG("%s:%d: map.rm.size = %lxh\n", func, line, m->rm.size); |
@@ -212,9 +213,15 @@ fail: | |||
212 | 213 | ||
213 | void ps3_mm_vas_destroy(void) | 214 | void ps3_mm_vas_destroy(void) |
214 | { | 215 | { |
216 | int result; | ||
217 | |||
218 | DBG("%s:%d: map.vas_id = %lu\n", __func__, __LINE__, map.vas_id); | ||
219 | |||
215 | if (map.vas_id) { | 220 | if (map.vas_id) { |
216 | lv1_select_virtual_address_space(0); | 221 | result = lv1_select_virtual_address_space(0); |
217 | lv1_destruct_virtual_address_space(map.vas_id); | 222 | BUG_ON(result); |
223 | result = lv1_destruct_virtual_address_space(map.vas_id); | ||
224 | BUG_ON(result); | ||
218 | map.vas_id = 0; | 225 | map.vas_id = 0; |
219 | } | 226 | } |
220 | } | 227 | } |
@@ -275,8 +282,12 @@ zero_region: | |||
275 | 282 | ||
276 | void ps3_mm_region_destroy(struct mem_region *r) | 283 | void ps3_mm_region_destroy(struct mem_region *r) |
277 | { | 284 | { |
285 | int result; | ||
286 | |||
287 | DBG("%s:%d: r->base = %lxh\n", __func__, __LINE__, r->base); | ||
278 | if (r->base) { | 288 | if (r->base) { |
279 | lv1_release_memory(r->base); | 289 | result = lv1_release_memory(r->base); |
290 | BUG_ON(result); | ||
280 | r->size = r->base = r->offset = 0; | 291 | r->size = r->base = r->offset = 0; |
281 | map.total = map.rm.size; | 292 | map.total = map.rm.size; |
282 | } | 293 | } |
@@ -329,31 +340,34 @@ core_initcall(ps3_mm_add_memory); | |||
329 | /*============================================================================*/ | 340 | /*============================================================================*/ |
330 | 341 | ||
331 | /** | 342 | /** |
332 | * dma_lpar_to_bus - Translate an lpar address to ioc mapped bus address. | 343 | * dma_sb_lpar_to_bus - Translate an lpar address to ioc mapped bus address. |
333 | * @r: pointer to dma region structure | 344 | * @r: pointer to dma region structure |
334 | * @lpar_addr: HV lpar address | 345 | * @lpar_addr: HV lpar address |
335 | */ | 346 | */ |
336 | 347 | ||
337 | static unsigned long dma_lpar_to_bus(struct ps3_dma_region *r, | 348 | static unsigned long dma_sb_lpar_to_bus(struct ps3_dma_region *r, |
338 | unsigned long lpar_addr) | 349 | unsigned long lpar_addr) |
339 | { | 350 | { |
340 | BUG_ON(lpar_addr >= map.r1.base + map.r1.size); | 351 | if (lpar_addr >= map.rm.size) |
341 | return r->bus_addr + (lpar_addr <= map.rm.size ? lpar_addr | 352 | lpar_addr -= map.r1.offset; |
342 | : lpar_addr - map.r1.offset); | 353 | BUG_ON(lpar_addr < r->offset); |
354 | BUG_ON(lpar_addr >= r->offset + r->len); | ||
355 | return r->bus_addr + lpar_addr - r->offset; | ||
343 | } | 356 | } |
344 | 357 | ||
345 | #define dma_dump_region(_a) _dma_dump_region(_a, __func__, __LINE__) | 358 | #define dma_dump_region(_a) _dma_dump_region(_a, __func__, __LINE__) |
346 | static void _dma_dump_region(const struct ps3_dma_region *r, const char* func, | 359 | static void __maybe_unused _dma_dump_region(const struct ps3_dma_region *r, |
347 | int line) | 360 | const char *func, int line) |
348 | { | 361 | { |
349 | DBG("%s:%d: dev %u:%u\n", func, line, r->did.bus_id, | 362 | DBG("%s:%d: dev %u:%u\n", func, line, r->dev->bus_id, |
350 | r->did.dev_id); | 363 | r->dev->dev_id); |
351 | DBG("%s:%d: page_size %u\n", func, line, r->page_size); | 364 | DBG("%s:%d: page_size %u\n", func, line, r->page_size); |
352 | DBG("%s:%d: bus_addr %lxh\n", func, line, r->bus_addr); | 365 | DBG("%s:%d: bus_addr %lxh\n", func, line, r->bus_addr); |
353 | DBG("%s:%d: len %lxh\n", func, line, r->len); | 366 | DBG("%s:%d: len %lxh\n", func, line, r->len); |
367 | DBG("%s:%d: offset %lxh\n", func, line, r->offset); | ||
354 | } | 368 | } |
355 | 369 | ||
356 | /** | 370 | /** |
357 | * dma_chunk - A chunk of dma pages mapped by the io controller. | 371 | * dma_chunk - A chunk of dma pages mapped by the io controller. |
358 | * @region - The dma region that owns this chunk. | 372 | * @region - The dma region that owns this chunk. |
359 | * @lpar_addr: Starting lpar address of the area to map. | 373 | * @lpar_addr: Starting lpar address of the area to map. |
@@ -381,10 +395,11 @@ static void _dma_dump_chunk (const struct dma_chunk* c, const char* func, | |||
381 | int line) | 395 | int line) |
382 | { | 396 | { |
383 | DBG("%s:%d: r.dev %u:%u\n", func, line, | 397 | DBG("%s:%d: r.dev %u:%u\n", func, line, |
384 | c->region->did.bus_id, c->region->did.dev_id); | 398 | c->region->dev->bus_id, c->region->dev->dev_id); |
385 | DBG("%s:%d: r.bus_addr %lxh\n", func, line, c->region->bus_addr); | 399 | DBG("%s:%d: r.bus_addr %lxh\n", func, line, c->region->bus_addr); |
386 | DBG("%s:%d: r.page_size %u\n", func, line, c->region->page_size); | 400 | DBG("%s:%d: r.page_size %u\n", func, line, c->region->page_size); |
387 | DBG("%s:%d: r.len %lxh\n", func, line, c->region->len); | 401 | DBG("%s:%d: r.len %lxh\n", func, line, c->region->len); |
402 | DBG("%s:%d: r.offset %lxh\n", func, line, c->region->offset); | ||
388 | DBG("%s:%d: c.lpar_addr %lxh\n", func, line, c->lpar_addr); | 403 | DBG("%s:%d: c.lpar_addr %lxh\n", func, line, c->lpar_addr); |
389 | DBG("%s:%d: c.bus_addr %lxh\n", func, line, c->bus_addr); | 404 | DBG("%s:%d: c.bus_addr %lxh\n", func, line, c->bus_addr); |
390 | DBG("%s:%d: c.len %lxh\n", func, line, c->len); | 405 | DBG("%s:%d: c.len %lxh\n", func, line, c->len); |
@@ -395,39 +410,68 @@ static struct dma_chunk * dma_find_chunk(struct ps3_dma_region *r, | |||
395 | { | 410 | { |
396 | struct dma_chunk *c; | 411 | struct dma_chunk *c; |
397 | unsigned long aligned_bus = _ALIGN_DOWN(bus_addr, 1 << r->page_size); | 412 | unsigned long aligned_bus = _ALIGN_DOWN(bus_addr, 1 << r->page_size); |
398 | unsigned long aligned_len = _ALIGN_UP(len, 1 << r->page_size); | 413 | unsigned long aligned_len = _ALIGN_UP(len+bus_addr-aligned_bus, |
414 | 1 << r->page_size); | ||
399 | 415 | ||
400 | list_for_each_entry(c, &r->chunk_list.head, link) { | 416 | list_for_each_entry(c, &r->chunk_list.head, link) { |
401 | /* intersection */ | 417 | /* intersection */ |
402 | if (aligned_bus >= c->bus_addr | 418 | if (aligned_bus >= c->bus_addr && |
403 | && aligned_bus < c->bus_addr + c->len | 419 | aligned_bus + aligned_len <= c->bus_addr + c->len) |
404 | && aligned_bus + aligned_len <= c->bus_addr + c->len) { | ||
405 | return c; | 420 | return c; |
406 | } | 421 | |
407 | /* below */ | 422 | /* below */ |
408 | if (aligned_bus + aligned_len <= c->bus_addr) { | 423 | if (aligned_bus + aligned_len <= c->bus_addr) |
409 | continue; | 424 | continue; |
410 | } | 425 | |
411 | /* above */ | 426 | /* above */ |
412 | if (aligned_bus >= c->bus_addr + c->len) { | 427 | if (aligned_bus >= c->bus_addr + c->len) |
413 | continue; | 428 | continue; |
414 | } | ||
415 | 429 | ||
416 | /* we don't handle the multi-chunk case for now */ | 430 | /* we don't handle the multi-chunk case for now */ |
417 | |||
418 | dma_dump_chunk(c); | 431 | dma_dump_chunk(c); |
419 | BUG(); | 432 | BUG(); |
420 | } | 433 | } |
421 | return NULL; | 434 | return NULL; |
422 | } | 435 | } |
423 | 436 | ||
424 | static int dma_free_chunk(struct dma_chunk *c) | 437 | static struct dma_chunk *dma_find_chunk_lpar(struct ps3_dma_region *r, |
438 | unsigned long lpar_addr, unsigned long len) | ||
439 | { | ||
440 | struct dma_chunk *c; | ||
441 | unsigned long aligned_lpar = _ALIGN_DOWN(lpar_addr, 1 << r->page_size); | ||
442 | unsigned long aligned_len = _ALIGN_UP(len + lpar_addr - aligned_lpar, | ||
443 | 1 << r->page_size); | ||
444 | |||
445 | list_for_each_entry(c, &r->chunk_list.head, link) { | ||
446 | /* intersection */ | ||
447 | if (c->lpar_addr <= aligned_lpar && | ||
448 | aligned_lpar < c->lpar_addr + c->len) { | ||
449 | if (aligned_lpar + aligned_len <= c->lpar_addr + c->len) | ||
450 | return c; | ||
451 | else { | ||
452 | dma_dump_chunk(c); | ||
453 | BUG(); | ||
454 | } | ||
455 | } | ||
456 | /* below */ | ||
457 | if (aligned_lpar + aligned_len <= c->lpar_addr) { | ||
458 | continue; | ||
459 | } | ||
460 | /* above */ | ||
461 | if (c->lpar_addr + c->len <= aligned_lpar) { | ||
462 | continue; | ||
463 | } | ||
464 | } | ||
465 | return NULL; | ||
466 | } | ||
467 | |||
468 | static int dma_sb_free_chunk(struct dma_chunk *c) | ||
425 | { | 469 | { |
426 | int result = 0; | 470 | int result = 0; |
427 | 471 | ||
428 | if (c->bus_addr) { | 472 | if (c->bus_addr) { |
429 | result = lv1_unmap_device_dma_region(c->region->did.bus_id, | 473 | result = lv1_unmap_device_dma_region(c->region->dev->bus_id, |
430 | c->region->did.dev_id, c->bus_addr, c->len); | 474 | c->region->dev->dev_id, c->bus_addr, c->len); |
431 | BUG_ON(result); | 475 | BUG_ON(result); |
432 | } | 476 | } |
433 | 477 | ||
@@ -435,8 +479,39 @@ static int dma_free_chunk(struct dma_chunk *c) | |||
435 | return result; | 479 | return result; |
436 | } | 480 | } |
437 | 481 | ||
482 | static int dma_ioc0_free_chunk(struct dma_chunk *c) | ||
483 | { | ||
484 | int result = 0; | ||
485 | int iopage; | ||
486 | unsigned long offset; | ||
487 | struct ps3_dma_region *r = c->region; | ||
488 | |||
489 | DBG("%s:start\n", __func__); | ||
490 | for (iopage = 0; iopage < (c->len >> r->page_size); iopage++) { | ||
491 | offset = (1 << r->page_size) * iopage; | ||
492 | /* put INVALID entry */ | ||
493 | result = lv1_put_iopte(0, | ||
494 | c->bus_addr + offset, | ||
495 | c->lpar_addr + offset, | ||
496 | r->ioid, | ||
497 | 0); | ||
498 | DBG("%s: bus=%#lx, lpar=%#lx, ioid=%d\n", __func__, | ||
499 | c->bus_addr + offset, | ||
500 | c->lpar_addr + offset, | ||
501 | r->ioid); | ||
502 | |||
503 | if (result) { | ||
504 | DBG("%s:%d: lv1_put_iopte failed: %s\n", __func__, | ||
505 | __LINE__, ps3_result(result)); | ||
506 | } | ||
507 | } | ||
508 | kfree(c); | ||
509 | DBG("%s:end\n", __func__); | ||
510 | return result; | ||
511 | } | ||
512 | |||
438 | /** | 513 | /** |
439 | * dma_map_pages - Maps dma pages into the io controller bus address space. | 514 | * dma_sb_map_pages - Maps dma pages into the io controller bus address space. |
440 | * @r: Pointer to a struct ps3_dma_region. | 515 | * @r: Pointer to a struct ps3_dma_region. |
441 | * @phys_addr: Starting physical address of the area to map. | 516 | * @phys_addr: Starting physical address of the area to map. |
442 | * @len: Length in bytes of the area to map. | 517 | * @len: Length in bytes of the area to map. |
@@ -446,8 +521,8 @@ static int dma_free_chunk(struct dma_chunk *c) | |||
446 | * make the HV call to add the pages into the io controller address space. | 521 | * make the HV call to add the pages into the io controller address space. |
447 | */ | 522 | */ |
448 | 523 | ||
449 | static int dma_map_pages(struct ps3_dma_region *r, unsigned long phys_addr, | 524 | static int dma_sb_map_pages(struct ps3_dma_region *r, unsigned long phys_addr, |
450 | unsigned long len, struct dma_chunk **c_out) | 525 | unsigned long len, struct dma_chunk **c_out, u64 iopte_flag) |
451 | { | 526 | { |
452 | int result; | 527 | int result; |
453 | struct dma_chunk *c; | 528 | struct dma_chunk *c; |
@@ -461,13 +536,13 @@ static int dma_map_pages(struct ps3_dma_region *r, unsigned long phys_addr, | |||
461 | 536 | ||
462 | c->region = r; | 537 | c->region = r; |
463 | c->lpar_addr = ps3_mm_phys_to_lpar(phys_addr); | 538 | c->lpar_addr = ps3_mm_phys_to_lpar(phys_addr); |
464 | c->bus_addr = dma_lpar_to_bus(r, c->lpar_addr); | 539 | c->bus_addr = dma_sb_lpar_to_bus(r, c->lpar_addr); |
465 | c->len = len; | 540 | c->len = len; |
466 | 541 | ||
467 | result = lv1_map_device_dma_region(c->region->did.bus_id, | 542 | BUG_ON(iopte_flag != 0xf800000000000000UL); |
468 | c->region->did.dev_id, c->lpar_addr, c->bus_addr, c->len, | 543 | result = lv1_map_device_dma_region(c->region->dev->bus_id, |
469 | 0xf800000000000000UL); | 544 | c->region->dev->dev_id, c->lpar_addr, |
470 | 545 | c->bus_addr, c->len, iopte_flag); | |
471 | if (result) { | 546 | if (result) { |
472 | DBG("%s:%d: lv1_map_device_dma_region failed: %s\n", | 547 | DBG("%s:%d: lv1_map_device_dma_region failed: %s\n", |
473 | __func__, __LINE__, ps3_result(result)); | 548 | __func__, __LINE__, ps3_result(result)); |
@@ -487,26 +562,120 @@ fail_alloc: | |||
487 | return result; | 562 | return result; |
488 | } | 563 | } |
489 | 564 | ||
565 | static int dma_ioc0_map_pages(struct ps3_dma_region *r, unsigned long phys_addr, | ||
566 | unsigned long len, struct dma_chunk **c_out, | ||
567 | u64 iopte_flag) | ||
568 | { | ||
569 | int result; | ||
570 | struct dma_chunk *c, *last; | ||
571 | int iopage, pages; | ||
572 | unsigned long offset; | ||
573 | |||
574 | DBG(KERN_ERR "%s: phy=%#lx, lpar%#lx, len=%#lx\n", __func__, | ||
575 | phys_addr, ps3_mm_phys_to_lpar(phys_addr), len); | ||
576 | c = kzalloc(sizeof(struct dma_chunk), GFP_ATOMIC); | ||
577 | |||
578 | if (!c) { | ||
579 | result = -ENOMEM; | ||
580 | goto fail_alloc; | ||
581 | } | ||
582 | |||
583 | c->region = r; | ||
584 | c->len = len; | ||
585 | c->lpar_addr = ps3_mm_phys_to_lpar(phys_addr); | ||
586 | /* allocate IO address */ | ||
587 | if (list_empty(&r->chunk_list.head)) { | ||
588 | /* first one */ | ||
589 | c->bus_addr = r->bus_addr; | ||
590 | } else { | ||
591 | /* derive from last bus addr*/ | ||
592 | last = list_entry(r->chunk_list.head.next, | ||
593 | struct dma_chunk, link); | ||
594 | c->bus_addr = last->bus_addr + last->len; | ||
595 | DBG("%s: last bus=%#lx, len=%#lx\n", __func__, | ||
596 | last->bus_addr, last->len); | ||
597 | } | ||
598 | |||
599 | /* FIXME: check whether length exceeds region size */ | ||
600 | |||
601 | /* build ioptes for the area */ | ||
602 | pages = len >> r->page_size; | ||
603 | DBG("%s: pgsize=%#x len=%#lx pages=%#x iopteflag=%#lx\n", __func__, | ||
604 | r->page_size, r->len, pages, iopte_flag); | ||
605 | for (iopage = 0; iopage < pages; iopage++) { | ||
606 | offset = (1 << r->page_size) * iopage; | ||
607 | result = lv1_put_iopte(0, | ||
608 | c->bus_addr + offset, | ||
609 | c->lpar_addr + offset, | ||
610 | r->ioid, | ||
611 | iopte_flag); | ||
612 | if (result) { | ||
613 | printk(KERN_WARNING "%s:%d: lv1_map_device_dma_region " | ||
614 | "failed: %s\n", __func__, __LINE__, | ||
615 | ps3_result(result)); | ||
616 | goto fail_map; | ||
617 | } | ||
618 | DBG("%s: pg=%d bus=%#lx, lpar=%#lx, ioid=%#x\n", __func__, | ||
619 | iopage, c->bus_addr + offset, c->lpar_addr + offset, | ||
620 | r->ioid); | ||
621 | } | ||
622 | |||
623 | /* be sure that last allocated one is inserted at head */ | ||
624 | list_add(&c->link, &r->chunk_list.head); | ||
625 | |||
626 | *c_out = c; | ||
627 | DBG("%s: end\n", __func__); | ||
628 | return 0; | ||
629 | |||
630 | fail_map: | ||
631 | for (iopage--; 0 <= iopage; iopage--) { | ||
632 | lv1_put_iopte(0, | ||
633 | c->bus_addr + offset, | ||
634 | c->lpar_addr + offset, | ||
635 | r->ioid, | ||
636 | 0); | ||
637 | } | ||
638 | kfree(c); | ||
639 | fail_alloc: | ||
640 | *c_out = NULL; | ||
641 | return result; | ||
642 | } | ||
643 | |||
490 | /** | 644 | /** |
491 | * dma_region_create - Create a device dma region. | 645 | * dma_sb_region_create - Create a device dma region. |
492 | * @r: Pointer to a struct ps3_dma_region. | 646 | * @r: Pointer to a struct ps3_dma_region. |
493 | * | 647 | * |
494 | * This is the lowest level dma region create routine, and is the one that | 648 | * This is the lowest level dma region create routine, and is the one that |
495 | * will make the HV call to create the region. | 649 | * will make the HV call to create the region. |
496 | */ | 650 | */ |
497 | 651 | ||
498 | static int dma_region_create(struct ps3_dma_region* r) | 652 | static int dma_sb_region_create(struct ps3_dma_region *r) |
499 | { | 653 | { |
500 | int result; | 654 | int result; |
501 | 655 | ||
502 | r->len = _ALIGN_UP(map.total, 1 << r->page_size); | 656 | pr_info(" -> %s:%d:\n", __func__, __LINE__); |
657 | |||
658 | BUG_ON(!r); | ||
659 | |||
660 | if (!r->dev->bus_id) { | ||
661 | pr_info("%s:%d: %u:%u no dma\n", __func__, __LINE__, | ||
662 | r->dev->bus_id, r->dev->dev_id); | ||
663 | return 0; | ||
664 | } | ||
665 | |||
666 | DBG("%s:%u: len = 0x%lx, page_size = %u, offset = 0x%lx\n", __func__, | ||
667 | __LINE__, r->len, r->page_size, r->offset); | ||
668 | |||
669 | BUG_ON(!r->len); | ||
670 | BUG_ON(!r->page_size); | ||
671 | BUG_ON(!r->region_ops); | ||
672 | |||
503 | INIT_LIST_HEAD(&r->chunk_list.head); | 673 | INIT_LIST_HEAD(&r->chunk_list.head); |
504 | spin_lock_init(&r->chunk_list.lock); | 674 | spin_lock_init(&r->chunk_list.lock); |
505 | 675 | ||
506 | result = lv1_allocate_device_dma_region(r->did.bus_id, r->did.dev_id, | 676 | result = lv1_allocate_device_dma_region(r->dev->bus_id, r->dev->dev_id, |
507 | r->len, r->page_size, r->region_type, &r->bus_addr); | 677 | roundup_pow_of_two(r->len), r->page_size, r->region_type, |
508 | 678 | &r->bus_addr); | |
509 | dma_dump_region(r); | ||
510 | 679 | ||
511 | if (result) { | 680 | if (result) { |
512 | DBG("%s:%d: lv1_allocate_device_dma_region failed: %s\n", | 681 | DBG("%s:%d: lv1_allocate_device_dma_region failed: %s\n", |
@@ -517,6 +686,27 @@ static int dma_region_create(struct ps3_dma_region* r) | |||
517 | return result; | 686 | return result; |
518 | } | 687 | } |
519 | 688 | ||
689 | static int dma_ioc0_region_create(struct ps3_dma_region *r) | ||
690 | { | ||
691 | int result; | ||
692 | |||
693 | INIT_LIST_HEAD(&r->chunk_list.head); | ||
694 | spin_lock_init(&r->chunk_list.lock); | ||
695 | |||
696 | result = lv1_allocate_io_segment(0, | ||
697 | r->len, | ||
698 | r->page_size, | ||
699 | &r->bus_addr); | ||
700 | if (result) { | ||
701 | DBG("%s:%d: lv1_allocate_io_segment failed: %s\n", | ||
702 | __func__, __LINE__, ps3_result(result)); | ||
703 | r->len = r->bus_addr = 0; | ||
704 | } | ||
705 | DBG("%s: len=%#lx, pg=%d, bus=%#lx\n", __func__, | ||
706 | r->len, r->page_size, r->bus_addr); | ||
707 | return result; | ||
708 | } | ||
709 | |||
520 | /** | 710 | /** |
521 | * dma_region_free - Free a device dma region. | 711 | * dma_region_free - Free a device dma region. |
522 | * @r: Pointer to a struct ps3_dma_region. | 712 | * @r: Pointer to a struct ps3_dma_region. |
@@ -525,31 +715,62 @@ static int dma_region_create(struct ps3_dma_region* r) | |||
525 | * will make the HV call to free the region. | 715 | * will make the HV call to free the region. |
526 | */ | 716 | */ |
527 | 717 | ||
528 | static int dma_region_free(struct ps3_dma_region* r) | 718 | static int dma_sb_region_free(struct ps3_dma_region *r) |
529 | { | 719 | { |
530 | int result; | 720 | int result; |
531 | struct dma_chunk *c; | 721 | struct dma_chunk *c; |
532 | struct dma_chunk *tmp; | 722 | struct dma_chunk *tmp; |
533 | 723 | ||
724 | BUG_ON(!r); | ||
725 | |||
726 | if (!r->dev->bus_id) { | ||
727 | pr_info("%s:%d: %u:%u no dma\n", __func__, __LINE__, | ||
728 | r->dev->bus_id, r->dev->dev_id); | ||
729 | return 0; | ||
730 | } | ||
731 | |||
534 | list_for_each_entry_safe(c, tmp, &r->chunk_list.head, link) { | 732 | list_for_each_entry_safe(c, tmp, &r->chunk_list.head, link) { |
535 | list_del(&c->link); | 733 | list_del(&c->link); |
536 | dma_free_chunk(c); | 734 | dma_sb_free_chunk(c); |
537 | } | 735 | } |
538 | 736 | ||
539 | result = lv1_free_device_dma_region(r->did.bus_id, r->did.dev_id, | 737 | result = lv1_free_device_dma_region(r->dev->bus_id, r->dev->dev_id, |
540 | r->bus_addr); | 738 | r->bus_addr); |
541 | 739 | ||
542 | if (result) | 740 | if (result) |
543 | DBG("%s:%d: lv1_free_device_dma_region failed: %s\n", | 741 | DBG("%s:%d: lv1_free_device_dma_region failed: %s\n", |
544 | __func__, __LINE__, ps3_result(result)); | 742 | __func__, __LINE__, ps3_result(result)); |
545 | 743 | ||
546 | r->len = r->bus_addr = 0; | 744 | r->bus_addr = 0; |
745 | |||
746 | return result; | ||
747 | } | ||
748 | |||
749 | static int dma_ioc0_region_free(struct ps3_dma_region *r) | ||
750 | { | ||
751 | int result; | ||
752 | struct dma_chunk *c, *n; | ||
753 | |||
754 | DBG("%s: start\n", __func__); | ||
755 | list_for_each_entry_safe(c, n, &r->chunk_list.head, link) { | ||
756 | list_del(&c->link); | ||
757 | dma_ioc0_free_chunk(c); | ||
758 | } | ||
759 | |||
760 | result = lv1_release_io_segment(0, r->bus_addr); | ||
761 | |||
762 | if (result) | ||
763 | DBG("%s:%d: lv1_free_device_dma_region failed: %s\n", | ||
764 | __func__, __LINE__, ps3_result(result)); | ||
765 | |||
766 | r->bus_addr = 0; | ||
767 | DBG("%s: end\n", __func__); | ||
547 | 768 | ||
548 | return result; | 769 | return result; |
549 | } | 770 | } |
550 | 771 | ||
551 | /** | 772 | /** |
552 | * dma_map_area - Map an area of memory into a device dma region. | 773 | * dma_sb_map_area - Map an area of memory into a device dma region. |
553 | * @r: Pointer to a struct ps3_dma_region. | 774 | * @r: Pointer to a struct ps3_dma_region. |
554 | * @virt_addr: Starting virtual address of the area to map. | 775 | * @virt_addr: Starting virtual address of the area to map. |
555 | * @len: Length in bytes of the area to map. | 776 | * @len: Length in bytes of the area to map. |
@@ -559,16 +780,19 @@ static int dma_region_free(struct ps3_dma_region* r) | |||
559 | * This is the common dma mapping routine. | 780 | * This is the common dma mapping routine. |
560 | */ | 781 | */ |
561 | 782 | ||
562 | static int dma_map_area(struct ps3_dma_region *r, unsigned long virt_addr, | 783 | static int dma_sb_map_area(struct ps3_dma_region *r, unsigned long virt_addr, |
563 | unsigned long len, unsigned long *bus_addr) | 784 | unsigned long len, unsigned long *bus_addr, |
785 | u64 iopte_flag) | ||
564 | { | 786 | { |
565 | int result; | 787 | int result; |
566 | unsigned long flags; | 788 | unsigned long flags; |
567 | struct dma_chunk *c; | 789 | struct dma_chunk *c; |
568 | unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr) | 790 | unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr) |
569 | : virt_addr; | 791 | : virt_addr; |
570 | 792 | unsigned long aligned_phys = _ALIGN_DOWN(phys_addr, 1 << r->page_size); | |
571 | *bus_addr = dma_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr)); | 793 | unsigned long aligned_len = _ALIGN_UP(len + phys_addr - aligned_phys, |
794 | 1 << r->page_size); | ||
795 | *bus_addr = dma_sb_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr)); | ||
572 | 796 | ||
573 | if (!USE_DYNAMIC_DMA) { | 797 | if (!USE_DYNAMIC_DMA) { |
574 | unsigned long lpar_addr = ps3_mm_phys_to_lpar(phys_addr); | 798 | unsigned long lpar_addr = ps3_mm_phys_to_lpar(phys_addr); |
@@ -588,17 +812,18 @@ static int dma_map_area(struct ps3_dma_region *r, unsigned long virt_addr, | |||
588 | c = dma_find_chunk(r, *bus_addr, len); | 812 | c = dma_find_chunk(r, *bus_addr, len); |
589 | 813 | ||
590 | if (c) { | 814 | if (c) { |
815 | DBG("%s:%d: reusing mapped chunk", __func__, __LINE__); | ||
816 | dma_dump_chunk(c); | ||
591 | c->usage_count++; | 817 | c->usage_count++; |
592 | spin_unlock_irqrestore(&r->chunk_list.lock, flags); | 818 | spin_unlock_irqrestore(&r->chunk_list.lock, flags); |
593 | return 0; | 819 | return 0; |
594 | } | 820 | } |
595 | 821 | ||
596 | result = dma_map_pages(r, _ALIGN_DOWN(phys_addr, 1 << r->page_size), | 822 | result = dma_sb_map_pages(r, aligned_phys, aligned_len, &c, iopte_flag); |
597 | _ALIGN_UP(len, 1 << r->page_size), &c); | ||
598 | 823 | ||
599 | if (result) { | 824 | if (result) { |
600 | *bus_addr = 0; | 825 | *bus_addr = 0; |
601 | DBG("%s:%d: dma_map_pages failed (%d)\n", | 826 | DBG("%s:%d: dma_sb_map_pages failed (%d)\n", |
602 | __func__, __LINE__, result); | 827 | __func__, __LINE__, result); |
603 | spin_unlock_irqrestore(&r->chunk_list.lock, flags); | 828 | spin_unlock_irqrestore(&r->chunk_list.lock, flags); |
604 | return result; | 829 | return result; |
@@ -610,8 +835,57 @@ static int dma_map_area(struct ps3_dma_region *r, unsigned long virt_addr, | |||
610 | return result; | 835 | return result; |
611 | } | 836 | } |
612 | 837 | ||
838 | static int dma_ioc0_map_area(struct ps3_dma_region *r, unsigned long virt_addr, | ||
839 | unsigned long len, unsigned long *bus_addr, | ||
840 | u64 iopte_flag) | ||
841 | { | ||
842 | int result; | ||
843 | unsigned long flags; | ||
844 | struct dma_chunk *c; | ||
845 | unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr) | ||
846 | : virt_addr; | ||
847 | unsigned long aligned_phys = _ALIGN_DOWN(phys_addr, 1 << r->page_size); | ||
848 | unsigned long aligned_len = _ALIGN_UP(len + phys_addr - aligned_phys, | ||
849 | 1 << r->page_size); | ||
850 | |||
851 | DBG(KERN_ERR "%s: vaddr=%#lx, len=%#lx\n", __func__, | ||
852 | virt_addr, len); | ||
853 | DBG(KERN_ERR "%s: ph=%#lx a_ph=%#lx a_l=%#lx\n", __func__, | ||
854 | phys_addr, aligned_phys, aligned_len); | ||
855 | |||
856 | spin_lock_irqsave(&r->chunk_list.lock, flags); | ||
857 | c = dma_find_chunk_lpar(r, ps3_mm_phys_to_lpar(phys_addr), len); | ||
858 | |||
859 | if (c) { | ||
860 | /* FIXME */ | ||
861 | BUG(); | ||
862 | *bus_addr = c->bus_addr + phys_addr - aligned_phys; | ||
863 | c->usage_count++; | ||
864 | spin_unlock_irqrestore(&r->chunk_list.lock, flags); | ||
865 | return 0; | ||
866 | } | ||
867 | |||
868 | result = dma_ioc0_map_pages(r, aligned_phys, aligned_len, &c, | ||
869 | iopte_flag); | ||
870 | |||
871 | if (result) { | ||
872 | *bus_addr = 0; | ||
873 | DBG("%s:%d: dma_ioc0_map_pages failed (%d)\n", | ||
874 | __func__, __LINE__, result); | ||
875 | spin_unlock_irqrestore(&r->chunk_list.lock, flags); | ||
876 | return result; | ||
877 | } | ||
878 | *bus_addr = c->bus_addr + phys_addr - aligned_phys; | ||
879 | DBG("%s: va=%#lx pa=%#lx a_pa=%#lx bus=%#lx\n", __func__, | ||
880 | virt_addr, phys_addr, aligned_phys, *bus_addr); | ||
881 | c->usage_count = 1; | ||
882 | |||
883 | spin_unlock_irqrestore(&r->chunk_list.lock, flags); | ||
884 | return result; | ||
885 | } | ||
886 | |||
613 | /** | 887 | /** |
614 | * dma_unmap_area - Unmap an area of memory from a device dma region. | 888 | * dma_sb_unmap_area - Unmap an area of memory from a device dma region. |
615 | * @r: Pointer to a struct ps3_dma_region. | 889 | * @r: Pointer to a struct ps3_dma_region. |
616 | * @bus_addr: The starting ioc bus address of the area to unmap. | 890 | * @bus_addr: The starting ioc bus address of the area to unmap. |
617 | * @len: Length in bytes of the area to unmap. | 891 | * @len: Length in bytes of the area to unmap. |
@@ -619,7 +893,7 @@ static int dma_map_area(struct ps3_dma_region *r, unsigned long virt_addr, | |||
619 | * This is the common dma unmap routine. | 893 | * This is the common dma unmap routine. |
620 | */ | 894 | */ |
621 | 895 | ||
622 | int dma_unmap_area(struct ps3_dma_region *r, unsigned long bus_addr, | 896 | int dma_sb_unmap_area(struct ps3_dma_region *r, unsigned long bus_addr, |
623 | unsigned long len) | 897 | unsigned long len) |
624 | { | 898 | { |
625 | unsigned long flags; | 899 | unsigned long flags; |
@@ -631,7 +905,8 @@ int dma_unmap_area(struct ps3_dma_region *r, unsigned long bus_addr, | |||
631 | if (!c) { | 905 | if (!c) { |
632 | unsigned long aligned_bus = _ALIGN_DOWN(bus_addr, | 906 | unsigned long aligned_bus = _ALIGN_DOWN(bus_addr, |
633 | 1 << r->page_size); | 907 | 1 << r->page_size); |
634 | unsigned long aligned_len = _ALIGN_UP(len, 1 << r->page_size); | 908 | unsigned long aligned_len = _ALIGN_UP(len + bus_addr |
909 | - aligned_bus, 1 << r->page_size); | ||
635 | DBG("%s:%d: not found: bus_addr %lxh\n", | 910 | DBG("%s:%d: not found: bus_addr %lxh\n", |
636 | __func__, __LINE__, bus_addr); | 911 | __func__, __LINE__, bus_addr); |
637 | DBG("%s:%d: not found: len %lxh\n", | 912 | DBG("%s:%d: not found: len %lxh\n", |
@@ -647,94 +922,166 @@ int dma_unmap_area(struct ps3_dma_region *r, unsigned long bus_addr, | |||
647 | 922 | ||
648 | if (!c->usage_count) { | 923 | if (!c->usage_count) { |
649 | list_del(&c->link); | 924 | list_del(&c->link); |
650 | dma_free_chunk(c); | 925 | dma_sb_free_chunk(c); |
651 | } | 926 | } |
652 | 927 | ||
653 | spin_unlock_irqrestore(&r->chunk_list.lock, flags); | 928 | spin_unlock_irqrestore(&r->chunk_list.lock, flags); |
654 | return 0; | 929 | return 0; |
655 | } | 930 | } |
656 | 931 | ||
932 | int dma_ioc0_unmap_area(struct ps3_dma_region *r, unsigned long bus_addr, | ||
933 | unsigned long len) | ||
934 | { | ||
935 | unsigned long flags; | ||
936 | struct dma_chunk *c; | ||
937 | |||
938 | DBG("%s: start a=%#lx l=%#lx\n", __func__, bus_addr, len); | ||
939 | spin_lock_irqsave(&r->chunk_list.lock, flags); | ||
940 | c = dma_find_chunk(r, bus_addr, len); | ||
941 | |||
942 | if (!c) { | ||
943 | unsigned long aligned_bus = _ALIGN_DOWN(bus_addr, | ||
944 | 1 << r->page_size); | ||
945 | unsigned long aligned_len = _ALIGN_UP(len + bus_addr | ||
946 | - aligned_bus, | ||
947 | 1 << r->page_size); | ||
948 | DBG("%s:%d: not found: bus_addr %lxh\n", | ||
949 | __func__, __LINE__, bus_addr); | ||
950 | DBG("%s:%d: not found: len %lxh\n", | ||
951 | __func__, __LINE__, len); | ||
952 | DBG("%s:%d: not found: aligned_bus %lxh\n", | ||
953 | __func__, __LINE__, aligned_bus); | ||
954 | DBG("%s:%d: not found: aligned_len %lxh\n", | ||
955 | __func__, __LINE__, aligned_len); | ||
956 | BUG(); | ||
957 | } | ||
958 | |||
959 | c->usage_count--; | ||
960 | |||
961 | if (!c->usage_count) { | ||
962 | list_del(&c->link); | ||
963 | dma_ioc0_free_chunk(c); | ||
964 | } | ||
965 | |||
966 | spin_unlock_irqrestore(&r->chunk_list.lock, flags); | ||
967 | DBG("%s: end\n", __func__); | ||
968 | return 0; | ||
969 | } | ||
970 | |||
657 | /** | 971 | /** |
658 | * dma_region_create_linear - Setup a linear dma maping for a device. | 972 | * dma_sb_region_create_linear - Setup a linear dma mapping for a device. |
659 | * @r: Pointer to a struct ps3_dma_region. | 973 | * @r: Pointer to a struct ps3_dma_region. |
660 | * | 974 | * |
661 | * This routine creates an HV dma region for the device and maps all available | 975 | * This routine creates an HV dma region for the device and maps all available |
662 | * ram into the io controller bus address space. | 976 | * ram into the io controller bus address space. |
663 | */ | 977 | */ |
664 | 978 | ||
665 | static int dma_region_create_linear(struct ps3_dma_region *r) | 979 | static int dma_sb_region_create_linear(struct ps3_dma_region *r) |
666 | { | 980 | { |
667 | int result; | 981 | int result; |
668 | unsigned long tmp; | 982 | unsigned long virt_addr, len, tmp; |
669 | 983 | ||
670 | /* force 16M dma pages for linear mapping */ | 984 | if (r->len > 16*1024*1024) { /* FIXME: need proper fix */ |
671 | 985 | /* force 16M dma pages for linear mapping */ | |
672 | if (r->page_size != PS3_DMA_16M) { | 986 | if (r->page_size != PS3_DMA_16M) { |
673 | pr_info("%s:%d: forcing 16M pages for linear map\n", | 987 | pr_info("%s:%d: forcing 16M pages for linear map\n", |
674 | __func__, __LINE__); | 988 | __func__, __LINE__); |
675 | r->page_size = PS3_DMA_16M; | 989 | r->page_size = PS3_DMA_16M; |
990 | r->len = _ALIGN_UP(r->len, 1 << r->page_size); | ||
991 | } | ||
676 | } | 992 | } |
677 | 993 | ||
678 | result = dma_region_create(r); | 994 | result = dma_sb_region_create(r); |
679 | BUG_ON(result); | 995 | BUG_ON(result); |
680 | 996 | ||
681 | result = dma_map_area(r, map.rm.base, map.rm.size, &tmp); | 997 | if (r->offset < map.rm.size) { |
682 | BUG_ON(result); | 998 | /* Map (part of) 1st RAM chunk */ |
683 | 999 | virt_addr = map.rm.base + r->offset; | |
684 | if (USE_LPAR_ADDR) | 1000 | len = map.rm.size - r->offset; |
685 | result = dma_map_area(r, map.r1.base, map.r1.size, | 1001 | if (len > r->len) |
686 | &tmp); | 1002 | len = r->len; |
687 | else | 1003 | result = dma_sb_map_area(r, virt_addr, len, &tmp, |
688 | result = dma_map_area(r, map.rm.size, map.r1.size, | 1004 | IOPTE_PP_W | IOPTE_PP_R | IOPTE_SO_RW | IOPTE_M); |
689 | &tmp); | 1005 | BUG_ON(result); |
1006 | } | ||
690 | 1007 | ||
691 | BUG_ON(result); | 1008 | if (r->offset + r->len > map.rm.size) { |
1009 | /* Map (part of) 2nd RAM chunk */ | ||
1010 | virt_addr = USE_LPAR_ADDR ? map.r1.base : map.rm.size; | ||
1011 | len = r->len; | ||
1012 | if (r->offset >= map.rm.size) | ||
1013 | virt_addr += r->offset - map.rm.size; | ||
1014 | else | ||
1015 | len -= map.rm.size - r->offset; | ||
1016 | result = dma_sb_map_area(r, virt_addr, len, &tmp, | ||
1017 | IOPTE_PP_W | IOPTE_PP_R | IOPTE_SO_RW | IOPTE_M); | ||
1018 | BUG_ON(result); | ||
1019 | } | ||
692 | 1020 | ||
693 | return result; | 1021 | return result; |
694 | } | 1022 | } |
695 | 1023 | ||
696 | /** | 1024 | /** |
697 | * dma_region_free_linear - Free a linear dma mapping for a device. | 1025 | * dma_sb_region_free_linear - Free a linear dma mapping for a device. |
698 | * @r: Pointer to a struct ps3_dma_region. | 1026 | * @r: Pointer to a struct ps3_dma_region. |
699 | * | 1027 | * |
700 | * This routine will unmap all mapped areas and free the HV dma region. | 1028 | * This routine will unmap all mapped areas and free the HV dma region. |
701 | */ | 1029 | */ |
702 | 1030 | ||
703 | static int dma_region_free_linear(struct ps3_dma_region *r) | 1031 | static int dma_sb_region_free_linear(struct ps3_dma_region *r) |
704 | { | 1032 | { |
705 | int result; | 1033 | int result; |
1034 | unsigned long bus_addr, len, lpar_addr; | ||
1035 | |||
1036 | if (r->offset < map.rm.size) { | ||
1037 | /* Unmap (part of) 1st RAM chunk */ | ||
1038 | lpar_addr = map.rm.base + r->offset; | ||
1039 | len = map.rm.size - r->offset; | ||
1040 | if (len > r->len) | ||
1041 | len = r->len; | ||
1042 | bus_addr = dma_sb_lpar_to_bus(r, lpar_addr); | ||
1043 | result = dma_sb_unmap_area(r, bus_addr, len); | ||
1044 | BUG_ON(result); | ||
1045 | } | ||
706 | 1046 | ||
707 | result = dma_unmap_area(r, dma_lpar_to_bus(r, 0), map.rm.size); | 1047 | if (r->offset + r->len > map.rm.size) { |
708 | BUG_ON(result); | 1048 | /* Unmap (part of) 2nd RAM chunk */ |
709 | 1049 | lpar_addr = map.r1.base; | |
710 | result = dma_unmap_area(r, dma_lpar_to_bus(r, map.r1.base), | 1050 | len = r->len; |
711 | map.r1.size); | 1051 | if (r->offset >= map.rm.size) |
712 | BUG_ON(result); | 1052 | lpar_addr += r->offset - map.rm.size; |
1053 | else | ||
1054 | len -= map.rm.size - r->offset; | ||
1055 | bus_addr = dma_sb_lpar_to_bus(r, lpar_addr); | ||
1056 | result = dma_sb_unmap_area(r, bus_addr, len); | ||
1057 | BUG_ON(result); | ||
1058 | } | ||
713 | 1059 | ||
714 | result = dma_region_free(r); | 1060 | result = dma_sb_region_free(r); |
715 | BUG_ON(result); | 1061 | BUG_ON(result); |
716 | 1062 | ||
717 | return result; | 1063 | return result; |
718 | } | 1064 | } |
719 | 1065 | ||
720 | /** | 1066 | /** |
721 | * dma_map_area_linear - Map an area of memory into a device dma region. | 1067 | * dma_sb_map_area_linear - Map an area of memory into a device dma region. |
722 | * @r: Pointer to a struct ps3_dma_region. | 1068 | * @r: Pointer to a struct ps3_dma_region. |
723 | * @virt_addr: Starting virtual address of the area to map. | 1069 | * @virt_addr: Starting virtual address of the area to map. |
724 | * @len: Length in bytes of the area to map. | 1070 | * @len: Length in bytes of the area to map. |
725 | * @bus_addr: A pointer to return the starting ioc bus address of the area to | 1071 | * @bus_addr: A pointer to return the starting ioc bus address of the area to |
726 | * map. | 1072 | * map. |
727 | * | 1073 | * |
728 | * This routine just returns the coresponding bus address. Actual mapping | 1074 | * This routine just returns the corresponding bus address. Actual mapping |
729 | * occurs in dma_region_create_linear(). | 1075 | * occurs in dma_region_create_linear(). |
730 | */ | 1076 | */ |
731 | 1077 | ||
732 | static int dma_map_area_linear(struct ps3_dma_region *r, | 1078 | static int dma_sb_map_area_linear(struct ps3_dma_region *r, |
733 | unsigned long virt_addr, unsigned long len, unsigned long *bus_addr) | 1079 | unsigned long virt_addr, unsigned long len, unsigned long *bus_addr, |
1080 | u64 iopte_flag) | ||
734 | { | 1081 | { |
735 | unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr) | 1082 | unsigned long phys_addr = is_kernel_addr(virt_addr) ? __pa(virt_addr) |
736 | : virt_addr; | 1083 | : virt_addr; |
737 | *bus_addr = dma_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr)); | 1084 | *bus_addr = dma_sb_lpar_to_bus(r, ps3_mm_phys_to_lpar(phys_addr)); |
738 | return 0; | 1085 | return 0; |
739 | } | 1086 | } |
740 | 1087 | ||
@@ -744,42 +1091,98 @@ static int dma_map_area_linear(struct ps3_dma_region *r, | |||
744 | * @bus_addr: The starting ioc bus address of the area to unmap. | 1091 | * @bus_addr: The starting ioc bus address of the area to unmap. |
745 | * @len: Length in bytes of the area to unmap. | 1092 | * @len: Length in bytes of the area to unmap. |
746 | * | 1093 | * |
747 | * This routine does nothing. Unmapping occurs in dma_region_free_linear(). | 1094 | * This routine does nothing. Unmapping occurs in dma_sb_region_free_linear(). |
748 | */ | 1095 | */ |
749 | 1096 | ||
750 | static int dma_unmap_area_linear(struct ps3_dma_region *r, | 1097 | static int dma_sb_unmap_area_linear(struct ps3_dma_region *r, |
751 | unsigned long bus_addr, unsigned long len) | 1098 | unsigned long bus_addr, unsigned long len) |
752 | { | 1099 | { |
753 | return 0; | 1100 | return 0; |
1101 | }; | ||
1102 | |||
1103 | static const struct ps3_dma_region_ops ps3_dma_sb_region_ops = { | ||
1104 | .create = dma_sb_region_create, | ||
1105 | .free = dma_sb_region_free, | ||
1106 | .map = dma_sb_map_area, | ||
1107 | .unmap = dma_sb_unmap_area | ||
1108 | }; | ||
1109 | |||
1110 | static const struct ps3_dma_region_ops ps3_dma_sb_region_linear_ops = { | ||
1111 | .create = dma_sb_region_create_linear, | ||
1112 | .free = dma_sb_region_free_linear, | ||
1113 | .map = dma_sb_map_area_linear, | ||
1114 | .unmap = dma_sb_unmap_area_linear | ||
1115 | }; | ||
1116 | |||
1117 | static const struct ps3_dma_region_ops ps3_dma_ioc0_region_ops = { | ||
1118 | .create = dma_ioc0_region_create, | ||
1119 | .free = dma_ioc0_region_free, | ||
1120 | .map = dma_ioc0_map_area, | ||
1121 | .unmap = dma_ioc0_unmap_area | ||
1122 | }; | ||
1123 | |||
1124 | int ps3_dma_region_init(struct ps3_system_bus_device *dev, | ||
1125 | struct ps3_dma_region *r, enum ps3_dma_page_size page_size, | ||
1126 | enum ps3_dma_region_type region_type, void *addr, unsigned long len) | ||
1127 | { | ||
1128 | unsigned long lpar_addr; | ||
1129 | |||
1130 | lpar_addr = addr ? ps3_mm_phys_to_lpar(__pa(addr)) : 0; | ||
1131 | |||
1132 | r->dev = dev; | ||
1133 | r->page_size = page_size; | ||
1134 | r->region_type = region_type; | ||
1135 | r->offset = lpar_addr; | ||
1136 | if (r->offset >= map.rm.size) | ||
1137 | r->offset -= map.r1.offset; | ||
1138 | r->len = len ? len : _ALIGN_UP(map.total, 1 << r->page_size); | ||
1139 | |||
1140 | switch (dev->dev_type) { | ||
1141 | case PS3_DEVICE_TYPE_SB: | ||
1142 | r->region_ops = (USE_DYNAMIC_DMA) | ||
1143 | ? &ps3_dma_sb_region_ops | ||
1144 | : &ps3_dma_sb_region_linear_ops; | ||
1145 | break; | ||
1146 | case PS3_DEVICE_TYPE_IOC0: | ||
1147 | r->region_ops = &ps3_dma_ioc0_region_ops; | ||
1148 | break; | ||
1149 | default: | ||
1150 | BUG(); | ||
1151 | return -EINVAL; | ||
1152 | } | ||
1153 | return 0; | ||
754 | } | 1154 | } |
1155 | EXPORT_SYMBOL(ps3_dma_region_init); | ||
755 | 1156 | ||
756 | int ps3_dma_region_create(struct ps3_dma_region *r) | 1157 | int ps3_dma_region_create(struct ps3_dma_region *r) |
757 | { | 1158 | { |
758 | return (USE_DYNAMIC_DMA) | 1159 | BUG_ON(!r); |
759 | ? dma_region_create(r) | 1160 | BUG_ON(!r->region_ops); |
760 | : dma_region_create_linear(r); | 1161 | BUG_ON(!r->region_ops->create); |
1162 | return r->region_ops->create(r); | ||
761 | } | 1163 | } |
1164 | EXPORT_SYMBOL(ps3_dma_region_create); | ||
762 | 1165 | ||
763 | int ps3_dma_region_free(struct ps3_dma_region *r) | 1166 | int ps3_dma_region_free(struct ps3_dma_region *r) |
764 | { | 1167 | { |
765 | return (USE_DYNAMIC_DMA) | 1168 | BUG_ON(!r); |
766 | ? dma_region_free(r) | 1169 | BUG_ON(!r->region_ops); |
767 | : dma_region_free_linear(r); | 1170 | BUG_ON(!r->region_ops->free); |
1171 | return r->region_ops->free(r); | ||
768 | } | 1172 | } |
1173 | EXPORT_SYMBOL(ps3_dma_region_free); | ||
769 | 1174 | ||
770 | int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr, | 1175 | int ps3_dma_map(struct ps3_dma_region *r, unsigned long virt_addr, |
771 | unsigned long len, unsigned long *bus_addr) | 1176 | unsigned long len, unsigned long *bus_addr, |
1177 | u64 iopte_flag) | ||
772 | { | 1178 | { |
773 | return (USE_DYNAMIC_DMA) | 1179 | return r->region_ops->map(r, virt_addr, len, bus_addr, iopte_flag); |
774 | ? dma_map_area(r, virt_addr, len, bus_addr) | ||
775 | : dma_map_area_linear(r, virt_addr, len, bus_addr); | ||
776 | } | 1180 | } |
777 | 1181 | ||
778 | int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr, | 1182 | int ps3_dma_unmap(struct ps3_dma_region *r, unsigned long bus_addr, |
779 | unsigned long len) | 1183 | unsigned long len) |
780 | { | 1184 | { |
781 | return (USE_DYNAMIC_DMA) ? dma_unmap_area(r, bus_addr, len) | 1185 | return r->region_ops->unmap(r, bus_addr, len); |
782 | : dma_unmap_area_linear(r, bus_addr, len); | ||
783 | } | 1186 | } |
784 | 1187 | ||
785 | /*============================================================================*/ | 1188 | /*============================================================================*/ |
@@ -816,6 +1219,9 @@ void __init ps3_mm_init(void) | |||
816 | /* arrange to do this in ps3_mm_add_memory */ | 1219 | /* arrange to do this in ps3_mm_add_memory */ |
817 | ps3_mm_region_create(&map.r1, map.total - map.rm.size); | 1220 | ps3_mm_region_create(&map.r1, map.total - map.rm.size); |
818 | 1221 | ||
1222 | /* correct map.total for the real total amount of memory we use */ | ||
1223 | map.total = map.rm.size + map.r1.size; | ||
1224 | |||
819 | DBG(" <- %s:%d\n", __func__, __LINE__); | 1225 | DBG(" <- %s:%d\n", __func__, __LINE__); |
820 | } | 1226 | } |
821 | 1227 | ||
diff --git a/arch/powerpc/platforms/ps3/platform.h b/arch/powerpc/platforms/ps3/platform.h index 0b93665829db..75cb8d9e90cb 100644 --- a/arch/powerpc/platforms/ps3/platform.h +++ b/arch/powerpc/platforms/ps3/platform.h | |||
@@ -83,6 +83,7 @@ enum ps3_dev_type { | |||
83 | PS3_DEV_TYPE_STOR_ROM = TYPE_ROM, /* 5 */ | 83 | PS3_DEV_TYPE_STOR_ROM = TYPE_ROM, /* 5 */ |
84 | PS3_DEV_TYPE_SB_GPIO = 6, | 84 | PS3_DEV_TYPE_SB_GPIO = 6, |
85 | PS3_DEV_TYPE_STOR_FLASH = TYPE_RBC, /* 14 */ | 85 | PS3_DEV_TYPE_STOR_FLASH = TYPE_RBC, /* 14 */ |
86 | PS3_DEV_TYPE_NOACCESS = 255, | ||
86 | }; | 87 | }; |
87 | 88 | ||
88 | int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str, | 89 | int ps3_repository_read_bus_str(unsigned int bus_index, const char *bus_str, |
@@ -217,4 +218,14 @@ int ps3_repository_read_num_spu_resource_id(unsigned int *num_resource_id); | |||
217 | int ps3_repository_read_spu_resource_id(unsigned int res_index, | 218 | int ps3_repository_read_spu_resource_id(unsigned int res_index, |
218 | enum ps3_spu_resource_type* resource_type, unsigned int *resource_id); | 219 | enum ps3_spu_resource_type* resource_type, unsigned int *resource_id); |
219 | 220 | ||
221 | /* Page table entries */ | ||
222 | #define IOPTE_PP_W 0x8000000000000000ul /* protection: write */ | ||
223 | #define IOPTE_PP_R 0x4000000000000000ul /* protection: read */ | ||
224 | #define IOPTE_M 0x2000000000000000ul /* coherency required */ | ||
225 | #define IOPTE_SO_R 0x1000000000000000ul /* ordering: writes */ | ||
226 | #define IOPTE_SO_RW 0x1800000000000000ul /* ordering: r & w */ | ||
227 | #define IOPTE_RPN_Mask 0x07fffffffffff000ul /* RPN */ | ||
228 | #define IOPTE_H 0x0000000000000800ul /* cache hint */ | ||
229 | #define IOPTE_IOID_Mask 0x00000000000007fful /* ioid */ | ||
230 | |||
220 | #endif | 231 | #endif |
diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platforms/ps3/system-bus.c index 6bda51027cc6..14bbaff93e57 100644 --- a/arch/powerpc/platforms/ps3/system-bus.c +++ b/arch/powerpc/platforms/ps3/system-bus.c | |||
@@ -30,22 +30,228 @@ | |||
30 | 30 | ||
31 | #include "platform.h" | 31 | #include "platform.h" |
32 | 32 | ||
33 | static struct device ps3_system_bus = { | ||
34 | .bus_id = "ps3_system", | ||
35 | }; | ||
36 | |||
37 | /* FIXME: need device usage counters! */ | ||
38 | struct { | ||
39 | struct mutex mutex; | ||
40 | int sb_11; /* usb 0 */ | ||
41 | int sb_12; /* usb 0 */ | ||
42 | int gpu; | ||
43 | } static usage_hack; | ||
44 | |||
45 | static int ps3_is_device(struct ps3_system_bus_device *dev, | ||
46 | unsigned int bus_id, unsigned int dev_id) | ||
47 | { | ||
48 | return dev->bus_id == bus_id && dev->dev_id == dev_id; | ||
49 | } | ||
50 | |||
51 | static int ps3_open_hv_device_sb(struct ps3_system_bus_device *dev) | ||
52 | { | ||
53 | int result; | ||
54 | |||
55 | BUG_ON(!dev->bus_id); | ||
56 | mutex_lock(&usage_hack.mutex); | ||
57 | |||
58 | if (ps3_is_device(dev, 1, 1)) { | ||
59 | usage_hack.sb_11++; | ||
60 | if (usage_hack.sb_11 > 1) { | ||
61 | result = 0; | ||
62 | goto done; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | if (ps3_is_device(dev, 1, 2)) { | ||
67 | usage_hack.sb_12++; | ||
68 | if (usage_hack.sb_12 > 1) { | ||
69 | result = 0; | ||
70 | goto done; | ||
71 | } | ||
72 | } | ||
73 | |||
74 | result = lv1_open_device(dev->bus_id, dev->dev_id, 0); | ||
75 | |||
76 | if (result) { | ||
77 | pr_debug("%s:%d: lv1_open_device failed: %s\n", __func__, | ||
78 | __LINE__, ps3_result(result)); | ||
79 | result = -EPERM; | ||
80 | } | ||
81 | |||
82 | done: | ||
83 | mutex_unlock(&usage_hack.mutex); | ||
84 | return result; | ||
85 | } | ||
86 | |||
87 | static int ps3_close_hv_device_sb(struct ps3_system_bus_device *dev) | ||
88 | { | ||
89 | int result; | ||
90 | |||
91 | BUG_ON(!dev->bus_id); | ||
92 | mutex_lock(&usage_hack.mutex); | ||
93 | |||
94 | if (ps3_is_device(dev, 1, 1)) { | ||
95 | usage_hack.sb_11--; | ||
96 | if (usage_hack.sb_11) { | ||
97 | result = 0; | ||
98 | goto done; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | if (ps3_is_device(dev, 1, 2)) { | ||
103 | usage_hack.sb_12--; | ||
104 | if (usage_hack.sb_12) { | ||
105 | result = 0; | ||
106 | goto done; | ||
107 | } | ||
108 | } | ||
109 | |||
110 | result = lv1_close_device(dev->bus_id, dev->dev_id); | ||
111 | BUG_ON(result); | ||
112 | |||
113 | done: | ||
114 | mutex_unlock(&usage_hack.mutex); | ||
115 | return result; | ||
116 | } | ||
117 | |||
118 | static int ps3_open_hv_device_gpu(struct ps3_system_bus_device *dev) | ||
119 | { | ||
120 | int result; | ||
121 | |||
122 | mutex_lock(&usage_hack.mutex); | ||
123 | |||
124 | usage_hack.gpu++; | ||
125 | if (usage_hack.gpu > 1) { | ||
126 | result = 0; | ||
127 | goto done; | ||
128 | } | ||
129 | |||
130 | result = lv1_gpu_open(0); | ||
131 | |||
132 | if (result) { | ||
133 | pr_debug("%s:%d: lv1_gpu_open failed: %s\n", __func__, | ||
134 | __LINE__, ps3_result(result)); | ||
135 | result = -EPERM; | ||
136 | } | ||
137 | |||
138 | done: | ||
139 | mutex_unlock(&usage_hack.mutex); | ||
140 | return result; | ||
141 | } | ||
142 | |||
143 | static int ps3_close_hv_device_gpu(struct ps3_system_bus_device *dev) | ||
144 | { | ||
145 | int result; | ||
146 | |||
147 | mutex_lock(&usage_hack.mutex); | ||
148 | |||
149 | usage_hack.gpu--; | ||
150 | if (usage_hack.gpu) { | ||
151 | result = 0; | ||
152 | goto done; | ||
153 | } | ||
154 | |||
155 | result = lv1_gpu_close(); | ||
156 | BUG_ON(result); | ||
157 | |||
158 | done: | ||
159 | mutex_unlock(&usage_hack.mutex); | ||
160 | return result; | ||
161 | } | ||
162 | |||
163 | int ps3_open_hv_device(struct ps3_system_bus_device *dev) | ||
164 | { | ||
165 | BUG_ON(!dev); | ||
166 | pr_debug("%s:%d: match_id: %u\n", __func__, __LINE__, dev->match_id); | ||
167 | |||
168 | switch (dev->match_id) { | ||
169 | case PS3_MATCH_ID_EHCI: | ||
170 | case PS3_MATCH_ID_OHCI: | ||
171 | case PS3_MATCH_ID_GELIC: | ||
172 | case PS3_MATCH_ID_STOR_DISK: | ||
173 | case PS3_MATCH_ID_STOR_ROM: | ||
174 | case PS3_MATCH_ID_STOR_FLASH: | ||
175 | return ps3_open_hv_device_sb(dev); | ||
176 | |||
177 | case PS3_MATCH_ID_SOUND: | ||
178 | case PS3_MATCH_ID_GRAPHICS: | ||
179 | return ps3_open_hv_device_gpu(dev); | ||
180 | |||
181 | case PS3_MATCH_ID_AV_SETTINGS: | ||
182 | case PS3_MATCH_ID_SYSTEM_MANAGER: | ||
183 | pr_debug("%s:%d: unsupported match_id: %u\n", __func__, | ||
184 | __LINE__, dev->match_id); | ||
185 | pr_debug("%s:%d: bus_id: %u\n", __func__, | ||
186 | __LINE__, dev->bus_id); | ||
187 | BUG(); | ||
188 | return -EINVAL; | ||
189 | |||
190 | default: | ||
191 | break; | ||
192 | } | ||
193 | |||
194 | pr_debug("%s:%d: unknown match_id: %u\n", __func__, __LINE__, | ||
195 | dev->match_id); | ||
196 | BUG(); | ||
197 | return -ENODEV; | ||
198 | } | ||
199 | EXPORT_SYMBOL_GPL(ps3_open_hv_device); | ||
200 | |||
201 | int ps3_close_hv_device(struct ps3_system_bus_device *dev) | ||
202 | { | ||
203 | BUG_ON(!dev); | ||
204 | pr_debug("%s:%d: match_id: %u\n", __func__, __LINE__, dev->match_id); | ||
205 | |||
206 | switch (dev->match_id) { | ||
207 | case PS3_MATCH_ID_EHCI: | ||
208 | case PS3_MATCH_ID_OHCI: | ||
209 | case PS3_MATCH_ID_GELIC: | ||
210 | case PS3_MATCH_ID_STOR_DISK: | ||
211 | case PS3_MATCH_ID_STOR_ROM: | ||
212 | case PS3_MATCH_ID_STOR_FLASH: | ||
213 | return ps3_close_hv_device_sb(dev); | ||
214 | |||
215 | case PS3_MATCH_ID_SOUND: | ||
216 | case PS3_MATCH_ID_GRAPHICS: | ||
217 | return ps3_close_hv_device_gpu(dev); | ||
218 | |||
219 | case PS3_MATCH_ID_AV_SETTINGS: | ||
220 | case PS3_MATCH_ID_SYSTEM_MANAGER: | ||
221 | pr_debug("%s:%d: unsupported match_id: %u\n", __func__, | ||
222 | __LINE__, dev->match_id); | ||
223 | pr_debug("%s:%d: bus_id: %u\n", __func__, | ||
224 | __LINE__, dev->bus_id); | ||
225 | BUG(); | ||
226 | return -EINVAL; | ||
227 | |||
228 | default: | ||
229 | break; | ||
230 | } | ||
231 | |||
232 | pr_debug("%s:%d: unknown match_id: %u\n", __func__, __LINE__, | ||
233 | dev->match_id); | ||
234 | BUG(); | ||
235 | return -ENODEV; | ||
236 | } | ||
237 | EXPORT_SYMBOL_GPL(ps3_close_hv_device); | ||
238 | |||
33 | #define dump_mmio_region(_a) _dump_mmio_region(_a, __func__, __LINE__) | 239 | #define dump_mmio_region(_a) _dump_mmio_region(_a, __func__, __LINE__) |
34 | static void _dump_mmio_region(const struct ps3_mmio_region* r, | 240 | static void _dump_mmio_region(const struct ps3_mmio_region* r, |
35 | const char* func, int line) | 241 | const char* func, int line) |
36 | { | 242 | { |
37 | pr_debug("%s:%d: dev %u:%u\n", func, line, r->did.bus_id, | 243 | pr_debug("%s:%d: dev %u:%u\n", func, line, r->dev->bus_id, |
38 | r->did.dev_id); | 244 | r->dev->dev_id); |
39 | pr_debug("%s:%d: bus_addr %lxh\n", func, line, r->bus_addr); | 245 | pr_debug("%s:%d: bus_addr %lxh\n", func, line, r->bus_addr); |
40 | pr_debug("%s:%d: len %lxh\n", func, line, r->len); | 246 | pr_debug("%s:%d: len %lxh\n", func, line, r->len); |
41 | pr_debug("%s:%d: lpar_addr %lxh\n", func, line, r->lpar_addr); | 247 | pr_debug("%s:%d: lpar_addr %lxh\n", func, line, r->lpar_addr); |
42 | } | 248 | } |
43 | 249 | ||
44 | int ps3_mmio_region_create(struct ps3_mmio_region *r) | 250 | static int ps3_sb_mmio_region_create(struct ps3_mmio_region *r) |
45 | { | 251 | { |
46 | int result; | 252 | int result; |
47 | 253 | ||
48 | result = lv1_map_device_mmio_region(r->did.bus_id, r->did.dev_id, | 254 | result = lv1_map_device_mmio_region(r->dev->bus_id, r->dev->dev_id, |
49 | r->bus_addr, r->len, r->page_size, &r->lpar_addr); | 255 | r->bus_addr, r->len, r->page_size, &r->lpar_addr); |
50 | 256 | ||
51 | if (result) { | 257 | if (result) { |
@@ -57,13 +263,26 @@ int ps3_mmio_region_create(struct ps3_mmio_region *r) | |||
57 | dump_mmio_region(r); | 263 | dump_mmio_region(r); |
58 | return result; | 264 | return result; |
59 | } | 265 | } |
266 | |||
267 | static int ps3_ioc0_mmio_region_create(struct ps3_mmio_region *r) | ||
268 | { | ||
269 | /* device specific; do nothing currently */ | ||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | int ps3_mmio_region_create(struct ps3_mmio_region *r) | ||
274 | { | ||
275 | return r->mmio_ops->create(r); | ||
276 | } | ||
60 | EXPORT_SYMBOL_GPL(ps3_mmio_region_create); | 277 | EXPORT_SYMBOL_GPL(ps3_mmio_region_create); |
61 | 278 | ||
62 | int ps3_free_mmio_region(struct ps3_mmio_region *r) | 279 | static int ps3_sb_free_mmio_region(struct ps3_mmio_region *r) |
63 | { | 280 | { |
64 | int result; | 281 | int result; |
65 | 282 | ||
66 | result = lv1_unmap_device_mmio_region(r->did.bus_id, r->did.dev_id, | 283 | dump_mmio_region(r); |
284 | ; | ||
285 | result = lv1_unmap_device_mmio_region(r->dev->bus_id, r->dev->dev_id, | ||
67 | r->lpar_addr); | 286 | r->lpar_addr); |
68 | 287 | ||
69 | if (result) | 288 | if (result) |
@@ -73,14 +292,60 @@ int ps3_free_mmio_region(struct ps3_mmio_region *r) | |||
73 | r->lpar_addr = 0; | 292 | r->lpar_addr = 0; |
74 | return result; | 293 | return result; |
75 | } | 294 | } |
295 | |||
296 | static int ps3_ioc0_free_mmio_region(struct ps3_mmio_region *r) | ||
297 | { | ||
298 | /* device specific; do nothing currently */ | ||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | |||
303 | int ps3_free_mmio_region(struct ps3_mmio_region *r) | ||
304 | { | ||
305 | return r->mmio_ops->free(r); | ||
306 | } | ||
307 | |||
76 | EXPORT_SYMBOL_GPL(ps3_free_mmio_region); | 308 | EXPORT_SYMBOL_GPL(ps3_free_mmio_region); |
77 | 309 | ||
310 | static const struct ps3_mmio_region_ops ps3_mmio_sb_region_ops = { | ||
311 | .create = ps3_sb_mmio_region_create, | ||
312 | .free = ps3_sb_free_mmio_region | ||
313 | }; | ||
314 | |||
315 | static const struct ps3_mmio_region_ops ps3_mmio_ioc0_region_ops = { | ||
316 | .create = ps3_ioc0_mmio_region_create, | ||
317 | .free = ps3_ioc0_free_mmio_region | ||
318 | }; | ||
319 | |||
320 | int ps3_mmio_region_init(struct ps3_system_bus_device *dev, | ||
321 | struct ps3_mmio_region *r, unsigned long bus_addr, unsigned long len, | ||
322 | enum ps3_mmio_page_size page_size) | ||
323 | { | ||
324 | r->dev = dev; | ||
325 | r->bus_addr = bus_addr; | ||
326 | r->len = len; | ||
327 | r->page_size = page_size; | ||
328 | switch (dev->dev_type) { | ||
329 | case PS3_DEVICE_TYPE_SB: | ||
330 | r->mmio_ops = &ps3_mmio_sb_region_ops; | ||
331 | break; | ||
332 | case PS3_DEVICE_TYPE_IOC0: | ||
333 | r->mmio_ops = &ps3_mmio_ioc0_region_ops; | ||
334 | break; | ||
335 | default: | ||
336 | BUG(); | ||
337 | return -EINVAL; | ||
338 | } | ||
339 | return 0; | ||
340 | } | ||
341 | EXPORT_SYMBOL_GPL(ps3_mmio_region_init); | ||
342 | |||
78 | static int ps3_system_bus_match(struct device *_dev, | 343 | static int ps3_system_bus_match(struct device *_dev, |
79 | struct device_driver *_drv) | 344 | struct device_driver *_drv) |
80 | { | 345 | { |
81 | int result; | 346 | int result; |
82 | struct ps3_system_bus_driver *drv = to_ps3_system_bus_driver(_drv); | 347 | struct ps3_system_bus_driver *drv = ps3_drv_to_system_bus_drv(_drv); |
83 | struct ps3_system_bus_device *dev = to_ps3_system_bus_device(_dev); | 348 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); |
84 | 349 | ||
85 | result = dev->match_id == drv->match_id; | 350 | result = dev->match_id == drv->match_id; |
86 | 351 | ||
@@ -92,32 +357,14 @@ static int ps3_system_bus_match(struct device *_dev, | |||
92 | 357 | ||
93 | static int ps3_system_bus_probe(struct device *_dev) | 358 | static int ps3_system_bus_probe(struct device *_dev) |
94 | { | 359 | { |
95 | int result; | 360 | int result = 0; |
96 | struct ps3_system_bus_device *dev = to_ps3_system_bus_device(_dev); | 361 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); |
97 | struct ps3_system_bus_driver *drv = | 362 | struct ps3_system_bus_driver *drv; |
98 | to_ps3_system_bus_driver(_dev->driver); | ||
99 | |||
100 | result = lv1_open_device(dev->did.bus_id, dev->did.dev_id, 0); | ||
101 | 363 | ||
102 | if (result) { | 364 | BUG_ON(!dev); |
103 | pr_debug("%s:%d: lv1_open_device failed (%d)\n", | 365 | pr_info(" -> %s:%d: %s\n", __func__, __LINE__, _dev->bus_id); |
104 | __func__, __LINE__, result); | ||
105 | result = -EACCES; | ||
106 | goto clean_none; | ||
107 | } | ||
108 | |||
109 | if (dev->d_region->did.bus_id) { | ||
110 | result = ps3_dma_region_create(dev->d_region); | ||
111 | |||
112 | if (result) { | ||
113 | pr_debug("%s:%d: ps3_dma_region_create failed (%d)\n", | ||
114 | __func__, __LINE__, result); | ||
115 | BUG_ON("check region type"); | ||
116 | result = -EINVAL; | ||
117 | goto clean_device; | ||
118 | } | ||
119 | } | ||
120 | 366 | ||
367 | drv = ps3_system_bus_dev_to_system_bus_drv(dev); | ||
121 | BUG_ON(!drv); | 368 | BUG_ON(!drv); |
122 | 369 | ||
123 | if (drv->probe) | 370 | if (drv->probe) |
@@ -126,38 +373,68 @@ static int ps3_system_bus_probe(struct device *_dev) | |||
126 | pr_info("%s:%d: %s no probe method\n", __func__, __LINE__, | 373 | pr_info("%s:%d: %s no probe method\n", __func__, __LINE__, |
127 | dev->core.bus_id); | 374 | dev->core.bus_id); |
128 | 375 | ||
129 | if (result) { | 376 | pr_info(" <- %s:%d: %s\n", __func__, __LINE__, dev->core.bus_id); |
130 | pr_debug("%s:%d: drv->probe failed\n", __func__, __LINE__); | ||
131 | goto clean_dma; | ||
132 | } | ||
133 | |||
134 | return result; | ||
135 | |||
136 | clean_dma: | ||
137 | ps3_dma_region_free(dev->d_region); | ||
138 | clean_device: | ||
139 | lv1_close_device(dev->did.bus_id, dev->did.dev_id); | ||
140 | clean_none: | ||
141 | return result; | 377 | return result; |
142 | } | 378 | } |
143 | 379 | ||
144 | static int ps3_system_bus_remove(struct device *_dev) | 380 | static int ps3_system_bus_remove(struct device *_dev) |
145 | { | 381 | { |
146 | struct ps3_system_bus_device *dev = to_ps3_system_bus_device(_dev); | 382 | int result = 0; |
147 | struct ps3_system_bus_driver *drv = | 383 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); |
148 | to_ps3_system_bus_driver(_dev->driver); | 384 | struct ps3_system_bus_driver *drv; |
385 | |||
386 | BUG_ON(!dev); | ||
387 | pr_info(" -> %s:%d: %s\n", __func__, __LINE__, _dev->bus_id); | ||
388 | |||
389 | drv = ps3_system_bus_dev_to_system_bus_drv(dev); | ||
390 | BUG_ON(!drv); | ||
149 | 391 | ||
150 | if (drv->remove) | 392 | if (drv->remove) |
151 | drv->remove(dev); | 393 | result = drv->remove(dev); |
152 | else | 394 | else |
153 | pr_info("%s:%d: %s no remove method\n", __func__, __LINE__, | 395 | dev_dbg(&dev->core, "%s:%d %s: no remove method\n", |
154 | dev->core.bus_id); | 396 | __func__, __LINE__, drv->core.name); |
397 | |||
398 | pr_info(" <- %s:%d: %s\n", __func__, __LINE__, dev->core.bus_id); | ||
399 | return result; | ||
400 | } | ||
155 | 401 | ||
156 | ps3_dma_region_free(dev->d_region); | 402 | static void ps3_system_bus_shutdown(struct device *_dev) |
157 | ps3_free_mmio_region(dev->m_region); | 403 | { |
158 | lv1_close_device(dev->did.bus_id, dev->did.dev_id); | 404 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); |
405 | struct ps3_system_bus_driver *drv; | ||
159 | 406 | ||
160 | return 0; | 407 | BUG_ON(!dev); |
408 | |||
409 | dev_dbg(&dev->core, " -> %s:%d: match_id %d\n", __func__, __LINE__, | ||
410 | dev->match_id); | ||
411 | |||
412 | if (!dev->core.driver) { | ||
413 | dev_dbg(&dev->core, "%s:%d: no driver bound\n", __func__, | ||
414 | __LINE__); | ||
415 | return; | ||
416 | } | ||
417 | |||
418 | drv = ps3_system_bus_dev_to_system_bus_drv(dev); | ||
419 | |||
420 | BUG_ON(!drv); | ||
421 | |||
422 | dev_dbg(&dev->core, "%s:%d: %s -> %s\n", __func__, __LINE__, | ||
423 | dev->core.bus_id, drv->core.name); | ||
424 | |||
425 | if (drv->shutdown) | ||
426 | drv->shutdown(dev); | ||
427 | else if (drv->remove) { | ||
428 | dev_dbg(&dev->core, "%s:%d %s: no shutdown, calling remove\n", | ||
429 | __func__, __LINE__, drv->core.name); | ||
430 | drv->remove(dev); | ||
431 | } else { | ||
432 | dev_dbg(&dev->core, "%s:%d %s: no shutdown method\n", | ||
433 | __func__, __LINE__, drv->core.name); | ||
434 | BUG(); | ||
435 | } | ||
436 | |||
437 | dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__); | ||
161 | } | 438 | } |
162 | 439 | ||
163 | struct bus_type ps3_system_bus_type = { | 440 | struct bus_type ps3_system_bus_type = { |
@@ -165,17 +442,27 @@ struct bus_type ps3_system_bus_type = { | |||
165 | .match = ps3_system_bus_match, | 442 | .match = ps3_system_bus_match, |
166 | .probe = ps3_system_bus_probe, | 443 | .probe = ps3_system_bus_probe, |
167 | .remove = ps3_system_bus_remove, | 444 | .remove = ps3_system_bus_remove, |
445 | .shutdown = ps3_system_bus_shutdown, | ||
168 | }; | 446 | }; |
169 | 447 | ||
170 | int __init ps3_system_bus_init(void) | 448 | static int __init ps3_system_bus_init(void) |
171 | { | 449 | { |
172 | int result; | 450 | int result; |
173 | 451 | ||
174 | if (!firmware_has_feature(FW_FEATURE_PS3_LV1)) | 452 | if (!firmware_has_feature(FW_FEATURE_PS3_LV1)) |
175 | return -ENODEV; | 453 | return -ENODEV; |
176 | 454 | ||
455 | pr_debug(" -> %s:%d\n", __func__, __LINE__); | ||
456 | |||
457 | mutex_init(&usage_hack.mutex); | ||
458 | |||
459 | result = device_register(&ps3_system_bus); | ||
460 | BUG_ON(result); | ||
461 | |||
177 | result = bus_register(&ps3_system_bus_type); | 462 | result = bus_register(&ps3_system_bus_type); |
178 | BUG_ON(result); | 463 | BUG_ON(result); |
464 | |||
465 | pr_debug(" <- %s:%d\n", __func__, __LINE__); | ||
179 | return result; | 466 | return result; |
180 | } | 467 | } |
181 | 468 | ||
@@ -185,16 +472,13 @@ core_initcall(ps3_system_bus_init); | |||
185 | * Returns the virtual address of the buffer and sets dma_handle | 472 | * Returns the virtual address of the buffer and sets dma_handle |
186 | * to the dma address (mapping) of the first page. | 473 | * to the dma address (mapping) of the first page. |
187 | */ | 474 | */ |
188 | |||
189 | static void * ps3_alloc_coherent(struct device *_dev, size_t size, | 475 | static void * ps3_alloc_coherent(struct device *_dev, size_t size, |
190 | dma_addr_t *dma_handle, gfp_t flag) | 476 | dma_addr_t *dma_handle, gfp_t flag) |
191 | { | 477 | { |
192 | int result; | 478 | int result; |
193 | struct ps3_system_bus_device *dev = to_ps3_system_bus_device(_dev); | 479 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); |
194 | unsigned long virt_addr; | 480 | unsigned long virt_addr; |
195 | 481 | ||
196 | BUG_ON(!dev->d_region->bus_addr); | ||
197 | |||
198 | flag &= ~(__GFP_DMA | __GFP_HIGHMEM); | 482 | flag &= ~(__GFP_DMA | __GFP_HIGHMEM); |
199 | flag |= __GFP_ZERO; | 483 | flag |= __GFP_ZERO; |
200 | 484 | ||
@@ -205,7 +489,8 @@ static void * ps3_alloc_coherent(struct device *_dev, size_t size, | |||
205 | goto clean_none; | 489 | goto clean_none; |
206 | } | 490 | } |
207 | 491 | ||
208 | result = ps3_dma_map(dev->d_region, virt_addr, size, dma_handle); | 492 | result = ps3_dma_map(dev->d_region, virt_addr, size, dma_handle, |
493 | IOPTE_PP_W | IOPTE_PP_R | IOPTE_SO_RW | IOPTE_M); | ||
209 | 494 | ||
210 | if (result) { | 495 | if (result) { |
211 | pr_debug("%s:%d: ps3_dma_map failed (%d)\n", | 496 | pr_debug("%s:%d: ps3_dma_map failed (%d)\n", |
@@ -226,7 +511,7 @@ clean_none: | |||
226 | static void ps3_free_coherent(struct device *_dev, size_t size, void *vaddr, | 511 | static void ps3_free_coherent(struct device *_dev, size_t size, void *vaddr, |
227 | dma_addr_t dma_handle) | 512 | dma_addr_t dma_handle) |
228 | { | 513 | { |
229 | struct ps3_system_bus_device *dev = to_ps3_system_bus_device(_dev); | 514 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); |
230 | 515 | ||
231 | ps3_dma_unmap(dev->d_region, dma_handle, size); | 516 | ps3_dma_unmap(dev->d_region, dma_handle, size); |
232 | free_pages((unsigned long)vaddr, get_order(size)); | 517 | free_pages((unsigned long)vaddr, get_order(size)); |
@@ -239,15 +524,16 @@ static void ps3_free_coherent(struct device *_dev, size_t size, void *vaddr, | |||
239 | * byte within the page as vaddr. | 524 | * byte within the page as vaddr. |
240 | */ | 525 | */ |
241 | 526 | ||
242 | static dma_addr_t ps3_map_single(struct device *_dev, void *ptr, size_t size, | 527 | static dma_addr_t ps3_sb_map_single(struct device *_dev, void *ptr, size_t size, |
243 | enum dma_data_direction direction) | 528 | enum dma_data_direction direction) |
244 | { | 529 | { |
245 | struct ps3_system_bus_device *dev = to_ps3_system_bus_device(_dev); | 530 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); |
246 | int result; | 531 | int result; |
247 | unsigned long bus_addr; | 532 | unsigned long bus_addr; |
248 | 533 | ||
249 | result = ps3_dma_map(dev->d_region, (unsigned long)ptr, size, | 534 | result = ps3_dma_map(dev->d_region, (unsigned long)ptr, size, |
250 | &bus_addr); | 535 | &bus_addr, |
536 | IOPTE_PP_R | IOPTE_PP_W | IOPTE_SO_RW | IOPTE_M); | ||
251 | 537 | ||
252 | if (result) { | 538 | if (result) { |
253 | pr_debug("%s:%d: ps3_dma_map failed (%d)\n", | 539 | pr_debug("%s:%d: ps3_dma_map failed (%d)\n", |
@@ -257,10 +543,44 @@ static dma_addr_t ps3_map_single(struct device *_dev, void *ptr, size_t size, | |||
257 | return bus_addr; | 543 | return bus_addr; |
258 | } | 544 | } |
259 | 545 | ||
546 | static dma_addr_t ps3_ioc0_map_single(struct device *_dev, void *ptr, | ||
547 | size_t size, | ||
548 | enum dma_data_direction direction) | ||
549 | { | ||
550 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); | ||
551 | int result; | ||
552 | unsigned long bus_addr; | ||
553 | u64 iopte_flag; | ||
554 | |||
555 | iopte_flag = IOPTE_M; | ||
556 | switch (direction) { | ||
557 | case DMA_BIDIRECTIONAL: | ||
558 | iopte_flag |= IOPTE_PP_R | IOPTE_PP_W | IOPTE_SO_RW; | ||
559 | break; | ||
560 | case DMA_TO_DEVICE: | ||
561 | iopte_flag |= IOPTE_PP_R | IOPTE_SO_R; | ||
562 | break; | ||
563 | case DMA_FROM_DEVICE: | ||
564 | iopte_flag |= IOPTE_PP_W | IOPTE_SO_RW; | ||
565 | break; | ||
566 | default: | ||
567 | /* not happned */ | ||
568 | BUG(); | ||
569 | }; | ||
570 | result = ps3_dma_map(dev->d_region, (unsigned long)ptr, size, | ||
571 | &bus_addr, iopte_flag); | ||
572 | |||
573 | if (result) { | ||
574 | pr_debug("%s:%d: ps3_dma_map failed (%d)\n", | ||
575 | __func__, __LINE__, result); | ||
576 | } | ||
577 | return bus_addr; | ||
578 | } | ||
579 | |||
260 | static void ps3_unmap_single(struct device *_dev, dma_addr_t dma_addr, | 580 | static void ps3_unmap_single(struct device *_dev, dma_addr_t dma_addr, |
261 | size_t size, enum dma_data_direction direction) | 581 | size_t size, enum dma_data_direction direction) |
262 | { | 582 | { |
263 | struct ps3_system_bus_device *dev = to_ps3_system_bus_device(_dev); | 583 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); |
264 | int result; | 584 | int result; |
265 | 585 | ||
266 | result = ps3_dma_unmap(dev->d_region, dma_addr, size); | 586 | result = ps3_dma_unmap(dev->d_region, dma_addr, size); |
@@ -271,20 +591,20 @@ static void ps3_unmap_single(struct device *_dev, dma_addr_t dma_addr, | |||
271 | } | 591 | } |
272 | } | 592 | } |
273 | 593 | ||
274 | static int ps3_map_sg(struct device *_dev, struct scatterlist *sg, int nents, | 594 | static int ps3_sb_map_sg(struct device *_dev, struct scatterlist *sg, int nents, |
275 | enum dma_data_direction direction) | 595 | enum dma_data_direction direction) |
276 | { | 596 | { |
277 | #if defined(CONFIG_PS3_DYNAMIC_DMA) | 597 | #if defined(CONFIG_PS3_DYNAMIC_DMA) |
278 | BUG_ON("do"); | 598 | BUG_ON("do"); |
279 | return -EPERM; | 599 | return -EPERM; |
280 | #else | 600 | #else |
281 | struct ps3_system_bus_device *dev = to_ps3_system_bus_device(_dev); | 601 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); |
282 | int i; | 602 | int i; |
283 | 603 | ||
284 | for (i = 0; i < nents; i++, sg++) { | 604 | for (i = 0; i < nents; i++, sg++) { |
285 | int result = ps3_dma_map(dev->d_region, | 605 | int result = ps3_dma_map(dev->d_region, |
286 | page_to_phys(sg->page) + sg->offset, sg->length, | 606 | page_to_phys(sg->page) + sg->offset, sg->length, |
287 | &sg->dma_address); | 607 | &sg->dma_address, 0); |
288 | 608 | ||
289 | if (result) { | 609 | if (result) { |
290 | pr_debug("%s:%d: ps3_dma_map failed (%d)\n", | 610 | pr_debug("%s:%d: ps3_dma_map failed (%d)\n", |
@@ -299,7 +619,15 @@ static int ps3_map_sg(struct device *_dev, struct scatterlist *sg, int nents, | |||
299 | #endif | 619 | #endif |
300 | } | 620 | } |
301 | 621 | ||
302 | static void ps3_unmap_sg(struct device *_dev, struct scatterlist *sg, | 622 | static int ps3_ioc0_map_sg(struct device *_dev, struct scatterlist *sg, |
623 | int nents, | ||
624 | enum dma_data_direction direction) | ||
625 | { | ||
626 | BUG(); | ||
627 | return 0; | ||
628 | } | ||
629 | |||
630 | static void ps3_sb_unmap_sg(struct device *_dev, struct scatterlist *sg, | ||
303 | int nents, enum dma_data_direction direction) | 631 | int nents, enum dma_data_direction direction) |
304 | { | 632 | { |
305 | #if defined(CONFIG_PS3_DYNAMIC_DMA) | 633 | #if defined(CONFIG_PS3_DYNAMIC_DMA) |
@@ -307,18 +635,34 @@ static void ps3_unmap_sg(struct device *_dev, struct scatterlist *sg, | |||
307 | #endif | 635 | #endif |
308 | } | 636 | } |
309 | 637 | ||
638 | static void ps3_ioc0_unmap_sg(struct device *_dev, struct scatterlist *sg, | ||
639 | int nents, enum dma_data_direction direction) | ||
640 | { | ||
641 | BUG(); | ||
642 | } | ||
643 | |||
310 | static int ps3_dma_supported(struct device *_dev, u64 mask) | 644 | static int ps3_dma_supported(struct device *_dev, u64 mask) |
311 | { | 645 | { |
312 | return mask >= DMA_32BIT_MASK; | 646 | return mask >= DMA_32BIT_MASK; |
313 | } | 647 | } |
314 | 648 | ||
315 | static struct dma_mapping_ops ps3_dma_ops = { | 649 | static struct dma_mapping_ops ps3_sb_dma_ops = { |
650 | .alloc_coherent = ps3_alloc_coherent, | ||
651 | .free_coherent = ps3_free_coherent, | ||
652 | .map_single = ps3_sb_map_single, | ||
653 | .unmap_single = ps3_unmap_single, | ||
654 | .map_sg = ps3_sb_map_sg, | ||
655 | .unmap_sg = ps3_sb_unmap_sg, | ||
656 | .dma_supported = ps3_dma_supported | ||
657 | }; | ||
658 | |||
659 | static struct dma_mapping_ops ps3_ioc0_dma_ops = { | ||
316 | .alloc_coherent = ps3_alloc_coherent, | 660 | .alloc_coherent = ps3_alloc_coherent, |
317 | .free_coherent = ps3_free_coherent, | 661 | .free_coherent = ps3_free_coherent, |
318 | .map_single = ps3_map_single, | 662 | .map_single = ps3_ioc0_map_single, |
319 | .unmap_single = ps3_unmap_single, | 663 | .unmap_single = ps3_unmap_single, |
320 | .map_sg = ps3_map_sg, | 664 | .map_sg = ps3_ioc0_map_sg, |
321 | .unmap_sg = ps3_unmap_sg, | 665 | .unmap_sg = ps3_ioc0_unmap_sg, |
322 | .dma_supported = ps3_dma_supported | 666 | .dma_supported = ps3_dma_supported |
323 | }; | 667 | }; |
324 | 668 | ||
@@ -328,7 +672,7 @@ static struct dma_mapping_ops ps3_dma_ops = { | |||
328 | 672 | ||
329 | static void ps3_system_bus_release_device(struct device *_dev) | 673 | static void ps3_system_bus_release_device(struct device *_dev) |
330 | { | 674 | { |
331 | struct ps3_system_bus_device *dev = to_ps3_system_bus_device(_dev); | 675 | struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); |
332 | kfree(dev); | 676 | kfree(dev); |
333 | } | 677 | } |
334 | 678 | ||
@@ -343,19 +687,38 @@ static void ps3_system_bus_release_device(struct device *_dev) | |||
343 | int ps3_system_bus_device_register(struct ps3_system_bus_device *dev) | 687 | int ps3_system_bus_device_register(struct ps3_system_bus_device *dev) |
344 | { | 688 | { |
345 | int result; | 689 | int result; |
346 | static unsigned int dev_count = 1; | 690 | static unsigned int dev_ioc0_count; |
691 | static unsigned int dev_sb_count; | ||
692 | static unsigned int dev_vuart_count; | ||
347 | 693 | ||
348 | dev->core.parent = NULL; | 694 | if (!dev->core.parent) |
695 | dev->core.parent = &ps3_system_bus; | ||
349 | dev->core.bus = &ps3_system_bus_type; | 696 | dev->core.bus = &ps3_system_bus_type; |
350 | dev->core.release = ps3_system_bus_release_device; | 697 | dev->core.release = ps3_system_bus_release_device; |
351 | 698 | ||
699 | switch (dev->dev_type) { | ||
700 | case PS3_DEVICE_TYPE_IOC0: | ||
701 | dev->core.archdata.dma_ops = &ps3_ioc0_dma_ops; | ||
702 | snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), | ||
703 | "ioc0_%02x", ++dev_ioc0_count); | ||
704 | break; | ||
705 | case PS3_DEVICE_TYPE_SB: | ||
706 | dev->core.archdata.dma_ops = &ps3_sb_dma_ops; | ||
707 | snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), | ||
708 | "sb_%02x", ++dev_sb_count); | ||
709 | |||
710 | break; | ||
711 | case PS3_DEVICE_TYPE_VUART: | ||
712 | snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), | ||
713 | "vuart_%02x", ++dev_vuart_count); | ||
714 | break; | ||
715 | default: | ||
716 | BUG(); | ||
717 | }; | ||
718 | |||
352 | dev->core.archdata.of_node = NULL; | 719 | dev->core.archdata.of_node = NULL; |
353 | dev->core.archdata.dma_ops = &ps3_dma_ops; | ||
354 | dev->core.archdata.numa_node = 0; | 720 | dev->core.archdata.numa_node = 0; |
355 | 721 | ||
356 | snprintf(dev->core.bus_id, sizeof(dev->core.bus_id), "sb_%02x", | ||
357 | dev_count++); | ||
358 | |||
359 | pr_debug("%s:%d add %s\n", __func__, __LINE__, dev->core.bus_id); | 722 | pr_debug("%s:%d add %s\n", __func__, __LINE__, dev->core.bus_id); |
360 | 723 | ||
361 | result = device_register(&dev->core); | 724 | result = device_register(&dev->core); |
@@ -368,9 +731,15 @@ int ps3_system_bus_driver_register(struct ps3_system_bus_driver *drv) | |||
368 | { | 731 | { |
369 | int result; | 732 | int result; |
370 | 733 | ||
734 | pr_debug(" -> %s:%d: %s\n", __func__, __LINE__, drv->core.name); | ||
735 | |||
736 | if (!firmware_has_feature(FW_FEATURE_PS3_LV1)) | ||
737 | return -ENODEV; | ||
738 | |||
371 | drv->core.bus = &ps3_system_bus_type; | 739 | drv->core.bus = &ps3_system_bus_type; |
372 | 740 | ||
373 | result = driver_register(&drv->core); | 741 | result = driver_register(&drv->core); |
742 | pr_debug(" <- %s:%d: %s\n", __func__, __LINE__, drv->core.name); | ||
374 | return result; | 743 | return result; |
375 | } | 744 | } |
376 | 745 | ||
@@ -378,7 +747,9 @@ EXPORT_SYMBOL_GPL(ps3_system_bus_driver_register); | |||
378 | 747 | ||
379 | void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv) | 748 | void ps3_system_bus_driver_unregister(struct ps3_system_bus_driver *drv) |
380 | { | 749 | { |
750 | pr_debug(" -> %s:%d: %s\n", __func__, __LINE__, drv->core.name); | ||
381 | driver_unregister(&drv->core); | 751 | driver_unregister(&drv->core); |
752 | pr_debug(" <- %s:%d: %s\n", __func__, __LINE__, drv->core.name); | ||
382 | } | 753 | } |
383 | 754 | ||
384 | EXPORT_SYMBOL_GPL(ps3_system_bus_driver_unregister); | 755 | EXPORT_SYMBOL_GPL(ps3_system_bus_driver_unregister); |