diff options
author | Gavin Shan <shangw@linux.vnet.ibm.com> | 2012-09-11 18:59:46 -0400 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2012-09-11 18:59:46 -0400 |
commit | c121504e899c19f7e25b4894f616475073876361 (patch) | |
tree | 2e945763382aeee02afb2ea4f38636f2ef6288e3 /drivers/pci/setup-bus.c | |
parent | 462d93030628a598bc440dcd35c89fb7fc63f58c (diff) |
PCI: Refactor pbus_size_mem()
The original idea comes from Ram Pai. This patch puts the chunk of
code for calculating the minimal alignment of memory window into a
separate inline function.
Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/setup-bus.c')
-rw-r--r-- | drivers/pci/setup-bus.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index a66cf0905a15..1e808ca338f8 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c | |||
@@ -812,6 +812,28 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, | |||
812 | } | 812 | } |
813 | } | 813 | } |
814 | 814 | ||
815 | static inline resource_size_t calculate_mem_align(resource_size_t *aligns, | ||
816 | int max_order) | ||
817 | { | ||
818 | resource_size_t align = 0; | ||
819 | resource_size_t min_align = 0; | ||
820 | int order; | ||
821 | |||
822 | for (order = 0; order <= max_order; order++) { | ||
823 | resource_size_t align1 = 1; | ||
824 | |||
825 | align1 <<= (order + 20); | ||
826 | |||
827 | if (!align) | ||
828 | min_align = align1; | ||
829 | else if (ALIGN(align + min_align, min_align) < align1) | ||
830 | min_align = align1 >> 1; | ||
831 | align += aligns[order]; | ||
832 | } | ||
833 | |||
834 | return min_align; | ||
835 | } | ||
836 | |||
815 | /** | 837 | /** |
816 | * pbus_size_mem() - size the memory window of a given bus | 838 | * pbus_size_mem() - size the memory window of a given bus |
817 | * | 839 | * |
@@ -891,20 +913,8 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, | |||
891 | children_add_size += get_res_add_size(realloc_head, r); | 913 | children_add_size += get_res_add_size(realloc_head, r); |
892 | } | 914 | } |
893 | } | 915 | } |
894 | align = 0; | ||
895 | min_align = 0; | ||
896 | for (order = 0; order <= max_order; order++) { | ||
897 | resource_size_t align1 = 1; | ||
898 | |||
899 | align1 <<= (order + 20); | ||
900 | |||
901 | if (!align) | ||
902 | min_align = align1; | ||
903 | else if (ALIGN(align + min_align, min_align) < align1) | ||
904 | min_align = align1 >> 1; | ||
905 | align += aligns[order]; | ||
906 | } | ||
907 | 916 | ||
917 | min_align = calculate_mem_align(aligns, max_order); | ||
908 | min_align = max(min_align, window_alignment(bus, b_res->flags & mask)); | 918 | min_align = max(min_align, window_alignment(bus, b_res->flags & mask)); |
909 | size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); | 919 | size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); |
910 | if (children_add_size > add_size) | 920 | if (children_add_size > add_size) |