coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
gma.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <arch/io.h>
4 #include <device/mmio.h>
5 #include <console/console.h>
6 #include <delay.h>
7 #include <device/device.h>
8 #include <device/pci.h>
9 #include <device/pci_ids.h>
10 #include <device/pci_ops.h>
11 #include <drivers/intel/gma/edid.h>
12 #include <drivers/intel/gma/i915.h>
15 #include <pc80/vga.h>
17 #include <types.h>
18 
19 #include "chip.h"
20 #include "ironlake.h"
21 
22 /* some vga option roms are used for several chipsets but they only have one
23  * PCI ID in their header. If we encounter such an option rom, we need to do
24  * the mapping ourselves
25  */
26 
28 {
29  u32 new_vendev = vendev;
30 
31  /* none currently. */
32 
33  return new_vendev;
34 }
35 
36 static struct resource *gtt_res = NULL;
37 
39 {
40  return read32(res2mmio(gtt_res, reg, 0));
41 }
42 
43 void gtt_write(u32 reg, u32 data)
44 {
45  write32(res2mmio(gtt_res, reg, 0), data);
46 }
47 
48 #define GTT_RETRY 1000
50 {
51  unsigned int try = GTT_RETRY;
52  u32 data;
53 
54  while (try--) {
55  data = gtt_read(reg);
56  if ((data & mask) == value)
57  return 1;
58  udelay(10);
59  }
60 
61  printk(BIOS_ERR, "GT init timeout\n");
62  return 0;
63 }
64 
65 static void gma_pm_init_post_vbios(struct device *dev)
66 {
67  struct northbridge_intel_ironlake_config *conf = dev->chip_info;
68  u32 reg32;
69 
70  printk(BIOS_DEBUG, "GT Power Management Init (post VBIOS)\n");
71 
72  /* Setup Digital Port Hotplug */
73  reg32 = gtt_read(0xc4030);
74  if (!reg32) {
75  reg32 = (conf->gpu_dp_b_hotplug & 0x7) << 2;
76  reg32 |= (conf->gpu_dp_c_hotplug & 0x7) << 10;
77  reg32 |= (conf->gpu_dp_d_hotplug & 0x7) << 18;
78  gtt_write(0xc4030, reg32);
79  }
80 
81  /* Setup Panel Power On Delays */
82  reg32 = gtt_read(0xc7208);
83  if (!reg32) {
84  reg32 = (conf->gpu_panel_port_select & 0x3) << 30;
85  reg32 |= (conf->gpu_panel_power_up_delay & 0x1fff) << 16;
86  reg32 |= (conf->gpu_panel_power_backlight_on_delay & 0x1fff);
87  gtt_write(0xc7208, reg32);
88  }
89 
90  /* Setup Panel Power Off Delays */
91  reg32 = gtt_read(0xc720c);
92  if (!reg32) {
93  reg32 = (conf->gpu_panel_power_down_delay & 0x1fff) << 16;
94  reg32 |= (conf->gpu_panel_power_backlight_off_delay & 0x1fff);
95  gtt_write(0xc720c, reg32);
96  }
97 
98  /* Setup Panel Power Cycle Delay */
99  if (conf->gpu_panel_power_cycle_delay) {
100  reg32 = gtt_read(0xc7210);
101  reg32 &= ~0xff;
102  reg32 |= conf->gpu_panel_power_cycle_delay & 0xff;
103  gtt_write(0xc7210, reg32);
104  }
105 
106  /* Enable Backlight if needed */
107  if (conf->gpu_cpu_backlight) {
108  gtt_write(0x48250, (1 << 31));
109  gtt_write(0x48254, conf->gpu_cpu_backlight);
110  }
111  if (conf->gpu_pch_backlight) {
112  gtt_write(0xc8250, (1 << 31));
113  gtt_write(0xc8254, conf->gpu_pch_backlight);
114  }
115 }
116 
117 /* Enable SCI to ACPI _GPE._L06 */
118 static void gma_enable_swsci(void)
119 {
120  u16 reg16;
121 
122  /* clear DMISCI status */
123  reg16 = inw(DEFAULT_PMBASE + TCO1_STS);
124  reg16 &= DMISCI_STS;
125  outw(DEFAULT_PMBASE + TCO1_STS, reg16);
126 
127  /* clear acpi tco status */
129 
130  /* enable acpi tco scis */
131  reg16 = inw(DEFAULT_PMBASE + GPE0_EN);
132  reg16 |= TCOSCI_EN;
133  outw(DEFAULT_PMBASE + GPE0_EN, reg16);
134 }
135 
136 static void gma_func0_init(struct device *dev)
137 {
139 
140  if (!CONFIG(NO_GFX_INIT))
142 
144  if (!gtt_res || !gtt_res->base)
145  return;
146 
147  if (!acpi_is_wakeup_s3() &&
148  CONFIG(MAINBOARD_USE_LIBGFXINIT)) {
149  struct northbridge_intel_ironlake_config *conf = dev->chip_info;
150  int lightup_ok;
151  printk(BIOS_SPEW, "Initializing VGA without OPROM.");
152 
153  gma_gfxinit(&lightup_ok);
154  /* Linux relies on VBT for panel info. */
155  generate_fake_intel_oprom(&conf->gfx, dev, "$VBT IRONLAKE-MOBILE");
156  } else {
157  /* PCI Init, will run VBIOS */
158  pci_dev_init(dev);
159  }
160 
161  /* Post VBIOS init */
163 
165 }
166 
167 static void gma_read_resources(struct device *dev)
168 {
170 
171  struct resource *res;
172 
173  /* Set the graphics memory to write combining. */
175  if (res == NULL) {
176  printk(BIOS_DEBUG, "gma: memory resource not found.\n");
177  return;
178  }
180  pci_write_config32(dev, PCI_BASE_ADDRESS_2, 0xd0000001);
182  res->base = (resource_t) 0xd0000000;
183  res->size = (resource_t) 0x10000000;
184 }
185 
186 static void gma_generate_ssdt(const struct device *device)
187 {
189 
191 }
192 
193 static struct device_operations gma_func0_ops = {
195  .set_resources = pci_dev_set_resources,
196  .enable_resources = pci_dev_enable_resources,
197  .acpi_fill_ssdt = gma_generate_ssdt,
198  .init = gma_func0_init,
199  .ops_pci = &pci_dev_ops_pci,
200 };
201 
202 static const unsigned short pci_device_ids[] = {
203  0x0046, 0x0102, 0x0106, 0x010a, 0x0112,
204  0x0116, 0x0122, 0x0126, 0x0156,
205  0x0166,
206  0
207 };
208 
209 static const struct pci_driver gma __pci_driver = {
210  .ops = &gma_func0_ops,
211  .vendor = PCI_VID_INTEL,
212  .devices = pci_device_ids,
213 };
#define GPE0_STS(x)
Definition: pm.h:81
#define GPE0_EN(x)
Definition: pm.h:99
#define TCOSCI_STS
Definition: pm.h:96
#define TCOSCI_EN
Definition: pm.h:109
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
pte_t value
Definition: mmu.c:91
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
#define DMISCI_STS
Definition: pm.h:59
#define printk(level,...)
Definition: stdlib.h:16
u16 inw(u16 port)
void outl(u32 val, u16 port)
void outw(u16 val, u16 port)
struct resource * probe_resource(const struct device *dev, unsigned int index)
See if a resource structure already exists for a given index.
Definition: device_util.c:323
void drivers_intel_gma_displays_ssdt_generate(const struct i915_gpu_controller_info *conf)
Definition: acpi.c:8
@ CONFIG
Definition: dsi_common.h:201
static struct tpm_chip chip
Definition: tis.c:17
void generate_fake_intel_oprom(const struct i915_gpu_controller_info *conf, struct device *dev, const char *idstr)
Definition: vbt.c:62
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_or_config16(const struct device *dev, u16 reg, u16 ormask)
Definition: pci_ops.h:180
#define DEFAULT_PMBASE
Definition: iomap.h:14
void gma_gfxinit(int *lightup_ok)
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define BIOS_SPEW
BIOS_SPEW - Excessively verbose output.
Definition: loglevel.h:142
u32 gtt_read(u32 reg)
Definition: gma.c:22
void gtt_write(u32 reg, u32 data)
Definition: gma.c:27
u32 map_oprom_vendev(u32 vendev)
Definition: gma.c:87
int gtt_poll(u32 reg, u32 mask, u32 value)
Definition: gma.c:154
static void gma_enable_swsci(void)
Definition: gma.c:118
static struct resource * gtt_res
Definition: gma.c:36
static void gma_func0_init(struct device *dev)
Definition: gma.c:136
static const struct pci_driver gma __pci_driver
Definition: gma.c:209
#define GTT_RETRY
Definition: gma.c:48
static const unsigned short pci_device_ids[]
Definition: gma.c:202
static void gma_pm_init_post_vbios(struct device *dev)
Definition: gma.c:65
static struct device_operations gma_func0_ops
Definition: gma.c:193
static void gma_read_resources(struct device *dev)
Definition: gma.c:167
static void gma_generate_ssdt(const struct device *device)
Definition: gma.c:186
enum cb_err intel_gma_init_igd_opregion(void)
Definition: opregion.c:310
#define PCI_COMMAND_MASTER
Definition: pci_def.h:13
#define PCI_BASE_ADDRESS_2
Definition: pci_def.h:65
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
#define PCI_COMMAND
Definition: pci_def.h:10
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_INTEL
Definition: pci_ids.h:2157
#define IORESOURCE_RESERVE
Definition: resource.h:30
#define IORESOURCE_ASSIGNED
Definition: resource.h:34
u64 resource_t
Definition: resource.h:43
static void * res2mmio(const struct resource *res, unsigned long offset, unsigned long mask)
Definition: resource.h:87
#define IORESOURCE_FIXED
Definition: resource.h:36
#define TCO1_STS
Definition: smbus.h:7
static const int mask[4]
Definition: gpio.c:308
#define NULL
Definition: stddef.h:19
uint32_t u32
Definition: stdint.h:51
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
struct i915_gpu_controller_info gfx
Definition: chip.h:36
enum northbridge_intel_ironlake_config::@325 gpu_panel_port_select
unsigned long flags
Definition: resource.h:49
resource_t base
Definition: resource.h:45
resource_t size
Definition: resource.h:46
void udelay(uint32_t us)
Definition: udelay.c:15