xref: /openbmc/u-boot/arch/x86/cpu/pci.c (revision 2f20aa82)
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>
13 #include <errno.h>
14 #include <malloc.h>
15 #include <pci.h>
16 #include <asm/pci.h>
17 
18 DECLARE_GLOBAL_DATA_PTR;
19 
20 static struct pci_controller x86_hose;
21 
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 	hose->last_busno = pci_hose_scan(hose);
33 	gd->hose = hose;
34 	*hosep = hose;
35 
36 	return 0;
37 }
38 
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 
49 void pci_init_board(void)
50 {
51 	struct pci_controller *hose = &x86_hose;
52 
53 	/* Stop using the early hose */
54 	gd->hose = NULL;
55 
56 	board_pci_setup_hose(hose);
57 	pci_setup_type1(hose);
58 	pci_register_hose(hose);
59 
60 	board_pci_pre_scan(hose);
61 	hose->last_busno = pci_hose_scan(hose);
62 	board_pci_post_scan(hose);
63 }
64 
65 static struct pci_controller *get_hose(void)
66 {
67 	if (gd->hose)
68 		return gd->hose;
69 
70 	return pci_bus_to_hose(0);
71 }
72 
73 unsigned int pci_read_config8(pci_dev_t dev, unsigned where)
74 {
75 	uint8_t value;
76 
77 	pci_hose_read_config_byte(get_hose(), dev, where, &value);
78 
79 	return value;
80 }
81 
82 unsigned int pci_read_config16(pci_dev_t dev, unsigned where)
83 {
84 	uint16_t value;
85 
86 	pci_hose_read_config_word(get_hose(), dev, where, &value);
87 
88 	return value;
89 }
90 
91 unsigned int pci_read_config32(pci_dev_t dev, unsigned where)
92 {
93 	uint32_t value;
94 
95 	pci_hose_read_config_dword(get_hose(), dev, where, &value);
96 
97 	return value;
98 }
99 
100 void pci_write_config8(pci_dev_t dev, unsigned where, unsigned value)
101 {
102 	pci_hose_write_config_byte(get_hose(), dev, where, value);
103 }
104 
105 void pci_write_config16(pci_dev_t dev, unsigned where, unsigned value)
106 {
107 	pci_hose_write_config_word(get_hose(), dev, where, value);
108 }
109 
110 void pci_write_config32(pci_dev_t dev, unsigned where, unsigned value)
111 {
112 	pci_hose_write_config_dword(get_hose(), dev, where, value);
113 }
114