73 changes: 73 additions & 0 deletions Documentation/mainboard/system76/lemp9.md
@@ -0,0 +1,73 @@
# System76 Lemur Pro (lemp9)

## Specs

- CPU
- Intel i7-10510U
- Intel i5-10210U
- EC
- ITE IT5570E running https://github.com/system76/ec
- Backlit Keyboard, with standard PS/2 keycodes and SCI hotkeys
- Battery
- Charger, using AC adapter or USB-C PD
- Suspend/resume
- Touchpad
- GPU
- Intel UHD Graphics 620
- GOP driver is recommended, VBT is provided
- eDP 14-inch 1920x1080 LCD
- HDMI video
- USB-C DisplayPort video
- Memory
- Channel 0: 8-GB on-board DDR4 Samsung K4AAG165WA-BCTD
- Channel 1: 8-GB/16-GB/32-GB DDR4 SO-DIMM
- Networking
- M.2 PCIe/CNVi WiFi/Bluetooth
- Sound
- Realtek ALC293D
- Internal speaker
- Internal microphone
- Combined headphone/microphone 3.5-mm jack
- HDMI audio
- USB-C DisplayPort audio
- Storage
- M.2 PCIe/SATA SSD-1
- M.2 PCIe/SATA SSD-2
- RTS5227S MicroSD card reader
- USB
- 1280x720 CCD camera
- USB 3.1 Gen 2 Type-C (left)
- USB 3.1 Gen 2 Type-A (left)
- USB 3.1 Gen 1 Type-A (right)

## Building coreboot

The following commands will build a working image:

```bash
make distclean
make defconfig KBUILD_DEFCONFIG=configs/config.system76_lemp9
make
```

## Flashing coreboot

```eval_rst
+---------------------+------------+
| Type | Value |
+=====================+============+
| Socketed flash | no |
+---------------------+------------+
| Vendor | GigaDevice |
+---------------------+------------+
| Model | GD25Q128C |
+---------------------+------------+
| Size | 16 MiB |
+---------------------+------------+
| Package | SOIC-8 |
+---------------------+------------+
| Internal flashing | yes |
+---------------------+------------+
| External flashing | yes |
+---------------------+------------+
```
114 changes: 114 additions & 0 deletions Documentation/superio/common/pnp.md
@@ -0,0 +1,114 @@
# PNP devices

Typical PNP devices are Super I/Os, LPC-connected TPMs and board
management controllers.

PNP devices are usually connected to the LPC or eSPI bus of a system
and shouldn't be confused with PCI(e) devices that use a completely
different plug and play mechanism. PNP originates in the ISA plug and
play specification. Since the original ISA bus is more or less extinct,
the auto-detection part of ISA PNP is mostly irrelevant nowadays. For
the register offsets for different functionality, appendix A of that
specification is still the main reference though.

## Configuration access and config mode

Super I/O chips connected via LPC to the southbridge usually have their
I/O-mapped configuration interface with a size of two bytes at the base
address 0x2e or 0x4e. Other PNP devices have their configuration
interface at other addresses.

The two byte registers allow access to an indirect 256 bytes big
register space that contains the configuration. By writing the index
to the lower byte (e.g. 0x2e), you can access the register contents at
that index by reading/writing the higher byte (e.g. 0x2f).

To prevent accidental changes of the Super I/O (SIO) configuration,
the SIOs need a configuration mode unlock sequence. After changing the
configuration, the configuration mode should be left again, by sending
the configuration mode lock sequence.

## Logical device numbers (LDN)

Each PNP device can contain multiple logical devices. The bytes from
0x00 to 0x2f in the indirect configuration register space are common
for all LDNs, but some SIO chips require a certain LDN to be selected
in order to write certain registers in there. An LDN gets selected by
writing the LDN number to the LDN select register 0x07. Registers 0x30
to 0xFF are specific to each LDN number.

coreboot encodes the physical LDN number in the lower byte of the LDN
number.

### Virtual logical device numbers

Register 0x30 is the LDN enable register and since it is an 8 bit
register, it can contain up to 8 enable bits for different parts of
the functionality of that logical device. To set a certain enable bit
in one physical LDN, the concept of virtual LDNs was introduced.
Virtual LDNs share the registers of their base LDN, but allow to
specify which part of a LDN should be enabled.

coreboot encodes the enable bit number and by that the virtual LDN
part in the lower 3 bits of the higher byte of the LDN number.

## I/O resources

Starting at register address 0x60, each LDN has 2 byte wide I/O base
address registers. The size of an I/O resource is always a power of
two.

### I/O resource masks

The I/O resource masks encode both the size and the maximum base
address of the corresponding IO resource. The number of zeros counted
from the least significant bit encode the resource size. If N is the
number of LSBs being zero, which can also be zero if the LSB is a one,
the resource has N address bits and a size of 2\*\*N bytes. The mask
address is also the highest possible address to map the I/O region.

A typical example for an I/O resource mask is 0x07f8 which is
0b0000011111111000 in binary notation. The three LSBs are zeros here,
so it's an eight byte I/O resource with three address offset bits
inside the resource. The highest base address it can be mapped to is
0x07f8, so the region will end at 0x07ff.

The Super I/O datasheets typically contain the information about the
I/O resource masks. On most Super I/O chips the mask can also be found
out by writing 0xffff to the corresponding I/O base address register
and reading back the value; since the lowest and highest bits are
hard-wired to zero according to the I/O resource size and maximal
possible I/O address, this gives the mask.

## IRQ resources

Each physical LDN has up to two configurable interrupt request
register pairs 0x70, 0x71 and 0x72, 0x73. Each pair can be configured
to use a certain IRQ number. Writing 1 to 15 into the first register
selects the IRQ number generated by the corresponding IRQ source and
enables IRQ generation; writing 0 to it disables the generation of
IRQs for the source. The second register selects the IRQ type (level
or edge) and IRQ level (high or low). For LPC SIOs the IRQ type is
hard-wired to edge.

On the LPC bus a shared SERIRQ line is used to signal IRQs to the
host; the IRQ number gets encoded by the number of LPC clock cycles
after the start frame before the device pulls the open drain
connection low.

SERIRQ can be used in two different modes: In the continuous SERIRQ
mode the host continuously sends IRQ frame starts and the devices
signal their IRQ request by pulling low the SERIRQ line at the right
time. In quiet SERIRQ mode the host doesn't send IRQ frame starts, so
the devices have to send both the IRQ frame start and the encoded IRQ
number. The quiet mode is often broken.

## DRQ resources

Each physical LDN has two legacy ISA-style DMA request channel
registers at 0x74 and 0x75. Those are only used for legacy devices
like parallel printer ports or floppy disk controllers.

Each device using LPC legacy DMA needs its own LDMA line to the host.
Some newer chipsets have dropped the LDMA line and with that the
legacy DMA capability on LPC.
1 change: 1 addition & 0 deletions Documentation/superio/index.md
Expand Up @@ -7,4 +7,5 @@ This section contains documentation about coreboot on specific SuperIOs.
- [NPCD378](nuvoton/npcd378.md)

## Common
- [PNP devices](common/pnp.md)
- [SSDT generator for generic SuperIOs](common/ssdt.md)
12 changes: 11 additions & 1 deletion MAINTAINERS
Expand Up @@ -163,6 +163,11 @@ M: Patrick Rudolph <siro@das-labor.org>
S: Maintained
F: src/mainboard/lenovo/

LENOVO G505S MAINBOARD
M: Mike Banon <mikebdp2@gmail.com>
S: Maintained
F: src/mainboard/lenovo/g505s/

APPLE MAINBOARDS
M: Evgeny Zinoviev <me@ch1p.io>
S: Maintained
Expand Down Expand Up @@ -282,6 +287,11 @@ M: Tristan Corrick <tristan@corrick.kiwi>
S: Maintained
F: src/mainboard/asrock/h81m-hds/

ASUS AM1I-A MAINBOARD
M: Mike Banon <mikebdp2@gmail.com>
S: Maintained
F: src/mainboard/asus/am1i-a/

ASUS MAXIMUS IV GENE-Z MAINBOARD
M: Tristan Corrick <tristan@corrick.kiwi>
S: Maintained
Expand Down Expand Up @@ -480,7 +490,7 @@ F: src/device/oprom/

CBFS
F: src/include/cbfs.h
F: src/include/cbfs_serialized.h
F: src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h
F: util/cbfstool/

