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 | |
Bin Meng | 9525645 | 2014-12-30 22:53:19 +0800 | [diff] [blame] | 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 20 | static struct pci_controller x86_hose; |
| 21 | |
Simon Glass | a54d981 | 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); |
Bin Meng | 9634dde | 2014-12-30 22:53:20 +0800 | [diff] [blame] | 32 | hose->last_busno = pci_hose_scan(hose); |
Bin Meng | f1b81fc | 2014-12-30 22:53:21 +0800 | [diff] [blame] | 33 | gd->hose = hose; |
Simon Glass | a54d981 | 2014-11-12 22:42:12 -0700 | [diff] [blame] | 34 | *hosep = hose; |
| 35 | |
| 36 | return 0; |
| 37 | } |
| 38 | |
Simon Glass | 75a042b | 2014-11-14 18:18:28 -0700 | [diff] [blame] | 39 | __weak int board_pci_pre_scan(struct pci_controller *hose) |
| 40 | { |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | __weak int board_pci_post_scan(struct pci_controller *hose) |
| 45 | { |
| 46 | return 0; |
| 47 | } |
| 48 | |
Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 49 | void pci_init_board(void) |
| 50 | { |
| 51 | struct pci_controller *hose = &x86_hose; |
| 52 | |
Simon Glass | a54d981 | 2014-11-12 22:42:12 -0700 | [diff] [blame] | 53 | /* Stop using the early hose */ |
Bin Meng | f1b81fc | 2014-12-30 22:53:21 +0800 | [diff] [blame] | 54 | gd->hose = NULL; |
Simon Glass | a54d981 | 2014-11-12 22:42:12 -0700 | [diff] [blame] | 55 | |
Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 56 | board_pci_setup_hose(hose); |
| 57 | pci_setup_type1(hose); |
| 58 | pci_register_hose(hose); |
| 59 | |
Simon Glass | 75a042b | 2014-11-14 18:18:28 -0700 | [diff] [blame] | 60 | board_pci_pre_scan(hose); |
Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 61 | hose->last_busno = pci_hose_scan(hose); |
Simon Glass | 75a042b | 2014-11-14 18:18:28 -0700 | [diff] [blame] | 62 | board_pci_post_scan(hose); |
Simon Glass | 7680550 | 2014-11-12 22:42:11 -0700 | [diff] [blame] | 63 | } |
Simon Glass | a205b1d | 2014-11-12 22:42:14 -0700 | [diff] [blame] | 64 | |
| 65 | static struct pci_controller *get_hose(void) |
| 66 | { |
Bin Meng | f1b81fc | 2014-12-30 22:53:21 +0800 | [diff] [blame] | 67 | if (gd->hose) |
| 68 | return gd->hose; |
Simon Glass | a205b1d | 2014-11-12 22:42:14 -0700 | [diff] [blame] | 69 | |
| 70 | return pci_bus_to_hose(0); |
| 71 | } |
| 72 | |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 73 | unsigned int x86_pci_read_config8(pci_dev_t dev, unsigned where) |
Simon Glass | a205b1d | 2014-11-12 22:42:14 -0700 | [diff] [blame] | 74 | { |
| 75 | uint8_t value; |
| 76 | |
| 77 | pci_hose_read_config_byte(get_hose(), dev, where, &value); |
| 78 | |
| 79 | return value; |
| 80 | } |
| 81 | |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 82 | unsigned int x86_pci_read_config16(pci_dev_t dev, unsigned where) |
Simon Glass | a205b1d | 2014-11-12 22:42:14 -0700 | [diff] [blame] | 83 | { |
| 84 | uint16_t value; |
| 85 | |
| 86 | pci_hose_read_config_word(get_hose(), dev, where, &value); |
| 87 | |
| 88 | return value; |
| 89 | } |
| 90 | |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 91 | unsigned int x86_pci_read_config32(pci_dev_t dev, unsigned where) |
Simon Glass | a205b1d | 2014-11-12 22:42:14 -0700 | [diff] [blame] | 92 | { |
| 93 | uint32_t value; |
| 94 | |
| 95 | pci_hose_read_config_dword(get_hose(), dev, where, &value); |
| 96 | |
| 97 | return value; |
| 98 | } |
| 99 | |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 100 | void x86_pci_write_config8(pci_dev_t dev, unsigned where, unsigned value) |
Simon Glass | a205b1d | 2014-11-12 22:42:14 -0700 | [diff] [blame] | 101 | { |
| 102 | pci_hose_write_config_byte(get_hose(), dev, where, value); |
| 103 | } |
| 104 | |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 105 | void x86_pci_write_config16(pci_dev_t dev, unsigned where, unsigned value) |
Simon Glass | a205b1d | 2014-11-12 22:42:14 -0700 | [diff] [blame] | 106 | { |
| 107 | pci_hose_write_config_word(get_hose(), dev, where, value); |
| 108 | } |
| 109 | |
Simon Glass | 240d06d | 2015-03-05 12:25:15 -0700 | [diff] [blame] | 110 | void x86_pci_write_config32(pci_dev_t dev, unsigned where, unsigned value) |
Simon Glass | a205b1d | 2014-11-12 22:42:14 -0700 | [diff] [blame] | 111 | { |
| 112 | pci_hose_write_config_dword(get_hose(), dev, where, value); |
| 113 | } |