Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 The Chromium OS Authors. |
| 3 | * (C) Copyright 2008,2009 |
| 4 | * Graeme Russ, <graeme.russ@gmail.com> |
| 5 | * |
| 6 | * (C) Copyright 2002 |
| 7 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0+ |
| 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | a54d981 | 2014-11-12 22:42:12 -0700 | [diff] [blame] | 13 | #include <errno.h> |
| 14 | #include <malloc.h> |
Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 15 | #include <pci.h> |
| 16 | #include <asm/pci.h> |
| 17 | |
| 18 | static struct pci_controller x86_hose; |
| 19 | |
Simon Glass | a54d981 | 2014-11-12 22:42:12 -0700 | [diff] [blame] | 20 | int pci_early_init_hose(struct pci_controller **hosep) |
| 21 | { |
| 22 | struct pci_controller *hose; |
| 23 | |
| 24 | hose = calloc(1, sizeof(struct pci_controller)); |
| 25 | if (!hose) |
| 26 | return -ENOMEM; |
| 27 | |
| 28 | board_pci_setup_hose(hose); |
| 29 | pci_setup_type1(hose); |
| 30 | gd->arch.hose = hose; |
| 31 | *hosep = hose; |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |
Simon Glass | 75a042b | 2014-11-14 18:18:28 -0700 | [diff] [blame] | 36 | __weak int board_pci_pre_scan(struct pci_controller *hose) |
| 37 | { |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | __weak int board_pci_post_scan(struct pci_controller *hose) |
| 42 | { |
| 43 | return 0; |
| 44 | } |
| 45 | |
Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 46 | void pci_init_board(void) |
| 47 | { |
| 48 | struct pci_controller *hose = &x86_hose; |
| 49 | |
Simon Glass | a54d981 | 2014-11-12 22:42:12 -0700 | [diff] [blame] | 50 | /* Stop using the early hose */ |
| 51 | gd->arch.hose = NULL; |
| 52 | |
Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 53 | board_pci_setup_hose(hose); |
| 54 | pci_setup_type1(hose); |
| 55 | pci_register_hose(hose); |
| 56 | |
Simon Glass | 75a042b | 2014-11-14 18:18:28 -0700 | [diff] [blame] | 57 | board_pci_pre_scan(hose); |
Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 58 | hose->last_busno = pci_hose_scan(hose); |
Simon Glass | 75a042b | 2014-11-14 18:18:28 -0700 | [diff] [blame] | 59 | board_pci_post_scan(hose); |
Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 60 | } |
Simon Glass | a205b1d | 2014-11-12 22:42:14 -0700 | [diff] [blame] | 61 | |
| 62 | static struct pci_controller *get_hose(void) |
| 63 | { |
| 64 | if (gd->arch.hose) |
| 65 | return gd->arch.hose; |
| 66 | |
| 67 | return pci_bus_to_hose(0); |
| 68 | } |
| 69 | |
| 70 | unsigned int pci_read_config8(pci_dev_t dev, unsigned where) |
| 71 | { |
| 72 | uint8_t value; |
| 73 | |
| 74 | pci_hose_read_config_byte(get_hose(), dev, where, &value); |
| 75 | |
| 76 | return value; |
| 77 | } |
| 78 | |
| 79 | unsigned int pci_read_config16(pci_dev_t dev, unsigned where) |
| 80 | { |
| 81 | uint16_t value; |
| 82 | |
| 83 | pci_hose_read_config_word(get_hose(), dev, where, &value); |
| 84 | |
| 85 | return value; |
| 86 | } |
| 87 | |
| 88 | unsigned int pci_read_config32(pci_dev_t dev, unsigned where) |
| 89 | { |
| 90 | uint32_t value; |
| 91 | |
| 92 | pci_hose_read_config_dword(get_hose(), dev, where, &value); |
| 93 | |
| 94 | return value; |
| 95 | } |
| 96 | |
| 97 | void pci_write_config8(pci_dev_t dev, unsigned where, unsigned value) |
| 98 | { |
| 99 | pci_hose_write_config_byte(get_hose(), dev, where, value); |
| 100 | } |
| 101 | |
| 102 | void pci_write_config16(pci_dev_t dev, unsigned where, unsigned value) |
| 103 | { |
| 104 | pci_hose_write_config_word(get_hose(), dev, where, value); |
| 105 | } |
| 106 | |
| 107 | void pci_write_config32(pci_dev_t dev, unsigned where, unsigned value) |
| 108 | { |
| 109 | pci_hose_write_config_dword(get_hose(), dev, where, value); |
| 110 | } |