Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2015 - 2017 Intel Corp. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * The sole purpose of this driver is to avoid BAR to be changed during |
| 19 | * resource allocation. Since configuration space is just 32 bytes it |
| 20 | * shouldn't cause any fragmentation. |
| 21 | */ |
| 22 | |
| 23 | #include <console/uart.h> |
| 24 | #include <device/device.h> |
| 25 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 26 | #include <device/pci_ops.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 27 | #include <device/pci_ids.h> |
| 28 | #include <soc/pci_devs.h> |
| 29 | #include <console/console.h> |
Julien Viard de Galbert | 546923f | 2018-03-05 11:10:16 +0100 | [diff] [blame] | 30 | #include <soc/uart.h> |
| 31 | #include <fsp/api.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 32 | |
| 33 | static void dnv_ns_uart_read_resources(struct device *dev) |
| 34 | { |
| 35 | /* read resources to be visible in the log*/ |
| 36 | pci_dev_read_resources(dev); |
Julien Viard de Galbert | 546923f | 2018-03-05 11:10:16 +0100 | [diff] [blame] | 37 | if (!IS_ENABLED(CONFIG_LEGACY_UART_MODE)) |
| 38 | return; |
| 39 | struct resource *res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 40 | if (res == NULL) |
| 41 | return; |
| 42 | res->size = 0x8; |
| 43 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 44 | /* Do not configure membar */ |
| 45 | res = find_resource(dev, PCI_BASE_ADDRESS_1); |
| 46 | if (res != NULL) |
| 47 | res->flags = 0; |
| 48 | compact_resources(dev); |
| 49 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static struct device_operations uart_ops = { |
| 53 | .read_resources = dnv_ns_uart_read_resources, |
| 54 | .set_resources = pci_dev_set_resources, |
| 55 | .enable_resources = pci_dev_enable_resources, |
| 56 | .init = pci_dev_init, |
| 57 | .enable = DEVICE_NOOP |
| 58 | }; |
| 59 | |
| 60 | static const unsigned short uart_ids[] = { |
| 61 | HSUART_DEVID, /* HSUART 0/1/2 */ |
| 62 | 0 |
| 63 | }; |
| 64 | |
| 65 | static const struct pci_driver uart_driver __pci_driver = { |
| 66 | .ops = &uart_ops, |
| 67 | .vendor = PCI_VENDOR_ID_INTEL, |
| 68 | .devices = uart_ids |
| 69 | }; |
Julien Viard de Galbert | 546923f | 2018-03-05 11:10:16 +0100 | [diff] [blame] | 70 | |
| 71 | static void hide_hsuarts(void) |
| 72 | { |
| 73 | int i; |
| 74 | printk(BIOS_DEBUG, "HIDING HSUARTs.\n"); |
| 75 | /* There is a hardware requirement to hide functions starting from the |
| 76 | last one. */ |
| 77 | for (i = DENVERTON_UARTS_TO_INI - 1; i >= 0; i--) { |
| 78 | struct device *uart_dev; |
| 79 | uart_dev = dev_find_slot(0, PCI_DEVFN(HSUART_DEV, i)); |
| 80 | if (uart_dev == NULL) |
| 81 | continue; |
| 82 | pci_or_config32(uart_dev, PCI_FUNC_RDCFG_HIDE, 1); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /* Hide HSUART PCI device very last when FSP no longer needs it */ |
| 87 | void platform_fsp_notify_status(enum fsp_notify_phase phase) |
| 88 | { |
| 89 | if (phase != END_OF_FIRMWARE) |
| 90 | return; |
| 91 | if (IS_ENABLED(CONFIG_LEGACY_UART_MODE)) |
| 92 | hide_hsuarts(); |
| 93 | } |