blob: ab1aaaa0599e0e195f910fd3c27e2fe3c28b9b6f [file] [log] [blame]
Simon Glass76805502014-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 Glassa54d9812014-11-12 22:42:12 -070013#include <errno.h>
14#include <malloc.h>
Simon Glass76805502014-11-12 22:42:11 -070015#include <pci.h>
16#include <asm/pci.h>
17
Bin Meng95256452014-12-30 22:53:19 +080018DECLARE_GLOBAL_DATA_PTR;
19
Simon Glass76805502014-11-12 22:42:11 -070020static struct pci_controller x86_hose;
21
Simon Glassa54d9812014-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);
Bin Meng9634dde2014-12-30 22:53:20 +080032 hose->last_busno = pci_hose_scan(hose);
Bin Mengf1b81fc2014-12-30 22:53:21 +080033 gd->hose = hose;
Simon Glassa54d9812014-11-12 22:42:12 -070034 *hosep = hose;
35
36 return 0;
37}
38
Simon Glass75a042b2014-11-14 18:18:28 -070039__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 Glass76805502014-11-12 22:42:11 -070049void pci_init_board(void)
50{
51 struct pci_controller *hose = &x86_hose;
52
Simon Glassa54d9812014-11-12 22:42:12 -070053 /* Stop using the early hose */
Bin Mengf1b81fc2014-12-30 22:53:21 +080054 gd->hose = NULL;
Simon Glassa54d9812014-11-12 22:42:12 -070055
Simon Glass76805502014-11-12 22:42:11 -070056 board_pci_setup_hose(hose);
57 pci_setup_type1(hose);
58 pci_register_hose(hose);
59
Simon Glass75a042b2014-11-14 18:18:28 -070060 board_pci_pre_scan(hose);
Simon Glass76805502014-11-12 22:42:11 -070061 hose->last_busno = pci_hose_scan(hose);
Simon Glass75a042b2014-11-14 18:18:28 -070062 board_pci_post_scan(hose);
Simon Glass76805502014-11-12 22:42:11 -070063}
Simon Glassa205b1d2014-11-12 22:42:14 -070064
65static struct pci_controller *get_hose(void)
66{
Bin Mengf1b81fc2014-12-30 22:53:21 +080067 if (gd->hose)
68 return gd->hose;
Simon Glassa205b1d2014-11-12 22:42:14 -070069
70 return pci_bus_to_hose(0);
71}
72
73unsigned 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
82unsigned 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
91unsigned 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
100void 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
105void 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
110void pci_write_config32(pci_dev_t dev, unsigned where, unsigned value)
111{
112 pci_hose_write_config_dword(get_hose(), dev, where, value);
113}