CBMEM
Expand Down
8 changes: 4 additions & 4 deletions Makefile.inc
Expand Up @@ -94,7 +94,7 @@ subdirs-y += src/superio
subdirs-y += $(wildcard src/drivers/*) $(wildcard src/drivers/*/*)
subdirs-y += src/cpu src/vendorcode
subdirs-y += util/cbfstool util/sconfig util/nvramtool util/pgtblgen
subdirs-y += util/futility util/marvell util/bincfg
subdirs-y += util/futility util/marvell util/bincfg util/supermicro
subdirs-y += $(wildcard src/arch/*)
subdirs-y += src/mainboard/$(MAINBOARDDIR)
subdirs-y += src/security
Expand Down Expand Up @@ -394,12 +394,12 @@ COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
COREBOOT_EXPORTS += COREBOOT_EXTRA_VERSION
endif

CPPFLAGS_common := -Isrc -Isrc/include -Isrc/commonlib/include -I$(obj)
CPPFLAGS_common := -Isrc -Isrc/include -Isrc/commonlib/include -Isrc/commonlib/bsd/include -I$(obj)
VBOOT_SOURCE ?= 3rdparty/vboot
CPPFLAGS_common += -I$(VBOOT_SOURCE)/firmware/include
CPPFLAGS_common += -include $(src)/include/kconfig.h
CPPFLAGS_common += -include $(src)/include/rules.h
CPPFLAGS_common += -include $(src)/commonlib/include/commonlib/compiler.h
CPPFLAGS_common += -include $(src)/commonlib/bsd/include/commonlib/bsd/compiler.h
CPPFLAGS_common += -I3rdparty
CPPFLAGS_common += -D__BUILD_DIR__=\"$(obj)\"

Expand Down Expand Up @@ -641,7 +641,7 @@ install-git-commit-clangfmt:
include util/crossgcc/Makefile.inc

.PHONY: tools
tools: $(objutil)/kconfig/conf $(objutil)/kconfig/toada $(CBFSTOOL) $(objutil)/cbfstool/cbfs-compression-tool $(FMAPTOOL) $(RMODTOOL) $(IFWITOOL) $(objutil)/nvramtool/nvramtool $(objutil)/sconfig/sconfig $(IFDTOOL) $(CBOOTIMAGE) $(AMDFWTOOL) $(AMDCOMPRESS) $(FUTILITY) $(BINCFG) $(IFITTOOL)
tools: $(objutil)/kconfig/conf $(objutil)/kconfig/toada $(CBFSTOOL) $(objutil)/cbfstool/cbfs-compression-tool $(FMAPTOOL) $(RMODTOOL) $(IFWITOOL) $(objutil)/nvramtool/nvramtool $(objutil)/sconfig/sconfig $(IFDTOOL) $(CBOOTIMAGE) $(AMDFWTOOL) $(AMDCOMPRESS) $(FUTILITY) $(BINCFG) $(IFITTOOL) $(objutil)/supermicro/smcbiosinfo

###########################################################################
# Common recipes for all stages
Expand Down
3 changes: 3 additions & 0 deletions configs/config.asus_p2b_ramdebug
@@ -0,0 +1,3 @@
CONFIG_VENDOR_ASUS=y
CONFIG_BOARD_ASUS_P2B=y
CONFIG_DEBUG_RAM_SETUP=y
4 changes: 3 additions & 1 deletion configs/config.pcengines_apu1
@@ -1,4 +1,4 @@
CONFIG_LOCALVERSION="v4.11.0.2"
CONFIG_LOCALVERSION="v4.11.0.3"
CONFIG_VENDOR_PCENGINES=y
CONFIG_PAYLOAD_CONFIGFILE="$(top)/src/mainboard/$(MAINBOARDDIR)/seabios_config"
CONFIG_NO_GFX_INIT=y
Expand All @@ -16,3 +16,5 @@ CONFIG_PXE_ADD_SCRIPT=y
CONFIG_PXE_SCRIPT="payloads/external/iPXE/menu.ipxe"
CONFIG_MEMTEST_SECONDARY_PAYLOAD=y
CONFIG_SORTBOOTORDER_SECONDARY_PAYLOAD=y
CONFIG_SORTBOOTORDER_REVISION=y
CONFIG_SORTBOOTORDER_REVISION_ID="v4.6.17"
4 changes: 3 additions & 1 deletion configs/config.pcengines_apu2
@@ -1,4 +1,4 @@
CONFIG_LOCALVERSION="v4.11.0.2"
CONFIG_LOCALVERSION="v4.11.0.3"
CONFIG_VENDOR_PCENGINES=y
CONFIG_PAYLOAD_CONFIGFILE="$(top)/src/mainboard/$(MAINBOARDDIR)/seabios_config"
CONFIG_BOARD_PCENGINES_APU2=y
Expand All @@ -20,3 +20,5 @@ CONFIG_MEMTEST_SECONDARY_PAYLOAD=y
CONFIG_SORTBOOTORDER_SECONDARY_PAYLOAD=y
CONFIG_MEMTEST_REVISION=y
CONFIG_MEMTEST_REVISION_ID="0bd34c22604660e4283316331f3e7bf8a3863753"
CONFIG_SORTBOOTORDER_REVISION=y
CONFIG_SORTBOOTORDER_REVISION_ID="v4.6.17"
4 changes: 3 additions & 1 deletion configs/config.pcengines_apu3
@@ -1,4 +1,4 @@
CONFIG_LOCALVERSION="v4.11.0.2"
CONFIG_LOCALVERSION="v4.11.0.3"
CONFIG_VENDOR_PCENGINES=y
CONFIG_PAYLOAD_CONFIGFILE="$(top)/src/mainboard/$(MAINBOARDDIR)/seabios_config"
CONFIG_BOARD_PCENGINES_APU3=y
Expand All @@ -19,3 +19,5 @@ CONFIG_MEMTEST_SECONDARY_PAYLOAD=y
CONFIG_SORTBOOTORDER_SECONDARY_PAYLOAD=y
CONFIG_MEMTEST_REVISION=y
CONFIG_MEMTEST_REVISION_ID="0bd34c22604660e4283316331f3e7bf8a3863753"
CONFIG_SORTBOOTORDER_REVISION=y
CONFIG_SORTBOOTORDER_REVISION_ID="v4.6.17"
4 changes: 3 additions & 1 deletion configs/config.pcengines_apu4
@@ -1,4 +1,4 @@
CONFIG_LOCALVERSION="v4.11.0.2"
CONFIG_LOCALVERSION="v4.11.0.3"
CONFIG_VENDOR_PCENGINES=y
CONFIG_PAYLOAD_CONFIGFILE="$(top)/src/mainboard/$(MAINBOARDDIR)/seabios_config"
CONFIG_BOARD_PCENGINES_APU4=y
Expand All @@ -19,3 +19,5 @@ CONFIG_MEMTEST_SECONDARY_PAYLOAD=y
CONFIG_SORTBOOTORDER_SECONDARY_PAYLOAD=y
CONFIG_MEMTEST_REVISION=y
CONFIG_MEMTEST_REVISION_ID="0bd34c22604660e4283316331f3e7bf8a3863753"
CONFIG_SORTBOOTORDER_REVISION=y
CONFIG_SORTBOOTORDER_REVISION_ID="v4.6.17"
4 changes: 3 additions & 1 deletion configs/config.pcengines_apu5
@@ -1,4 +1,4 @@
CONFIG_LOCALVERSION="v4.11.0.2"
CONFIG_LOCALVERSION="v4.11.0.3"
CONFIG_VENDOR_PCENGINES=y
CONFIG_PAYLOAD_CONFIGFILE="$(top)/src/mainboard/$(MAINBOARDDIR)/seabios_config"
CONFIG_BOARD_PCENGINES_APU5=y
Expand All @@ -20,3 +20,5 @@ CONFIG_MEMTEST_SECONDARY_PAYLOAD=y
CONFIG_SORTBOOTORDER_SECONDARY_PAYLOAD=y
CONFIG_MEMTEST_REVISION=y
CONFIG_MEMTEST_REVISION_ID="0bd34c22604660e4283316331f3e7bf8a3863753"
CONFIG_SORTBOOTORDER_REVISION=y
CONFIG_SORTBOOTORDER_REVISION_ID="v4.6.17"
5 changes: 5 additions & 0 deletions configs/config.system76_lemp9
@@ -0,0 +1,5 @@
CONFIG_VENDOR_SYSTEM76=y
CONFIG_BOARD_SYSTEM76_LEMP9=y
CONFIG_PAYLOAD_TIANOCORE=y
CONFIG_RUN_FSP_GOP=y
CONFIG_SMMSTORE=y
@@ -1,2 +1,3 @@
CONFIG_VENDOR_UP=y
CONFIG_VBOOT=y
CONFIG_CONSOLE_SPI_FLASH=y
1 change: 0 additions & 1 deletion payloads/Kconfig
Expand Up @@ -139,7 +139,6 @@ config TINT_SECONDARY_PAYLOAD
tint can be loaded as a secondary payload under SeaBIOS, GRUB,
or any other payload that can load additional payloads.


config SORTBOOTORDER_SECONDARY_PAYLOAD
bool "Load sortbootorder as a secondary payload"
default n
Expand Down
9 changes: 7 additions & 2 deletions payloads/external/Makefile.inc
Expand Up @@ -271,8 +271,13 @@ payloads/external/Memtest86Plus/memtest86plus/memtest: $(DOTCONFIG)
# sortbootorder

payloads/external/sortbootorder/sortbootorder/sortbootorder.elf sortbootorder:
$(MAKE) -C payloads/external/sortbootorder \
TARGET_APU1=$(CONFIG_BOARD_PCENGINES_APU1)
$(MAKE) -C payloads/external/sortbootorder all \
TARGET_APU1=$(CONFIG_BOARD_PCENGINES_APU1) \
SORTBOOTORDER_REVISION=$(CONFIG_SORTBOOTORDER_REVISION) \
SORTBOOTORDER_REVISION_ID=$(CONFIG_SORTBOOTORDER_REVISION_ID) \
SORTBOOTORDER_MASTER=$(CONFIG_SORTBOOTORDER_MASTER) \
SORTBOOTORDER_STABLE=$(CONFIG_SORTBOOTORDER_STABLE) \


cbfs-files-$(CONFIG_SORTBOOTORDER_SECONDARY_PAYLOAD) += img/setup
img/setup-file := payloads/external/sortbootorder/sortbootorder/sortbootorder.elf
Expand Down
36 changes: 36 additions & 0 deletions payloads/external/sortbootorder/Kconfig.secondary
@@ -0,0 +1,36 @@
if SORTBOOTORDER_SECONDARY_PAYLOAD

choice
prompt "sortbootorder version"
default SORTBOOTORDER_STABLE

config SORTBOOTORDER_STABLE
bool "v4.6.17"
help
Stable sortbootorder version

config SORTBOOTORDER_MASTER
bool "master"
help
Newest sortbootorder version

config SORTBOOTORDER_REVISION
bool "git revision"
help
Select this option if you have a specific commit or branch
that you want to use as the revision from which to
build sortbootorder.

You will be able to specify the name of a branch or a commit id
later.

endchoice

config SORTBOOTORDER_REVISION_ID
string "Insert sortbootorder commit's SHA-1 or a branch name"
depends on SORTBOOTORDER_REVISION
default "origin/master"
help
The commit's SHA-1 or branch name of the revision to use.

endif
50 changes: 36 additions & 14 deletions payloads/external/sortbootorder/Makefile
@@ -1,7 +1,10 @@
version=4.6.16
branch_name=v$(version)
project_url=https://github.com/pcengines/sortbootorder/archive/$(branch_name).tar.gz
archive_name=$(branch_name).tar.gz
TAG-$(SORTBOOTORDER_MASTER)=origin/master
TAG-$(SORTBOOTORDER_STABLE)=v4.6.17
TAG-$(SORTBOOTORDER_REVISION)=$(SORTBOOTORDER_REVISION_ID)

project_git_repo=https://github.com/pcengines/sortbootorder.git
project_name=sortbootorder
project_dir=$(CURDIR)/sortbootorder

unexport KCONFIG_AUTOHEADER
unexport KCONFIG_AUTOCONFIG
Expand All @@ -10,22 +13,41 @@ unexport KCONFIG_SPLITCONFIG
unexport KCONFIG_TRISTATE
unexport KCONFIG_NEGATIVES

all: sortbootorder
all: build

$(project_dir):
echo " Cloning sortbootorder from Git"
git clone $(project_git_repo) $(project_dir)

sortbootorder: download
echo " MAKE sortbootorder "
$(MAKE) -C sortbootorder VERSION=$(branch_name) APU1=$(TARGET_APU1)
fetch: $(project_dir)
ifeq ($(TAG-y),)
echo "Error: The specified tag is invalid"
ifeq ($(SORTBOOTORDER_REVISION),y)
echo "Error: There is no revision specified for sortbootorder"
false
endif
false
endif
cd sortbootorder; git show $(TAG-y) >/dev/null 2>&1 ; \
if [ $$? -ne 0 ] || [ "$(TAG-y)" = "origin/master" ]; then \
echo " Fetching new commits from the sortbootorder repo"; \
git fetch; fi

download:
test -d sortbootorder || { wget $(project_url); \
tar -xvf $(archive_name); \
rm $(archive_name); \
mv sortbootorder-$(version) sortbootorder; }
checkout: fetch
echo " Checking out sortbootorder revision $(TAG-y)"
cd sortbootorder; git checkout master; git branch -D coreboot 2>/dev/null; git checkout -b coreboot $(TAG-y)

build: checkout
echo " MAKE sortbootorder"
$(MAKE) -C sortbootorder VERSION=$(TAG-y) APU1=$(TARGET_APU1)

clean:
test -d sortbootorder && $(MAKE) -C sortbootorder clean || exit 0

distclean:
rm -rf sortbootorder

.PHONY: download patch sortbootorder clean distclean
print-repo-info:
echo "$(project_git_repo) $(project_dir)"

.PHONY: checkout build clean distclean fetch sortbootorder print-repo-info
156 changes: 156 additions & 0 deletions payloads/libpayload/drivers/video/graphics.c
Expand Up @@ -243,6 +243,162 @@ int draw_box(const struct rect *box, const struct rgb_color *rgb)
return CBGFX_SUCCESS;
}

int draw_rounded_box(const struct scale *pos_rel, const struct scale *dim_rel,
const struct rgb_color *rgb,
const struct fraction *thickness,
const struct fraction *radius)
{
struct vector top_left;
struct vector size;
struct vector p, t;

if (cbgfx_init())
return CBGFX_ERROR_INIT;

const uint32_t color = calculate_color(rgb, 0);

transform_vector(&top_left, &canvas.size, pos_rel, &canvas.offset);
transform_vector(&size, &canvas.size, dim_rel, &vzero);
add_vectors(&t, &top_left, &size);
if (within_box(&t, &canvas) < 0) {
LOG("Box exceeds canvas boundary\n");
return CBGFX_ERROR_BOUNDARY;
}

if (!is_valid_fraction(thickness) || !is_valid_fraction(radius))
return CBGFX_ERROR_INVALID_PARAMETER;

struct scale thickness_scale = {
.x = { .n = thickness->n, .d = thickness->d },
.y = { .n = thickness->n, .d = thickness->d },
};
struct scale radius_scale = {
.x = { .n = radius->n, .d = radius->d },
.y = { .n = radius->n, .d = radius->d },
};
struct vector d, r, s;
transform_vector(&d, &canvas.size, &thickness_scale, &vzero);
transform_vector(&r, &canvas.size, &radius_scale, &vzero);
const uint8_t has_thickness = d.x > 0 && d.y > 0;
if (thickness->n != 0 && !has_thickness)
LOG("Thickness truncated to 0\n");
const uint8_t has_radius = r.x > 0 && r.y > 0;
if (radius->n != 0 && !has_radius)
LOG("Radius truncated to 0\n");
if (has_radius) {
if (d.x > r.x || d.y > r.y) {
LOG("Thickness cannot be greater than radius\n");
return CBGFX_ERROR_INVALID_PARAMETER;
}
if (r.x * 2 > t.x - top_left.x || r.y * 2 > t.y - top_left.y) {
LOG("Radius cannot be greater than half of the box\n");
return CBGFX_ERROR_INVALID_PARAMETER;
}
}

/* Step 1: Draw edges */
int32_t x_begin, x_end;
if (has_thickness) {
/* top */
for (p.y = top_left.y; p.y < top_left.y + d.y; p.y++)
for (p.x = top_left.x + r.x; p.x < t.x - r.x; p.x++)
set_pixel(&p, color);
/* bottom */
for (p.y = t.y - d.y; p.y < t.y; p.y++)
for (p.x = top_left.x + r.x; p.x < t.x - r.x; p.x++)
set_pixel(&p, color);
for (p.y = top_left.y + r.y; p.y < t.y - r.y; p.y++) {
/* left */
for (p.x = top_left.x; p.x < top_left.x + d.x; p.x++)
set_pixel(&p, color);
/* right */
for (p.x = t.x - d.x; p.x < t.x; p.x++)
set_pixel(&p, color);
}
} else {
/* Fill the regions except circular sectors */
for (p.y = top_left.y; p.y < t.y; p.y++) {
if (p.y >= top_left.y + r.y && p.y < t.y - r.y) {
x_begin = top_left.x;
x_end = t.x;
} else {
x_begin = top_left.x + r.x;
x_end = t.x - r.x;
}
for (p.x = x_begin; p.x < x_end; p.x++)
set_pixel(&p, color);
}
}

if (!has_radius)
return CBGFX_SUCCESS;

/*
* Step 2: Draw rounded corners
* When has_thickness, only the border is drawn. With fixed thickness,
* the time complexity is linear to the size of the box.
*/
if (has_thickness) {
s.x = r.x - d.x;
s.y = r.y - d.y;
} else {
s.x = 0;
s.y = 0;
}

/* Use 64 bits to avoid overflow */
int32_t x, y;
uint64_t yy;
const uint64_t rrx = r.x * r.x, rry = r.y * r.y;
const uint64_t ssx = s.x * s.x, ssy = s.y * s.y;
x_begin = 0;
x_end = 0;
for (y = r.y - 1; y >= 0; y--) {
/*
* The inequality is valid in the beginning of each iteration:
* y^2 + x_end^2 < r^2
*/
yy = y * y;
/* Check yy/ssy + xx/ssx < 1 */
while (yy * ssx + x_begin * x_begin * ssy < ssx * ssy)
x_begin++;
/* The inequality must be valid now: y^2 + x_begin >= s^2 */
x = x_begin;
/* Check yy/rry + xx/rrx < 1 */
while (x < x_end || yy * rrx + x * x * rry < rrx * rry) {
/*
* Example sequence of (y, x) when s = (4, 4) and
* r = (5, 5):
* [(4, 0), (4, 1), (4, 2), (3, 3), (2, 4),
* (1, 4), (0, 4)].
* If s.x==s.y r.x==r.y, then the sequence will be
* symmetric, and x and y will range from 0 to (r-1).
*/
/* top left */
p.y = top_left.y + r.y - 1 - y;
p.x = top_left.x + r.x - 1 - x;
set_pixel(&p, color);
/* top right */
p.y = top_left.y + r.y - 1 - y;
p.x = t.x - r.x + x;
set_pixel(&p, color);
/* bottom left */
p.y = t.y - r.y + y;
p.x = top_left.x + r.x - 1 - x;
set_pixel(&p, color);
/* bottom right */
p.y = t.y - r.y + y;
p.x = t.x - r.x + x;
set_pixel(&p, color);
x++;
}
x_end = x;
/* (x_begin <= x_end) must hold now */
}

return CBGFX_SUCCESS;
}

