// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* * Copyright(c) 2015, 2016 Intel Corporation. */ #include <linux/delay.h> #include "hfi.h" #include "common.h" #include "eprom.h" /* * The EPROM is logically divided into three partitions: * partition 0: the first 128K, visible from PCI ROM BAR * partition 1: 4K config file (sector size) * partition 2: the rest */ #define P0_SIZE … #define P1_SIZE … #define P1_START … #define P2_START … /* controller page size, in bytes */ #define EP_PAGE_SIZE … #define EP_PAGE_MASK … #define EP_PAGE_DWORDS … /* controller commands */ #define CMD_SHIFT … #define CMD_NOP … #define CMD_READ_DATA(addr) … #define CMD_RELEASE_POWERDOWN_NOID … /* controller interface speeds */ #define EP_SPEED_FULL … /* * How long to wait for the EPROM to become available, in ms. * The spec 32 Mb EPROM takes around 40s to erase then write. * Double it for safety. */ #define EPROM_TIMEOUT … /* * Read a 256 byte (64 dword) EPROM page. * All callers have verified the offset is at a page boundary. */ static void read_page(struct hfi1_devdata *dd, u32 offset, u32 *result) { … } /* * Read length bytes starting at offset from the start of the EPROM. */ static int read_length(struct hfi1_devdata *dd, u32 start, u32 len, void *dest) { … } /* * Initialize the EPROM handler. */ int eprom_init(struct hfi1_devdata *dd) { … } /* magic character sequence that begins an image */ #define IMAGE_START_MAGIC … /* magic character sequence that might trail an image */ #define IMAGE_TRAIL_MAGIC … /* EPROM file types */ #define HFI1_EFT_PLATFORM_CONFIG … /* segment size - 128 KiB */ #define SEG_SIZE … struct hfi1_eprom_footer { … }; struct hfi1_eprom_table_entry { … }; /* * Calculate the max number of table entries that will fit within a directory * buffer of size 'dir_size'. */ #define MAX_TABLE_ENTRIES(dir_size) … #define DIRECTORY_SIZE(n) … #define MAGIC4(a, b, c, d) … #define FOOTER_MAGIC … #define FOOTER_VERSION … /* * Read all of partition 1. The actual file is at the front. Adjust * the returned size if a trailing image magic is found. */ static int read_partition_platform_config(struct hfi1_devdata *dd, void **data, u32 *size) { … } /* * The segment magic has been checked. There is a footer and table of * contents present. * * directory is a u32 aligned buffer of size EP_PAGE_SIZE. */ static int read_segment_platform_config(struct hfi1_devdata *dd, void *directory, void **data, u32 *size) { … } /* * Read the platform configuration file from the EPROM. * * On success, an allocated buffer containing the data and its size are * returned. It is up to the caller to free this buffer. * * Return value: * 0 - success * -ENXIO - no EPROM is available * -EBUSY - not able to acquire access to the EPROM * -ENOENT - no recognizable file written * -ENOMEM - buffer could not be allocated * -EINVAL - invalid EPROM contentents found */ int eprom_read_platform_config(struct hfi1_devdata *dd, void **data, u32 *size) { … }