blob: 470bfb1a966d819e8946ea00223aacd272ead324 [file] [log] [blame]
Raul E Rangel3ba21802021-06-24 17:03:35 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <boot_device.h>
4#include <commonlib/helpers.h>
5#include <commonlib/region.h>
6#include <spi_flash.h>
7#include <string.h>
8#include <types.h>
9
10/* The ROM is memory mapped just below 4GiB. Form a pointer for the base. */
11#define rom_base ((void *)(uintptr_t)(0x100000000ULL - CONFIG_ROM_SIZE))
12
13static void *spi_dma_mmap(const struct region_device *rd, size_t offset, size_t size __unused)
14{
15 const struct mem_region_device *mdev;
16
17 mdev = container_of(rd, __typeof__(*mdev), rdev);
18
19 return &mdev->base[offset];
20}
21
22static int spi_dma_munmap(const struct region_device *rd __unused, void *mapping __unused)
23{
24 return 0;
25}
26
27static ssize_t spi_dma_readat_mmap(const struct region_device *rd, void *b, size_t offset,
28 size_t size)
29{
30 const struct mem_region_device *mdev;
31
32 mdev = container_of(rd, __typeof__(*mdev), rdev);
33
34 memcpy(b, &mdev->base[offset], size);
35
36 return size;
37}
38
39const struct region_device_ops spi_dma_rdev_ro_ops = {
40 .mmap = spi_dma_mmap,
41 .munmap = spi_dma_munmap,
42 .readat = spi_dma_readat_mmap,
43};
44
45static const struct mem_region_device boot_dev = {
46 .base = rom_base,
47 .rdev = REGION_DEV_INIT(&spi_dma_rdev_ro_ops, 0, CONFIG_ROM_SIZE),
48};
49
50const struct region_device *boot_device_ro(void)
51{
52 return &boot_dev.rdev;
53}
54
55uint32_t spi_flash_get_mmap_windows(struct flash_mmap_window *table)
56{
57 table->flash_base = 0;
58 table->host_base = (uint32_t)(uintptr_t)rom_base;
59 table->size = CONFIG_ROM_SIZE;
60
61 return 1;
62}