blob: e3993880dbef93b91bda50a2078e9f30369d7a60 [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
18static struct pci_controller x86_hose;
19
Simon Glassa54d9812014-11-12 22:42:12 -070020int pci_early_init_hose(struct pci_controller **hosep)
21{
22 struct pci_controller *hose;
23
24 hose = calloc(1, sizeof(struct pci_controller));
25 if (!hose)
26 return -ENOMEM;
27
28 board_pci_setup_hose(hose);
29 pci_setup_type1(hose);
30 gd->arch.hose = hose;
31 *hosep = hose;
32
33 return 0;
34}
35
Simon Glass76805502014-11-12 22:42:11 -070036void pci_init_board(void)
37{
38 struct pci_controller *hose = &x86_hose;
39
Simon Glassa54d9812014-11-12 22:42:12 -070040 /* Stop using the early hose */
41 gd->arch.hose = NULL;
42
Simon Glass76805502014-11-12 22:42:11 -070043 board_pci_setup_hose(hose);
44 pci_setup_type1(hose);
45 pci_register_hose(hose);
46
47 hose->last_busno = pci_hose_scan(hose);
48}
Simon Glassa205b1d2014-11-12 22:42:14 -070049
50static struct pci_controller *get_hose(void)
51{
52 if (gd->arch.hose)
53 return gd->arch.hose;
54
55 return pci_bus_to_hose(0);
56}
57
58unsigned int pci_read_config8(pci_dev_t dev, unsigned where)
59{
60 uint8_t value;
61
62 pci_hose_read_config_byte(get_hose(), dev, where, &value);
63
64 return value;
65}
66
67unsigned int pci_read_config16(pci_dev_t dev, unsigned where)
68{
69 uint16_t value;
70
71 pci_hose_read_config_word(get_hose(), dev, where, &value);
72
73 return value;
74}
75
76unsigned int pci_read_config32(pci_dev_t dev, unsigned where)
77{
78 uint32_t value;
79
80 pci_hose_read_config_dword(get_hose(), dev, where, &value);
81
82 return value;
83}
84
85void pci_write_config8(pci_dev_t dev, unsigned where, unsigned value)
86{
87 pci_hose_write_config_byte(get_hose(), dev, where, value);
88}
89
90void pci_write_config16(pci_dev_t dev, unsigned where, unsigned value)
91{
92 pci_hose_write_config_word(get_hose(), dev, where, value);
93}
94
95void pci_write_config32(pci_dev_t dev, unsigned where, unsigned value)
96{
97 pci_hose_write_config_dword(get_hose(), dev, where, value);
98}