coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
sata.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/mmio.h>
4 #include <device/pci_ops.h>
5 #include <console/console.h>
6 #include <device/device.h>
7 #include <device/pci.h>
8 #include <device/pci_ids.h>
9 
10 #include <soc/pci_devs.h>
11 #include <soc/ramstage.h>
12 #include <soc/sata.h>
13 
14 #include "chip.h"
15 
16 static void sata_init(struct device *dev)
17 {
18  u32 reg32;
19  u32 abar;
20 
21  printk(BIOS_DEBUG, "SATA: Initializing...\n");
22 
23  /* SATA configuration is handled by the FSP */
24 
25  /* Enable BARs */
29 
30  printk(BIOS_DEBUG, "SATA: Controller in AHCI mode.\n");
31 
32  /* Set the controller mode */
33  reg32 = pci_read_config32(dev, SATAGC);
34  reg32 &= ~SATAGC_AHCI;
35  pci_write_config32(dev, SATAGC, reg32);
36 
37  /* Initialize AHCI memory-mapped space */
39  printk(BIOS_DEBUG, "ABAR: %08X\n", abar);
40 
41  /* Enable AHCI Mode */
42  reg32 = read32((void *)(abar + 0x04));
43  reg32 |= (1 << 31);
44  write32((void *)(abar + 0x04), reg32);
45 }
46 
47 static void sata_enable(struct device *dev) { /* TODO */ }
48 
49 static struct device_operations sata_ops = {
51  .set_resources = pci_dev_set_resources,
52  .enable_resources = pci_dev_enable_resources,
53  .init = sata_init,
54  .enable = sata_enable,
55  .ops_pci = &soc_pci_ops,
56 };
57 
58 static const unsigned short pci_device_ids[] = {
61  0
62 };
63 
64 static const struct pci_driver soc_sata __pci_driver = {
65  .ops = &sata_ops,
66  .vendor = PCI_VID_INTEL,
67  .devices = pci_device_ids,
68 };
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define printk(level,...)
Definition: stdlib.h:16
static __always_inline void pci_write_config32(const struct device *dev, u16 reg, u32 val)
Definition: pci_ops.h:76
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
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define PCI_COMMAND_IO
Definition: pci_def.h:11
#define PCI_COMMAND_MASTER
Definition: pci_def.h:13
#define PCI_COMMAND_MEMORY
Definition: pci_def.h:12
#define PCI_COMMAND
Definition: pci_def.h:10
#define PCI_BASE_ADDRESS_5
Definition: pci_def.h:68
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
void pci_dev_set_resources(struct device *dev)
Definition: pci_device.c:691
#define PCI_DID_INTEL_DNV_SATA_AHCI_1
Definition: pci_ids.h:2772
#define PCI_VID_INTEL
Definition: pci_ids.h:2157
#define PCI_DID_INTEL_DNV_SATA_AHCI_2
Definition: pci_ids.h:2773
struct pci_operations soc_pci_ops
Definition: chip.c:51
#define SATAGC
Definition: sata.h:11
#define SATAGC_AHCI
Definition: sata.h:12
static void sata_enable(struct device *dev)
Definition: sata.c:47
static const struct pci_driver soc_sata __pci_driver
Definition: sata.c:64
static void sata_init(struct device *dev)
Definition: sata.c:16
static struct device_operations sata_ops
Definition: sata.c:49
static const unsigned short pci_device_ids[]
Definition: sata.c:58
uint32_t u32
Definition: stdint.h:51
void(* read_resources)(struct device *dev)
Definition: device.h:39
Definition: device.h:107