int clear_canvas(const struct rgb_color *rgb)
{
const struct rect box = {
Expand Down
19 changes: 19 additions & 0 deletions payloads/libpayload/include/cbgfx.h
Expand Up @@ -114,6 +114,25 @@ struct rgb_color {
*/
int draw_box(const struct rect *box, const struct rgb_color *rgb);

/**
* Draw a box with rounded corners on screen.
*
* @param[in] pos_rel Coordinate of the top left corner of the box relative to
* the canvas.
* @param[in] dim_rel Width and height of the image relative to the canvas.
* @param[in] rgb Color of the border of the box.
* @param[in] thickness Thickness of the border relative to the canvas. If zero
* is given, the box will be filled with the rgb color.
* @param[in] radius Radius of the rounded corners relative to the canvas. A
* zero value indicates sharp corners will be drawn.
*
* @return CBGFX_* error codes
*/
int draw_rounded_box(const struct scale *pos_rel, const struct scale *dim_rel,
const struct rgb_color *rgb,
const struct fraction *thickness,
const struct fraction *radius);

/**
* Clear the canvas
*/
Expand Down
12 changes: 7 additions & 5 deletions src/Kconfig
Expand Up @@ -224,7 +224,7 @@ config TIMESTAMPS_ON_CONSOLE
default n
depends on COLLECT_TIMESTAMPS
help
Print the timestamps to the debug console if enabled at level spew.
Print the timestamps to the debug console if enabled at level info.

config USE_BLOBS
bool "Allow use of binary-only repository"
Expand Down Expand Up @@ -525,6 +525,12 @@ config HAVE_ACPI_RESUME
default n
depends on RELOCATABLE_RAMSTAGE

config DISABLE_ACPI_HIBERNATE
bool
default n
help
Removes S4 from the available sleepstates

config RESUME_PATH_SAME_AS_BOOT
bool
default y if ARCH_X86
Expand Down Expand Up @@ -1081,10 +1087,6 @@ endmenu

source "src/lib/Kconfig"

config ENABLE_APIC_EXT_ID
bool
default n

config WARNINGS_ARE_ERRORS
bool
default y
Expand Down
2 changes: 2 additions & 0 deletions src/acpi/Kconfig
@@ -1,3 +1,5 @@
# SPDX-License-Identifier: GPL-2.0-only
# This file is part of the coreboot project.

config ACPI_SATA_GENERATOR
bool
Expand Down
3 changes: 3 additions & 0 deletions src/acpi/Makefile.inc
@@ -1 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only
# This file is part of the coreboot project.

ramstage-$(CONFIG_ACPI_SATA_GENERATOR) += sata.c
14 changes: 2 additions & 12 deletions src/acpi/sata.c
@@ -1,15 +1,5 @@
/*
* This file is part of the coreboot project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/* SPDX-License-Identifier: GPL-2.0-only */
/* This file is part of the coreboot project. */

#include "sata.h"

Expand Down
14 changes: 2 additions & 12 deletions src/acpi/sata.h
@@ -1,15 +1,5 @@
/*
* This file is part of the coreboot project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/* SPDX-License-Identifier: GPL-2.0-only */
/* This file is part of the coreboot project. */

#ifndef __ACPI_SATA_H__
#define __ACPI_SATA_H__
Expand Down
5 changes: 2 additions & 3 deletions src/arch/arm64/fit_payload.c
Expand Up @@ -12,13 +12,12 @@
* GNU General Public License for more details.
*/

#include <cbfs.h>
#include <commonlib/bsd/compression.h>
#include <console/console.h>
#include <bootmem.h>
#include <program_loading.h>
#include <string.h>
#include <commonlib/compression.h>
#include <commonlib/cbfs_serialized.h>
#include <commonlib/helpers.h>
#include <lib.h>
#include <fit.h>
#include <endian.h>
Expand Down
2 changes: 1 addition & 1 deletion src/arch/riscv/boot.c
Expand Up @@ -19,7 +19,7 @@
#include <arch/encoding.h>
#include <arch/smp/smp.h>
#include <mcall.h>
#include <commonlib/cbfs_serialized.h>
#include <cbfs.h>
#include <console/console.h>

struct arch_prog_run_args {
Expand Down
4 changes: 2 additions & 2 deletions src/arch/riscv/fit_payload.c
Expand Up @@ -14,11 +14,11 @@
* GNU General Public License for more details.
*/

#include <cbfs.h>
#include <commonlib/bsd/compression.h>
#include <console/console.h>
#include <bootmem.h>
#include <program_loading.h>
#include <commonlib/compression.h>
#include <commonlib/cbfs_serialized.h>
#include <lib.h>
#include <fit.h>
#include <endian.h>
Expand Down
1 change: 0 additions & 1 deletion src/arch/riscv/sbi.c
Expand Up @@ -15,7 +15,6 @@

#include <mcall.h>
#include <stdint.h>
#include <commonlib/compiler.h>
#include <arch/exception.h>
#include <sbi.h>
#include <vm.h>
Expand Down
1 change: 0 additions & 1 deletion src/arch/riscv/smp.c
Expand Up @@ -18,7 +18,6 @@
#include <arch/smp/smp.h>
#include <arch/smp/spinlock.h>
#include <mcall.h>
#include <commonlib/compiler.h>
#include <console/console.h>

void smp_pause(int working_hartid)
Expand Down
3 changes: 0 additions & 3 deletions src/arch/x86/Kconfig
Expand Up @@ -166,9 +166,6 @@ config BOOTBLOCK_DEBUG_SPINLOOP
Add a spin (JMP .) in bootblock_crt0.S during early bootblock to wait
for a JTAG debugger to break into the execution sequence.

config BOOTBLOCK_RESETS
string

config HAVE_CMOS_DEFAULT
def_bool n
depends on HAVE_OPTION_TABLE
Expand Down
1 change: 1 addition & 0 deletions src/arch/x86/Makefile.inc
Expand Up @@ -99,6 +99,7 @@ all-y += boot.c
all-y += memcpy.c
all-y += memset.c
all-y += cpu_common.c
all-y += post.c

endif

Expand Down
24 changes: 23 additions & 1 deletion src/arch/x86/acpi_device.c
Expand Up @@ -18,6 +18,8 @@
#include <device/device.h>
#include <device/path.h>
#include <stdlib.h>
#include <crc_byte.h>

#if CONFIG(GENERIC_GPIO_LIB)
#include <gpio.h>
#endif
Expand Down Expand Up @@ -98,6 +100,19 @@ const char *acpi_device_hid(const struct device *dev)
return NULL;
}

/*
* Generate unique ID based on the ACPI path.
* Collisions on the same _HID are possible but very unlikely.
*/
uint32_t acpi_device_uid(struct device *dev)
{
const char *path = acpi_device_path(dev);
if (!path)
return 0;

return CRC(path, strlen(path), crc32_byte);
}

/* Recursive function to find the root device and print a path from there */
static ssize_t acpi_device_path_fill(const struct device *dev, char *buf,
size_t buf_len, size_t cur)
Expand Down Expand Up @@ -161,7 +176,7 @@ const char *acpi_device_scope(const struct device *dev)
return buf;
}

/* Concatentate the device path and provided name suffix */
/* Concatenate the device path and provided name suffix */
const char *acpi_device_path_join(const struct device *dev, const char *name)
{
static char buf[DEVICE_PATH_MAX] = {};
Expand Down Expand Up @@ -192,6 +207,13 @@ int acpi_device_status(const struct device *dev)
return ACPI_STATUS_DEVICE_ALL_ON;
}


/* Write the unique _UID based on ACPI device path. */
void acpi_device_write_uid(struct device *dev)
{
acpigen_write_name_integer("_UID", acpi_device_uid(dev));
}

/* ACPI 6.1 section 6.4.3.6: Extended Interrupt Descriptor */
void acpi_device_write_interrupt(const struct acpi_irq *irq)
{
Expand Down
17 changes: 16 additions & 1 deletion src/arch/x86/acpigen.c
Expand Up @@ -199,6 +199,21 @@ void acpigen_write_name_string(const char *name, const char *string)
acpigen_write_string(string);
}

void acpigen_write_name_unicode(const char *name, const char *string)
{
const size_t len = strlen(string) + 1;
acpigen_write_name(name);
acpigen_emit_byte(BUFFER_OP);
acpigen_write_len_f();
acpigen_write_integer(len);
for (size_t i = 0; i < len; i++) {
const char c = string[i];
/* Simple ASCII to UTF-16 conversion, replace non ASCII characters */
acpigen_emit_word(c >= 0 ? c : '?');
}
acpigen_pop_len();
}

void acpigen_emit_stream(const char *data, int size)
{
int i;
Expand Down Expand Up @@ -991,7 +1006,7 @@ void acpigen_write_resourcetemplate_header(void)
acpigen_emit_byte(WORD_PREFIX);
len_stack[ltop++] = acpigen_get_current();
/* Add 2 dummy bytes for the ACPI word (keep aligned with
the calclulation in acpigen_write_resourcetemplate() below). */
the calculation in acpigen_write_resourcetemplate() below). */
acpigen_emit_byte(0x00);
acpigen_emit_byte(0x00);
}
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86/bootblock_normal.c
Expand Up @@ -12,7 +12,7 @@
*/

#include <cbfs.h>
#include <pc80/mc146818rtc.h>
#include <fallback.h>
#include <program_loading.h>
#include <stddef.h>
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86/cf9_reset.c
Expand Up @@ -35,7 +35,7 @@ void do_system_reset(void)
* A full reset in terms of the CF9 register triggers a power cycle
* (i.e. S0 -> S5 -> S0 transition). Thus, it could be called a
* "cold reset".
* Note: Not all x86 implementations comply with this defitinion,
* Note: Not all x86 implementations comply with this definition,
* some may require additional configuration to power cycle.
*/
void do_full_reset(void)
Expand Down
22 changes: 22 additions & 0 deletions src/arch/x86/include/arch/acpi_device.h
Expand Up @@ -62,10 +62,12 @@ struct acpi_dp {
struct device;
const char *acpi_device_name(const struct device *dev);
const char *acpi_device_hid(const struct device *dev);
uint32_t acpi_device_uid(struct device *dev);
const char *acpi_device_path(const struct device *dev);
const char *acpi_device_scope(const struct device *dev);
const char *acpi_device_path_join(const struct device *dev, const char *name);
int acpi_device_status(const struct device *dev);
void acpi_device_write_uid(struct device *dev);

/*
* ACPI Descriptor for extended Interrupt()
Expand Down Expand Up @@ -301,6 +303,26 @@ struct acpi_gpio {
.pin_count = 1, \
.pins = { (gpio) } }

/* Level Triggered Active High GPIO interrupt with wake */
#define ACPI_GPIO_IRQ_LEVEL_HIGH_WAKE(gpio) { \
.type = ACPI_GPIO_TYPE_INTERRUPT, \
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_LEVEL_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_HIGH, \
.irq.wake = ACPI_IRQ_WAKE, \
.pin_count = 1, \
.pins = { (gpio) } }

/* Level Triggered Active Low GPIO interrupt with wake */
#define ACPI_GPIO_IRQ_LEVEL_LOW_WAKE(gpio) { \
.type = ACPI_GPIO_TYPE_INTERRUPT, \
.pull = ACPI_GPIO_PULL_DEFAULT, \
.irq.mode = ACPI_IRQ_LEVEL_TRIGGERED, \
.irq.polarity = ACPI_IRQ_ACTIVE_LOW, \
.irq.wake = ACPI_IRQ_WAKE, \
.pin_count = 1, \
.pins = { (gpio) } }

