coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
pcie.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_def.h>
7 #include <device/pci_ops.h>
8 #include <device/pciexp.h>
9 #include <device/pci_ids.h>
11 #include "chip.h"
12 
13 static void pci_init(struct device *dev)
14 {
16 
17  printk(BIOS_DEBUG, "Initializing ICH10 PCIe root port.\n");
18 
19  /* Enable Bus Master */
21 
22  /* Set Cache Line Size to 0x10 */
23  // This has no effect but the OS might expect it
24  pci_write_config8(dev, 0x0c, 0x10);
25 
27 
28  /* Enable IO xAPIC on this PCIe port */
29  pci_or_config32(dev, 0xd8, 1 << 7);
30 
31  /* Enable Backbone Clock Gating */
32  pci_or_config32(dev, 0xe1, (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
33 
34  /* Set VC0 transaction class */
35  pci_update_config32(dev, 0x114, ~0x000000ff, 1);
36 
37  /* Mask completion timeouts */
38  pci_or_config32(dev, 0x148, 1 << 14);
39 
40  /* Lock R/WO Correctable Error Mask. */
41  pci_update_config32(dev, 0x154, ~0, 0);
42 
43  /* Clear errors in status registers */
44  pci_update_config16(dev, 0x06, ~0, 0);
45  pci_update_config16(dev, 0x1e, ~0, 0);
46 
47  /* Get configured ASPM state */
48  const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
49 
50  /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
51  if (apmc == PCIE_ASPM_BOTH)
52  pci_or_config32(dev, 0xe8, 1 << 1);
53 
54  /* Enable expresscard hotplug events. */
55  if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
56 
57  pci_or_config32(dev, 0xd8, 1 << 30);
58  pci_write_config16(dev, 0x42, 0x142);
59  }
60 }
61 
62 static void pch_pciexp_scan_bridge(struct device *dev)
63 {
65 
66  if (CONFIG(PCIEXP_HOTPLUG) && config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
68  } else {
69  /* Normal PCIe Scan */
70  pciexp_scan_bridge(dev);
71  }
72 }
73 
74 static struct device_operations device_ops = {
76  .set_resources = pci_dev_set_resources,
77  .enable_resources = pci_bus_enable_resources,
78  .init = pci_init,
79  .scan_bus = pch_pciexp_scan_bridge,
80  .ops_pci = &pci_dev_ops_pci,
81 };
82 
83 /* 82801lJx, ICH10 */
84 static const unsigned short pci_device_ids[] = {
85  0x3a40, /* Port 1 */
86  0x3a42, /* Port 2 */
87  0x3a44, /* Port 3 */
88  0x3a46, /* Port 4 */
89  0x3a48, /* Port 5 */
90  0x3a4a, /* Port 6 */
91 
92  0x3a70, /* Port 1 */
93  0x3a72, /* Port 2 */
94  0x3a74, /* Port 3 */
95  0x3a76, /* Port 4 */
96  0x3a78, /* Port 5 */
97  0x3a7a, /* Port 6 */
98  0
99 };
100 
101 static const struct pci_driver ich10_pcie __pci_driver = {
102  .ops = &device_ops,
103  .vendor = PCI_VID_INTEL,
104  .devices = pci_device_ids,
105 };
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
static __always_inline void pci_or_config32(const struct device *dev, u16 reg, u32 ormask)
Definition: pci_ops.h:191
static __always_inline void pci_and_config16(const struct device *dev, u16 reg, u16 andmask)
Definition: pci_ops.h:147
static __always_inline void pci_update_config32(const struct device *dev, u16 reg, u32 mask, u32 or)
Definition: pci_ops.h:120
static __always_inline void pci_or_config16(const struct device *dev, u16 reg, u16 ormask)
Definition: pci_ops.h:180
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
static __always_inline void pci_write_config16(const struct device *dev, u16 reg, u16 val)
Definition: pci_ops.h:70
static __always_inline void pci_update_config16(const struct device *dev, u16 reg, u16 mask, u16 or)
Definition: pci_ops.h:104
static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val)
Definition: pci_ops.h:64
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
enum board_config config
Definition: memory.c:448
#define PCI_BRIDGE_CTL_PARITY
Definition: pci_def.h:136
#define PCI_BRIDGE_CONTROL
Definition: pci_def.h:134
#define PCI_COMMAND_MASTER
Definition: pci_def.h:13
#define PCI_FUNC(devfn)
Definition: pci_def.h:550
#define PCI_COMMAND
Definition: pci_def.h:10
void pci_bus_enable_resources(struct device *dev)
Definition: pci_device.c:758
void pci_bus_read_resources(struct device *dev)
Definition: pci_device.c:540
struct pci_operations pci_dev_ops_pci
Default device operation for PCI devices.
Definition: pci_device.c:911
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
aspm_type
Definition: pciexp.h:5
@ PCIE_ASPM_BOTH
Definition: pciexp.h:9
void pciexp_hotplug_scan_bridge(struct device *dev)
void pciexp_scan_bridge(struct device *dev)
static struct device_operations device_ops
Definition: pcie.c:74
static void pci_init(struct device *dev)
Definition: pcie.c:13
static const unsigned short pci_device_ids[]
Definition: pcie.c:84
static void pch_pciexp_scan_bridge(struct device *dev)
Definition: pcie.c:62
static const struct pci_driver ich10_pcie __pci_driver
Definition: pcie.c:101
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct pci_path pci
Definition: path.h:116
Definition: device.h:107
struct device_path path
Definition: device.h:115
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned int devfn
Definition: path.h:54