aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/message
diff options
context:
space:
mode:
authorBjorn Helgaas <bhelgaas@google.com>2014-02-26 13:25:57 -0500
committerBjorn Helgaas <bhelgaas@google.com>2014-02-26 13:56:09 -0500
commit60f061e19311771e67a484184340e5359493f557 (patch)
treef72569d718ec4c23fea14337e77ac118e9eace9a /drivers/message
parent5c513bd580323dbe794270c5a96b65ba22f376eb (diff)
i2o: Refactor i2o_iop_systab_set() PCI space allocation
Refactor the PCI space allocation in i2o_iop_systab_set(). This might improve readability slightly, but mainly it is to make the next patch simpler. No functional change. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/message')
-rw-r--r--drivers/message/i2o/iop.c89
1 files changed, 46 insertions, 43 deletions
diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
index 68aef58bf89c..bd971b1b88e3 100644
--- a/drivers/message/i2o/iop.c
+++ b/drivers/message/i2o/iop.c
@@ -652,6 +652,48 @@ static int i2o_iop_activate(struct i2o_controller *c)
652 return i2o_hrt_get(c); 652 return i2o_hrt_get(c);
653}; 653};
654 654
655static void i2o_res_alloc(struct i2o_controller *c, unsigned long flags)
656{
657 i2o_status_block *sb = c->status_block.virt;
658 struct resource *root, *res = &c->mem_resource;
659 resource_size_t size, min, max, align;
660 int err;
661
662 res->name = c->pdev->bus->name;
663 res->flags = flags;
664 res->start = 0;
665 res->end = 0;
666 osm_info("%s: requires private memory resources.\n", c->name);
667 root = pci_find_parent_resource(c->pdev, res);
668 if (root == NULL) {
669 osm_warn("%s: Can't find parent resource!\n", c->name);
670 return;
671 }
672
673 if (flags & IORESOURCE_MEM) {
674 size = min = max = sb->desired_mem_size;
675 align = 1 << 20; /* unspecified, use 1Mb and play safe */
676 } else {
677 size = min = max = sb->desired_io_size;
678 align = 1 << 12; /* unspecified, use 4Kb and play safe */
679 }
680
681 err = allocate_resource(root, res, size, min, max, align, NULL, NULL);
682 if (err < 0)
683 return;
684
685 if (flags & IORESOURCE_MEM) {
686 c->mem_alloc = 1;
687 sb->current_mem_size = resource_size(res);
688 sb->current_mem_base = res->start;
689 } else if (flags & IORESOURCE_IO) {
690 c->io_alloc = 1;
691 sb->current_io_size = resource_size(res);
692 sb->current_io_base = res->start;
693 }
694 osm_info("%s: allocated PCI space %pR\n", c->name, res);
695}
696
655/** 697/**
656 * i2o_iop_systab_set - Set the I2O System Table of the specified IOP 698 * i2o_iop_systab_set - Set the I2O System Table of the specified IOP
657 * @c: I2O controller to which the system table should be send 699 * @c: I2O controller to which the system table should be send
@@ -665,52 +707,13 @@ static int i2o_iop_systab_set(struct i2o_controller *c)
665 struct i2o_message *msg; 707 struct i2o_message *msg;
666 i2o_status_block *sb = c->status_block.virt; 708 i2o_status_block *sb = c->status_block.virt;
667 struct device *dev = &c->pdev->dev; 709 struct device *dev = &c->pdev->dev;
668 struct resource *root;
669 int rc; 710 int rc;
670 711
671 if (sb->current_mem_size < sb->desired_mem_size) { 712 if (sb->current_mem_size < sb->desired_mem_size)
672 struct resource *res = &c->mem_resource; 713 i2o_res_alloc(c, IORESOURCE_MEM);
673 res->name = c->pdev->bus->name;
674 res->flags = IORESOURCE_MEM;
675 res->start = 0;
676 res->end = 0;
677 osm_info("%s: requires private memory resources.\n", c->name);
678 root = pci_find_parent_resource(c->pdev, res);
679 if (root == NULL)
680 osm_warn("%s: Can't find parent resource!\n", c->name);
681 if (root && allocate_resource(root, res, sb->desired_mem_size, sb->desired_mem_size, sb->desired_mem_size, 1 << 20, /* Unspecified, so use 1Mb and play safe */
682 NULL, NULL) >= 0) {
683 c->mem_alloc = 1;
684 sb->current_mem_size = resource_size(res);
685 sb->current_mem_base = res->start;
686 osm_info("%s: allocated %llu bytes of PCI memory at "
687 "0x%016llX.\n", c->name,
688 (unsigned long long)resource_size(res),
689 (unsigned long long)res->start);
690 }
691 }
692 714
693 if (sb->current_io_size < sb->desired_io_size) { 715 if (sb->current_io_size < sb->desired_io_size)
694 struct resource *res = &c->io_resource; 716 i2o_res_alloc(c, IORESOURCE_IO);
695 res->name = c->pdev->bus->name;
696 res->flags = IORESOURCE_IO;
697 res->start = 0;
698 res->end = 0;
699 osm_info("%s: requires private memory resources.\n", c->name);
700 root = pci_find_parent_resource(c->pdev, res);
701 if (root == NULL)
702 osm_warn("%s: Can't find parent resource!\n", c->name);
703 if (root && allocate_resource(root, res, sb->desired_io_size, sb->desired_io_size, sb->desired_io_size, 1 << 12, /* Unspecified, so use 4Kb and play safe */
704 NULL, NULL) >= 0) {
705 c->io_alloc = 1;
706 sb->current_io_size = resource_size(res);
707 sb->current_io_base = res->start;
708 osm_info("%s: allocated %llu bytes of PCI I/O at "
709 "0x%016llX.\n", c->name,
710 (unsigned long long)resource_size(res),
711 (unsigned long long)res->start);
712 }
713 }
714 717
715 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); 718 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
716 if (IS_ERR(msg)) 719 if (IS_ERR(msg))