/* Write GpioIo() or GpioInt() descriptor to SSDT AML output */
void acpi_device_write_gpio(const struct acpi_gpio *gpio);

Expand Down
3 changes: 2 additions & 1 deletion src/arch/x86/include/arch/acpigen.h
Expand Up @@ -309,6 +309,7 @@ void acpigen_write_dword(unsigned int data);
void acpigen_write_qword(uint64_t data);
void acpigen_write_integer(uint64_t data);
void acpigen_write_string(const char *string);
void acpigen_write_name_unicode(const char *name, const char *string);
void acpigen_write_name(const char *name);
void acpigen_write_name_zero(const char *name);
void acpigen_write_name_one(const char *name);
Expand Down Expand Up @@ -388,7 +389,7 @@ void acpigen_write_dsm(const char *uuid, void (**callbacks)(void *),
void acpigen_write_dsm_uuid_arr(struct dsm_uuid *ids, size_t count);

/*
* Generate ACPI AML code for _CPC (Continuous Perfmance Control).
* Generate ACPI AML code for _CPC (Continuous Performance Control).
* Execute the package function once to create a global table, then
* execute the method function within each processor object to
* create a method that points to the global table.
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86/include/arch/romstage.h
Expand Up @@ -75,7 +75,7 @@ void prepare_and_run_postcar(struct postcar_frame *pcf);
* tears down CAR and loads ramstage. The postcar_frame object
* indicates how to set up the frame. If caching is enabled at
* the time of the call it is up to the platform code to handle
* coherency with dirty lines in the cache using some mechansim
* coherency with dirty lines in the cache using some mechanism
* such as platform_prog_run() because run_postcar_phase()
* utilizes prog_run() internally.
*/
Expand Down
@@ -1,10 +1,6 @@
/*
* This file is part of the coreboot project.
*
* Copyright (C) 2012 Google Inc.
* Copyright (C) 2015 Intel Corp.
* Copyright (C) 2018 Eltan B.V.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; version 2 of
Expand All @@ -16,11 +12,15 @@
* GNU General Public License for more details.
*/

Scope (\_SB)
#include <stdint.h>
#include <console/console.h>
#include <arch/io.h>

void arch_post_code(uint8_t value)
{
Device (PWRB)
{
Name (_HID, EisaId ("PNP0C0C"))
Name (_UID, 1)
}
if (CONFIG(POST_IO))
outb(value, CONFIG_POST_IO_PORT);

if (CONFIG(CMOS_POST) && !ENV_SMM)
cmos_post_code(value);
}
19 changes: 1 addition & 18 deletions src/arch/x86/smbios.c
Expand Up @@ -491,7 +491,7 @@ smbios_board_type __weak smbios_mainboard_board_type(void)
return SMBIOS_BOARD_TYPE_UNKNOWN;
}

