coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
lpc.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/pci.h>
5 #include <device/pci_def.h>
6 #include <arch/ioapic.h>
7 #include "lpc.h"
8 #include <device/pci_ops.h>
9 
10 void lpc_read_resources(struct device *dev)
11 {
12  struct resource *res;
13 
14  printk(BIOS_DEBUG, "SB800 - Lpc.c - %s - Start.\n", __func__);
15  /* Get the normal pci resources of this device */
16  pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */
17 
18  /* Add an extra subtractive resource for both memory and I/O. */
19  res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
20  res->base = 0;
21  res->size = 0x1000;
24 
25  res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
26  res->base = 0xff800000;
27  res->size = 0x00800000; /* 8 MB for flash */
30 
31  /* Add a memory resource for the SPI BAR. */
33 
34  res = new_resource(dev, 3);
35  res->base = IO_APIC_ADDR;
36  res->size = 0x00001000;
38 
39  compact_resources(dev);
40  printk(BIOS_DEBUG, "SB800 - Lpc.c - %s - End.\n", __func__);
41 }
42 
43 void lpc_set_resources(struct device *dev)
44 {
45  struct resource *res;
46 
47  printk(BIOS_DEBUG, "SB800 - Lpc.c - %s - Start.\n", __func__);
48 
49  /* Special case. SPI Base Address. The SpiRomEnable should STAY set. */
50  res = find_resource(dev, 2);
52 
54 
55  printk(BIOS_DEBUG, "SB800 - Lpc.c - %s - End.\n", __func__);
56 }
57 
58 /**
59  * @brief Enable resources for children devices
60  *
61  * @param dev the device whose children's resources are to be enabled
62  *
63  */
65 {
66  struct bus *link;
67  u32 reg, reg_x;
68  int var_num = 0;
69  u16 reg_var[3];
70 
71  printk(BIOS_DEBUG, "SB800 - Lpc.c - %s - Start.\n", __func__);
72  reg = pci_read_config32(dev, 0x44);
73  reg_x = pci_read_config32(dev, 0x48);
74 
75  for (link = dev->link_list; link; link = link->next) {
76  struct device *child;
77  for (child = link->children; child;
78  child = child->sibling) {
79  if (child->enabled
80  && (child->path.type == DEVICE_PATH_PNP)) {
81  struct resource *res;
82  for (res = child->resource_list; res; res = res->next) {
83  u32 base; /* don't need long long */
84  if (!(res->flags & IORESOURCE_IO))
85  continue;
86  base = res->base;
87 /*
88  printk(BIOS_DEBUG, "sb800 lpc decode:%s,
89  base=0x%08x, end=0x%08x\n",
90  dev_path(child), base,
91  resource_end(res));
92 */
93  switch (base) {
94  case 0x60: /* KB */
95  case 0x64: /* MS */
96  reg |= (1 << 29);
97  break;
98  case 0x3f8: /* COM1 */
99  reg |= (1 << 6);
100  break;
101  case 0x2f8: /* COM2 */
102  reg |= (1 << 7);
103  break;
104  case 0x378: /* Parallel 1 */
105  reg |= (1 << 0);
106  break;
107  case 0x3f0: /* FD0 */
108  reg |= (1 << 26);
109  break;
110  case 0x220: /* Audio 0 */
111  reg |= (1 << 8);
112  break;
113  case 0x300: /* Midi 0 */
114  reg |= (1 << 18);
115  break;
116  case 0x400:
117  reg_x |= (1 << 16);
118  break;
119  case 0x480:
120  reg_x |= (1 << 17);
121  break;
122  case 0x500:
123  reg_x |= (1 << 18);
124  break;
125  case 0x580:
126  reg_x |= (1 << 19);
127  break;
128  case 0x4700:
129  reg_x |= (1 << 22);
130  break;
131  case 0xfd60:
132  reg_x |= (1 << 23);
133  break;
134  default:
135  if (var_num >= 3)
136  continue; /* only 3 var ; compact them ? */
137  switch (var_num) {
138  case 0:
139  reg_x |= (1 << 2);
140  break;
141  case 1:
142  reg_x |= (1 << 24);
143  break;
144  case 2:
145  reg_x |= (1 << 25);
146  break;
147  }
148  reg_var[var_num++] =
149  base & 0xffff;
150  }
151  }
152  }
153  }
154  }
155  pci_write_config32(dev, 0x44, reg);
156  pci_write_config32(dev, 0x48, reg_x);
157  /* Set WideIO for as many IOs found (fall through is on purpose) */
158  switch (var_num) {
159  case 3:
160  pci_write_config16(dev, 0x90, reg_var[2]);
162  case 2:
163  pci_write_config16(dev, 0x66, reg_var[1]);
165  case 1:
166  //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata
167  break;
168  }
169  printk(BIOS_DEBUG, "SB800 - Lpc.c - %s - End.\n", __func__);
170 }
#define SPIROM_BASE_ADDRESS_REGISTER
Definition: hudson.h:75
#define SPI_BASE_ADDRESS
Definition: iomap.h:8
#define IO_APIC_ADDR
Definition: ioapic.h:6
#define printk(level,...)
Definition: stdlib.h:16
#define __fallthrough
Definition: compiler.h:39
void fixed_mem_resource(struct device *dev, unsigned long index, unsigned long basek, unsigned long sizek, unsigned long type)
Definition: device_util.c:825
struct resource * new_resource(struct device *dev, unsigned int index)
See if a resource structure already exists for a given index and if not allocate one.
Definition: device_util.c:346
void compact_resources(struct device *dev)
See if we have unused but allocated resource structures.
Definition: device_util.c:302
struct resource * find_resource(const struct device *dev, unsigned int index)
Return an existing resource structure for a given index.
Definition: device_util.c:394
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
@ DEVICE_PATH_PNP
Definition: path.h:10
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 IORESOURCE_MEM
Definition: resource.h:10
#define IORESOURCE_SUBTRACTIVE
Definition: resource.h:24
#define IORESOURCE_ASSIGNED
Definition: resource.h:34
#define IORESOURCE_IO
Definition: resource.h:9
#define IOINDEX_SUBTRACTIVE(IDX, LINK)
Definition: resource.h:57
#define IORESOURCE_FIXED
Definition: resource.h:36
#define SPI_ROM_ENABLE
Definition: lpc.h:18
uintptr_t base
Definition: uart.c:17
void lpc_enable_childrens_resources(struct device *dev)
Enable resources for children devices.
Definition: lpc.c:64
void lpc_set_resources(struct device *dev)
Definition: lpc.c:43
void lpc_read_resources(struct device *dev)
Definition: lpc.c:10
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
Definition: device.h:76
DEVTREE_CONST struct bus * next
Definition: device.h:80
DEVTREE_CONST struct device * children
Definition: device.h:79
DEVTREE_CONST struct device * dev
Definition: device.h:78
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 struct bus * link_list
Definition: device.h:139
DEVTREE_CONST struct resource * resource_list
Definition: device.h:134
unsigned int enabled
Definition: device.h:122
unsigned long flags
Definition: resource.h:49
resource_t base
Definition: resource.h:45
resource_t size
Definition: resource.h:46
DEVTREE_CONST struct resource * next
Definition: resource.h:48