Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / x86 / cpu / coreboot / tables.c
index 92b75286b188f3e9f383582e05efb96cf578cc7c..a5d31d1deab2d5b6dd27584e5ffe1d6ce9981b87 100644 (file)
@@ -1,16 +1,14 @@
+// SPDX-License-Identifier: BSD-3-Clause
 /*
  * This file is part of the libpayload project.
  *
  * Copyright (C) 2008 Advanced Micro Devices, Inc.
  * Copyright (C) 2009 coresystems GmbH
- *
- * SPDX-License-Identifier:    BSD-3-Clause
  */
 
 #include <common.h>
-#include <asm/arch/ipchecksum.h>
+#include <net.h>
 #include <asm/arch/sysinfo.h>
-#include <asm/arch/tables.h>
 
 /*
  * This needs to be in the .data section so that it's copied over during
@@ -71,6 +69,17 @@ static void cb_parse_vbnv(unsigned char *ptr, struct sysinfo_t *info)
        info->vbnv_size = vbnv->vbnv_size;
 }
 
+static void cb_parse_cbmem_entry(unsigned char *ptr, struct sysinfo_t *info)
+{
+       struct cb_cbmem_entry *entry = (struct cb_cbmem_entry *)ptr;
+
+       if (entry->id != CBMEM_ID_SMBIOS)
+               return;
+
+       info->smbios_start = entry->address;
+       info->smbios_size = entry->entry_size;
+}
+
 static void cb_parse_gpios(unsigned char *ptr, struct sysinfo_t *info)
 {
        int i;
@@ -111,31 +120,26 @@ static void cb_parse_string(unsigned char *ptr, char **info)
        *info = (char *)((struct cb_string *)ptr)->string;
 }
 
+__weak void cb_parse_unhandled(u32 tag, unsigned char *ptr)
+{
+}
+
 static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
 {
+       unsigned char *ptr = addr;
        struct cb_header *header;
-       unsigned char *ptr = (unsigned char *)addr;
        int i;
 
-       for (i = 0; i < len; i += 16, ptr += 16) {
-               header = (struct cb_header *)ptr;
-               if (!strncmp((const char *)header->signature, "LBIO", 4))
-                       break;
-       }
-
-       /* We walked the entire space and didn't find anything. */
-       if (i >= len)
-               return -1;
-
+       header = (struct cb_header *)ptr;
        if (!header->table_bytes)
                return 0;
 
        /* Make sure the checksums match. */
-       if (ipchksum((u16 *) header, sizeof(*header)) != 0)
+       if (!ip_checksum_ok(header, sizeof(*header)))
                return -1;
 
-       if (ipchksum((u16 *) (ptr + sizeof(*header)),
-                    header->table_bytes) != header->table_checksum)
+       if (compute_ip_checksum(ptr + sizeof(*header), header->table_bytes) !=
+           header->table_checksum)
                return -1;
 
        /* Now, walk the tables. */
@@ -213,6 +217,12 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
                case CB_TAG_VBNV:
                        cb_parse_vbnv(ptr, info);
                        break;
+               case CB_TAG_CBMEM_ENTRY:
+                       cb_parse_cbmem_entry(ptr, info);
+                       break;
+               default:
+                       cb_parse_unhandled(rec->tag, ptr);
+                       break;
                }
 
                ptr += rec->size;
@@ -226,10 +236,13 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
 
 int get_coreboot_info(struct sysinfo_t *info)
 {
-       int ret = cb_parse_header((void *)0x00000000, 0x1000, info);
+       long addr;
+       int ret;
 
-       if (ret != 1)
-               ret = cb_parse_header((void *)0x000f0000, 0x1000, info);
+       addr = locate_coreboot_table();
+       if (addr < 0)
+               return addr;
+       ret = cb_parse_header((void *)addr, 0x1000, info);
 
-       return (ret == 1) ? 0 : -1;
+       return ret == 1 ? 0 : -ENOENT;
 }