u8 __weak smbios_mainboard_enclosure_type(void)
smbios_enclosure_type __weak smbios_mainboard_enclosure_type(void)
{
return CONFIG_SMBIOS_ENCLOSURE_TYPE;
}
Expand Down Expand Up @@ -536,11 +536,6 @@ const char *__weak smbios_system_sku(void)
return "";
}

int __weak fill_mainboard_smbios_type16(unsigned long *current, int *handle)
{
return 0;
}

static int get_socket_type(void)
{
if (CONFIG(CPU_INTEL_SLOT_1))
Expand Down Expand Up @@ -970,16 +965,6 @@ static int smbios_write_type11(unsigned long *current, int *handle)
return len;
}

static int smbios_write_type16(unsigned long *current, int *handle)
{
int len = fill_mainboard_smbios_type16(current, handle);
if(len){
*current += len;
(*handle)++;
}
return len;
}

static int smbios_write_type17(unsigned long *current, int *handle)
{
int len = sizeof(struct smbios_type17);
Expand Down Expand Up @@ -1218,8 +1203,6 @@ unsigned long smbios_write_tables(unsigned long current)
if (CONFIG(ELOG))
update_max(len, max_struct_size,
elog_smbios_write_type15(&current,handle++));
update_max(len, max_struct_size, smbios_write_type16(&current,
&handle));
update_max(len, max_struct_size, smbios_write_type17(&current,
&handle));
update_max(len, max_struct_size, smbios_write_type32(&current,
Expand Down
12 changes: 6 additions & 6 deletions src/commonlib/Makefile.inc
Expand Up @@ -30,11 +30,11 @@ ramstage-y += cbfs.c
smm-y += cbfs.c
postcar-y += cbfs.c

decompressor-y += lz4_wrapper.c
bootblock-y += lz4_wrapper.c
verstage-y += lz4_wrapper.c
romstage-y += lz4_wrapper.c
ramstage-y += lz4_wrapper.c
postcar-y += lz4_wrapper.c
decompressor-y += bsd/lz4_wrapper.c
bootblock-y += bsd/lz4_wrapper.c
verstage-y += bsd/lz4_wrapper.c
romstage-y += bsd/lz4_wrapper.c
ramstage-y += bsd/lz4_wrapper.c
postcar-y += bsd/lz4_wrapper.c

ramstage-y += sort.c
42 changes: 42 additions & 0 deletions src/commonlib/bsd/include/commonlib/bsd/cb_err.h
@@ -0,0 +1,42 @@
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-or-later */

#ifndef _COMMONLIB_BSD_CB_ERR_H_
#define _COMMONLIB_BSD_CB_ERR_H_

#include <stdint.h>

/**
* coreboot error codes
*
* Common error definitions that can be used for any function. All error values
* should be negative -- when useful, positive values can also be used to denote
* success. Allocate a new group or errors every 100 values.
*/
enum cb_err {
CB_SUCCESS = 0, /**< Call completed successfully */
CB_ERR = -1, /**< Generic error code */
CB_ERR_ARG = -2, /**< Invalid argument */

/* NVRAM/CMOS errors */
CB_CMOS_OTABLE_DISABLED = -100, /**< Option table disabled */
CB_CMOS_LAYOUT_NOT_FOUND = -101, /**< Layout file not found */
CB_CMOS_OPTION_NOT_FOUND = -102, /**< Option string not found */
CB_CMOS_ACCESS_ERROR = -103, /**< CMOS access error */
CB_CMOS_CHECKSUM_INVALID = -104, /**< CMOS checksum is invalid */

/* Keyboard test failures */
CB_KBD_CONTROLLER_FAILURE = -200,
CB_KBD_INTERFACE_FAILURE = -201,

/* I2C controller failures */
CB_I2C_NO_DEVICE = -300, /**< Device is not responding */
CB_I2C_BUSY = -301, /**< Device tells it's busy */
CB_I2C_PROTOCOL_ERROR = -302, /**< Data lost or spurious slave
device response, try again? */
CB_I2C_TIMEOUT = -303, /**< Transmission timed out */
};

/* Don't typedef the enum directly, so the size is unambiguous for serialization. */
typedef int32_t cb_err_t;

#endif /* _COMMONLIB_BSD_CB_ERR_H_ */
@@ -1,48 +1,4 @@
/*
* This file is part of the coreboot project.
*
* Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
* Copyright (C) 2012 Google, Inc.
* Copyright (C) 2013 The Chromium OS Authors. All rights reserved.
*
* This file is dual-licensed. You can choose between:
* - The GNU GPL, version 2, as published by the Free Software Foundation
* - The revised BSD license (without advertising clause)
*
* ---------------------------------------------------------------------------
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ---------------------------------------------------------------------------
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ---------------------------------------------------------------------------
*/
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */

#ifndef _CBFS_SERIALIZED_H_
#define _CBFS_SERIALIZED_H_
Expand Down
@@ -1,18 +1,7 @@
/*
* This file is part of the coreboot project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */

#ifndef _COMMONLIB_COMPILER_H_
#define _COMMONLIB_COMPILER_H_
#ifndef _COMMONLIB_BSD_COMPILER_H_
#define _COMMONLIB_BSD_COMPILER_H_

#ifndef __packed
#if defined(__WIN32) || defined(__WIN64)
Expand Down
@@ -1,15 +1,4 @@
/*
* This file is part of the coreboot project.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */

#ifndef _COMMONLIB_COMPRESSION_H_
#define _COMMONLIB_COMPRESSION_H_
Expand Down
41 changes: 41 additions & 0 deletions src/commonlib/bsd/include/commonlib/bsd/fmap_serialized.h
@@ -0,0 +1,41 @@
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */

#ifndef FLASHMAP_SERIALIZED_H__
#define FLASHMAP_SERIALIZED_H__

#include <stdint.h>

#define FMAP_SIGNATURE "__FMAP__"
#define FMAP_VER_MAJOR 1 /* this header's FMAP minor version */
#define FMAP_VER_MINOR 1 /* this header's FMAP minor version */
#define FMAP_STRLEN 32 /* maximum length for strings, */
/* including null-terminator */

enum fmap_flags {
FMAP_AREA_STATIC = 1 << 0,
FMAP_AREA_COMPRESSED = 1 << 1,
FMAP_AREA_RO = 1 << 2,
FMAP_AREA_PRESERVE = 1 << 3,
};

/* Mapping of volatile and static regions in firmware binary */
struct fmap_area {
uint32_t offset; /* offset relative to base */
uint32_t size; /* size in bytes */
uint8_t name[FMAP_STRLEN]; /* descriptive name */
uint16_t flags; /* flags for this area */
} __packed;

struct fmap {
uint8_t signature[8]; /* "__FMAP__" (0x5F5F464D41505F5F) */
uint8_t ver_major; /* major version */
uint8_t ver_minor; /* minor version */
uint64_t base; /* address of the firmware binary */
uint32_t size; /* size of firmware binary in bytes */
uint8_t name[FMAP_STRLEN]; /* name of this firmware binary */
uint16_t nareas; /* number of areas described by
fmap_areas[] below */
struct fmap_area areas[];
} __packed;

#endif /* FLASHMAP_SERIALIZED_H__ */
89 changes: 89 additions & 0 deletions src/commonlib/bsd/include/commonlib/bsd/helpers.h
@@ -0,0 +1,89 @@
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */

#ifndef COMMONLIB_BSD_HELPERS_H
#define COMMONLIB_BSD_HELPERS_H

#ifndef __ASSEMBLER__
#include <commonlib/bsd/compiler.h>
#include <stddef.h>
#endif

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif

#define ALIGN(x, a) __ALIGN_MASK(x, (__typeof__(x))(a)-1UL)
#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
#define ALIGN_UP(x, a) ALIGN((x), (a))
#define ALIGN_DOWN(x, a) ((x) & ~((__typeof__(x))(a)-1UL))
#define IS_ALIGNED(x, a) (((x) & ((__typeof__(x))(a)-1UL)) == 0)

/* Double-evaluation unsafe min/max, for bitfields and outside of functions */
#define __CMP_UNSAFE(a, b, op) ((a) op (b) ? (a) : (b))
#define MIN_UNSAFE(a, b) __CMP_UNSAFE(a, b, <)
#define MAX_UNSAFE(a, b) __CMP_UNSAFE(a, b, >)

#define __CMP_SAFE(a, b, op, var_a, var_b) ({ \
__TYPEOF_UNLESS_CONST(a, b) var_a = (a); \
__TYPEOF_UNLESS_CONST(b, a) var_b = (b); \
var_a op var_b ? var_a : var_b; \
})

#define __CMP(a, b, op) __builtin_choose_expr( \
__builtin_constant_p(a) && __builtin_constant_p(b), \
__CMP_UNSAFE(a, b, op), __CMP_SAFE(a, b, op, __TMPNAME, __TMPNAME))

#ifndef MIN
#define MIN(a, b) __CMP(a, b, <)
#endif
#ifndef MAX
#define MAX(a, b) __CMP(a, b, >)
#endif

#ifndef ABS
#define ABS(a) ({ \
__typeof__(a) _abs_local_a = (a); \
(_abs_local_a < 0) ? (-_abs_local_a) : _abs_local_a; \
})
#endif

#define IS_POWER_OF_2(x) ({ \
__typeof__(x) _power_local_x = (x); \
(_power_local_x & (_power_local_x - 1)) == 0; \
})

#define DIV_ROUND_UP(x, y) ({ \
__typeof__(x) _div_local_x = (x); \
__typeof__(y) _div_local_y = (y); \
(_div_local_x + _div_local_y - 1) / _div_local_y; \
})

#define SWAP(a, b) do { \
__typeof__(&(a)) _swap_local_a = &(a); \
__typeof__(&(b)) _swap_local_b = &(b); \
__typeof__(a) _swap_local_tmp = *_swap_local_a; \
*_swap_local_a = *_swap_local_b; \
*_swap_local_b = _swap_local_tmp; \
} while (0)

/* Standard units. */
#define KiB (1<<10)
#define MiB (1<<20)
#define GiB (1<<30)

#define KHz (1000)
#define MHz (1000 * KHz)
#define GHz (1000 * MHz)

#ifndef offsetof
#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
#endif

#define check_member(structure, member, offset) _Static_assert( \
offsetof(struct structure, member) == offset, \
"`struct " #structure "` offset for `" #member "` is not " #offset)

