Werner Zeh | 42b8835 | 2021-11-16 07:31:44 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Elyes Haouas | 8823ba1 | 2022-12-05 08:48:50 +0100 | [diff] [blame] | 3 | #include <device/mmio.h> |
Werner Zeh | 42b8835 | 2021-11-16 07:31:44 +0100 | [diff] [blame] | 4 | #include <device/pci.h> |
Werner Zeh | 42b8835 | 2021-11-16 07:31:44 +0100 | [diff] [blame] | 5 | #include <device/pci_ids.h> |
| 6 | #include <device/pci_ops.h> |
| 7 | #include <types.h> |
| 8 | |
| 9 | #include "nc_fpga.h" |
| 10 | |
| 11 | static DEVTREE_CONST uint32_t fpga_bar = CONFIG_EARLY_PCI_MMIO_BASE; |
| 12 | static bool nc_fpga_present = false; |
| 13 | |
| 14 | int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base) |
| 15 | { |
| 16 | pci_devfn_t pci_dev = PCI_DEV(bus, dev, 0); |
| 17 | uint32_t id = pci_s_read_config32(pci_dev, PCI_VENDOR_ID); |
| 18 | |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 19 | if (id != (0x4091 << 16 | PCI_VID_SIEMENS)) |
Werner Zeh | 42b8835 | 2021-11-16 07:31:44 +0100 | [diff] [blame] | 20 | return -1; |
| 21 | |
| 22 | /* Setup base address for BAR0. */ |
| 23 | pci_s_write_config32(pci_dev, PCI_BASE_ADDRESS_0, mmio_base); |
| 24 | /* Enable memory access for pci_dev. */ |
| 25 | u16 reg16 = pci_s_read_config16(pci_dev, PCI_COMMAND); |
| 26 | reg16 |= PCI_COMMAND_MEMORY; |
| 27 | pci_s_write_config16(pci_dev, PCI_COMMAND, reg16); |
| 28 | nc_fpga_present = true; |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | void nc_fpga_remap(uint32_t new_mmio) |
| 34 | { |
| 35 | #if ENV_RAMSTAGE |
| 36 | fpga_bar = new_mmio; |
| 37 | #endif |
| 38 | } |
| 39 | |
| 40 | void nc_fpga_post(uint8_t value) |
| 41 | { |
Angel Pons | ccf8134 | 2022-08-15 14:26:36 +0200 | [diff] [blame] | 42 | /* The function pci_early_device_probe is called in bootblock and romstage. Make sure |
Werner Zeh | 42b8835 | 2021-11-16 07:31:44 +0100 | [diff] [blame] | 43 | that in these stages the initialization code was successful before the POST code |
| 44 | value is written to the register. */ |
Arthur Heymans | a2bc254 | 2021-05-29 08:10:49 +0200 | [diff] [blame^] | 45 | if ((ENV_BOOTBLOCK || ENV_SEPARATE_ROMSTAGE) && nc_fpga_present == false) |
Werner Zeh | 42b8835 | 2021-11-16 07:31:44 +0100 | [diff] [blame] | 46 | return; |
Elyes Haouas | 0a7a269 | 2022-12-08 08:45:29 +0100 | [diff] [blame] | 47 | write32p(fpga_bar + NC_FPGA_POST_OFFSET, value); |
Werner Zeh | 42b8835 | 2021-11-16 07:31:44 +0100 | [diff] [blame] | 48 | } |