aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/macintosh/macio_asic.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/macintosh/macio_asic.c')
-rw-r--r--drivers/macintosh/macio_asic.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
index 588a5b0bc4b5..26a303a1d1ab 100644
--- a/drivers/macintosh/macio_asic.c
+++ b/drivers/macintosh/macio_asic.c
@@ -379,6 +379,11 @@ static struct macio_dev * macio_add_one_device(struct macio_chip *chip,
379 dev->ofdev.dev.parent = parent; 379 dev->ofdev.dev.parent = parent;
380 dev->ofdev.dev.bus = &macio_bus_type; 380 dev->ofdev.dev.bus = &macio_bus_type;
381 dev->ofdev.dev.release = macio_release_dev; 381 dev->ofdev.dev.release = macio_release_dev;
382 dev->ofdev.dev.dma_parms = &dev->dma_parms;
383
384 /* Standard DMA paremeters */
385 dma_set_max_seg_size(&dev->ofdev.dev, 65536);
386 dma_set_seg_boundary(&dev->ofdev.dev, 0xffffffff);
382 387
383#ifdef CONFIG_PCI 388#ifdef CONFIG_PCI
384 /* Set the DMA ops to the ones from the PCI device, this could be 389 /* Set the DMA ops to the ones from the PCI device, this could be
@@ -538,6 +543,42 @@ void macio_unregister_driver(struct macio_driver *drv)
538 driver_unregister(&drv->driver); 543 driver_unregister(&drv->driver);
539} 544}
540 545
546/* Managed MacIO resources */
547struct macio_devres {
548 u32 res_mask;
549};
550
551static void maciom_release(struct device *gendev, void *res)
552{
553 struct macio_dev *dev = to_macio_device(gendev);
554 struct macio_devres *dr = res;
555 int i, max;
556
557 max = min(dev->n_resources, 32);
558 for (i = 0; i < max; i++) {
559 if (dr->res_mask & (1 << i))
560 macio_release_resource(dev, i);
561 }
562}
563
564int macio_enable_devres(struct macio_dev *dev)
565{
566 struct macio_devres *dr;
567
568 dr = devres_find(&dev->ofdev.dev, maciom_release, NULL, NULL);
569 if (!dr) {
570 dr = devres_alloc(maciom_release, sizeof(*dr), GFP_KERNEL);
571 if (!dr)
572 return -ENOMEM;
573 }
574 return devres_get(&dev->ofdev.dev, dr, NULL, NULL) != NULL;
575}
576
577static struct macio_devres * find_macio_dr(struct macio_dev *dev)
578{
579 return devres_find(&dev->ofdev.dev, maciom_release, NULL, NULL);
580}
581
541/** 582/**
542 * macio_request_resource - Request an MMIO resource 583 * macio_request_resource - Request an MMIO resource
543 * @dev: pointer to the device holding the resource 584 * @dev: pointer to the device holding the resource
@@ -555,6 +596,8 @@ void macio_unregister_driver(struct macio_driver *drv)
555int macio_request_resource(struct macio_dev *dev, int resource_no, 596int macio_request_resource(struct macio_dev *dev, int resource_no,
556 const char *name) 597 const char *name)
557{ 598{
599 struct macio_devres *dr = find_macio_dr(dev);
600
558 if (macio_resource_len(dev, resource_no) == 0) 601 if (macio_resource_len(dev, resource_no) == 0)
559 return 0; 602 return 0;
560 603
@@ -562,6 +605,9 @@ int macio_request_resource(struct macio_dev *dev, int resource_no,
562 macio_resource_len(dev, resource_no), 605 macio_resource_len(dev, resource_no),
563 name)) 606 name))
564 goto err_out; 607 goto err_out;
608
609 if (dr && resource_no < 32)
610 dr->res_mask |= 1 << resource_no;
565 611
566 return 0; 612 return 0;
567 613
@@ -582,10 +628,14 @@ err_out:
582 */ 628 */
583void macio_release_resource(struct macio_dev *dev, int resource_no) 629void macio_release_resource(struct macio_dev *dev, int resource_no)
584{ 630{
631 struct macio_devres *dr = find_macio_dr(dev);
632
585 if (macio_resource_len(dev, resource_no) == 0) 633 if (macio_resource_len(dev, resource_no) == 0)
586 return; 634 return;
587 release_mem_region(macio_resource_start(dev, resource_no), 635 release_mem_region(macio_resource_start(dev, resource_no),
588 macio_resource_len(dev, resource_no)); 636 macio_resource_len(dev, resource_no));
637 if (dr && resource_no < 32)
638 dr->res_mask &= ~(1 << resource_no);
589} 639}
590 640
591/** 641/**
@@ -744,3 +794,5 @@ EXPORT_SYMBOL(macio_request_resource);
744EXPORT_SYMBOL(macio_release_resource); 794EXPORT_SYMBOL(macio_release_resource);
745EXPORT_SYMBOL(macio_request_resources); 795EXPORT_SYMBOL(macio_request_resources);
746EXPORT_SYMBOL(macio_release_resources); 796EXPORT_SYMBOL(macio_release_resources);
797EXPORT_SYMBOL(macio_enable_devres);
798