/* Calculate size of structure member. */
#define member_size(type, member) (sizeof(((type *)0)->member))

#endif /* COMMONLIB_BSD_HELPERS_H */
File renamed without changes.
@@ -1,37 +1,8 @@
/*
* Copyright 2015-2016 Google Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#include <commonlib/compression.h>
#include <commonlib/endian.h>
#include <commonlib/helpers.h>
/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only */

#include <commonlib/bsd/compression.h>
#include <commonlib/bsd/helpers.h>
#include <endian.h>
#include <stdint.h>
#include <string.h>

Expand All @@ -41,7 +12,7 @@
* access support), we can easily write the ones we need ourselves. */
static uint16_t LZ4_readLE16(const void *src)
{
return read_le16(src);
return le16toh(*(const uint16_t *)src);
}
static void LZ4_copy8(void *dst, const void *src)
{
Expand Down Expand Up @@ -143,7 +114,7 @@ size_t ulz4fn(const void *src, size_t srcn, void *dst, size_t dstn)
return 0; /* input overrun */

/* We assume there's always only a single, standard frame. */
if (read_le32(&h->magic) != LZ4F_MAGICNUMBER || h->version != 1)
if (le32toh(h->magic) != LZ4F_MAGICNUMBER || h->version != 1)
return 0; /* unknown format */
if (h->reserved0 || h->reserved1 || h->reserved2)
return 0; /* reserved must be zero */
Expand All @@ -158,7 +129,9 @@ size_t ulz4fn(const void *src, size_t srcn, void *dst, size_t dstn)
}

while (1) {
struct lz4_block_header b = { { .raw = read_le32(in) } };
struct lz4_block_header b = {
{ .raw = le32toh(*(const uint32_t *)in) }
};
in += sizeof(struct lz4_block_header);

if ((size_t)(in - src) + b.size > srcn)
Expand Down
2 changes: 1 addition & 1 deletion src/commonlib/include/commonlib/cbfs.h
Expand Up @@ -14,7 +14,7 @@
#ifndef _COMMONLIB_CBFS_H_
#define _COMMONLIB_CBFS_H_

#include <commonlib/cbfs_serialized.h>
#include <commonlib/bsd/cbfs_serialized.h>
#include <commonlib/region.h>
#include <vb2_api.h>

Expand Down
74 changes: 0 additions & 74 deletions src/commonlib/include/commonlib/fmap_serialized.h

This file was deleted.

89 changes: 4 additions & 85 deletions src/commonlib/include/commonlib/helpers.h
Expand Up @@ -13,71 +13,12 @@

#ifndef COMMONLIB_HELPERS_H
#define COMMONLIB_HELPERS_H
/* This file is for helpers for both coreboot firmware and its utilities. */

#ifndef __ASSEMBLER__
#include <commonlib/compiler.h>
#include <stddef.h>
#endif

#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
#endif

#define ALIGN(x, a) __ALIGN_MASK(x, (__typeof__(x))(a)-1UL)
#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
#define ALIGN_UP(x, a) ALIGN((x), (a))
#define ALIGN_DOWN(x, a) ((x) & ~((__typeof__(x))(a)-1UL))
#define IS_ALIGNED(x, a) (((x) & ((__typeof__(x))(a)-1UL)) == 0)

/* Double-evaluation unsafe min/max, for bitfields and outside of functions */
#define __CMP_UNSAFE(a, b, op) ((a) op (b) ? (a) : (b))
#define MIN_UNSAFE(a, b) __CMP_UNSAFE(a, b, <)
#define MAX_UNSAFE(a, b) __CMP_UNSAFE(a, b, >)

#define __CMP_SAFE(a, b, op, var_a, var_b) ({ \
__TYPEOF_UNLESS_CONST(a, b) var_a = (a); \
__TYPEOF_UNLESS_CONST(b, a) var_b = (b); \
var_a op var_b ? var_a : var_b; \
})
/* This file is for helpers for both coreboot firmware and its utilities. Most
of this has moved into <commonlib/bsd/helpers.h> now, this wrapper is just
for the stuff that nobody bothered to confirm BSD-licensability of yet. */


#define __CMP(a, b, op) __builtin_choose_expr( \
__builtin_constant_p(a) && __builtin_constant_p(b), \
__CMP_UNSAFE(a, b, op), __CMP_SAFE(a, b, op, __TMPNAME, __TMPNAME))

#ifndef MIN
#define MIN(a, b) __CMP(a, b, <)
#endif
#ifndef MAX
#define MAX(a, b) __CMP(a, b, >)
#endif

#ifndef ABS
#define ABS(a) ({ \
__typeof__(a) _abs_local_a = (a); \
(_abs_local_a < 0) ? (-_abs_local_a) : _abs_local_a; \
})
#endif

#define IS_POWER_OF_2(x) ({ \
__typeof__(x) _power_local_x = (x); \
(_power_local_x & (_power_local_x - 1)) == 0; \
})

#define DIV_ROUND_UP(x, y) ({ \
__typeof__(x) _div_local_x = (x); \
__typeof__(y) _div_local_y = (y); \
(_div_local_x + _div_local_y - 1) / _div_local_y; \
})

#define SWAP(a, b) do { \
__typeof__(&(a)) _swap_local_a = &(a); \
__typeof__(&(b)) _swap_local_b = &(b); \
__typeof__(a) _swap_local_tmp = *_swap_local_a; \
*_swap_local_a = *_swap_local_b; \
*_swap_local_b = _swap_local_tmp; \
} while (0)
#include <commonlib/bsd/helpers.h>

/*
* Divide positive or negative dividend by positive divisor and round
Expand All @@ -93,25 +34,6 @@
((_div_local_x - (_div_local_d / 2)) / _div_local_d); \
})

/* Standard units. */
#define KiB (1<<10)
#define MiB (1<<20)
#define GiB (1<<30)
/* Could we ever run into this one? I hope we get this much memory! */
#define TiB (1<<40)

#define KHz (1000)
#define MHz (1000 * KHz)
#define GHz (1000 * MHz)

#ifndef offsetof
#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
#endif

#define check_member(structure, member, offset) _Static_assert( \
offsetof(struct structure, member) == offset, \
"`struct " #structure "` offset for `" #member "` is not " #offset)

/**
* container_of - cast a member of a structure out to the containing structure
* @param ptr: the pointer to the member.
Expand All @@ -123,9 +45,6 @@
const __typeof__(((type *)0)->member) *__mptr = (ptr); \
(type *)((char *)__mptr - offsetof(type, member)); })

/* Calculate size of structure member. */
#define member_size(type, member) (sizeof(((type *)0)->member))

#ifndef __unused
#define __unused __attribute__((unused))
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/commonlib/include/commonlib/region.h
Expand Up @@ -31,7 +31,7 @@
struct region_device;

/*
* Returns NULL on error otherwise a buffer is returned with the conents of
* Returns NULL on error otherwise a buffer is returned with the contents of
* the requested data at offset of size.
*/
void *rdev_mmap(const struct region_device *rd, size_t offset, size_t size);
Expand Down Expand Up @@ -173,7 +173,7 @@ struct mem_region_device {
struct region_device rdev;
};

/* Inititalize at runtime a mem_region_device. This would be used when
/* Initialize at runtime a mem_region_device. This would be used when
* the base and size are dynamic or can't be known during linking.
* There are two variants: read-only and read-write. */
void mem_region_device_ro_init(struct mem_region_device *mdev, void *base,
Expand Down
2 changes: 1 addition & 1 deletion src/commonlib/storage/mmc.c
Expand Up @@ -436,7 +436,7 @@ int mmc_update_capacity(struct storage_media *media)
if ((capacity >> 20) > 2 * 1024)
media->capacity[MMC_PARTITION_USER] = capacity;

/* Determine the boot parition sizes */
/* Determine the boot partition sizes */
hc_erase_size = ext_csd[224] * 512 * KiB;
capacity = ext_csd[EXT_CSD_BOOT_SIZE_MULT] * 128 * KiB;
media->capacity[MMC_PARTITION_BOOT_1] = capacity;
Expand Down
2 changes: 1 addition & 1 deletion src/commonlib/storage/sd_mmc.c
Expand Up @@ -199,7 +199,7 @@ int sd_mmc_enter_standby(struct storage_media *media)

/*
* For MMC cards, set the Relative Address.
* For SD cards, get the Relatvie Address.
* For SD cards, get the Relative Address.
* This also puts the cards into Standby State
*/
cmd.cmdidx = SD_CMD_SEND_RELATIVE_ADDR;
Expand Down
2 changes: 1 addition & 1 deletion src/commonlib/storage/sdhci.c
Expand Up @@ -146,7 +146,7 @@ static int sdhci_send_command_bounced(struct sd_mmc_ctrlr *ctrlr,
sdhci_writel(sdhci_ctrlr, SDHCI_INT_ALL_MASK, SDHCI_INT_STATUS);
mask = SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT;

/* We shouldn't wait for data inihibit for stop commands, even
/* We shouldn't wait for data inhibit for stop commands, even
though they might use busy signaling */
if (cmd->flags & CMD_FLAG_IGNORE_INHIBIT)
mask &= ~SDHCI_DATA_INHIBIT;
Expand Down
132 changes: 10 additions & 122 deletions src/console/post.c
Expand Up @@ -13,138 +13,26 @@
*/

#include <stdint.h>
#include <elog.h>
#include <console/console.h>
#include <device/device.h>
#include <pc80/mc146818rtc.h>
#include <smp/spinlock.h>
#if CONFIG(POST_IO)
#include <arch/io.h>
#endif

/* Write POST information */
void __weak arch_post_code(uint8_t value) { }

/* Some mainboards have very nice features beyond just a simple display.
* They can override this function.
*/
void __weak mainboard_post(uint8_t value)
{
}

#if CONFIG(CMOS_POST)

DECLARE_SPIN_LOCK(cmos_post_lock)

void cmos_post_log(void)
{
u8 code = 0;
#if CONFIG(CMOS_POST_EXTRA)
u32 extra = 0;
#endif

spin_lock(&cmos_post_lock);

/* Get post code from other bank */
switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
case CMOS_POST_BANK_0_MAGIC:
code = cmos_read(CMOS_POST_BANK_1_OFFSET);
#if CONFIG(CMOS_POST_EXTRA)
extra = cmos_read32(CMOS_POST_BANK_1_EXTRA);
#endif
break;
case CMOS_POST_BANK_1_MAGIC:
code = cmos_read(CMOS_POST_BANK_0_OFFSET);
#if CONFIG(CMOS_POST_EXTRA)
extra = cmos_read32(CMOS_POST_BANK_0_EXTRA);
#endif
break;
}

spin_unlock(&cmos_post_lock);

/* Check last post code in previous boot against normal list */
switch (code) {
case POST_OS_BOOT:
case POST_OS_RESUME:
case POST_ENTER_ELF_BOOT:
case 0:
break;
default:
printk(BIOS_WARNING, "POST: Unexpected post code "
"in previous boot: 0x%02x\n", code);
#if CONFIG(ELOG) && (ENV_RAMSTAGE || CONFIG(ELOG_PRERAM))
elog_add_event_word(ELOG_TYPE_LAST_POST_CODE, code);
#if CONFIG(CMOS_POST_EXTRA)
if (extra)
elog_add_event_dword(ELOG_TYPE_POST_EXTRA, extra);
#endif
#endif
}
}

#if CONFIG(CMOS_POST_EXTRA)
void post_log_extra(u32 value)
{
spin_lock(&cmos_post_lock);
void __weak mainboard_post(uint8_t value) { }

switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
case CMOS_POST_BANK_0_MAGIC:
cmos_write32(CMOS_POST_BANK_0_EXTRA, value);
break;
case CMOS_POST_BANK_1_MAGIC:
cmos_write32(CMOS_POST_BANK_1_EXTRA, value);
break;
}

spin_unlock(&cmos_post_lock);
}

