coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
lv2.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 /* Driver for BayHub Technology LV2 PCI to SD bridge */
4 
5 #include <console/console.h>
6 #include <device/device.h>
7 #include <device/path.h>
8 #include <device/pci.h>
9 #include <device/pciexp.h>
10 #include <device/pci_ops.h>
11 #include <device/pci_ids.h>
12 #include "chip.h"
13 #include "lv2.h"
14 
15 /*
16  * This chip has an errata where PCIe config space registers 0x234, 0x248, and
17  * 0x24C only support DWORD access, therefore reprogram these in the `finalize`
18  * callback.
19  */
20 static void lv2_enable_ltr(struct device *dev)
21 {
22  u16 max_snoop, max_nosnoop;
23  if (!pciexp_get_ltr_max_latencies(dev, &max_snoop, &max_nosnoop))
24  return;
25 
26  const unsigned int ltr_cap = pciexp_find_extended_cap(dev, PCIE_EXT_CAP_LTR_ID);
27  if (!ltr_cap)
28  return;
29 
30  pci_write_config32(dev, ltr_cap + PCI_LTR_MAX_SNOOP, (max_snoop << 16) | max_nosnoop);
31  printk(BIOS_INFO, "%s: Re-programmed LTR max latencies using chip-specific quirk\n",
32  dev_path(dev));
33 }
34 
35 static void lv2_enable(struct device *dev)
36 {
38  pci_dev_init(dev);
39 
40  if (!config || !config->enable_power_saving)
41  return;
42  /*
43  * This procedure for enabling power-saving mode is from the
44  * BayHub BIOS Implementation Guideline document.
45  */
60  printk(BIOS_INFO, "BayHub LV2: Power-saving enabled\n");
61 }
62 
63 static struct device_operations lv2_ops = {
65  .set_resources = pci_dev_set_resources,
66  .enable_resources = pci_dev_enable_resources,
67  .ops_pci = &pci_dev_ops_pci,
68  .enable = lv2_enable,
69  .final = lv2_enable_ltr,
70 };
71 
72 static const unsigned short pci_device_ids[] = {
74  0
75 };
76 
77 static const struct pci_driver bayhub_lv2 __pci_driver = {
78  .ops = &lv2_ops,
79  .vendor = PCI_VID_O2,
80  .devices = pci_device_ids,
81 };
82 
84  CHIP_NAME("BayHub Technology LV2 PCIe to SD bridge")
85 };
#define printk(level,...)
Definition: stdlib.h:16
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
#define CHIP_NAME(X)
Definition: device.h:32
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_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
static __always_inline void pci_update_config32(const struct device *dev, u16 reg, u32 mask, u32 or)
Definition: pci_ops.h:120
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
static void lv2_enable_ltr(struct device *dev)
Definition: lv2.c:20
static void lv2_enable(struct device *dev)
Definition: lv2.c:35
static const unsigned short pci_device_ids[]
Definition: lv2.c:72
static struct device_operations lv2_ops
Definition: lv2.c:63
static const struct pci_driver bayhub_lv2 __pci_driver
Definition: lv2.c:77
struct chip_operations drivers_generic_bayhub_lv2_ops
Definition: lv2.c:83
@ LV2_PROTECT
Definition: lv2.h:8
@ LV2_DRIVER_STRENGTH_MASK
Definition: lv2.h:32
@ LV2_RESET_DMA_DISABLE
Definition: lv2.h:34
@ LV2_PCR_HEX_300
Definition: lv2.h:27
@ LV2_DRIVER_STRENGTH
Definition: lv2.h:31
@ LV2_PCR_HEX_FC
Definition: lv2.h:13
@ LV2_L1_SUBSTATE_OPTIMISE
Definition: lv2.h:25
@ LV2_PCIE_PHY_P1_ENABLE
Definition: lv2.h:14
@ LV2_PCI_PM_L1_TIMER_MASK
Definition: lv2.h:21
@ LV2_PCR_HEX_E0
Definition: lv2.h:19
@ LV2_PCR_HEX_234
Definition: lv2.h:22
@ LV2_MAX_LATENCY_SETTING
Definition: lv2.h:23
@ LV2_RESET_DMA_DISABLE_MASK
Definition: lv2.h:35
@ LV2_PCR_HEX_3F4
Definition: lv2.h:24
@ LV2_PROTECT_OFF
Definition: lv2.h:11
@ LV2_ASPM_L1_TIMER
Definition: lv2.h:15
@ LV2_LTR_ENABLE
Definition: lv2.h:18
@ LV2_PCR_HEX_308
Definition: lv2.h:33
@ LV2_TUNING_WINDOW
Definition: lv2.h:28
@ LV2_PROTECT_LOCK_OFF
Definition: lv2.h:9
@ LV2_PCR_HEX_304
Definition: lv2.h:30
@ LV2_PROTECT_LOCK_ON
Definition: lv2.h:10
@ LV2_PCR_HEX_A8
Definition: lv2.h:17
@ LV2_TUNING_WINDOW_MASK
Definition: lv2.h:29
@ LV2_PROTECT_ON
Definition: lv2.h:12
@ LV2_PCI_PM_L1_TIMER
Definition: lv2.h:20
@ LV2_L1_SUBSTATE_OPTIMISE_MASK
Definition: lv2.h:26
@ LV2_ASPM_L1_TIMER_MASK
Definition: lv2.h:16
enum board_config config
Definition: memory.c:448
#define PCIE_EXT_CAP_LTR_ID
Definition: pci_def.h:465
#define PCI_LTR_MAX_SNOOP
Definition: pci_def.h:527
void pci_dev_init(struct device *dev)
Default handler: only runs the relevant PCI BIOS.
Definition: pci_device.c:873
void pci_dev_enable_resources(struct device *dev)
Definition: pci_device.c:721
void pci_dev_read_resources(struct device *dev)
Definition: pci_device.c:534
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_O2
Definition: pci_ids.h:1772
#define PCI_DID_O2_LV2
Definition: pci_ids.h:1778
unsigned int pciexp_find_extended_cap(const struct device *dev, unsigned int cap)
Definition: pciexp_device.c:39
bool pciexp_get_ltr_max_latencies(struct device *dev, u16 *max_snoop, u16 *max_nosnoop)
uint16_t u16
Definition: stdint.h:48
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107
DEVTREE_CONST void * chip_info
Definition: device.h:164