Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * The sole purpose of this driver is to avoid BAR to be changed during |
| 5 | * resource allocation. Since configuration space is just 32 bytes it |
| 6 | * shouldn't cause any fragmentation. |
| 7 | */ |
| 8 | |
| 9 | #include <console/uart.h> |
| 10 | #include <device/device.h> |
| 11 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 12 | #include <device/pci_ops.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 13 | #include <device/pci_ids.h> |
| 14 | #include <soc/pci_devs.h> |
| 15 | #include <console/console.h> |
Julien Viard de Galbert | 546923f | 2018-03-05 11:10:16 +0100 | [diff] [blame] | 16 | #include <soc/uart.h> |
| 17 | #include <fsp/api.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 18 | |
| 19 | static void dnv_ns_uart_read_resources(struct device *dev) |
| 20 | { |
| 21 | /* read resources to be visible in the log*/ |
| 22 | pci_dev_read_resources(dev); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 23 | if (!CONFIG(LEGACY_UART_MODE)) |
Julien Viard de Galbert | 546923f | 2018-03-05 11:10:16 +0100 | [diff] [blame] | 24 | return; |
Angel Pons | c1bfbe0 | 2021-11-03 13:18:53 +0100 | [diff] [blame] | 25 | struct resource *res = probe_resource(dev, PCI_BASE_ADDRESS_0); |
Julien Viard de Galbert | 546923f | 2018-03-05 11:10:16 +0100 | [diff] [blame] | 26 | if (res == NULL) |
| 27 | return; |
| 28 | res->size = 0x8; |
| 29 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 30 | /* Do not configure membar */ |
Angel Pons | c1bfbe0 | 2021-11-03 13:18:53 +0100 | [diff] [blame] | 31 | res = probe_resource(dev, PCI_BASE_ADDRESS_1); |
Julien Viard de Galbert | 546923f | 2018-03-05 11:10:16 +0100 | [diff] [blame] | 32 | if (res != NULL) |
| 33 | res->flags = 0; |
| 34 | compact_resources(dev); |
| 35 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static struct device_operations uart_ops = { |
| 39 | .read_resources = dnv_ns_uart_read_resources, |
| 40 | .set_resources = pci_dev_set_resources, |
| 41 | .enable_resources = pci_dev_enable_resources, |
| 42 | .init = pci_dev_init, |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 43 | }; |
| 44 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 45 | static const struct pci_driver uart_driver __pci_driver = { |
| 46 | .ops = &uart_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 47 | .vendor = PCI_VID_INTEL, |
| 48 | .device = PCI_DID_INTEL_DNV_HSUART |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 49 | }; |
Julien Viard de Galbert | 546923f | 2018-03-05 11:10:16 +0100 | [diff] [blame] | 50 | |
| 51 | static void hide_hsuarts(void) |
| 52 | { |
| 53 | int i; |
| 54 | printk(BIOS_DEBUG, "HIDING HSUARTs.\n"); |
| 55 | /* There is a hardware requirement to hide functions starting from the |
| 56 | last one. */ |
| 57 | for (i = DENVERTON_UARTS_TO_INI - 1; i >= 0; i--) { |
| 58 | struct device *uart_dev; |
Kyösti Mälkki | 903b40a | 2019-07-03 07:25:59 +0300 | [diff] [blame] | 59 | uart_dev = pcidev_on_root(HSUART_DEV, i); |
Julien Viard de Galbert | 546923f | 2018-03-05 11:10:16 +0100 | [diff] [blame] | 60 | if (uart_dev == NULL) |
| 61 | continue; |
| 62 | pci_or_config32(uart_dev, PCI_FUNC_RDCFG_HIDE, 1); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | /* Hide HSUART PCI device very last when FSP no longer needs it */ |
| 67 | void platform_fsp_notify_status(enum fsp_notify_phase phase) |
| 68 | { |
| 69 | if (phase != END_OF_FIRMWARE) |
| 70 | return; |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 71 | if (CONFIG(LEGACY_UART_MODE)) |
Julien Viard de Galbert | 546923f | 2018-03-05 11:10:16 +0100 | [diff] [blame] | 72 | hide_hsuarts(); |
| 73 | } |