void post_log_path(const struct device *dev)
void post_code(uint8_t value)
{
if (dev) {
/* Encode path into lower 3 bytes */
u32 path = dev_path_encode(dev);
/* Upper byte contains the log type */
path |= CMOS_POST_EXTRA_DEV_PATH << 24;
post_log_extra(path);
}
}
if (!CONFIG(NO_POST)) {
/* Assume this to be the most reliable and simplest type
for displaying POST so keep it first. */
arch_post_code(value);

void post_log_clear(void)
{
post_log_extra(0);
}
#endif /* CONFIG_CMOS_POST_EXTRA */
if (CONFIG(CONSOLE_POST))
printk(BIOS_EMERG, "POST: 0x%02x\n", value);

static void cmos_post_code(u8 value)
{
spin_lock(&cmos_post_lock);

switch (cmos_read(CMOS_POST_BANK_OFFSET)) {
case CMOS_POST_BANK_0_MAGIC:
cmos_write(value, CMOS_POST_BANK_0_OFFSET);
break;
case CMOS_POST_BANK_1_MAGIC:
cmos_write(value, CMOS_POST_BANK_1_OFFSET);
break;
mainboard_post(value);
}

spin_unlock(&cmos_post_lock);
}
#endif /* CONFIG_CMOS_POST */

void post_code(uint8_t value)
{
#if !CONFIG(NO_POST)
#if CONFIG(CONSOLE_POST)
printk(BIOS_EMERG, "POST: 0x%02x\n", value);
#endif
#if CONFIG(CMOS_POST)
cmos_post_code(value);
#endif
#if CONFIG(POST_IO)
outb(value, CONFIG_POST_IO_PORT);
#endif
#endif
mainboard_post(value);
}
2 changes: 1 addition & 1 deletion src/console/printk.c
Expand Up @@ -49,7 +49,7 @@ void console_time_report(void)
if (!TRACK_CONSOLE_TIME)
return;

printk(BIOS_DEBUG, "Accumulated console time in " ENV_STRING " %ld ms\n",
printk(BIOS_DEBUG, "BS: " ENV_STRING " times (exec / console): total (unknown) / %ld ms\n",
DIV_ROUND_CLOSEST(console_usecs, USECS_PER_MSEC));
}

Expand Down
2 changes: 1 addition & 1 deletion src/cpu/intel/hyperthreading/intel_sibling.c
Expand Up @@ -15,7 +15,7 @@
#include <cpu/x86/lapic.h>
#include <cpu/intel/hyperthreading.h>
#include <device/device.h>
#include <pc80/mc146818rtc.h>
#include <option.h>
#include <smp/spinlock.h>

#if CONFIG(PARALLEL_CPU_INIT)
Expand Down
1 change: 0 additions & 1 deletion src/cpu/intel/model_65x/Kconfig
Expand Up @@ -4,5 +4,4 @@ config CPU_INTEL_MODEL_65X
select ARCH_VERSTAGE_X86_32
select ARCH_ROMSTAGE_X86_32
select ARCH_RAMSTAGE_X86_32
select SMP
select SUPPORT_CPU_UCODE_IN_CBFS
1 change: 0 additions & 1 deletion src/cpu/intel/model_67x/Kconfig
Expand Up @@ -4,5 +4,4 @@ config CPU_INTEL_MODEL_67X
select ARCH_VERSTAGE_X86_32
select ARCH_ROMSTAGE_X86_32
select ARCH_RAMSTAGE_X86_32
select SMP
select SUPPORT_CPU_UCODE_IN_CBFS
1 change: 0 additions & 1 deletion src/cpu/intel/model_68x/Kconfig
Expand Up @@ -18,5 +18,4 @@ config CPU_INTEL_MODEL_68X
select ARCH_VERSTAGE_X86_32
select ARCH_ROMSTAGE_X86_32
select ARCH_RAMSTAGE_X86_32
select SMP
select SUPPORT_CPU_UCODE_IN_CBFS
1 change: 0 additions & 1 deletion src/cpu/intel/model_6bx/Kconfig
Expand Up @@ -4,5 +4,4 @@ config CPU_INTEL_MODEL_6BX
select ARCH_VERSTAGE_X86_32
select ARCH_ROMSTAGE_X86_32
select ARCH_RAMSTAGE_X86_32
select SMP
select SUPPORT_CPU_UCODE_IN_CBFS
1 change: 0 additions & 1 deletion src/cpu/intel/model_6xx/Kconfig
Expand Up @@ -4,5 +4,4 @@ config CPU_INTEL_MODEL_6XX
select ARCH_VERSTAGE_X86_32
select ARCH_ROMSTAGE_X86_32
select ARCH_RAMSTAGE_X86_32
select SMP
select SUPPORT_CPU_UCODE_IN_CBFS
7 changes: 3 additions & 4 deletions src/device/Kconfig
Expand Up @@ -15,17 +15,20 @@ menu "Devices"

config HAVE_VGA_TEXT_FRAMEBUFFER
bool
depends on !NO_GFX_INIT
help
Selected by graphics drivers that support legacy VGA text mode.

config HAVE_VBE_LINEAR_FRAMEBUFFER
bool
depends on !NO_GFX_INIT
help
Selected by graphics drivers that can set up a VBE linear-framebuffer
mode.

config HAVE_LINEAR_FRAMEBUFFER
bool
depends on !NO_GFX_INIT
help
Selected by graphics drivers that can set up a generic linear
framebuffer.
Expand Down Expand Up @@ -477,10 +480,6 @@ config LINEAR_FRAMEBUFFER_MAX_HEIGHT

endmenu # "Display"

config SMBUS_HAS_AUX_CHANNELS
bool
default n

config PCI
bool
default n
Expand Down
29 changes: 16 additions & 13 deletions src/device/device.c
Expand Up @@ -903,16 +903,17 @@ static void scan_bus(struct device *busdev)
{
int do_scan_bus;
struct stopwatch sw;

stopwatch_init(&sw);
long scan_time;

if (!busdev->enabled)
return;

printk(BIOS_SPEW, "%s scanning...\n", dev_path(busdev));
printk(BIOS_DEBUG, "%s scanning...\n", dev_path(busdev));

post_log_path(busdev);

stopwatch_init(&sw);

do_scan_bus = 1;
while (do_scan_bus) {
struct bus *link;
Expand All @@ -928,8 +929,9 @@ static void scan_bus(struct device *busdev)
}
}

printk(BIOS_DEBUG, "%s: scanning of bus %s took %ld usecs\n",
__func__, dev_path(busdev), stopwatch_duration_usecs(&sw));
scan_time = stopwatch_duration_msecs(&sw);
printk(BIOS_DEBUG, "%s: bus %s finished in %ld msecs\n", __func__,
dev_path(busdev), scan_time);
}

void scan_bridges(struct bus *bus)
Expand Down Expand Up @@ -1116,22 +1118,23 @@ static void init_dev(struct device *dev)
return;

if (!dev->initialized && dev->ops && dev->ops->init) {
#if CONFIG(HAVE_MONOTONIC_TIMER)
struct stopwatch sw;
stopwatch_init(&sw);
#endif
long init_time;

if (dev->path.type == DEVICE_PATH_I2C) {
printk(BIOS_DEBUG, "smbus: %s[%d]->",
dev_path(dev->bus->dev), dev->bus->link_num);
}

printk(BIOS_DEBUG, "%s init ...\n", dev_path(dev));
printk(BIOS_DEBUG, "%s init\n", dev_path(dev));

stopwatch_init(&sw);
dev->initialized = 1;
dev->ops->init(dev);
#if CONFIG(HAVE_MONOTONIC_TIMER)
printk(BIOS_DEBUG, "%s init finished in %ld usecs\n", dev_path(dev),
stopwatch_duration_usecs(&sw));
#endif

init_time = stopwatch_duration_msecs(&sw);
printk(BIOS_DEBUG, "%s init finished in %ld msecs\n", dev_path(dev),
init_time);
}
}

Expand Down
14 changes: 12 additions & 2 deletions src/device/pci_class.c
Expand Up @@ -42,6 +42,7 @@ static const PCI_SUBCLASS mass_storage[] = {
{ 0x06, "SATA controller" },
{ 0x07, "Serial Attached SCSI controller" },
{ 0x08, "Non-Volatile memory controller" },
{ 0x09, "Universal Flash Storage controller" },
{ 0x80, "Mass storage controller" }
};

Expand All @@ -53,6 +54,8 @@ static const PCI_SUBCLASS network[] = {
{ 0x04, "ISDN controller" },
{ 0x05, "WorldFip controller" },
{ 0x06, "PICMG controller" },
{ 0x07, "InfiniBand Controller" },
{ 0x08, "Host fabric controller" },
{ 0x80, "Network controller" }
};

Expand Down Expand Up @@ -89,6 +92,7 @@ static const PCI_SUBCLASS bridge[] = {
{ 0x08, "RACEway bridge" },
{ 0x09, "Semi-transparent PCI-to-PCI bridge" },
{ 0x0a, "InfiniBand to PCI host bridge" },
{ 0x0b, "Advanced Switching to PCI host bridge" },
{ 0x80, "Bridge" }
};

Expand All @@ -110,6 +114,7 @@ static const PCI_SUBCLASS generic[] = {
{ 0x04, "PCI Hot-plug controller" },
{ 0x05, "SD Host controller" },
{ 0x06, "IOMMU" },
{ 0x07, "Root Complex Event Collector" },
{ 0x80, "System peripheral" }
};

