Commit 238fe16c40f640e5b78828b21990a0565f408813

Authored by Bin Meng
Committed by Simon Glass
1 parent d8abb46b37

pci: Move pci_hose_phys_to_bus() to pci_common.c

pci_hose_phys_to_bus() is needed by several drivers. Move it to
pci_common.c to avoid a broken build when CONFIG_DM_PCI is on.

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Acked-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 66 additions and 70 deletions Side-by-side Diff

... ... @@ -186,72 +186,6 @@
186 186 return -1;
187 187 }
188 188  
189   -/*
190   - *
191   - */
192   -
193   -int __pci_hose_phys_to_bus(struct pci_controller *hose,
194   - phys_addr_t phys_addr,
195   - unsigned long flags,
196   - unsigned long skip_mask,
197   - pci_addr_t *ba)
198   -{
199   - struct pci_region *res;
200   - pci_addr_t bus_addr;
201   - int i;
202   -
203   - for (i = 0; i < hose->region_count; i++) {
204   - res = &hose->regions[i];
205   -
206   - if (((res->flags ^ flags) & PCI_REGION_TYPE) != 0)
207   - continue;
208   -
209   - if (res->flags & skip_mask)
210   - continue;
211   -
212   - bus_addr = phys_addr - res->phys_start + res->bus_start;
213   -
214   - if (bus_addr >= res->bus_start &&
215   - bus_addr < res->bus_start + res->size) {
216   - *ba = bus_addr;
217   - return 0;
218   - }
219   - }
220   -
221   - return 1;
222   -}
223   -
224   -pci_addr_t pci_hose_phys_to_bus (struct pci_controller *hose,
225   - phys_addr_t phys_addr,
226   - unsigned long flags)
227   -{
228   - pci_addr_t bus_addr = 0;
229   - int ret;
230   -
231   - if (!hose) {
232   - puts("pci_hose_phys_to_bus: invalid hose\n");
233   - return bus_addr;
234   - }
235   -
236   - /*
237   - * if PCI_REGION_MEM is set we do a two pass search with preference
238   - * on matches that don't have PCI_REGION_SYS_MEMORY set
239   - */
240   - if ((flags & PCI_REGION_MEM) == PCI_REGION_MEM) {
241   - ret = __pci_hose_phys_to_bus(hose, phys_addr,
242   - flags, PCI_REGION_SYS_MEMORY, &bus_addr);
243   - if (!ret)
244   - return bus_addr;
245   - }
246   -
247   - ret = __pci_hose_phys_to_bus(hose, phys_addr, flags, 0, &bus_addr);
248   -
249   - if (ret)
250   - puts("pci_hose_phys_to_bus: invalid physical address\n");
251   -
252   - return bus_addr;
253   -}
254   -
255 189 int pci_hose_config_device(struct pci_controller *hose,
256 190 pci_dev_t dev,
257 191 unsigned long io,
drivers/pci/pci_common.c
... ... @@ -182,10 +182,10 @@
182 182 }
183 183  
184 184 int __pci_hose_bus_to_phys(struct pci_controller *hose,
185   - pci_addr_t bus_addr,
186   - unsigned long flags,
187   - unsigned long skip_mask,
188   - phys_addr_t *pa)
  185 + pci_addr_t bus_addr,
  186 + unsigned long flags,
  187 + unsigned long skip_mask,
  188 + phys_addr_t *pa)
189 189 {
190 190 struct pci_region *res;
191 191 int i;
... ... @@ -238,6 +238,68 @@
238 238 puts("pci_hose_bus_to_phys: invalid physical address\n");
239 239  
240 240 return phys_addr;
  241 +}
  242 +
  243 +int __pci_hose_phys_to_bus(struct pci_controller *hose,
  244 + phys_addr_t phys_addr,
  245 + unsigned long flags,
  246 + unsigned long skip_mask,
  247 + pci_addr_t *ba)
  248 +{
  249 + struct pci_region *res;
  250 + pci_addr_t bus_addr;
  251 + int i;
  252 +
  253 + for (i = 0; i < hose->region_count; i++) {
  254 + res = &hose->regions[i];
  255 +
  256 + if (((res->flags ^ flags) & PCI_REGION_TYPE) != 0)
  257 + continue;
  258 +
  259 + if (res->flags & skip_mask)
  260 + continue;
  261 +
  262 + bus_addr = phys_addr - res->phys_start + res->bus_start;
  263 +
  264 + if (bus_addr >= res->bus_start &&
  265 + bus_addr < res->bus_start + res->size) {
  266 + *ba = bus_addr;
  267 + return 0;
  268 + }
  269 + }
  270 +
  271 + return 1;
  272 +}
  273 +
  274 +pci_addr_t pci_hose_phys_to_bus(struct pci_controller *hose,
  275 + phys_addr_t phys_addr,
  276 + unsigned long flags)
  277 +{
  278 + pci_addr_t bus_addr = 0;
  279 + int ret;
  280 +
  281 + if (!hose) {
  282 + puts("pci_hose_phys_to_bus: invalid hose\n");
  283 + return bus_addr;
  284 + }
  285 +
  286 + /*
  287 + * if PCI_REGION_MEM is set we do a two pass search with preference
  288 + * on matches that don't have PCI_REGION_SYS_MEMORY set
  289 + */
  290 + if ((flags & PCI_REGION_MEM) == PCI_REGION_MEM) {
  291 + ret = __pci_hose_phys_to_bus(hose, phys_addr,
  292 + flags, PCI_REGION_SYS_MEMORY, &bus_addr);
  293 + if (!ret)
  294 + return bus_addr;
  295 + }
  296 +
  297 + ret = __pci_hose_phys_to_bus(hose, phys_addr, flags, 0, &bus_addr);
  298 +
  299 + if (ret)
  300 + puts("pci_hose_phys_to_bus: invalid physical address\n");
  301 +
  302 + return bus_addr;
241 303 }
242 304  
243 305 pci_dev_t pci_find_device(unsigned int vendor, unsigned int device, int index)