lib/cbfs,device/pci_rom: Move cbfs_boot_map_optionrom and modernize

These methods are oprom specific. Move them out of CBFS. I also deleted
the tohex methods and replaced them with snprintf.

BUG=b:179699789
TEST=Boot guybrush and see oprom still loads

Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Change-Id: I03791f19c93fabfe62d9ecd4f9b4fad0e6a6146e
Reviewed-on: https://review.coreboot.org/c/coreboot/+/56393
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Raul E Rangel 2021-07-16 14:03:21 -06:00 committed by Felix Held
parent 21863e33c8
commit a736f48088
3 changed files with 19 additions and 46 deletions

View File

@ -6,6 +6,7 @@
#include <device/pci.h> #include <device/pci.h>
#include <device/pci_ids.h> #include <device/pci_ids.h>
#include <device/pci_ops.h> #include <device/pci_ops.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <cbfs.h> #include <cbfs.h>
#include <cbmem.h> #include <cbmem.h>
@ -15,6 +16,24 @@
void __weak map_oprom_vendev_rev(u32 *vendev, u8 *rev) { return; } void __weak map_oprom_vendev_rev(u32 *vendev, u8 *rev) { return; }
u32 __weak map_oprom_vendev(u32 vendev) { return vendev; } u32 __weak map_oprom_vendev(u32 vendev) { return vendev; }
static void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device)
{
char name[17] = "pciXXXX,XXXX.rom";
snprintf(name, sizeof(name), "pci%04hx,%04hx.rom", vendor, device);
return cbfs_map(name, NULL);
}
static void *cbfs_boot_map_optionrom_revision(uint16_t vendor, uint16_t device, uint8_t rev)
{
char name[20] = "pciXXXX,XXXX,XX.rom";
snprintf(name, sizeof(name), "pci%04hx,%04hx,%02hhx.rom", vendor, device, rev);
return cbfs_map(name, NULL);
}
struct rom_header *pci_rom_probe(const struct device *dev) struct rom_header *pci_rom_probe(const struct device *dev)
{ {
struct rom_header *rom_header = NULL; struct rom_header *rom_header = NULL;

View File

@ -160,12 +160,6 @@ int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type);
int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name, int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name,
const char *name, uint32_t *type); const char *name, uint32_t *type);
/* Return mapping of option ROM found in boot device. NULL on error. */
void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device);
/* Return mapping of option ROM with revision number. Returns NULL on error. */
void *cbfs_boot_map_optionrom_revision(uint16_t vendor, uint16_t device, uint8_t rev);
/********************************************************************************************** /**********************************************************************************************
* INTERNAL HELPERS FOR INLINES, DO NOT USE. * * INTERNAL HELPERS FOR INLINES, DO NOT USE. *
**********************************************************************************************/ **********************************************************************************************/

View File

@ -264,46 +264,6 @@ static size_t cbfs_load_and_decompress(const struct region_device *rdev, void *b
} }
} }
static inline int tohex4(unsigned int c)
{
return (c <= 9) ? (c + '0') : (c - 10 + 'a');
}
static void tohex8(unsigned int val, char *dest)
{
dest[0] = tohex4((val >> 4) & 0xf);
dest[1] = tohex4(val & 0xf);
}
static void tohex16(unsigned int val, char *dest)
{
dest[0] = tohex4(val >> 12);
dest[1] = tohex4((val >> 8) & 0xf);
dest[2] = tohex4((val >> 4) & 0xf);
dest[3] = tohex4(val & 0xf);
}
void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device)
{
char name[17] = "pciXXXX,XXXX.rom";
tohex16(vendor, name + 3);
tohex16(device, name + 8);
return cbfs_map(name, NULL);
}
void *cbfs_boot_map_optionrom_revision(uint16_t vendor, uint16_t device, uint8_t rev)
{
char name[20] = "pciXXXX,XXXX,XX.rom";
tohex16(vendor, name + 3);
tohex16(device, name + 8);
tohex8(rev, name + 13);
return cbfs_map(name, NULL);
}
void *_cbfs_alloc(const char *name, cbfs_allocator_t allocator, void *arg, void *_cbfs_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
size_t *size_out, bool force_ro, enum cbfs_type *type) size_t *size_out, bool force_ro, enum cbfs_type *type)
{ {