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