aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r--drivers/pci/pci.c80
1 files changed, 63 insertions, 17 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 287b685aaa5c..599978631a46 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -921,6 +921,47 @@ err_out:
921 return -EBUSY; 921 return -EBUSY;
922} 922}
923 923
924/**
925 * pci_release_selected_regions - Release selected PCI I/O and memory resources
926 * @pdev: PCI device whose resources were previously reserved
927 * @bars: Bitmask of BARs to be released
928 *
929 * Release selected PCI I/O and memory resources previously reserved.
930 * Call this function only after all use of the PCI regions has ceased.
931 */
932void pci_release_selected_regions(struct pci_dev *pdev, int bars)
933{
934 int i;
935
936 for (i = 0; i < 6; i++)
937 if (bars & (1 << i))
938 pci_release_region(pdev, i);
939}
940
941/**
942 * pci_request_selected_regions - Reserve selected PCI I/O and memory resources
943 * @pdev: PCI device whose resources are to be reserved
944 * @bars: Bitmask of BARs to be requested
945 * @res_name: Name to be associated with resource
946 */
947int pci_request_selected_regions(struct pci_dev *pdev, int bars,
948 const char *res_name)
949{
950 int i;
951
952 for (i = 0; i < 6; i++)
953 if (bars & (1 << i))
954 if(pci_request_region(pdev, i, res_name))
955 goto err_out;
956 return 0;
957
958err_out:
959 while(--i >= 0)
960 if (bars & (1 << i))
961 pci_release_region(pdev, i);
962
963 return -EBUSY;
964}
924 965
925/** 966/**
926 * pci_release_regions - Release reserved PCI I/O and memory resources 967 * pci_release_regions - Release reserved PCI I/O and memory resources
@@ -933,10 +974,7 @@ err_out:
933 974
934void pci_release_regions(struct pci_dev *pdev) 975void pci_release_regions(struct pci_dev *pdev)
935{ 976{
936 int i; 977 pci_release_selected_regions(pdev, (1 << 6) - 1);
937
938 for (i = 0; i < 6; i++)
939 pci_release_region(pdev, i);
940} 978}
941 979
942/** 980/**
@@ -954,18 +992,7 @@ void pci_release_regions(struct pci_dev *pdev)
954 */ 992 */
955int pci_request_regions(struct pci_dev *pdev, const char *res_name) 993int pci_request_regions(struct pci_dev *pdev, const char *res_name)
956{ 994{
957 int i; 995 return pci_request_selected_regions(pdev, ((1 << 6) - 1), res_name);
958
959 for (i = 0; i < 6; i++)
960 if(pci_request_region(pdev, i, res_name))
961 goto err_out;
962 return 0;
963
964err_out:
965 while(--i >= 0)
966 pci_release_region(pdev, i);
967
968 return -EBUSY;
969} 996}
970 997
971/** 998/**
@@ -1148,7 +1175,23 @@ pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask)
1148 return 0; 1175 return 0;
1149} 1176}
1150#endif 1177#endif
1151 1178
1179/**
1180 * pci_select_bars - Make BAR mask from the type of resource
1181 * @pdev: the PCI device for which BAR mask is made
1182 * @flags: resource type mask to be selected
1183 *
1184 * This helper routine makes bar mask from the type of resource.
1185 */
1186int pci_select_bars(struct pci_dev *dev, unsigned long flags)
1187{
1188 int i, bars = 0;
1189 for (i = 0; i < PCI_NUM_RESOURCES; i++)
1190 if (pci_resource_flags(dev, i) & flags)
1191 bars |= (1 << i);
1192 return bars;
1193}
1194
1152static int __devinit pci_init(void) 1195static int __devinit pci_init(void)
1153{ 1196{
1154 struct pci_dev *dev = NULL; 1197 struct pci_dev *dev = NULL;
@@ -1197,6 +1240,8 @@ EXPORT_SYMBOL(pci_release_regions);
1197EXPORT_SYMBOL(pci_request_regions); 1240EXPORT_SYMBOL(pci_request_regions);
1198EXPORT_SYMBOL(pci_release_region); 1241EXPORT_SYMBOL(pci_release_region);
1199EXPORT_SYMBOL(pci_request_region); 1242EXPORT_SYMBOL(pci_request_region);
1243EXPORT_SYMBOL(pci_release_selected_regions);
1244EXPORT_SYMBOL(pci_request_selected_regions);
1200EXPORT_SYMBOL(pci_set_master); 1245EXPORT_SYMBOL(pci_set_master);
1201EXPORT_SYMBOL(pci_set_mwi); 1246EXPORT_SYMBOL(pci_set_mwi);
1202EXPORT_SYMBOL(pci_clear_mwi); 1247EXPORT_SYMBOL(pci_clear_mwi);
@@ -1205,6 +1250,7 @@ EXPORT_SYMBOL(pci_set_dma_mask);
1205EXPORT_SYMBOL(pci_set_consistent_dma_mask); 1250EXPORT_SYMBOL(pci_set_consistent_dma_mask);
1206EXPORT_SYMBOL(pci_assign_resource); 1251EXPORT_SYMBOL(pci_assign_resource);
1207EXPORT_SYMBOL(pci_find_parent_resource); 1252EXPORT_SYMBOL(pci_find_parent_resource);
1253EXPORT_SYMBOL(pci_select_bars);
1208 1254
1209EXPORT_SYMBOL(pci_set_power_state); 1255EXPORT_SYMBOL(pci_set_power_state);
1210EXPORT_SYMBOL(pci_save_state); 1256EXPORT_SYMBOL(pci_save_state);