blob: 404fbb68609d9fc2c55dbffe3de86fcdc1ff52f4 [file] [log] [blame]
Simon Glassd188b182014-11-12 22:42:11 -07001/*
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 Glass7430f102014-11-12 22:42:12 -070013#include <errno.h>
14#include <malloc.h>
Simon Glassd188b182014-11-12 22:42:11 -070015#include <pci.h>
16#include <asm/pci.h>
17
Bin Meng4722c032014-12-30 22:53:19 +080018DECLARE_GLOBAL_DATA_PTR;
19
Simon Glassd188b182014-11-12 22:42:11 -070020static struct pci_controller x86_hose;
21
Simon Glass7430f102014-11-12 22:42:12 -070022int 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 Glasse94ea6f2014-11-14 18:18:28 -070038__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 Glassd188b182014-11-12 22:42:11 -070048void pci_init_board(void)
49{
50 struct pci_controller *hose = &x86_hose;
51
Simon Glass7430f102014-11-12 22:42:12 -070052 /* Stop using the early hose */
53 gd->arch.hose = NULL;
54
Simon Glassd188b182014-11-12 22:42:11 -070055 board_pci_setup_hose(hose);
56 pci_setup_type1(hose);
57 pci_register_hose(hose);
58
Simon Glasse94ea6f2014-11-14 18:18:28 -070059 board_pci_pre_scan(hose);
Simon Glassd188b182014-11-12 22:42:11 -070060 hose->last_busno = pci_hose_scan(hose);
Simon Glasse94ea6f2014-11-14 18:18:28 -070061 board_pci_post_scan(hose);
Simon Glassd188b182014-11-12 22:42:11 -070062}
Simon Glass6fb3b722014-11-12 22:42:14 -070063
64static 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
72unsigned 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
81unsigned 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
90unsigned 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
99void 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
104void 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
109void pci_write_config32(pci_dev_t dev, unsigned where, unsigned value)
110{
111 pci_hose_write_config_dword(get_hose(), dev, where, value);
112}