Simon Glass | d188b18 | 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 | 7430f10 | 2014-11-12 22:42:12 -0700 | [diff] [blame] | 13 | #include <errno.h> |
| 14 | #include <malloc.h> |
Simon Glass | d188b18 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 15 | #include <pci.h> |
| 16 | #include <asm/pci.h> |
| 17 | |
Bin Meng | 4722c03 | 2014-12-30 22:53:19 +0800 | [diff] [blame^] | 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Simon Glass | d188b18 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 20 | static struct pci_controller x86_hose; |
| 21 | |
Simon Glass | 7430f10 | 2014-11-12 22:42:12 -0700 | [diff] [blame] | 22 | int pci_early_init_hose(struct pci_controller **hosep) |
| 23 | { |
| 24 | struct pci_controller *hose; |
| 25 | |
| 26 | hose = calloc(1, sizeof(struct pci_controller)); |
| 27 | if (!hose) |
| 28 | return -ENOMEM; |
| 29 | |
| 30 | board_pci_setup_hose(hose); |
| 31 | pci_setup_type1(hose); |
| 32 | gd->arch.hose = hose; |
| 33 | *hosep = hose; |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
Simon Glass | e94ea6f | 2014-11-14 18:18:28 -0700 | [diff] [blame] | 38 | __weak int board_pci_pre_scan(struct pci_controller *hose) |
| 39 | { |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | __weak int board_pci_post_scan(struct pci_controller *hose) |
| 44 | { |
| 45 | return 0; |
| 46 | } |
| 47 | |
Simon Glass | d188b18 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 48 | void pci_init_board(void) |
| 49 | { |
| 50 | struct pci_controller *hose = &x86_hose; |
| 51 | |
Simon Glass | 7430f10 | 2014-11-12 22:42:12 -0700 | [diff] [blame] | 52 | /* Stop using the early hose */ |
| 53 | gd->arch.hose = NULL; |
| 54 | |
Simon Glass | d188b18 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 55 | board_pci_setup_hose(hose); |
| 56 | pci_setup_type1(hose); |
| 57 | pci_register_hose(hose); |
| 58 | |
Simon Glass | e94ea6f | 2014-11-14 18:18:28 -0700 | [diff] [blame] | 59 | board_pci_pre_scan(hose); |
Simon Glass | d188b18 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 60 | hose->last_busno = pci_hose_scan(hose); |
Simon Glass | e94ea6f | 2014-11-14 18:18:28 -0700 | [diff] [blame] | 61 | board_pci_post_scan(hose); |
Simon Glass | d188b18 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 62 | } |
Simon Glass | 6fb3b72 | 2014-11-12 22:42:14 -0700 | [diff] [blame] | 63 | |
| 64 | static struct pci_controller *get_hose(void) |
| 65 | { |
| 66 | if (gd->arch.hose) |
| 67 | return gd->arch.hose; |
| 68 | |
| 69 | return pci_bus_to_hose(0); |
| 70 | } |
| 71 | |
| 72 | unsigned int pci_read_config8(pci_dev_t dev, unsigned where) |
| 73 | { |
| 74 | uint8_t value; |
| 75 | |
| 76 | pci_hose_read_config_byte(get_hose(), dev, where, &value); |
| 77 | |
| 78 | return value; |
| 79 | } |
| 80 | |
| 81 | unsigned int pci_read_config16(pci_dev_t dev, unsigned where) |
| 82 | { |
| 83 | uint16_t value; |
| 84 | |
| 85 | pci_hose_read_config_word(get_hose(), dev, where, &value); |
| 86 | |
| 87 | return value; |
| 88 | } |
| 89 | |
| 90 | unsigned int pci_read_config32(pci_dev_t dev, unsigned where) |
| 91 | { |
| 92 | uint32_t value; |
| 93 | |
| 94 | pci_hose_read_config_dword(get_hose(), dev, where, &value); |
| 95 | |
| 96 | return value; |
| 97 | } |
| 98 | |
| 99 | void pci_write_config8(pci_dev_t dev, unsigned where, unsigned value) |
| 100 | { |
| 101 | pci_hose_write_config_byte(get_hose(), dev, where, value); |
| 102 | } |
| 103 | |
| 104 | void pci_write_config16(pci_dev_t dev, unsigned where, unsigned value) |
| 105 | { |
| 106 | pci_hose_write_config_word(get_hose(), dev, where, value); |
| 107 | } |
| 108 | |
| 109 | void pci_write_config32(pci_dev_t dev, unsigned where, unsigned value) |
| 110 | { |
| 111 | pci_hose_write_config_dword(get_hose(), dev, where, value); |
| 112 | } |