1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2019 Google LLC
8 #include <asm/cpu_common.h>
9 #include <asm/fast_spi.h>
13 * Returns bios_start and fills in size of the BIOS region.
15 static ulong
fast_spi_get_bios_region(struct fast_spi_regs
*regs
,
18 ulong bios_start
, bios_end
;
21 * BIOS_BFPREG provides info about BIOS-Flash Primary Region Base and
22 * Limit. Base and Limit fields are in units of 4K.
24 u32 val
= readl(®s
->bfp
);
26 bios_start
= (val
& SPIBAR_BFPREG_PRB_MASK
) << 12;
27 bios_end
= (((val
& SPIBAR_BFPREG_PRL_MASK
) >>
28 SPIBAR_BFPREG_PRL_SHIFT
) + 1) << 12;
29 *bios_size
= bios_end
- bios_start
;
34 int fast_spi_get_bios_mmap(pci_dev_t pdev
, ulong
*map_basep
, uint
*map_sizep
,
37 struct fast_spi_regs
*regs
;
38 ulong bar
, base
, mmio_base
;
40 /* Special case to find mapping without probing the device */
41 pci_x86_read_config(pdev
, PCI_BASE_ADDRESS_0
, &bar
, PCI_SIZE_32
);
42 mmio_base
= bar
& PCI_BASE_ADDRESS_MEM_MASK
;
43 regs
= (struct fast_spi_regs
*)mmio_base
;
44 base
= fast_spi_get_bios_region(regs
, map_sizep
);
45 *map_basep
= (u32
)-*map_sizep
- base
;
51 int fast_spi_early_init(pci_dev_t pdev
, ulong mmio_base
)
53 /* Program Temporary BAR for SPI */
54 pci_x86_write_config(pdev
, PCI_BASE_ADDRESS_0
,
55 mmio_base
| PCI_BASE_ADDRESS_SPACE_MEMORY
,
58 /* Enable Bus Master and MMIO Space */
59 pci_x86_clrset_config(pdev
, PCI_COMMAND
, 0, PCI_COMMAND_MASTER
|
60 PCI_COMMAND_MEMORY
, PCI_SIZE_8
);
63 * Disable the BIOS write protect so write commands are allowed.
64 * Enable Prefetching and caching.
66 pci_x86_clrset_config(pdev
, SPIBAR_BIOS_CONTROL
,
67 SPIBAR_BIOS_CONTROL_EISS
|
68 SPIBAR_BIOS_CONTROL_CACHE_DISABLE
,
69 SPIBAR_BIOS_CONTROL_WPD
|
70 SPIBAR_BIOS_CONTROL_PREFETCH_ENABLE
, PCI_SIZE_8
);