Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Compatibility functions for pre-driver-model code |
| 4 | * |
| 5 | * Copyright (C) 2014 Google, Inc |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 6 | */ |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <errno.h> |
| 10 | #include <malloc.h> |
| 11 | #include <pci.h> |
| 12 | #include <dm/device-internal.h> |
| 13 | #include <dm/lists.h> |
Simon Glass | 2e4e443 | 2016-01-18 20:19:14 -0700 | [diff] [blame] | 14 | #include "pci_internal.h" |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 15 | |
| 16 | #define PCI_HOSE_OP(rw, name, size, type) \ |
| 17 | int pci_hose_##rw##_config_##name(struct pci_controller *hose, \ |
| 18 | pci_dev_t dev, \ |
| 19 | int offset, type value) \ |
| 20 | { \ |
| 21 | return pci_##rw##_config##size(dev, offset, value); \ |
| 22 | } |
| 23 | |
| 24 | PCI_HOSE_OP(read, byte, 8, u8 *) |
| 25 | PCI_HOSE_OP(read, word, 16, u16 *) |
| 26 | PCI_HOSE_OP(read, dword, 32, u32 *) |
| 27 | PCI_HOSE_OP(write, byte, 8, u8) |
| 28 | PCI_HOSE_OP(write, word, 16, u16) |
| 29 | PCI_HOSE_OP(write, dword, 32, u32) |
| 30 | |
| 31 | pci_dev_t pci_find_devices(struct pci_device_id *ids, int index) |
| 32 | { |
Simon Glass | c9118d4 | 2015-07-06 16:47:46 -0600 | [diff] [blame] | 33 | struct udevice *dev; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 34 | |
| 35 | if (pci_find_device_id(ids, index, &dev)) |
| 36 | return -1; |
Simon Glass | eaa1489 | 2015-11-29 13:17:47 -0700 | [diff] [blame] | 37 | return dm_pci_get_bdf(dev); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 38 | } |
Simon Glass | 2e4e443 | 2016-01-18 20:19:14 -0700 | [diff] [blame] | 39 | |
| 40 | struct pci_controller *pci_bus_to_hose(int busnum) |
| 41 | { |
| 42 | struct udevice *bus; |
| 43 | int ret; |
| 44 | |
| 45 | ret = pci_get_bus(busnum, &bus); |
| 46 | if (ret) { |
| 47 | debug("%s: Cannot get bus %d: ret=%d\n", __func__, busnum, ret); |
| 48 | return NULL; |
| 49 | } |
| 50 | |
Minghuan Lian | ddd6f95 | 2016-12-13 14:54:09 +0800 | [diff] [blame] | 51 | return dev_get_uclass_priv(pci_get_controller(bus)); |
Simon Glass | 2e4e443 | 2016-01-18 20:19:14 -0700 | [diff] [blame] | 52 | } |