Expand All @@ -134,7 +139,8 @@ static const PCI_SUBCLASS processor[] = {
{ 0x10, "Alpha" },
{ 0x20, "Power PC" },
{ 0x30, "MIPS" },
{ 0x40, "Co-processor" }
{ 0x40, "Co-processor" },
{ 0x80, "Processor" }
};

static const PCI_SUBCLASS serial_bus[] = {
Expand All @@ -147,7 +153,9 @@ static const PCI_SUBCLASS serial_bus[] = {
{ 0x06, "InfiniBand" },
{ 0x07, "IPMI SMIC interface" },
{ 0x08, "SERCOS interface" },
{ 0x09, "CANBUS" }
{ 0x09, "CANBUS" },
{ 0x0a, "MIPI I3C SM Host Controller Interface" },
{ 0x80, "Serial Bus Controller" }
};

static const PCI_SUBCLASS wireless[] = {
Expand All @@ -158,6 +166,8 @@ static const PCI_SUBCLASS wireless[] = {
{ 0x12, "Broadband" },
{ 0x20, "802.1a controller" },
{ 0x21, "802.1b controller" },
{ 0x40, "Cellular controller/modem" },
{ 0x41, "Cellular controller/modem plus Ethernet (802.11)" },
{ 0x80, "Wireless controller" }
};

Expand Down
37 changes: 0 additions & 37 deletions src/device/smbus_ops.c
Expand Up @@ -27,43 +27,6 @@ struct bus *get_pbus_smbus(struct device *dev)
return pbus;
}

/*
* Multi-level I2C MUX? May need to find the first I2C device and then set link
* down to current dev.
*
* 1 store get_pbus_smbus list link
* 2 reverse the link and call set link.
*
* @param dev TODO.
*/
int smbus_set_link(struct device *dev)
{
struct bus *pbus_a[4]; // 4 level mux only. Enough?
struct bus *pbus = dev->bus;
int pbus_num = 0;
int i;

while (pbus && pbus->dev && (pbus->dev->path.type == DEVICE_PATH_I2C)) {
pbus_a[pbus_num++] = pbus;
pbus = pbus->dev->bus;
}

// printk(BIOS_INFO, "smbus_set_link: ");
for (i = pbus_num - 1; i >= 0; i--) {
// printk(BIOS_INFO, " %s[%d] -> ", dev_path(pbus_a[i]->dev),
// pbus_a[i]->link);
if (ops_smbus_bus(get_pbus_smbus(pbus_a[i]->dev))) {
if (pbus_a[i]->dev->ops
&& pbus_a[i]->dev->ops->set_link)
pbus_a[i]->dev->ops->set_link(pbus_a[i]->dev,
pbus_a[i]->link_num);
}
}
// printk(BIOS_INFO, " %s\n", dev_path(dev));

return pbus_num;
}

#define CHECK_PRESENCE(x) \
if (!ops_smbus_bus(get_pbus_smbus(dev))->x) { \
printk(BIOS_ERR, "%s missing " #x "\n", \
Expand Down
4 changes: 4 additions & 0 deletions src/drivers/amd/agesa/state_machine.c
Expand Up @@ -223,6 +223,8 @@ static AGESA_STATUS ramstage_dispatch(struct sysinfo *cb,
case AMD_INIT_LATE:
{
AMD_LATE_PARAMS *param = (void *)StdHeader;
platform_BeforeInitLate(cb, param);
board_BeforeInitLate(cb, param);
status = module_dispatch(func, StdHeader);
platform_AfterInitLate(cb, param);
completion_InitLate(cb, param);
Expand Down Expand Up @@ -364,6 +366,8 @@ void __weak
board_BeforeInitEnv(struct sysinfo *cb, AMD_ENV_PARAMS *Env) { }
void __weak
board_BeforeInitMid(struct sysinfo *cb, AMD_MID_PARAMS *Mid) { }
void __weak
board_BeforeInitLate(struct sysinfo *cb, AMD_LATE_PARAMS *Late) { }

AGESA_STATUS __weak
fchs3earlyrestore(AMD_CONFIG_PARAMS *StdHeader)
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/crb/tis.c
Expand Up @@ -117,7 +117,7 @@ static void crb_tpm_fill_ssdt(struct device *dev)
acpigen_write_name_string("_HID", "MSFT0101");
acpigen_write_name_string("_CID", "MSFT0101");

acpigen_write_name_integer("_UID", 1);
acpi_device_write_uid(dev);

acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);

Expand Down
2 changes: 0 additions & 2 deletions src/drivers/i2c/adm1026/Kconfig

This file was deleted.

1 change: 0 additions & 1 deletion src/drivers/i2c/adm1026/Makefile.inc

This file was deleted.

71 changes: 0 additions & 71 deletions src/drivers/i2c/adm1026/adm1026.c

This file was deleted.

2 changes: 0 additions & 2 deletions src/drivers/i2c/adm1027/Kconfig

This file was deleted.

1 change: 0 additions & 1 deletion src/drivers/i2c/adm1027/Makefile.inc

This file was deleted.

77 changes: 0 additions & 77 deletions src/drivers/i2c/adm1027/adm1027.c

This file was deleted.

2 changes: 0 additions & 2 deletions src/drivers/i2c/i2cmux/Kconfig

This file was deleted.

1 change: 0 additions & 1 deletion src/drivers/i2c/i2cmux/Makefile.inc

This file was deleted.

45 changes: 0 additions & 45 deletions src/drivers/i2c/i2cmux/i2cmux.c

This file was deleted.

2 changes: 0 additions & 2 deletions src/drivers/i2c/i2cmux2/Kconfig

This file was deleted.

1 change: 0 additions & 1 deletion src/drivers/i2c/i2cmux2/Makefile.inc

This file was deleted.

44 changes: 0 additions & 44 deletions src/drivers/i2c/i2cmux2/i2cmux2.c

This file was deleted.

2 changes: 0 additions & 2 deletions src/drivers/i2c/lm63/Kconfig

This file was deleted.

1 change: 0 additions & 1 deletion src/drivers/i2c/lm63/Makefile.inc

This file was deleted.

47 changes: 0 additions & 47 deletions src/drivers/i2c/lm63/lm63.c

This file was deleted.

2 changes: 0 additions & 2 deletions src/drivers/i2c/w83795/Kconfig

This file was deleted.

1 change: 0 additions & 1 deletion src/drivers/i2c/w83795/Makefile.inc

This file was deleted.

145 changes: 0 additions & 145 deletions src/drivers/i2c/w83795/chip.h

This file was deleted.

386 changes: 0 additions & 386 deletions src/drivers/i2c/w83795/w83795.c

This file was deleted.

88 changes: 0 additions & 88 deletions src/drivers/i2c/w83795/w83795.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/drivers/intel/fsp1_1/logo.c
Expand Up @@ -26,7 +26,7 @@ const struct cbmem_entry *fsp_load_logo(UINT32 *logo_ptr, UINT32 *logo_size)
if (logo_buffer) {
*logo_size = cbfs_boot_load_file("logo.bmp", (void *)logo_buffer,
1 * MiB, CBFS_TYPE_RAW);
if (logo_size)
if (*logo_size)
*logo_ptr = (UINT32)logo_buffer;
}
}
Expand Down
6 changes: 0 additions & 6 deletions src/drivers/intel/fsp1_1/ramstage.c
Expand Up @@ -209,9 +209,3 @@ __weak void soc_display_silicon_init_params(
__weak void soc_silicon_init_params(SILICON_INIT_UPD *params)
{
}

/* Load bmp and set FSP parameters, fsp_load_logo can be used */
__weak const struct cbmem_entry *soc_load_logo(SILICON_INIT_UPD *params)
{
return NULL;
}
2 changes: 1 addition & 1 deletion src/drivers/intel/fsp2_0/logo.c
Expand Up @@ -26,7 +26,7 @@ const struct cbmem_entry *fsp_load_logo(UINT32 *logo_ptr, UINT32 *logo_size)
if (logo_buffer) {
*logo_size = cbfs_boot_load_file("logo.bmp", (void *)logo_buffer,
1 * MiB, CBFS_TYPE_RAW);
if (logo_size)
if (*logo_size)
*logo_ptr = (UINT32)logo_buffer;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/ipmi/ipmi_kcs_ops.c
Expand Up @@ -253,7 +253,7 @@ static void ipmi_ssdt(struct device *dev)
acpigen_write_scope(scope);
acpigen_write_device("SPMI");
acpigen_write_name_string("_HID", "IPI0001");
acpigen_write_name_string("_STR", "IPMI_KCS");
acpigen_write_name_unicode("_STR", "IPMI_KCS");
acpigen_write_name_byte("_UID", dev->command);
acpigen_write_STA(0xf);
acpigen_write_name("_CRS");
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/net/r8168.c
Expand Up @@ -312,7 +312,8 @@ static void r8168_net_fill_ssdt(struct device *dev)
acpigen_write_scope(path);
acpigen_write_device(acpi_device_name(dev));
acpigen_write_name_string("_HID", R8168_ACPI_HID);
acpigen_write_name_integer("_UID", 0);
acpi_device_write_uid(dev);

if (dev->chip_ops)
acpigen_write_name_string("_DDN", dev->chip_ops->name);

Expand Down
8 changes: 7 additions & 1 deletion src/drivers/pc80/rtc/Makefile.inc
@@ -1,12 +1,18 @@
ifeq ($(CONFIG_ARCH_X86),y)

bootblock-$(CONFIG_DRIVERS_MC146818) += mc146818rtc_boot.c
all-$(CONFIG_DRIVERS_MC146818) += mc146818rtc_boot.c

bootblock-$(CONFIG_DRIVERS_MC146818) += mc146818rtc.c
postcar-$(CONFIG_DRIVERS_MC146818) += mc146818rtc.c
romstage-$(CONFIG_DRIVERS_MC146818) += mc146818rtc.c
ramstage-$(CONFIG_DRIVERS_MC146818) += mc146818rtc.c
smm-$(CONFIG_DRIVERS_MC146818) += mc146818rtc.c

all-$(CONFIG_USE_OPTION_TABLE) += option.c
smm-$(CONFIG_USE_OPTION_TABLE) += option.c

all-$(CONFIG_CMOS_POST) += post.c

ifeq ($(CONFIG_USE_OPTION_TABLE),y)
cbfs-files-$(CONFIG_HAVE_CMOS_DEFAULT) += cmos.default
cmos.default-file = $(CONFIG_CMOS_DEFAULT_FILE):nvramtool
Expand Down