diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2009-12-01 09:36:26 -0500 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2009-12-08 00:02:51 -0500 |
commit | 7fb19ea054a0cdf1a4d935e68d51bde4d3725414 (patch) | |
tree | ec4882255440c93c8104e59efaceffae98f379d3 /drivers/macintosh | |
parent | e15a113700324f7fdcee95589875daed2b98a2fe (diff) |
powerpc/macio: Add devres support to macio_device
This adds some basic devres support. When enabled via macio_enable_devres()
resources requested by drivers will be automatically released.
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'drivers/macintosh')
-rw-r--r-- | drivers/macintosh/macio_asic.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c index 588a5b0bc4b5..5200acfc9d38 100644 --- a/drivers/macintosh/macio_asic.c +++ b/drivers/macintosh/macio_asic.c | |||
@@ -538,6 +538,42 @@ void macio_unregister_driver(struct macio_driver *drv) | |||
538 | driver_unregister(&drv->driver); | 538 | driver_unregister(&drv->driver); |
539 | } | 539 | } |
540 | 540 | ||
541 | /* Managed MacIO resources */ | ||
542 | struct macio_devres { | ||
543 | u32 res_mask; | ||
544 | }; | ||
545 | |||
546 | static void maciom_release(struct device *gendev, void *res) | ||
547 | { | ||
548 | struct macio_dev *dev = to_macio_device(gendev); | ||
549 | struct macio_devres *dr = res; | ||
550 | int i, max; | ||
551 | |||
552 | max = min(dev->n_resources, 32); | ||
553 | for (i = 0; i < max; i++) { | ||
554 | if (dr->res_mask & (1 << i)) | ||
555 | macio_release_resource(dev, i); | ||
556 | } | ||
557 | } | ||
558 | |||
559 | int macio_enable_devres(struct macio_dev *dev) | ||
560 | { | ||
561 | struct macio_devres *dr; | ||
562 | |||
563 | dr = devres_find(&dev->ofdev.dev, maciom_release, NULL, NULL); | ||
564 | if (!dr) { | ||
565 | dr = devres_alloc(maciom_release, sizeof(*dr), GFP_KERNEL); | ||
566 | if (!dr) | ||
567 | return -ENOMEM; | ||
568 | } | ||
569 | return devres_get(&dev->ofdev.dev, dr, NULL, NULL) != NULL; | ||
570 | } | ||
571 | |||
572 | static struct macio_devres * find_macio_dr(struct macio_dev *dev) | ||
573 | { | ||
574 | return devres_find(&dev->ofdev.dev, maciom_release, NULL, NULL); | ||
575 | } | ||
576 | |||
541 | /** | 577 | /** |
542 | * macio_request_resource - Request an MMIO resource | 578 | * macio_request_resource - Request an MMIO resource |
543 | * @dev: pointer to the device holding the resource | 579 | * @dev: pointer to the device holding the resource |
@@ -555,6 +591,8 @@ void macio_unregister_driver(struct macio_driver *drv) | |||
555 | int macio_request_resource(struct macio_dev *dev, int resource_no, | 591 | int macio_request_resource(struct macio_dev *dev, int resource_no, |
556 | const char *name) | 592 | const char *name) |
557 | { | 593 | { |
594 | struct macio_devres *dr = find_macio_dr(dev); | ||
595 | |||
558 | if (macio_resource_len(dev, resource_no) == 0) | 596 | if (macio_resource_len(dev, resource_no) == 0) |
559 | return 0; | 597 | return 0; |
560 | 598 | ||
@@ -562,6 +600,9 @@ int macio_request_resource(struct macio_dev *dev, int resource_no, | |||
562 | macio_resource_len(dev, resource_no), | 600 | macio_resource_len(dev, resource_no), |
563 | name)) | 601 | name)) |
564 | goto err_out; | 602 | goto err_out; |
603 | |||
604 | if (dr && resource_no < 32) | ||
605 | dr->res_mask |= 1 << resource_no; | ||
565 | 606 | ||
566 | return 0; | 607 | return 0; |
567 | 608 | ||
@@ -582,10 +623,14 @@ err_out: | |||
582 | */ | 623 | */ |
583 | void macio_release_resource(struct macio_dev *dev, int resource_no) | 624 | void macio_release_resource(struct macio_dev *dev, int resource_no) |
584 | { | 625 | { |
626 | struct macio_devres *dr = find_macio_dr(dev); | ||
627 | |||
585 | if (macio_resource_len(dev, resource_no) == 0) | 628 | if (macio_resource_len(dev, resource_no) == 0) |
586 | return; | 629 | return; |
587 | release_mem_region(macio_resource_start(dev, resource_no), | 630 | release_mem_region(macio_resource_start(dev, resource_no), |
588 | macio_resource_len(dev, resource_no)); | 631 | macio_resource_len(dev, resource_no)); |
632 | if (dr && resource_no < 32) | ||
633 | dr->res_mask &= ~(1 << resource_no); | ||
589 | } | 634 | } |
590 | 635 | ||
591 | /** | 636 | /** |
@@ -744,3 +789,5 @@ EXPORT_SYMBOL(macio_request_resource); | |||
744 | EXPORT_SYMBOL(macio_release_resource); | 789 | EXPORT_SYMBOL(macio_release_resource); |
745 | EXPORT_SYMBOL(macio_request_resources); | 790 | EXPORT_SYMBOL(macio_request_resources); |
746 | EXPORT_SYMBOL(macio_release_resources); | 791 | EXPORT_SYMBOL(macio_release_resources); |
792 | EXPORT_SYMBOL(macio_enable_devres); | ||
793 | |||