coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
late.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <amdblocks/acpimmio.h>
4 #include <device/mmio.h>
5 #include <device/device.h>
6 #include <device/pci.h> /* device_operations */
7 #include <device/pci_ops.h>
8 #include <device/pci_ids.h>
9 #include <bootstate.h>
10 #include <arch/ioapic.h>
11 #include <device/smbus.h> /* smbus_bus_operations */
12 #include <pc80/mc146818rtc.h>
13 #include <pc80/i8254.h>
14 #include <pc80/i8259.h>
15 #include <console/console.h> /* printk */
16 #include <acpi/acpi.h>
17 #include <device/pci_ehci.h>
18 #include "lpc.h" /* lpc_read_resources */
19 #include "SBPLATFORM.h" /* Platform Specific Definitions */
20 #include "cfg.h" /* sb800 Cimx configuration */
21 #include "chip.h" /* struct southbridge_amd_cimx_sb800_config */
22 #include "sb_cimx.h" /* AMD CIMX wrapper entries */
23 #include "smbus.h"
24 #include "fan.h"
25 #include "pci_devs.h"
27 
28 static AMDSBCFG sb_late_cfg; //global, init in sb800_cimx_config
29 static AMDSBCFG *sb_config = &sb_late_cfg;
30 
31 /**
32  * @brief Entry point of Southbridge CIMx callout
33  *
34  * prototype UINT32 (*SBCIM_HOOK_ENTRY)(UINT32 Param1, UINT32 Param2, void* pConfig)
35  *
36  * @param[in] func Southbridge CIMx Function ID.
37  * @param[in] data Southbridge Input Data.
38  * @param[in] config Southbridge configuration structure pointer.
39  *
40  */
41 static u32 sb800_callout_entry(u32 func, u32 data, void *config)
42 {
43  u32 ret = 0;
44  printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__);
45  switch (func) {
46  case CB_SBGPP_RESET_ASSERT:
47  break;
48 
49  case CB_SBGPP_RESET_DEASSERT:
50  break;
51 
52  case IMC_FIRMWARE_FAIL:
53  break;
54 
55  default:
56  break;
57  }
58 
59  printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__);
60  return ret;
61 }
62 
63 #define HOST_CAP 0x00 /* host capabilities */
64 #define HOST_CTL 0x04 /* global host control */
65 #define HOST_IRQ_STAT 0x08 /* interrupt status */
66 #define HOST_PORTS_IMPL 0x0c /* bitmap of implemented ports */
67 
68 #define HOST_CTL_AHCI_EN (1 << 31) /* AHCI enabled */
69 static void ahci_raid_init(struct device *dev)
70 {
71  u8 irq = 0;
72  void *bar5;
73  u32 caps, ports, val;
74 
76  if (val == PCI_CLASS_STORAGE_SATA) {
77  printk(BIOS_DEBUG, "AHCI controller ");
78  } else if (val == PCI_CLASS_STORAGE_RAID) {
79  printk(BIOS_DEBUG, "RAID controller ");
80  } else {
81  printk(BIOS_WARNING, "device class:%x, neither in ahci or raid mode\n", val);
82  return;
83  }
84 
86  bar5 = (void *)(uintptr_t)pci_read_config32(dev, PCI_BASE_ADDRESS_5);
87  printk(BIOS_DEBUG, "IOMEM base: %p, IRQ: 0x%X\n", bar5, irq);
88 
89  caps = read32(bar5 + HOST_CAP);
90  caps = (caps & 0x1F) + 1;
91  ports= read32(bar5 + HOST_PORTS_IMPL);
92  printk(BIOS_DEBUG, "Number of Ports: 0x%x, Port implemented(bit map): 0x%x\n", caps, ports);
93 
94  /* make sure ahci is enabled */
95  val = read32(bar5 + HOST_CTL);
96  if (!(val & HOST_CTL_AHCI_EN)) {
98  }
99 
100  dev->command |= PCI_COMMAND_MASTER;
102  printk(BIOS_DEBUG, "AHCI/RAID controller initialized\n");
103 }
104 
105 static void lpc_init(struct device *dev)
106 {
107  printk(BIOS_DEBUG, "SB800 - Late.c - %s - Start.\n", __func__);
108 
110 
111  /* Initialize the real time clock.
112  * The 0 argument tells cmos_init not to
113  * update CMOS unless it is invalid.
114  * 1 tells cmos_init to always initialize the CMOS.
115  */
116  cmos_init(0);
117 
118  setup_i8259(); /* Initialize i8259 pic */
119  setup_i8254(); /* Initialize i8254 timers */
120 
121  printk(BIOS_DEBUG, "SB800 - Late.c - %s - End.\n", __func__);
122 }
123 
124 static const char *lpc_acpi_name(const struct device *dev)
125 {
126  if (dev->path.type != DEVICE_PATH_PCI)
127  return NULL;
128 
129  switch (dev->path.pci.devfn) {
130  /* DSDT: acpi/lpc.asl */
131  case LPC_DEVFN:
132  return "LIBR";
133  }
134 
135  return NULL;
136 }
137 
138 static struct device_operations lpc_ops = {
140  .set_resources = lpc_set_resources,
141  .enable_resources = pci_dev_enable_resources,
142 #if CONFIG(HAVE_ACPI_TABLES)
143  .write_acpi_tables = acpi_write_hpet,
144 #endif
145  .init = lpc_init,
146  .scan_bus = scan_static_bus,
147  .ops_pci = &pci_dev_ops_pci,
148  .acpi_name = lpc_acpi_name,
149 };
150 
151 static const struct pci_driver lpc_driver __pci_driver = {
152  .ops = &lpc_ops,
153  .vendor = PCI_VID_ATI,
154  .device = PCI_DID_ATI_SB800_LPC,
155 };
156 
157 static struct device_operations sata_ops = {
159  .set_resources = pci_dev_set_resources,
160  .enable_resources = pci_dev_enable_resources,
161  .init = ahci_raid_init,
162  .ops_pci = &pci_dev_ops_pci,
163 };
164 
165 static const struct pci_driver ahci_driver __pci_driver = {
166  .ops = &sata_ops,
167  .vendor = PCI_VID_ATI,
168  .device = PCI_DID_ATI_SB800_SATA_AHCI,
169 };
170 
171 static const struct pci_driver raid_driver __pci_driver = {
172  .ops = &sata_ops,
173  .vendor = PCI_VID_ATI,
174  .device = PCI_DID_ATI_SB800_SATA_RAID,
175 };
176 static const struct pci_driver raid5_driver __pci_driver = {
177  .ops = &sata_ops,
178  .vendor = PCI_VID_ATI,
180 };
181 
182 static struct device_operations usb_ops = {
184  .set_resources = pci_dev_set_resources,
185  .enable_resources = pci_dev_enable_resources,
186  .ops_pci = &pci_dev_ops_pci,
187 };
188 
189 /*
190  * The pci id of USB ctrl 0 and 1 are the same.
191  */
192 static const struct pci_driver usb_ohci123_driver __pci_driver = {
193  .ops = &usb_ops,
194  .vendor = PCI_VID_ATI,
195  .device = PCI_DID_ATI_SB800_USB_18_0, /* OHCI-USB1, OHCI-USB2, OHCI-USB3 */
196 };
197 
198 static const struct pci_driver usb_ehci123_driver __pci_driver = {
199  .ops = &usb_ops,
200  .vendor = PCI_VID_ATI,
201  .device = PCI_DID_ATI_SB800_USB_18_2, /* EHCI-USB1, EHCI-USB2, EHCI-USB3 */
202 };
203 
204 static const struct pci_driver usb_ohci4_driver __pci_driver = {
205  .ops = &usb_ops,
206  .vendor = PCI_VID_ATI,
207  .device = PCI_DID_ATI_SB800_USB_20_5, /* OHCI-USB4 */
208 };
209 
210 static struct device_operations azalia_ops = {
212  .set_resources = pci_dev_set_resources,
213  .enable_resources = pci_dev_enable_resources,
214  .ops_pci = &pci_dev_ops_pci,
215 };
216 
217 static const struct pci_driver azalia_driver __pci_driver = {
218  .ops = &azalia_ops,
219  .vendor = PCI_VID_ATI,
220  .device = PCI_DID_ATI_SB800_HDA,
221 };
222 
223 static struct device_operations gec_ops = {
225  .set_resources = pci_dev_set_resources,
226  .enable_resources = pci_dev_enable_resources,
227  .ops_pci = &pci_dev_ops_pci,
228 };
229 
230 static const struct pci_driver gec_driver __pci_driver = {
231  .ops = &gec_ops,
232  .vendor = PCI_VID_ATI,
233  .device = PCI_DID_ATI_SB800_GEC,
234 };
235 
236 /**
237  * Fill build time defaults.
238  */
239 static void sb800_init(void *chip_info)
240 {
241  printk(BIOS_DEBUG, "SB800: %s\n", __func__);
242  sb_config->StdHeader.CALLBACK.CalloutPtr = sb800_callout_entry;
244 
245  /* Initially enable all GPP ports 0 to 3 */
246  abcfg_reg(0xc0, 0x01FF, 0x0F4);
247 }
248 
249 /**
250  * South Bridge CIMx ramstage entry point wrapper.
251  */
253 {
254  printk(BIOS_DEBUG, "SB800: %s\n", __func__);
255  sb_config->StdHeader.Func = SB_BEFORE_PCI_INIT;
256  AmdSbDispatcher(sb_config);
257 }
258 
260 {
261  printk(BIOS_DEBUG, "SB800: %s\n", __func__);
262  sb_config->StdHeader.Func = SB_AFTER_PCI_INIT;
263  AmdSbDispatcher(sb_config);
264 }
265 
267 {
268  printk(BIOS_DEBUG, "SB800: %s\n", __func__);
269  sb_config->StdHeader.Func = SB_MID_POST_INIT;
270  AmdSbDispatcher(sb_config);
271 }
272 
273 void sb_Late_Post(void)
274 {
275  printk(BIOS_DEBUG, "SB800: %s\n", __func__);
276  sb_config->StdHeader.Func = SB_LATE_POST_INIT;
277  AmdSbDispatcher(sb_config);
278 }
279 
281 {
282  printk(BIOS_DEBUG, "SB800: %s\n", __func__);
283  sb_config->StdHeader.Func = SB_BEFORE_PCI_RESTORE_INIT;
284  AmdSbDispatcher(sb_config);
285 }
286 
288 {
289  printk(BIOS_DEBUG, "SB800: %s\n", __func__);
290  sb_config->StdHeader.Func = SB_AFTER_PCI_RESTORE_INIT;
291  AmdSbDispatcher(sb_config);
292 }
293 
294 /*
295  * Update the PCI devices with a valid IRQ number
296  * that is set in the mainboard PCI_IRQ structures.
297  */
298 static void set_pci_irqs(void *unused)
299 {
300  /* Write PCI_INTR regs 0xC00/0xC01 */
302 
303  /* Write IRQs for all devicetree enabled devices */
305 }
306 
307 /*
308  * Hook this function into the PCI state machine
309  * on entry into BS_DEV_ENABLE.
310  */
312 
313 /**
314  * @brief SB Cimx entry point sbBeforePciInit wrapper
315  */
316 static void sb800_enable(struct device *dev)
317 {
318  struct southbridge_amd_cimx_sb800_config *sb_chip =
320 
321  switch (dev->path.pci.devfn) {
322  case PCI_DEVFN(0x11, 0): /* 0:11.0 SATA */
323  if (dev->enabled) {
324  sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_ENABLED;
325  if (sb_chip->boot_switch_sata_ide == 1)
326  sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 0; //0 -IDE as primary.
327  else if (sb_chip->boot_switch_sata_ide == 0)
328  sb_config->SATAMODE.SataMode.SataIdeCombMdPriSecOpt = 1; //1 -IDE as secondary.
329  } else {
330  sb_config->SATAMODE.SataMode.SataController = CIMX_OPTION_DISABLED;
331  }
332  break;
333 
334  case PCI_DEVFN(0x14, 0): /* 0:14:0 SMBUS */
335  /* Assign the ioapic ID the next available number after the processor core local APIC IDs */
336  setup_ioapic(VIO_APIC_VADDR, CONFIG_MAX_CPUS);
337  break;
338 
339  case PCI_DEVFN(0x14, 1): /* 0:14:1 IDE */
340  break;
341 
342  case PCI_DEVFN(0x14, 2): /* 0:14:2 HDA */
343  if (dev->enabled) {
344  if (sb_config->AzaliaController == AZALIA_DISABLE) {
345  sb_config->AzaliaController = AZALIA_AUTO;
346  }
347  } else {
348  sb_config->AzaliaController = AZALIA_DISABLE;
349  }
350  break;
351 
352  case PCI_DEVFN(0x14, 3): /* 0:14:3 LPC */
353  /* Initialize the fans */
354 #if CONFIG(SB800_IMC_FAN_CONTROL)
355  init_sb800_IMC_fans(dev);
356 #elif CONFIG(SB800_MANUAL_FAN_CONTROL)
358 #endif
359  break;
360 
361  case PCI_DEVFN(0x14, 4): /* 0:14:4 PCI */
362  /* PcibConfig [PM_Reg: EAh], PCIDisable [Bit0]
363  * 'PCIDisable' set to 0 to enable P2P bridge.
364  * 'PCIDisable' set to 1 to disable P2P bridge and enable PCI interface pins
365  * to function as GPIO {GPIO 35:0}.
366  */
367  if (!sb_chip->disconnect_pcib && dev->enabled)
368  pm_write8(0xea, pm_read8(0xea) & 0xfe);
369  else
370  pm_write8(0xea, (pm_read8(0xea) & 0xfe) | 1);
371  break;
372 
373  case PCI_DEVFN(0x14, 6): /* 0:14:6 GEC */
374  if (dev->enabled) {
375  sb_config->GecConfig = 0;
376  } else {
377  sb_config->GecConfig = 1;
378  }
379  break;
380 
381  case PCI_DEVFN(0x15, 0): /* 0:15:0 PCIe PortA */
382  {
383  struct device *device;
384  for (device = dev; device; device = device->sibling) {
385  if ((device->path.pci.devfn & ~3) != PCI_DEVFN(0x15,0)) break;
386  sb_config->PORTCONFIG[device->path.pci.devfn & 3].PortCfg.PortPresent = device->enabled;
387  }
388 
389  /*
390  * GPP_CFGMODE_X4000: PortA Lanes[3:0]
391  * GPP_CFGMODE_X2200: PortA Lanes[1:0], PortB Lanes[3:2]
392  * GPP_CFGMODE_X2110: PortA Lanes[1:0], PortB Lane2, PortC Lane3
393  * GPP_CFGMODE_X1111: PortA Lanes0, PortB Lane1, PortC Lane2, PortD Lane3
394  */
395  sb_config->GppLinkConfig = sb_chip->gpp_configuration;
396  }
397  break;
398 
399  case PCI_DEVFN(0x12, 0): /* 0:12:0 OHCI-USB1 */
400  sb_config->USBMODE.UsbMode.Ohci1 = dev->enabled;
401  break;
402  case PCI_DEVFN(0x12, 2): /* 0:12:2 EHCI-USB1 */
403  sb_config->USBMODE.UsbMode.Ehci1 = dev->enabled;
404  break;
405  case PCI_DEVFN(0x13, 0): /* 0:13:0 OHCI-USB2 */
406  sb_config->USBMODE.UsbMode.Ohci2 = dev->enabled;
407  break;
408  case PCI_DEVFN(0x13, 2): /* 0:13:2 EHCI-USB2 */
409  sb_config->USBMODE.UsbMode.Ehci2 = dev->enabled;
410  break;
411  case PCI_DEVFN(0x14, 5): /* 0:14:5 OHCI-USB4 */
412  sb_config->USBMODE.UsbMode.Ohci4 = dev->enabled;
413  break;
414  case PCI_DEVFN(0x16, 0): /* 0:16:0 OHCI-USB3 */
415  sb_config->USBMODE.UsbMode.Ohci3 = dev->enabled;
416  break;
417  case PCI_DEVFN(0x16, 2): /* 0:16:2 EHCI-USB3 */
418  sb_config->USBMODE.UsbMode.Ehci3 = dev->enabled;
419 
420  /* FIXME: Find better callsites for these.
421  * call the CIMX entry at the last sb800 device,
422  * so make sure the mainboard devicetree is complete
423  */
424  if (!acpi_is_wakeup_s3())
426  else
428  break;
429 
430  default:
431  break;
432  }
433 }
434 
436  CHIP_NAME("ATI SB800")
437  .init = sb800_init,
438  .enable_dev = sb800_enable,
439 };
unsigned long acpi_write_hpet(const struct device *device, unsigned long current, acpi_rsdp_t *rsdp)
Definition: acpi.c:1141
static uint8_t pm_read8(uint8_t reg)
Definition: acpimmio.h:166
static void pm_write8(uint8_t reg, uint8_t value)
Definition: acpimmio.h:181
#define AZALIA_AUTO
Detect Azalia controller automatically.
Definition: platform_cfg.h:121
#define AZALIA_DISABLE
Disable Azalia controller.
Definition: platform_cfg.h:122
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define VIO_APIC_VADDR
Definition: ioapic.h:7
void setup_ioapic(void *ioapic_base, u8 ioapic_id)
Definition: ioapic.c:160
@ BS_DEV_ENABLE
Definition: bootstate.h:82
@ BS_ON_ENTRY
Definition: bootstate.h:95
void sb800_cimx_config(AMDSBCFG *sb_config)
South Bridge CIMx configuration.
Definition: cfg.c:16
enum fch_io_device device
Definition: fch.c:74
#define printk(level,...)
Definition: stdlib.h:16
void init_sb800_IMC_fans(struct device *dev)
Definition: fan.c:44
void init_sb800_MANUAL_fans(struct device *dev)
Definition: fan.c:12
void setup_i8254(void)
Definition: i8254.c:10
void setup_i8259(void)
Definition: i8259.c:46
#define CHIP_NAME(X)
Definition: device.h:32
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
static __always_inline void pci_write_config8(const struct device *dev, u16 reg, u8 val)
Definition: pci_ops.h:64
static const char * lpc_acpi_name(const struct device *dev)
Definition: late.c:124
static void sb800_init(void *chip_info)
Fill build time defaults.
Definition: late.c:239
BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL)
void sb_After_Pci_Init(void)
Definition: late.c:259
static AMDSBCFG sb_late_cfg
Definition: late.c:28
void sb_Mid_Post_Init(void)
Definition: late.c:266
static AMDSBCFG * sb_config
Definition: late.c:29
static struct device_operations usb_ops
Definition: late.c:182
static u32 sb800_callout_entry(u32 func, u32 data, void *config)
Entry point of Southbridge CIMx callout.
Definition: late.c:41
#define HOST_CAP
Definition: late.c:63
#define HOST_PORTS_IMPL
Definition: late.c:66
static struct device_operations sata_ops
Definition: late.c:157
static struct device_operations lpc_ops
Definition: late.c:138
#define HOST_CTL_AHCI_EN
Definition: late.c:68
static void sb800_enable(struct device *dev)
SB Cimx entry point sbBeforePciInit wrapper.
Definition: late.c:316
static const struct pci_driver lpc_driver __pci_driver
Definition: late.c:151
struct chip_operations southbridge_amd_cimx_sb800_ops
Definition: late.c:435
#define HOST_CTL
Definition: late.c:64
static void lpc_init(struct device *dev)
Definition: late.c:105
void sb_Before_Pci_Init(void)
South Bridge CIMx ramstage entry point wrapper.
Definition: late.c:252
void sb_Before_Pci_Restore_Init(void)
Definition: late.c:280
void sb_After_Pci_Restore_Init(void)
Definition: late.c:287
static struct device_operations gec_ops
Definition: late.c:223
static void ahci_raid_init(struct device *dev)
Definition: late.c:69
static struct device_operations azalia_ops
Definition: late.c:210
void sb_Late_Post(void)
Definition: late.c:273
static void set_pci_irqs(void *unused)
Definition: late.c:298
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
Definition: loglevel.h:86
enum board_config config
Definition: memory.c:448
void cmos_check_update_date(void)
Definition: mc146818rtc.c:192
void cmos_init(bool invalid)
Definition: mc146818rtc.c:156
@ DEVICE_PATH_PCI
Definition: path.h:9
#define PCI_DEVFN(slot, func)
Definition: pci_def.h:548
#define PCI_CLASS_DEVICE
Definition: pci_def.h:43
#define PCI_INTERRUPT_LINE
Definition: pci_def.h:94
#define PCI_COMMAND_MASTER
Definition: pci_def.h:13
#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
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_ehci_read_resources
Definition: pci_ehci.h:22
#define PCI_DID_ATI_SB800_LPC
Definition: pci_ids.h:327
#define PCI_DID_ATI_SB800_HDA
Definition: pci_ids.h:333
#define PCI_DID_ATI_SB800_SATA_RAID
Definition: pci_ids.h:330
#define PCI_DID_ATI_SB800_USB_18_2
Definition: pci_ids.h:341
#define PCI_VID_ATI
Definition: pci_ids.h:204
#define PCI_DID_ATI_SB800_GEC
Definition: pci_ids.h:347
#define PCI_DID_ATI_SB800_USB_20_5
Definition: pci_ids.h:344
#define PCI_CLASS_STORAGE_RAID
Definition: pci_ids.h:21
#define PCI_DID_ATI_SB800_USB_18_0
Definition: pci_ids.h:340
#define PCI_CLASS_STORAGE_SATA
Definition: pci_ids.h:23
#define PCI_DID_ATI_SB800_SATA_AHCI
Definition: pci_ids.h:329
#define PCI_DID_ATI_SB800_SATA_RAID5
Definition: pci_ids.h:331
void scan_static_bus(struct device *bus)
Definition: root_device.c:89
#define LPC_DEVFN
Definition: pci_devs.h:123
void write_pci_cfg_irqs(void)
Definition: amd_pci_util.c:84
void write_pci_int_table(void)
Definition: amd_pci_util.c:41
static void lpc_read_resources(struct device *dev)
Definition: lpc.c:99
static void lpc_set_resources(struct device *dev)
Definition: lpc.c:131
#define NULL
Definition: stddef.h:19
uint32_t u32
Definition: stdint.h:51
unsigned long uintptr_t
Definition: stdint.h:21
uint8_t u8
Definition: stdint.h:45
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct pci_path pci
Definition: path.h:116
enum device_path_type type
Definition: path.h:114
Definition: device.h:107
DEVTREE_CONST struct device * sibling
Definition: device.h:111
struct device_path path
Definition: device.h:115
DEVTREE_CONST void * chip_info
Definition: device.h:164
unsigned int enabled
Definition: device.h:122
u8 command
Definition: device.h:130
unsigned int devfn
Definition: path.h:54
u8 val
Definition: sys.c:300