Alexandru Gagniuc | c364019 | 2015-12-15 16:06:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2015-2016 Intel Corp. |
| 5 | * (Written by Alexandru Gagniuc <alexandrux.gagniuc@intel.com> for Intel Corp.) |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 18 | #include <arch/acpi.h> |
| 19 | #include <arch/acpigen.h> |
Alexandru Gagniuc | c364019 | 2015-12-15 16:06:15 -0800 | [diff] [blame] | 20 | #include <console/console.h> |
| 21 | #include <fsp/util.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <soc/pci_ids.h> |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 26 | #include <soc/intel/common/opregion.h> |
Alexandru Gagniuc | c364019 | 2015-12-15 16:06:15 -0800 | [diff] [blame] | 27 | |
| 28 | static uintptr_t framebuffer_bar = (uintptr_t)NULL; |
| 29 | |
| 30 | void lb_framebuffer(struct lb_header *header) |
| 31 | { |
| 32 | enum cb_err ret; |
| 33 | struct lb_framebuffer *framebuffer; |
| 34 | |
| 35 | framebuffer = (void *)lb_new_record(header); |
| 36 | ret = fsp_fill_lb_framebuffer(framebuffer); |
| 37 | if (ret != CB_SUCCESS) { |
| 38 | printk(BIOS_ALERT, "FSP did not return a valid framebuffer\n"); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | if (!framebuffer_bar) { |
| 43 | printk(BIOS_ALERT, "Framebuffer BAR invalid (00:02.0 BAR2)\n"); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | /* Resource allocator can move the BAR around after FSP configures it */ |
| 48 | framebuffer->physical_address = framebuffer_bar; |
| 49 | printk(BIOS_DEBUG, "Graphics framebuffer located at 0x%llx\n", |
| 50 | framebuffer->physical_address); |
| 51 | } |
| 52 | |
| 53 | static void igd_set_resources(struct device *dev) |
| 54 | { |
| 55 | framebuffer_bar = find_resource(dev, PCI_BASE_ADDRESS_2)->base; |
| 56 | pci_dev_set_resources(dev); |
| 57 | } |
| 58 | |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 59 | static unsigned long igd_write_opregion(device_t dev, unsigned long current, |
| 60 | struct acpi_rsdp *rsdp) |
| 61 | { |
| 62 | igd_opregion_t *opregion; |
| 63 | uint16_t reg16; |
| 64 | |
| 65 | printk(BIOS_DEBUG, "ACPI: * IGD OpRegion\n"); |
| 66 | opregion = (igd_opregion_t *)current; |
| 67 | |
| 68 | if (!init_igd_opregion(opregion)) |
| 69 | return current; |
| 70 | |
| 71 | current += sizeof(igd_opregion_t); |
| 72 | |
| 73 | /* TODO Initialize Mailbox 3 */ |
| 74 | opregion->mailbox3.bclp = IGD_BACKLIGHT_BRIGHTNESS; |
| 75 | opregion->mailbox3.pfit = IGD_FIELD_VALID | IGD_PFIT_STRETCH; |
| 76 | opregion->mailbox3.pcft = 0; /* should be (IMON << 1) & 0x3e */ |
| 77 | opregion->mailbox3.cblv = IGD_FIELD_VALID | IGD_INITIAL_BRIGHTNESS; |
| 78 | opregion->mailbox3.bclm[0] = IGD_WORD_FIELD_VALID + 0x0000; |
| 79 | opregion->mailbox3.bclm[1] = IGD_WORD_FIELD_VALID + 0x0a19; |
| 80 | opregion->mailbox3.bclm[2] = IGD_WORD_FIELD_VALID + 0x1433; |
| 81 | opregion->mailbox3.bclm[3] = IGD_WORD_FIELD_VALID + 0x1e4c; |
| 82 | opregion->mailbox3.bclm[4] = IGD_WORD_FIELD_VALID + 0x2866; |
| 83 | opregion->mailbox3.bclm[5] = IGD_WORD_FIELD_VALID + 0x327f; |
| 84 | opregion->mailbox3.bclm[6] = IGD_WORD_FIELD_VALID + 0x3c99; |
| 85 | opregion->mailbox3.bclm[7] = IGD_WORD_FIELD_VALID + 0x46b2; |
| 86 | opregion->mailbox3.bclm[8] = IGD_WORD_FIELD_VALID + 0x50cc; |
| 87 | opregion->mailbox3.bclm[9] = IGD_WORD_FIELD_VALID + 0x5ae5; |
| 88 | opregion->mailbox3.bclm[10] = IGD_WORD_FIELD_VALID + 0x64ff; |
| 89 | |
| 90 | /* |
| 91 | * TODO This needs to happen in S3 resume, too. |
| 92 | * Maybe it should move to the finalize handler. |
| 93 | */ |
| 94 | |
| 95 | pci_write_config32(dev, ASLS, (uintptr_t)opregion); |
| 96 | reg16 = pci_read_config16(dev, SWSCI); |
| 97 | reg16 &= ~(1 << 0); |
| 98 | reg16 |= (1 << 15); |
| 99 | pci_write_config16(dev, SWSCI, reg16); |
| 100 | |
| 101 | return acpi_align_current(current); |
| 102 | } |
| 103 | |
Alexandru Gagniuc | c364019 | 2015-12-15 16:06:15 -0800 | [diff] [blame] | 104 | static const struct device_operations igd_ops = { |
| 105 | .read_resources = pci_dev_read_resources, |
| 106 | .set_resources = igd_set_resources, |
| 107 | .enable_resources = pci_dev_enable_resources, |
| 108 | .init = pci_dev_init, |
Andrey Petrov | 868679f | 2016-05-12 19:11:48 -0700 | [diff] [blame] | 109 | .write_acpi_tables = igd_write_opregion, |
Alexandru Gagniuc | c364019 | 2015-12-15 16:06:15 -0800 | [diff] [blame] | 110 | .enable = DEVICE_NOOP |
| 111 | }; |
| 112 | |
| 113 | static const struct pci_driver integrated_graphics_driver __pci_driver = { |
| 114 | .ops = &igd_ops, |
| 115 | .vendor = PCI_VENDOR_ID_INTEL, |
| 116 | .device = PCI_DEVICE_ID_APOLLOLAKE_IGD, |
| 117 | }; |