4 changes: 2 additions & 2 deletions src/drivers/genesyslogic/gl9755/gl9755.c
Expand Up @@ -47,13 +47,13 @@ static struct device_operations gl9755_ops = {
};

static const unsigned short pci_device_ids[] = {
PCI_DEVICE_ID_GLI_9755,
PCI_DID_GLI_9755,
0
};

static const struct pci_driver genesyslogic_gl9755 __pci_driver = {
.ops = &gl9755_ops,
.vendor = PCI_VENDOR_ID_GLI,
.vendor = PCI_VID_GLI,
.devices = pci_device_ids,
};

Expand Down
8 changes: 7 additions & 1 deletion src/drivers/genesyslogic/gl9763e/Kconfig
@@ -1,2 +1,8 @@
config DRIVERS_GENESYSLOGIC_GL9763E
bool
bool "Genesys Logic GL9763E"
default n

config DRIVERS_GENESYSLOGIC_GL9763E_L1_MAX
bool "Set L1 entry delay to MAX"
depends on DRIVERS_GENESYSLOGIC_GL9763E
default n
9 changes: 7 additions & 2 deletions src/drivers/genesyslogic/gl9763e/gl9763e.c
Expand Up @@ -23,6 +23,11 @@ static void gl9763e_init(struct device *dev)
pci_or_config32(dev, SCR, SCR_AXI_REQ);
/* Disable L0s support */
pci_and_config32(dev, CFG_REG_2, ~CFG_REG_2_L0S);

if (CONFIG(DRIVERS_GENESYSLOGIC_GL9763E_L1_MAX))
/* Set L1 entry delay to MAX */
pci_or_config32(dev, CFG_REG_2, CFG_REG_2_L1DLY_MAX);

/* Set SSC to 30000 ppm */
pci_update_config32(dev, PLL_CTL_2, ~PLL_CTL_2_MAX_SSC_MASK, MAX_SSC_30000PPM);
/* Enable SSC */
Expand Down Expand Up @@ -50,13 +55,13 @@ static struct device_operations gl9763e_ops = {
};

static const unsigned short pci_device_ids[] = {
PCI_DEVICE_ID_GLI_9763E,
PCI_DID_GLI_9763E,
0
};

static const struct pci_driver genesyslogic_gl9763e __pci_driver = {
.ops = &gl9763e_ops,
.vendor = PCI_VENDOR_ID_GLI,
.vendor = PCI_VID_GLI,
.devices = pci_device_ids,
};

Expand Down
1 change: 1 addition & 0 deletions src/drivers/genesyslogic/gl9763e/gl9763e.h
Expand Up @@ -14,6 +14,7 @@

#define CFG_REG_2 0x8A4
#define CFG_REG_2_L0S BIT(11)
#define CFG_REG_2_L1DLY_MAX (0x3FF << 19)

#define PLL_CTL 0x938
#define PLL_CTL_SSC BIT(19)
Expand Down
3 changes: 3 additions & 0 deletions src/drivers/i2c/cs35l53/Kconfig
@@ -0,0 +1,3 @@
config DRIVERS_I2C_CS35L53
bool
depends on HAVE_ACPI_TABLES
1 change: 1 addition & 0 deletions src/drivers/i2c/cs35l53/Makefile.inc
@@ -0,0 +1 @@
ramstage-$(CONFIG_DRIVERS_I2C_CS35L53) += cs35l53.c
149 changes: 149 additions & 0 deletions src/drivers/i2c/cs35l53/chip.h
@@ -0,0 +1,149 @@
/* SPDX-License-Identifier: GPL-2.0-only */

#include <acpi/acpi_device.h>

#define CS35L53_MAX_GPIOS 2

enum cs35l53_boost_type {
INTERNAL_BOOST = 0,
EXTERNAL_BOOST = 1,
};

enum cs35l53_boost_ind_nanohenrys {
BOOST_IND_1000_NH = 1000,
BOOST_IND_1200_NH = 1200,
BOOST_IND_1500_NH = 1500,
BOOST_IND_2200_NH = 2200,
};

enum cs35l53_asp_sdout_hiz {
ASP_SDOUT_LOGIC0_UNUSED_LOGIC0_DISABLED = 0,
ASP_SDOUT_HIZ_UNUSED_LOGIC0_DISABLED = 1,
ASP_SDOUT_LOGIC0_UNUSED_HIZ_DISABLED = 2,
ASP_SDOUT_HIZ_UNUSED_HIZ_DISABLED = 3,
};

enum cs35l53_gpio1_src {
GPIO1_SRC_HIGH_IMPEDANCE = 0,
GPIO1_SRC_GPIO = 1,
GPIO1_SRC_SYNC = 2,
GPIO1_SRC_MCLK_INPUT = 3,
};

enum cs35l53_gpio2_src {
GPIO2_SRC_HIGH_IMPEDANCE = 0,
GPIO2_SRC_GPIO = 1,
GPIO2_SRC_OPEN_DRAIN = 2,
GPIO2_SRC_MCLK_INPUT = 3,
GPIO2_SRC_PUSH_PULL_INTB = 4,
GPIO2_SRC_PUSH_PULL_INT = 5,
};

/*
* Cirrus Logic CS35L53 Audio Codec devicetree bindings
* linux/Documentation/devicetree/bindings/sound/cirrus,cs35l53.yaml
*/
struct drivers_i2c_cs35l53_config {
const char *name; /* ACPI Device Name */

const char *sub; /* SUB ID to uniquely identify system */

/* Interrupt configuration */
struct acpi_irq irq;

/* Use GPIO based interrupt instead of PIRQ */
struct acpi_gpio irq_gpio;

/* Use GPIO based reset gpio */
struct acpi_gpio reset_gpio;

/* I2C Bus Frequency in Hertz (default 400kHz) */
unsigned int bus_speed;

/* Define cs35l53 parameters */
/*
* cirrus,boost-type : Configures the type of Boost being used.
* Internal boost requires boost-peak-milliamp, boost-ind-nanohenry and
* boost-cap-microfarad.
* External Boost must have GPIO1 as GPIO output. GPIO1 will be set high to
* enable boost voltage.
*/
enum cs35l53_boost_type boost_type;

/*
* cirrus,boost-peak-milliamp : Boost-converter peak current limit in mA.
* Configures the peak current by monitoring the current through the boost FET.
* Range starts at 1600 mA and goes to a maximum of 4500 mA with increments
* of 50 mA. See section 4.3.6 of the datasheet for details.
*/
unsigned int boost_peak_milliamp;

/*
* cirrus,boost-ind-nanohenry : Boost inductor value, expressed in nH. Valid
* values include 1000, 1200, 1500 and 2200.
*/
enum cs35l53_boost_ind_nanohenrys boost_ind_nanohenry;

/*
* cirrus,boost-cap-microfarad : Total equivalent boost capacitance on the VBST
* and VAMP pins, derated at 11 volts DC. The value must be rounded to the
* nearest integer and expressed in uF.
*/
unsigned int boost_cap_microfarad;

/*
* cirrus,asp-sdout-hiz : Audio serial port SDOUT Hi-Z control. Sets the Hi-Z
* configuration for SDOUT pin of amplifier.
* 0 = Logic 0 during unused slots, and while all transmit channels disabled
* 1 = Hi-Z during unused slots but logic 0 while all transmit channels disabled
* 2 = Logic 0 during unused slots, but Hi-Z while all transmit channels disabled
* 3 = Hi-Z during unused slots and while all transmit channels disabled
*/
enum cs35l53_asp_sdout_hiz asp_sdout_hiz;

/*
* cirrus,gpio1-polarity-invert : Boolean which specifies whether the GPIO1
* level is inverted.
*/
bool gpio1_polarity_invert;

/*
* cirrus,gpio2-polarity-invert : Boolean which specifies whether the GPIO2
* level is inverted.
*/
bool gpio2_polarity_invert;

/*
* cirrus,gpio1-output-enable : Boolean which specifies whether the GPIO1 pin
* is configured as an output.
*/
bool gpio1_output_enable;

/*
* cirrus,gpio2-output-enable : Boolean which specifies whether the GPIO2 pin
* is configured as an output.
*/
bool gpio2_output_enable;

/*
* cirrus,gpio1-src-select : Configures the function of the GPIO1 pin.
* GPIO1:
* 0 = High Impedance (Default)
* 1 = GPIO
* 2 = Sync
* 3 = MCLK input
*/
enum cs35l53_gpio1_src gpio1_src_select;

/*
* cirrus,gpio2-src-select : Configures the function of the GPIO2 pin.
* GPIO2:
* 0 = High Impedance (Default)
* 1 = GPIO
* 2 = Open Drain INTB
* 3 = MCLK input
* 4 = Push-pull INTB (active low)
* 5 = Push-pull INT (active high)
*/
enum cs35l53_gpio2_src gpio2_src_select;
};
147 changes: 147 additions & 0 deletions src/drivers/i2c/cs35l53/cs35l53.c
@@ -0,0 +1,147 @@
/* SPDX-License-Identifier: GPL-2.0-only */

#include <acpi/acpi.h>
#include <acpi/acpi_device.h>
#include <acpi/acpigen.h>
#include <console/console.h>
#include <device/i2c_simple.h>
#include <device/device.h>
#include <device/path.h>

#include "chip.h"

#define CS35L53_ACPI_HID "CSC3541"

static void cs35l53_fill_ssdt(const struct device *dev)
{
struct drivers_i2c_cs35l53_config *config = dev->chip_info;
const char *scope = acpi_device_scope(dev);
const char *path = acpi_device_path(dev);
struct acpi_i2c i2c = {
.address = dev->path.i2c.device,
.mode_10bit = dev->path.i2c.mode_10bit,
.speed = config->bus_speed ? : I2C_SPEED_FAST,
.resource = scope,
};
struct acpi_dp *dsd;
int gpio_index = 0;

if (!scope)
return;

/* Device */
acpigen_write_scope(scope);
acpigen_write_device(acpi_device_name(dev));
acpigen_write_name_string("_HID", CS35L53_ACPI_HID);
acpigen_write_name_integer("_UID", 0);
acpigen_write_name_string("_DDN", dev->chip_ops->name);
acpigen_write_name_string("_SUB", config->sub);
acpigen_write_STA(acpi_device_status(dev));

/* Resources */
acpigen_write_name("_CRS");
acpigen_write_resourcetemplate_header();
acpi_device_write_i2c(&i2c);
/* Use either Interrupt() or GpioInt() */
if (config->irq_gpio.pin_count)
acpi_device_write_gpio(&config->irq_gpio);
else
acpi_device_write_interrupt(&config->irq);

/* for cs35l53 reset gpio */
if (config->reset_gpio.pin_count)
acpi_device_write_gpio(&config->reset_gpio);

acpigen_write_resourcetemplate_footer();

/* Add Child Device Properties */
dsd = acpi_dp_new_table("_DSD");
if (config->irq_gpio.pin_count)
acpi_dp_add_gpio(dsd, "irq-gpios", path,
gpio_index++, /* Index = 0 */
0, /* Pin = 0 (There is a single pin in the GPIO resource). */
config->irq_gpio.active_low);
if (config->reset_gpio.pin_count)
acpi_dp_add_gpio(dsd, "reset-gpios", path,
gpio_index++, /* Index = 0 or 1 (if irq gpio is written). */
0, /* Pin = 0 (There is a single pin in the GPIO resource). */
config->reset_gpio.active_low);

acpi_dp_add_integer(dsd, "cirrus,boost-type", config->boost_type);

switch (config->boost_type) {
case INTERNAL_BOOST:
if ((config->boost_peak_milliamp > 4500) ||
(config->boost_peak_milliamp < 1600) ||
(config->boost_peak_milliamp % 50)) {
printk(BIOS_ERR,
"%s: Incorrect boost_peak_milliamp(%d). Using default of 4500 mA\n",
__func__, config->boost_peak_milliamp);
config->boost_peak_milliamp = 4500;
}
acpi_dp_add_integer(dsd, "cirrus,boost-peak-milliamp",
config->boost_peak_milliamp);
acpi_dp_add_integer(dsd, "cirrus,boost-ind-nanohenry",
config->boost_ind_nanohenry);
acpi_dp_add_integer(dsd, "cirrus,boost-cap-microfarad",
config->boost_cap_microfarad);
break;
case EXTERNAL_BOOST:
config->gpio1_output_enable = true;
config->gpio1_src_select = GPIO1_SRC_GPIO;
break;
default:
break;
}

acpi_dp_add_integer(dsd, "cirrus,asp-sdout-hiz", config->asp_sdout_hiz);
acpi_dp_add_integer(dsd, "cirrus,gpio1-polarity-invert",
config->gpio1_polarity_invert);
acpi_dp_add_integer(dsd, "cirrus,gpio1-output-enable",
config->gpio1_output_enable);
acpi_dp_add_integer(dsd, "cirrus,gpio1-src-select", config->gpio1_src_select);
acpi_dp_add_integer(dsd, "cirrus,gpio2-polarity-invert",
config->gpio2_polarity_invert);
acpi_dp_add_integer(dsd, "cirrus,gpio2-output-enable",
config->gpio2_output_enable);
acpi_dp_add_integer(dsd, "cirrus,gpio2-src-select", config->gpio2_src_select);

/* Write Device Property Hierarchy */
acpi_dp_write(dsd);

acpigen_pop_len(); /* Device */
acpigen_pop_len(); /* Scope */

printk(BIOS_INFO, "%s: %s address 0%xh irq %d\n",
acpi_device_path(dev), dev->chip_ops->name,
dev->path.i2c.device, config->irq.pin);
}

static const char *cs35l53_acpi_name(const struct device *dev)
{
struct drivers_i2c_cs35l53_config *config = dev->chip_info;
static char name[ACPI_NAME_BUFFER_SIZE];

if (config->name)
return config->name;

snprintf(name, sizeof(name), "D%03.3X", dev->path.i2c.device);
return name;
}

static struct device_operations cs35l53_ops = {
.read_resources = noop_read_resources,
.set_resources = noop_set_resources,
.acpi_name = cs35l53_acpi_name,
.acpi_fill_ssdt = cs35l53_fill_ssdt,
};

static void cs35l53_enable(struct device *dev)
{
dev->ops = &cs35l53_ops;
}

struct chip_operations drivers_i2c_cs35l53_ops = {
CHIP_NAME("Cirrus Logic CS35L53 Audio Codec")
.enable_dev = cs35l53_enable
};
10 changes: 6 additions & 4 deletions src/drivers/i2c/designware/dw_i2c.c
Expand Up @@ -13,6 +13,8 @@

/* Use a ~10ms timeout for various operations */
#define DW_I2C_TIMEOUT_US 10000
/* Timeout for waiting for FIFO to flush */
#define DW_I2C_FLUSH_TIMEOUT_US 160000

/* High and low times in different speed modes (in ns) */
enum {
Expand Down Expand Up @@ -290,7 +292,7 @@ static enum cb_err dw_i2c_wait_for_bus_idle(struct dw_i2c_regs *regs)
struct stopwatch sw;

/* Start timeout for up to 16 bytes in FIFO */
stopwatch_init_usecs_expire(&sw, 16 * DW_I2C_TIMEOUT_US);
stopwatch_init_usecs_expire(&sw, DW_I2C_FLUSH_TIMEOUT_US);

while (!stopwatch_expired(&sw)) {
uint32_t status = read32(&regs->status);
Expand All @@ -316,7 +318,7 @@ static enum cb_err dw_i2c_transfer_byte(struct dw_i2c_regs *regs,
struct stopwatch sw;
uint32_t cmd = CMD_DATA_CMD; /* Read op */

stopwatch_init_usecs_expire(&sw, DW_I2C_TIMEOUT_US);
stopwatch_init_usecs_expire(&sw, CONFIG_I2C_TRANSFER_TIMEOUT_US);

if (!(segment->flags & I2C_M_RD)) {
/* Write op only: Wait for FIFO not full */
Expand Down Expand Up @@ -409,7 +411,7 @@ static enum cb_err _dw_i2c_transfer(unsigned int bus, const struct i2c_msg *segm
}

/* Wait for interrupt status to indicate transfer is complete */
stopwatch_init_usecs_expire(&sw, DW_I2C_TIMEOUT_US);
stopwatch_init_usecs_expire(&sw, CONFIG_I2C_TRANSFER_TIMEOUT_US);
while (!(read32(&regs->raw_intr_stat) & INTR_STAT_STOP_DET)) {
if (stopwatch_expired(&sw)) {
printk(BIOS_ERR, "I2C stop bit not received\n");
Expand All @@ -436,7 +438,7 @@ static enum cb_err _dw_i2c_transfer(unsigned int bus, const struct i2c_msg *segm
}

/* Flush the RX FIFO in case it is not empty */
stopwatch_init_usecs_expire(&sw, 16 * DW_I2C_TIMEOUT_US);
stopwatch_init_usecs_expire(&sw, DW_I2C_FLUSH_TIMEOUT_US);
while (read32(&regs->status) & STATUS_RX_FIFO_NOT_EMPTY) {
if (stopwatch_expired(&sw)) {
printk(BIOS_ERR, "I2C timeout flushing RX FIFO\n");
Expand Down
28 changes: 23 additions & 5 deletions src/drivers/i2c/tpm/cr50.c
Expand Up @@ -17,14 +17,15 @@

#include <commonlib/endian.h>
#include <commonlib/helpers.h>
#include <string.h>
#include <types.h>
#include <delay.h>
#include <console/console.h>
#include <delay.h>
#include <device/i2c_simple.h>
#include <drivers/tpm/cr50.h>
#include <endian.h>
#include <timer.h>
#include <security/tpm/tis.h>
#include <string.h>
#include <types.h>
#include <timer.h>

#include "tpm.h"

Expand Down Expand Up @@ -126,7 +127,7 @@ static int cr50_i2c_read(uint8_t addr, uint8_t *buffer, size_t len)
*
* Returns -1 on error, 0 on success.
*/
static int cr50_i2c_write(uint8_t addr, uint8_t *buffer, size_t len)
static int cr50_i2c_write(uint8_t addr, const uint8_t *buffer, size_t len)
{
if (tpm_dev.addr == 0)
return -1;
Expand Down Expand Up @@ -473,6 +474,7 @@ static int cr50_i2c_probe(struct tpm_chip *chip, uint32_t *did_vid)

int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
{
struct cr50_firmware_version ver;
uint32_t did_vid = 0;

if (dev_addr == 0) {
Expand All @@ -498,10 +500,26 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
printk(BIOS_DEBUG, "cr50 TPM 2.0 (i2c %u:0x%02x id 0x%x)\n",
bus, dev_addr, did_vid >> 16);

if (tpm_first_access_this_boot()) {
/* This is called for the side-effect of printing the version string. */
cr50_get_firmware_version(&ver);
cr50_set_board_cfg();
}

chip->is_open = 1;
return 0;
}

void tpm_vendor_cleanup(struct tpm_chip *chip)
{
}

enum cb_err tis_vendor_write(unsigned int addr, const void *buffer, size_t bytes)
{
return cr50_i2c_write(addr & 0xff, buffer, bytes) ? CB_ERR : CB_SUCCESS;
}

enum cb_err tis_vendor_read(unsigned int addr, void *buffer, size_t bytes)
{
return cr50_i2c_read(addr & 0xff, buffer, bytes) ? CB_ERR : CB_SUCCESS;
}
6 changes: 3 additions & 3 deletions src/drivers/intel/fsp1_1/fsp_util.c
Expand Up @@ -134,17 +134,17 @@ void fsp_notify(u32 phase)
notify_phase_params.Phase = phase;

if (phase == EnumInitPhaseReadyToBoot) {
timestamp_add_now(TS_FSP_BEFORE_FINALIZE);
timestamp_add_now(TS_FSP_FINALIZE_START);
post_code(POST_FSP_NOTIFY_BEFORE_FINALIZE);
} else {
timestamp_add_now(TS_FSP_BEFORE_ENUMERATE);
timestamp_add_now(TS_FSP_ENUMERATE_START);
post_code(POST_FSP_NOTIFY_BEFORE_ENUMERATE);
}

status = notify_phase_proc(&notify_phase_params);

timestamp_add_now(phase == EnumInitPhaseReadyToBoot ?
TS_FSP_AFTER_FINALIZE : TS_FSP_AFTER_ENUMERATE);
TS_FSP_FINALIZE_END : TS_FSP_ENUMERATE_END);

if (status != 0)
printk(BIOS_ERR, "FSP API NotifyPhase failed for phase 0x%x with status: 0x%x\n",
Expand Down
6 changes: 3 additions & 3 deletions src/drivers/intel/fsp1_1/romstage.c
Expand Up @@ -26,7 +26,7 @@ static void raminit_common(struct romstage_params *params)

post_code(0x32);

timestamp_add_now(TS_BEFORE_INITRAM);
timestamp_add_now(TS_INITRAM_START);

s3wake = params->power_state->prev_sleep_state == ACPI_S3;

Expand Down Expand Up @@ -66,7 +66,7 @@ static void raminit_common(struct romstage_params *params)

/* Initialize RAM */
raminit(params);
timestamp_add_now(TS_AFTER_INITRAM);
timestamp_add_now(TS_INITRAM_END);

/* Save MRC output */
if (CONFIG(CACHE_MRC_SETTINGS)) {
Expand Down Expand Up @@ -100,7 +100,7 @@ void cache_as_ram_stage_main(FSP_INFO_HEADER *fih)

post_code(0x30);

timestamp_add_now(TS_START_ROMSTAGE);
timestamp_add_now(TS_ROMSTAGE_START);

/* Display parameters */
if (!CONFIG(NO_ECAM_MMCONF_SUPPORT))
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/intel/fsp2_0/memory_init.c
Expand Up @@ -380,9 +380,9 @@ void fsp_memory_init(bool s3wake)
die("FSPM XIP base does not match: %p vs %p\n",
(void *)(uintptr_t)hdr->image_base, prog_start(&fspld.fsp_prog));

timestamp_add_now(TS_BEFORE_INITRAM);
timestamp_add_now(TS_INITRAM_START);

do_fsp_memory_init(&context, s3wake);

timestamp_add_now(TS_AFTER_INITRAM);
timestamp_add_now(TS_INITRAM_END);
}
12 changes: 6 additions & 6 deletions src/drivers/intel/fsp2_0/notify.c
Expand Up @@ -23,24 +23,24 @@ static const struct fsp_notify_phase_data notify_data[] = {
.skip = !CONFIG(USE_FSP_NOTIFY_PHASE_POST_PCI_ENUM),
.post_code_before = POST_FSP_NOTIFY_BEFORE_ENUMERATE,
.post_code_after = POST_FSP_NOTIFY_AFTER_ENUMERATE,
.timestamp_before = TS_FSP_BEFORE_ENUMERATE,
.timestamp_after = TS_FSP_AFTER_ENUMERATE,
.timestamp_before = TS_FSP_ENUMERATE_START,
.timestamp_after = TS_FSP_ENUMERATE_END,
},
{
.notify_phase = READY_TO_BOOT,
.skip = !CONFIG(USE_FSP_NOTIFY_PHASE_READY_TO_BOOT),
.post_code_before = POST_FSP_NOTIFY_BEFORE_FINALIZE,
.post_code_after = POST_FSP_NOTIFY_AFTER_FINALIZE,
.timestamp_before = TS_FSP_BEFORE_FINALIZE,
.timestamp_after = TS_FSP_AFTER_FINALIZE,
.timestamp_before = TS_FSP_FINALIZE_START,
.timestamp_after = TS_FSP_FINALIZE_END,
},
{
.notify_phase = END_OF_FIRMWARE,
.skip = !CONFIG(USE_FSP_NOTIFY_PHASE_END_OF_FIRMWARE),
.post_code_before = POST_FSP_NOTIFY_BEFORE_END_OF_FIRMWARE,
.post_code_after = POST_FSP_NOTIFY_AFTER_END_OF_FIRMWARE,
.timestamp_before = TS_FSP_BEFORE_END_OF_FIRMWARE,
.timestamp_after = TS_FSP_AFTER_END_OF_FIRMWARE,
.timestamp_before = TS_FSP_END_OF_FIRMWARE_START,
.timestamp_after = TS_FSP_END_OF_FIRMWARE_END,
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/intel/gma/opregion.c
Expand Up @@ -159,7 +159,7 @@ static enum cb_err locate_vbt_vbios(const u8 *vbios, struct region_device *rdev)

/* Make sure we got an Intel VGA option rom */
if ((oprom->signature != OPROM_SIGNATURE) ||
(pcir->vendor != PCI_VENDOR_ID_INTEL) ||
(pcir->vendor != PCI_VID_INTEL) ||
(pcir->signature != 0x52494350) ||
(pcir->classcode[0] != 0x00) ||
(pcir->classcode[1] != 0x00) ||
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/intel/i210/i210.c
Expand Up @@ -187,7 +187,7 @@ static void init(struct device *dev)
/*Check first whether there is a valid MAC address available */
status = mainboard_get_mac_address(dev, adr_to_set);
if (status != CB_SUCCESS) {
printk(BIOS_ERR, "I210: No valid MAC address found\n");
printk(BIOS_NOTICE, "I210: Mainboard has no address, keep the one in MAC.\n");
return;
}
/* Before we will write a new address, check the existing one */
Expand Down Expand Up @@ -224,6 +224,6 @@ static const unsigned short i210_device_ids[] = { 0x1537, 0x1538, 0x1533, 0 };

static const struct pci_driver i210_driver __pci_driver = {
.ops = &i210_ops,
.vendor = PCI_VENDOR_ID_INTEL,
.vendor = PCI_VID_INTEL,
.devices = i210_device_ids,
};
11 changes: 6 additions & 5 deletions src/drivers/intel/ish/ish.c
Expand Up @@ -51,16 +51,17 @@ static const struct device_operations pci_ish_device_ops = {
};

static const unsigned short pci_device_ids[] = {
PCI_DEVICE_ID_INTEL_CNL_ISHB,
PCI_DEVICE_ID_INTEL_CML_ISHB,
PCI_DEVICE_ID_INTEL_TGL_ISHB,
PCI_DEVICE_ID_INTEL_TGL_H_ISHB,
PCI_DID_INTEL_MTL_ISHB,
PCI_DID_INTEL_CNL_ISHB,
PCI_DID_INTEL_CML_ISHB,
PCI_DID_INTEL_TGL_ISHB,
PCI_DID_INTEL_TGL_H_ISHB,
0
};

static const struct pci_driver ish_intel_driver __pci_driver = {
.ops = &pci_ish_device_ops,
.vendor = PCI_VENDOR_ID_INTEL,
.vendor = PCI_VID_INTEL,
.devices = pci_device_ids,
};

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/intel/usb4/retimer/retimer.c
Expand Up @@ -358,7 +358,7 @@ static void usb4_retimer_fill_ssdt(const struct device *dev)
for (dfp_port = 0; dfp_port < DFP_NUM_MAX; dfp_port++) {

if (!config->dfp[dfp_port].power_gpio.pin_count) {
printk(BIOS_ERR, "%s: No DFP%1d power GPIO for %s\n",
printk(BIOS_WARNING, "%s: No DFP%1d power GPIO for %s\n",
__func__, dfp_port, dev_path(dev));
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/mipi/panel.c
Expand Up @@ -4,7 +4,7 @@
#include <delay.h>
#include <mipi/panel.h>

cb_err_t mipi_panel_parse_init_commands(const void *buf, mipi_cmd_func_t cmd_func)
enum cb_err mipi_panel_parse_init_commands(const void *buf, mipi_cmd_func_t cmd_func)
{
const struct panel_init_command *init = buf;
enum mipi_dsi_transaction type;
Expand Down Expand Up @@ -68,7 +68,7 @@ cb_err_t mipi_panel_parse_init_commands(const void *buf, mipi_cmd_func_t cmd_fun
return CB_ERR;
}

cb_err_t ret = cmd_func(type, init->data, len);
enum cb_err ret = cmd_func(type, init->data, len);
if (ret != CB_SUCCESS)
return ret;
buf += len;
Expand Down
9 changes: 5 additions & 4 deletions src/drivers/net/r8168.c
Expand Up @@ -267,7 +267,7 @@ static void r8168_set_customized_led(struct device *dev, u16 io_base)
if (!config)
return;

if (dev->device == PCI_DEVICE_ID_REALTEK_8125) {
if (dev->device == PCI_DID_REALTEK_8125) {
/* Set LED global Feature register */
outb(config->led_feature, io_base + CMD_LED_FEATURE);
printk(BIOS_DEBUG, "r8125: read back LED global feature setting as 0x%x\n",
Expand Down Expand Up @@ -425,14 +425,15 @@ static struct device_operations r8168_ops = {
};

static const unsigned short pci_device_ids[] = {
PCI_DEVICE_ID_REALTEK_8168,
PCI_DEVICE_ID_REALTEK_8125,
PCI_DID_REALTEK_8168,
PCI_DID_REALTEK_8125,
PCI_DID_REALTEK_8111,
0
};

static const struct pci_driver r8168_driver __pci_driver = {
.ops = &r8168_ops,
.vendor = PCI_VENDOR_ID_REALTEK,
.vendor = PCI_VID_REALTEK,
.devices = pci_device_ids,
};

Expand Down
12 changes: 6 additions & 6 deletions src/drivers/parade/ps8640/ps8640.c
Expand Up @@ -81,12 +81,12 @@ int ps8640_init(uint8_t bus, uint8_t chip)
return 0;
}

static cb_err_t ps8640_bridge_aux_request(uint8_t bus,
uint8_t chip,
unsigned int target_reg,
unsigned int total_size,
enum aux_request request,
uint8_t *data)
static enum cb_err ps8640_bridge_aux_request(uint8_t bus,
uint8_t chip,
unsigned int target_reg,
unsigned int total_size,
enum aux_request request,
uint8_t *data)
{
int i;
uint32_t length;
Expand Down
8 changes: 2 additions & 6 deletions src/drivers/pc80/tpm/tis.c
Expand Up @@ -779,12 +779,8 @@ static void lpc_tpm_set_resources(struct device *dev)
#if CONFIG(HAVE_ACPI_TABLES)
static void lpc_tpm_fill_ssdt(const struct device *dev)
{
const char *path = acpi_device_path(dev->bus->dev);

if (!path) {
path = "\\_SB_.PCI0.LPCB";
printk(BIOS_DEBUG, "Using default TPM ACPI path: '%s'\n", path);
}
/* Windows 11 requires the following path for TPM to be detected */
const char *path = "\\_SB_.PCI0";

/* Device */
acpigen_write_scope(path);
Expand Down
7 changes: 3 additions & 4 deletions src/drivers/pcie/generic/Kconfig
Expand Up @@ -5,7 +5,6 @@ config DRIVERS_PCIE_GENERIC
help
This driver allows attaching arbitrary ACPI properties to
arbitrary PCI root ports or devices. Currently it supports one
property, "UntrustedDevice". This property indicates to the
operating system that the PCIe device may be considered
untrusted, and appropriate policies, e.g. IOMMU isolation,
should take place.
property, "DmaProperty", which indicates to the operating system that
the PCIe device may be considered untrusted, and appropriate policies,
e.g. IOMMU isolation, should take place.
8 changes: 8 additions & 0 deletions src/drivers/pcie/generic/chip.h
Expand Up @@ -7,6 +7,14 @@

struct drivers_pcie_generic_config {
bool is_untrusted;
/*
* This needs to be pointed to the device instance in the device tree when
* there is already a device with the root port so that the ACPI code to be
* generated will be added to that existing device.
* By default, an ACPI device named 'DEV0' is created under the root port if
* this does not reference to a device.
*/
DEVTREE_CONST struct device *companion_dev;
};

#endif /* _PCIE_GENERIC_H_ */
29 changes: 20 additions & 9 deletions src/drivers/pcie/generic/generic.c
Expand Up @@ -9,6 +9,10 @@

static const char *pcie_generic_acpi_name(const struct device *dev)
{
struct drivers_pcie_generic_config *config = dev->chip_info;

if (config->companion_dev)
return acpi_device_name(config->companion_dev);
return "DEV0";
}

Expand All @@ -26,22 +30,29 @@ static void pcie_generic_fill_ssdt(const struct device *dev)
if (!config || !config->is_untrusted || !dev->bus || !dev->bus->dev)
return;

const char *scope = acpi_device_path(dev->bus->dev);
const char *name = acpi_device_name(dev);
const char *scope;
const char *name;

/* Code will be generated under companion device instead if present. */
if (config->companion_dev)
scope = acpi_device_path(config->companion_dev);
else
scope = acpi_device_path(dev->bus->dev);
name = acpi_device_name(dev);
acpigen_write_scope(scope);
acpigen_write_device(name);
acpigen_write_ADR_pci_device(dev);

if (!config->companion_dev) {
acpigen_write_device(name);
acpigen_write_ADR_pci_device(dev);
}
dsd = acpi_dp_new_table("_DSD");
acpi_dp_add_integer(dsd, "UntrustedDevice", 1);
acpi_dp_add_integer(dsd, "DmaProperty", 1);
acpi_dp_write(dsd);

acpigen_write_device_end();
if (!config->companion_dev)
acpigen_write_device_end();
acpigen_write_scope_end();

printk(BIOS_INFO, "%s.%s: Enable ACPI properties for %s (%s)\n", scope, name,
dev_path(dev), dev->chip_ops->name);
dev_path(dev), dev->chip_ops->name);
}

struct device_operations pcie_generic_ops = {
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/ricoh/rce822/rce822.c
Expand Up @@ -53,7 +53,7 @@ static const unsigned short pci_device_ids[] = { 0xe822, 0xe823, 0 };

static const struct pci_driver rce822 __pci_driver = {
.ops = &rce822_ops,
.vendor = PCI_VENDOR_ID_RICOH,
.vendor = PCI_VID_RICOH,
.devices = pci_device_ids,
};

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/siemens/nc_fpga/nc_fpga.c
Expand Up @@ -165,6 +165,6 @@ static const unsigned short nc_fpga_device_ids[] = { 0x4080, 0x4091, 0 };

static const struct pci_driver nc_fpga_driver __pci_driver = {
.ops = &nc_fpga_ops,
.vendor = PCI_VENDOR_ID_SIEMENS,
.vendor = PCI_VID_SIEMENS,
.devices = nc_fpga_device_ids,
};
2 changes: 1 addition & 1 deletion src/drivers/siemens/nc_fpga/nc_fpga_early.c
Expand Up @@ -17,7 +17,7 @@ int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base)
pci_devfn_t pci_dev = PCI_DEV(bus, dev, 0);
uint32_t id = pci_s_read_config32(pci_dev, PCI_VENDOR_ID);

if (id != (0x4091 << 16 | PCI_VENDOR_ID_SIEMENS))
if (id != (0x4091 << 16 | PCI_VID_SIEMENS))
return -1;

/* Setup base address for BAR0. */
Expand Down
269 changes: 67 additions & 202 deletions src/drivers/spi/tpm/tpm.c

Large diffs are not rendered by default.

16 changes: 3 additions & 13 deletions src/drivers/spi/tpm/tpm.h
Expand Up @@ -3,9 +3,12 @@
#ifndef __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H
#define __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H

#include <drivers/tpm/cr50.h>
#include <stddef.h>
#include <spi-generic.h>

#define TPM_LOCALITY_0_SPI_BASE 0x00d40000

/*
* A tpm device descriptor, values read from the appropriate device regisrers
* are cached here.
Expand All @@ -16,13 +19,6 @@ struct tpm2_info {
uint16_t revision;
};

/* Structure describing the elements of Cr50 firmware version. */
struct cr50_firmware_version {
int epoch;
int major;
int minor;
};

/*
* Initialize a TPM2 device: read its id, claim locality of zero, verify that
* this indeed is a TPM2 device. Use the passed in handle to access the right
Expand All @@ -47,10 +43,4 @@ size_t tpm2_process_command(const void *tpm2_command, size_t command_size,
/* Get information about previously initialized TPM device. */
void tpm2_get_info(struct tpm2_info *info);

/* Indicates whether Cr50 ready pulses are guaranteed to be at least 100us. */
bool cr50_is_long_interrupt_pulse_enabled(void);

/* Get the cr50 firmware version information. */
void cr50_get_firmware_version(struct cr50_firmware_version *version);

#endif /* ! __COREBOOT_SRC_DRIVERS_SPI_TPM_TPM_H */
16 changes: 8 additions & 8 deletions src/drivers/ti/sn65dsi86bridge/sn65dsi86bridge.c
Expand Up @@ -155,12 +155,12 @@ static const unsigned int sn65dsi86_bridge_dp_rate_lut[] = {
0, 1620, 2160, 2430, 2700, 3240, 4320, 5400
};

static cb_err_t sn65dsi86_bridge_aux_request(uint8_t bus,
uint8_t chip,
unsigned int target_reg,
unsigned int total_size,
enum aux_request request,
uint8_t *data)
static enum cb_err sn65dsi86_bridge_aux_request(uint8_t bus,
uint8_t chip,
unsigned int target_reg,
unsigned int total_size,
enum aux_request request,
uint8_t *data)
{
int i;
uint32_t length;
Expand Down Expand Up @@ -217,9 +217,9 @@ static cb_err_t sn65dsi86_bridge_aux_request(uint8_t bus,
return CB_SUCCESS;
}

cb_err_t sn65dsi86_bridge_read_edid(uint8_t bus, uint8_t chip, struct edid *out)
enum cb_err sn65dsi86_bridge_read_edid(uint8_t bus, uint8_t chip, struct edid *out)
{
cb_err_t err;
enum cb_err err;
u8 edid[EDID_LENGTH * 2];
int edid_size = EDID_LENGTH;

Expand Down
6 changes: 6 additions & 0 deletions src/drivers/tpm/Makefile.inc
Expand Up @@ -5,3 +5,9 @@ ramstage-$(CONFIG_HAVE_ACPI_TABLES) += ppi.c
else
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += ppi_stub.c
endif

bootblock-$(CONFIG_TPM_CR50) += cr50.c
verstage-$(CONFIG_TPM_CR50) += cr50.c
romstage-$(CONFIG_TPM_CR50) += cr50.c
ramstage-$(CONFIG_TPM_CR50) += cr50.c
postcar-$(CONFIG_TPM_CR50) += cr50.c
216 changes: 216 additions & 0 deletions src/drivers/tpm/cr50.c
@@ -0,0 +1,216 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#include <drivers/spi/tpm/tpm.h>
#include <security/tpm/tis.h>
#include <string.h>
#include <types.h>

#define CR50_BOARD_CFG_LOCKBIT_MASK 0x80000000U
#define CR50_BOARD_CFG_FEATUREBITS_MASK 0x3FFFFFFFU

#define CR50_BOARD_CFG_100US_READY_PULSE 0x00000001U
#define CR50_BOARD_CFG_VALUE \
(CONFIG(CR50_USE_LONG_INTERRUPT_PULSES) \
? CR50_BOARD_CFG_100US_READY_PULSE : 0)

enum cr50_register {
CR50_FW_VER_REG,
CR50_BOARD_CFG_REG,
};

#define CR50_FW_VER_REG_SPI (TPM_LOCALITY_0_SPI_BASE + 0xf90)
#define CR50_BOARD_CFG_REG_SPI (TPM_LOCALITY_0_SPI_BASE + 0xfe0)

#define CR50_FW_VER_REG_I2C 0x0f
#define CR50_BOARD_CFG_REG_I2C 0x1c

/* Return register address, which depends on the bus type, or -1 for error. */
static int get_reg_addr(enum cr50_register reg)
{
if (CONFIG(SPI_TPM)) {
switch (reg) {
case CR50_FW_VER_REG:
return CR50_FW_VER_REG_SPI;
case CR50_BOARD_CFG_REG:
return CR50_BOARD_CFG_REG_SPI;
default:
return -1;
}
}

if (CONFIG(I2C_TPM)) {
switch (reg) {
case CR50_FW_VER_REG:
return CR50_FW_VER_REG_I2C;
case CR50_BOARD_CFG_REG:
return CR50_BOARD_CFG_REG_I2C;
default:
return -1;
}
}

return -1;
}

static bool cr50_fw_supports_board_cfg(struct cr50_firmware_version *version)
{
/* Cr50 supports the CR50_BOARD_CFG register from version 0.5.5 / 0.6.5
* and onwards. */
if (version->epoch > 0 || version->major >= 7
|| (version->major >= 5 && version->minor >= 5))
return true;

printk(BIOS_INFO, "Cr50 firmware does not support CR50_BOARD_CFG, version: %d.%d.%d\n",
version->epoch, version->major, version->minor);

return false;
}

/*
* Expose method to read the CR50_BOARD_CFG register, will return zero if
* register not supported by Cr50 firmware.
*/
static uint32_t cr50_get_board_cfg(void)
{
struct cr50_firmware_version ver;
uint32_t value;

if (cr50_get_firmware_version(&ver) != CB_SUCCESS)
return 0;

if (!cr50_fw_supports_board_cfg(&ver))
return 0;

const enum cb_err ret = tis_vendor_read(get_reg_addr(CR50_BOARD_CFG_REG), &value,
sizeof(value));
if (ret != CB_SUCCESS) {
printk(BIOS_INFO, "Error reading from cr50\n");
return 0;
}

return value & CR50_BOARD_CFG_FEATUREBITS_MASK;
}

/**
* Set the BOARD_CFG register on the TPM chip to a particular compile-time constant value.
*/
enum cb_err cr50_set_board_cfg(void)
{
struct cr50_firmware_version ver;
enum cb_err ret;
uint32_t value;

if (cr50_get_firmware_version(&ver) != CB_SUCCESS)
return CB_ERR;

if (!cr50_fw_supports_board_cfg(&ver))
return CB_ERR;

/* Set the CR50_BOARD_CFG register, for e.g. asking cr50 to use longer ready pulses. */
ret = tis_vendor_read(get_reg_addr(CR50_BOARD_CFG_REG), &value, sizeof(value));
if (ret != CB_SUCCESS) {
printk(BIOS_INFO, "Error reading from cr50\n");
return CB_ERR;
}

if ((value & CR50_BOARD_CFG_FEATUREBITS_MASK) == CR50_BOARD_CFG_VALUE) {
printk(BIOS_INFO, "Current CR50_BOARD_CFG = 0x%08x, matches desired = 0x%08x\n",
value, CR50_BOARD_CFG_VALUE);
return CB_SUCCESS;
}

if (value & CR50_BOARD_CFG_LOCKBIT_MASK) {
/* The high bit is set, meaning that the Cr50 is already locked on a particular
* value for the register, but not the one we wanted. */
printk(BIOS_ERR, "Current CR50_BOARD_CFG = 0x%08x, does not match"
"desired = 0x%08x\n", value, CR50_BOARD_CFG_VALUE);
return CB_ERR;
}

printk(BIOS_INFO, "Current CR50_BOARD_CFG = 0x%08x, setting to 0x%08x\n",
value, CR50_BOARD_CFG_VALUE);
value = CR50_BOARD_CFG_VALUE;

ret = tis_vendor_write(get_reg_addr(CR50_BOARD_CFG_REG), &value, sizeof(value));
if (ret != CB_SUCCESS) {
printk(BIOS_ERR, "Error writing to cr50\n");
return ret;
}

return CB_SUCCESS;
}

bool cr50_is_long_interrupt_pulse_enabled(void)
{
return !!(cr50_get_board_cfg() & CR50_BOARD_CFG_100US_READY_PULSE);
}

static enum cb_err cr50_parse_fw_version(const char *version_str,
struct cr50_firmware_version *ver)
{
int epoch, major, minor;

char *number = strstr(version_str, " RW_A:");
if (!number)
number = strstr(version_str, " RW_B:");
if (!number)
return CB_ERR_ARG;
number += 6; /* Skip past the colon. */

epoch = skip_atoi(&number);
if (*number++ != '.')
return CB_ERR_ARG;
major = skip_atoi(&number);
if (*number++ != '.')
return CB_ERR_ARG;
minor = skip_atoi(&number);

ver->epoch = epoch;
ver->major = major;
ver->minor = minor;
return CB_SUCCESS;
}

enum cb_err cr50_get_firmware_version(struct cr50_firmware_version *version)
{
static struct cr50_firmware_version cr50_firmware_version;

if (cr50_firmware_version.epoch || cr50_firmware_version.major ||
cr50_firmware_version.minor)
goto success;

int chunk_count = 0;
size_t chunk_size = 50;
char version_str[301];
int addr = get_reg_addr(CR50_FW_VER_REG);

/*
* Does not really matter what's written, this just makes sure
* the version is reported from the beginning.
*/
tis_vendor_write(addr, &chunk_size, 1);

/*
* Read chunk_size bytes at a time, last chunk will be zero padded.
*/
do {
uint8_t *buf = (uint8_t *)version_str + chunk_count * chunk_size;
tis_vendor_read(addr, buf, chunk_size);
if (!version_str[++chunk_count * chunk_size - 1])
/* Zero padding detected: end of string. */
break;
/* Check if there is enough room for reading one more chunk. */
} while (chunk_count * chunk_size < sizeof(version_str) - chunk_size);

version_str[chunk_count * chunk_size] = '\0';
printk(BIOS_INFO, "Firmware version: %s\n", version_str);

if (cr50_parse_fw_version(version_str, &cr50_firmware_version) != CB_SUCCESS) {
printk(BIOS_ERR, "Did not recognize Cr50 version format\n");
return CB_ERR;
}

success:
*version = cr50_firmware_version;
return CB_SUCCESS;
}
24 changes: 24 additions & 0 deletions src/drivers/tpm/cr50.h
@@ -0,0 +1,24 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#ifndef __DRIVERS_TPM_CR50_H__
#define __DRIVERS_TPM_CR50_H__

#include <types.h>

/* Structure describing the elements of Cr50 firmware version. */
struct cr50_firmware_version {
int epoch;
int major;
int minor;
};

/* Indicates whether Cr50 ready pulses are guaranteed to be at least 100us. */
bool cr50_is_long_interrupt_pulse_enabled(void);

/* Get the Cr50 firmware version information. */
enum cb_err cr50_get_firmware_version(struct cr50_firmware_version *version);

/* Set the BOARD_CFG register depending on Cr50 Kconfigs */
enum cb_err cr50_set_board_cfg(void);

#endif /* __DRIVERS_TPM_CR50_H__ */
10 changes: 5 additions & 5 deletions src/drivers/usb/pci_xhci/pci_xhci.c
Expand Up @@ -253,15 +253,15 @@ static const struct device_operations xhci_pci_ops = {
};

static const unsigned short amd_pci_device_ids[] = {
PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_XHCI0,
PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_XHCI1,
PCI_DEVICE_ID_AMD_FAM17H_MODEL20H_XHCI0,
PCI_DEVICE_ID_AMD_FAM17H_MODEL60H_XHCI,
PCI_DID_AMD_FAM17H_MODEL18H_XHCI0,
PCI_DID_AMD_FAM17H_MODEL18H_XHCI1,
PCI_DID_AMD_FAM17H_MODEL20H_XHCI0,
PCI_DID_AMD_FAM17H_MODEL60H_XHCI,
0
};

static const struct pci_driver xhci_pci_driver __pci_driver = {
.ops = &xhci_pci_ops,
.vendor = PCI_VENDOR_ID_AMD,
.vendor = PCI_VID_AMD,
.devices = amd_pci_device_ids,
};
6 changes: 3 additions & 3 deletions src/drivers/vpd/vpd.c
Expand Up @@ -126,7 +126,7 @@ static void cbmem_add_cros_vpd(int is_recovery)
{
struct vpd_cbmem *cbmem;

timestamp_add_now(TS_START_COPYVPD);
timestamp_add_now(TS_COPYVPD_START);

init_vpd_rdevs();

Expand Down Expand Up @@ -154,7 +154,7 @@ static void cbmem_add_cros_vpd(int is_recovery)
printk(BIOS_ERR, "Couldn't read RO VPD\n");
cbmem->ro_size = ro_size = 0;
}
timestamp_add_now(TS_END_COPYVPD_RO);
timestamp_add_now(TS_COPYVPD_RO_END);
}

if (rw_size) {
Expand All @@ -163,7 +163,7 @@ static void cbmem_add_cros_vpd(int is_recovery)
printk(BIOS_ERR, "Couldn't read RW VPD\n");
cbmem->rw_size = rw_size = 0;
}
timestamp_add_now(TS_END_COPYVPD_RW);
timestamp_add_now(TS_COPYVPD_RW_END);
}

init_vpd_rdevs_from_cbmem();
Expand Down
2 changes: 2 additions & 0 deletions src/drivers/wifi/generic/Makefile.inc
@@ -1,6 +1,8 @@

ifeq ($(CONFIG_DRIVERS_WIFI_GENERIC),y)

romstage-y += generic.c

ramstage-y += generic.c
ramstage-$(CONFIG_GENERATE_SMBIOS_TABLES) += smbios.c
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpi.c
Expand Down
107 changes: 85 additions & 22 deletions src/drivers/wifi/generic/acpi.c
Expand Up @@ -10,11 +10,15 @@
#include <wrdd.h>

#include "chip.h"
#include "wifi.h"
#include "wifi_private.h"

/* WIFI Domain type */
#define DOMAIN_TYPE_WIFI 0x7

/* Maximum number DSM UUID bifurcations in _DSM */
#define MAX_DSM_FUNCS 2

/*
* WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
* The above representation returns unique and consistent name every time
Expand All @@ -26,8 +30,11 @@
/* Unique ID for the WIFI _DSM */
#define ACPI_DSM_OEM_WIFI_UUID "F21202BF-8F78-4DC6-A5B3-1F738E285ADE"

/* Unique ID for the Wifi _DSD */
#define ACPI_DSD_UNTRUSTED_UUID "88566a92-1a61-466d-949a-6d12809d480c"
/* ID for the Wifi DmaProperty _DSD */
#define ACPI_DSD_DMA_PROPERTY_UUID "70D24161-6DD5-4C9E-8070-705531292865"

/* Unique ID for CnviDdrRfim entry in WIFI _DSM */
#define ACPI_DSM_RFIM_WIFI_UUID "7266172C-220B-4B29-814F-75E4DD26B5FD"

__weak int get_wifi_sar_limits(union wifi_sar_limits *sar_limits)
{
Expand Down Expand Up @@ -145,6 +152,12 @@ static void wifi_dsm_unii4_control_enable(void *args)
acpigen_write_return_integer(dsm_config->unii_4);
}

static void wifi_dsm_ddrrfim_func3_cb(void *ptr)
{
const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr;
acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 1 : 0);
}

static void (*wifi_dsm_callbacks[])(void *) = {
NULL, /* Function 0 */
wifi_dsm_srd_active_channels, /* Function 1 */
Expand All @@ -156,6 +169,17 @@ static void (*wifi_dsm_callbacks[])(void *) = {
wifi_dsm_unii4_control_enable, /* Function 7 */
};

/*
* The current DSM2 table is only exporting one function (function 3), some more
* functions are reserved so marking them NULL.
*/
static void (*wifi_dsm2_callbacks[])(void *) = {
NULL, /* Function 0 */
NULL, /* Function 1 */
NULL, /* Function 2 */
wifi_dsm_ddrrfim_func3_cb, /* Function 3 */
};

void wifi_emit_dsm(struct dsm_profile *dsm)
{
int i;
Expand Down Expand Up @@ -462,15 +486,15 @@ static void sar_emit_wtas(struct avg_profile *wtas)
acpigen_write_package_end();
}

static void emit_sar_acpi_structures(const struct device *dev)
static void emit_sar_acpi_structures(const struct device *dev, struct dsm_profile *dsm)
{
union wifi_sar_limits sar_limits;
union wifi_sar_limits sar_limits = {{NULL, NULL, NULL, NULL, NULL} };

/*
* If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
* ACPI tables are currently used only by Intel WiFi devices.
*/
if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VENDOR_ID_INTEL)
if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL)
return;

/* Retrieve the sar limits data */
Expand All @@ -484,7 +508,10 @@ static void emit_sar_acpi_structures(const struct device *dev)
sar_emit_wgds(sar_limits.wgds);
sar_emit_ppag(sar_limits.ppag);
sar_emit_wtas(sar_limits.wtas);
wifi_emit_dsm(sar_limits.dsm);

/* copy the dsm data to be later used for creating _DSM function */
if (sar_limits.dsm != NULL)
memcpy(dsm, &sar_limits.dsm, sizeof(struct dsm_profile));

free(sar_limits.sar);
}
Expand All @@ -506,24 +533,30 @@ static void wifi_ssdt_write_device(const struct device *dev, const char *path)

static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
{
bool is_cnvi_ddr_rfim_enabled = false;

const struct drivers_wifi_generic_config *config = dev->chip_info;
if (dev && config)
is_cnvi_ddr_rfim_enabled = config->enable_cnvi_ddr_rfim;

/* Scope */
acpigen_write_scope(scope);

if (config) {
/* Wake capabilities */
acpigen_write_PRW(config->wake, ACPI_S3);

/* Add _DSD for UntrustedDevice property. */
if (config->is_untrusted) {
struct acpi_dp *dsd, *pkg;

dsd = acpi_dp_new_table("_DSD");
pkg = acpi_dp_new_table(ACPI_DSD_UNTRUSTED_UUID);
acpi_dp_add_integer(pkg, "UntrustedDevice", 1);
acpi_dp_add_package(dsd, pkg);
acpi_dp_write(dsd);
if (dev->path.type == DEVICE_PATH_GENERIC) {
if (config) {
/* Wake capabilities */
acpigen_write_PRW(config->wake, ACPI_S3);

/* Add _DSD for DmaProperty property. */
if (config->is_untrusted) {
struct acpi_dp *dsd, *pkg;

dsd = acpi_dp_new_table("_DSD");
pkg = acpi_dp_new_table(ACPI_DSD_DMA_PROPERTY_UUID);
acpi_dp_add_integer(pkg, "DmaProperty", 1);
acpi_dp_add_package(dsd, pkg);
acpi_dp_write(dsd);
}
}
}

Expand All @@ -548,9 +581,37 @@ static void wifi_ssdt_write_properties(const struct device *dev, const char *sco
acpigen_pop_len();
}

struct dsm_uuid dsm_ids[MAX_DSM_FUNCS];
/* We will need a copy dsm data to be used later for creating _DSM function */
struct dsm_profile dsm = {0};
uint8_t dsm_count = 0;

/* Fill Wifi sar related ACPI structures */
if (CONFIG(USE_SAR))
emit_sar_acpi_structures(dev);
if (CONFIG(USE_SAR)) {
emit_sar_acpi_structures(dev, &dsm);

if (dsm.supported_functions != 0) {
for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++)
if (!(dsm.supported_functions & (1 << i)))
wifi_dsm_callbacks[i] = NULL;

dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID;
dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0];
dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks);
dsm_ids[dsm_count].arg = NULL;
dsm_count++;
}
}

if (is_cnvi_ddr_rfim_enabled) {
dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID;
dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0];
dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks);
dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled;
dsm_count++;
}

acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count);

acpigen_pop_len(); /* Scope */

Expand All @@ -567,7 +628,9 @@ void wifi_pcie_fill_ssdt(const struct device *dev)
return;

wifi_ssdt_write_device(dev, path);
wifi_ssdt_write_properties(dev, path);
const struct device *child = dev->link_list->children;
if (child && child->path.type == DEVICE_PATH_GENERIC)
wifi_ssdt_write_properties(child, path);
}

const char *wifi_pcie_acpi_name(const struct device *dev)
Expand Down
9 changes: 8 additions & 1 deletion src/drivers/wifi/generic/chip.h
Expand Up @@ -10,8 +10,15 @@
struct drivers_wifi_generic_config {
unsigned int wake;
/* When set to true, this will add a _DSD which contains a single
property, `UntrustedDevice`, set to 1, to the ACPI Device. */
property, `DmaProperty`, set to 1, under the ACPI Device. */
bool is_untrusted;

/*
* Applicable for Intel chipsets that use CNVi WiFi only. Set this to 1
* to enable CNVi DDR RFIM (radio frequency interference mitigation);
* SoC code propagates this value the applicable FSP UPD.
*/
bool enable_cnvi_ddr_rfim;
};

#endif /* _GENERIC_WIFI_H_ */
95 changes: 58 additions & 37 deletions src/drivers/wifi/generic/generic.c
Expand Up @@ -7,6 +7,7 @@
#include <elog.h>
#include "chip.h"
#include "wifi_private.h"
#include "wifi.h"

static void wifi_pci_dev_init(struct device *dev)
{
Expand All @@ -20,6 +21,7 @@ struct device_operations wifi_pcie_ops = {
.enable_resources = pci_dev_enable_resources,
.init = wifi_pci_dev_init,
.ops_pci = &pci_dev_ops_pci,
.scan_bus = scan_static_bus,
#if CONFIG(HAVE_ACPI_TABLES)
.acpi_name = wifi_pcie_acpi_name,
.acpi_fill_ssdt = wifi_pcie_fill_ssdt,
Expand All @@ -40,17 +42,36 @@ struct device_operations wifi_cnvi_ops = {
#endif
};

static void wifi_generic_enable(struct device *dev)
struct device_operations wifi_generic_ops = {
.read_resources = noop_read_resources,
.set_resources = noop_set_resources,
};

static bool is_cnvi(const struct device *dev)
{
struct drivers_wifi_generic_config *config = dev ? dev->chip_info : NULL;
return dev && dev->path.type != DEVICE_PATH_PCI;
}

if (!config)
return;
bool wifi_generic_cnvi_ddr_rfim_enabled(const struct device *dev)
{
const struct drivers_wifi_generic_config *config;

if (dev->path.type == DEVICE_PATH_PCI)
dev->ops = &wifi_pcie_ops;
if (!dev || !is_cnvi(dev) || !dev->chip_info)
return false;

config = dev->chip_info;
return config->enable_cnvi_ddr_rfim;
}

static void wifi_generic_enable(struct device *dev)
{
#if !DEVTREE_EARLY
const struct device *parent = dev->bus->dev;
if (parent && parent->ops == &wifi_pcie_ops)
dev->ops = &wifi_generic_ops;
else
dev->ops = &wifi_cnvi_ops;
#endif
}

struct chip_operations drivers_wifi_generic_ops = {
Expand All @@ -59,44 +80,44 @@ struct chip_operations drivers_wifi_generic_ops = {
};

static const unsigned short intel_pci_device_ids[] = {
PCI_DEVICE_ID_1000_SERIES_WIFI,
PCI_DEVICE_ID_6005_SERIES_WIFI,
PCI_DEVICE_ID_6005_I_SERIES_WIFI,
PCI_DEVICE_ID_1030_SERIES_WIFI,
PCI_DEVICE_ID_6030_I_SERIES_WIFI,
PCI_DEVICE_ID_6030_SERIES_WIFI,
PCI_DEVICE_ID_6150_SERIES_WIFI,
PCI_DEVICE_ID_2030_SERIES_WIFI,
PCI_DEVICE_ID_2000_SERIES_WIFI,
PCI_DEVICE_ID_0135_SERIES_WIFI,
PCI_DEVICE_ID_0105_SERIES_WIFI,
PCI_DEVICE_ID_6035_SERIES_WIFI,
PCI_DEVICE_ID_5300_SERIES_WIFI,
PCI_DEVICE_ID_5100_SERIES_WIFI,
PCI_DEVICE_ID_6000_SERIES_WIFI,
PCI_DEVICE_ID_6000_I_SERIES_WIFI,
PCI_DEVICE_ID_5350_SERIES_WIFI,
PCI_DEVICE_ID_5150_SERIES_WIFI,
PCI_DID_1000_SERIES_WIFI,
PCI_DID_6005_SERIES_WIFI,
PCI_DID_6005_I_SERIES_WIFI,
PCI_DID_1030_SERIES_WIFI,
PCI_DID_6030_I_SERIES_WIFI,
PCI_DID_6030_SERIES_WIFI,
PCI_DID_6150_SERIES_WIFI,
PCI_DID_2030_SERIES_WIFI,
PCI_DID_2000_SERIES_WIFI,
PCI_DID_0135_SERIES_WIFI,
PCI_DID_0105_SERIES_WIFI,
PCI_DID_6035_SERIES_WIFI,
PCI_DID_5300_SERIES_WIFI,
PCI_DID_5100_SERIES_WIFI,
PCI_DID_6000_SERIES_WIFI,
PCI_DID_6000_I_SERIES_WIFI,
PCI_DID_5350_SERIES_WIFI,
PCI_DID_5150_SERIES_WIFI,
/* Wilkins Peak 2 */
PCI_DEVICE_ID_WP_7260_SERIES_1_WIFI,
PCI_DEVICE_ID_WP_7260_SERIES_2_WIFI,
PCI_DID_WP_7260_SERIES_1_WIFI,
PCI_DID_WP_7260_SERIES_2_WIFI,
/* Stone Peak 2 */
PCI_DEVICE_ID_SP_7265_SERIES_1_WIFI,
PCI_DEVICE_ID_SP_7265_SERIES_2_WIFI,
PCI_DID_SP_7265_SERIES_1_WIFI,
PCI_DID_SP_7265_SERIES_2_WIFI,
/* Stone Field Peak */
PCI_DEVICE_ID_SFP_8260_SERIES_1_WIFI,
PCI_DEVICE_ID_SFP_8260_SERIES_2_WIFI,
PCI_DID_SFP_8260_SERIES_1_WIFI,
PCI_DID_SFP_8260_SERIES_2_WIFI,
/* Windstorm Peak */
PCI_DEVICE_ID_WSP_8275_SERIES_1_WIFI,
PCI_DID_WSP_8275_SERIES_1_WIFI,
/* Thunder Peak 2 */
PCI_DEVICE_ID_TP_9260_SERIES_WIFI,
PCI_DID_TP_9260_SERIES_WIFI,
/* Cyclone Peak */
PCI_DEVICE_ID_CyP_6SERIES_WIFI,
PCI_DID_CyP_6SERIES_WIFI,
/* Typhoon Peak */
PCI_DEVICE_ID_TyP_6SERIES_WIFI,
PCI_DID_TyP_6SERIES_WIFI,
/* Garfield Peak */
PCI_DEVICE_ID_GrP_6SERIES_1_WIFI,
PCI_DEVICE_ID_GrP_6SERIES_2_WIFI,
PCI_DID_GrP_6SERIES_1_WIFI,
PCI_DID_GrP_6SERIES_2_WIFI,
0
};

Expand All @@ -108,6 +129,6 @@ static const unsigned short intel_pci_device_ids[] = {
*/
static const struct pci_driver intel_wifi_pci_driver __pci_driver = {
.ops = &wifi_pcie_ops,
.vendor = PCI_VENDOR_ID_INTEL,
.vendor = PCI_VID_INTEL,
.devices = intel_pci_device_ids,
};
2 changes: 1 addition & 1 deletion src/drivers/wifi/generic/smbios.c
Expand Up @@ -8,7 +8,7 @@

static int smbios_write_intel_wifi(struct device *dev, int *handle, unsigned long *current)
{
if (dev->vendor != PCI_VENDOR_ID_INTEL)
if (dev->vendor != PCI_VID_INTEL)
return 0;

struct smbios_type_intel_wifi {
Expand Down
10 changes: 10 additions & 0 deletions src/drivers/wifi/generic/wifi.h
@@ -0,0 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0-only */

#include <device/device.h>

#ifndef _WIFI_GENERIC_WIFI_H_
#define _WIFI_GENERIC_WIFI_H_

bool wifi_generic_cnvi_ddr_rfim_enabled(const struct device *dev);

#endif /* _WIFI_GENERIC_WIFI_H_ */
9 changes: 9 additions & 0 deletions src/drivers/wwan/fm/acpi_fm350gl.c
Expand Up @@ -241,6 +241,14 @@ static void wwan_fm350gl_acpi_fill_ssdt(const struct device *dev)
wwan_fm350gl_acpi_method_shrf(parent, config);
wwan_fm350gl_acpi_method_rst(parent, config);
wwan_fm350gl_acpi_method_dpts(parent, config);

if (config->add_acpi_dma_property) {
struct acpi_dp *dsd;
dsd = acpi_dp_new_table("_DSD");
acpi_dp_add_integer(dsd, "DmaProperty", 1);
acpi_dp_write(dsd);
}

/* NOTE: the 5G driver will call MRST._RST to trigger a cold reset
* during firmware update.
*/
Expand All @@ -249,6 +257,7 @@ static void wwan_fm350gl_acpi_fill_ssdt(const struct device *dev)
acpigen_write_ADR(0);
wwan_fm350gl_acpi_method_mrst_rst(parent, config);
}

acpigen_write_device_end(); /* Device */
}
acpigen_write_device_end(); /* Device */
Expand Down
3 changes: 3 additions & 0 deletions src/drivers/wwan/fm/chip.h
Expand Up @@ -20,6 +20,9 @@ struct drivers_wwan_fm_config {

/* Pointer to the corresponding RTD3 */
DEVTREE_CONST struct device *rtd3dev;

/* Add `DmaProperty` in _DSD */
bool add_acpi_dma_property;
};

#endif /* __DRIVERS_WWAN_FM_CHIP_H__ */
7 changes: 6 additions & 1 deletion src/ec/google/chromeec/ec_smbios.c
Expand Up @@ -29,11 +29,16 @@ const char *smbios_mainboard_manufacturer(void)

if (google_chromeec_cbi_get_oem_name(&oem_name[0],
ARRAY_SIZE(oem_name)) < 0) {
printk(BIOS_ERR, "Couldn't obtain OEM name from CBI\n");
printk(BIOS_INFO, "Couldn't obtain OEM name from CBI\n");
manuf = CONFIG_MAINBOARD_SMBIOS_MANUFACTURER;
} else {
manuf = &oem_name[0];
}

return manuf;
}

const char *smbios_system_manufacturer(void)
{
return "Google";
}
7 changes: 7 additions & 0 deletions src/ec/starlabs/merlin/Kconfig
Expand Up @@ -44,6 +44,13 @@ config EC_STARLABS_FAN
help
Select if the mainboard has a fan.

config EC_STARLABS_MAX_CHARGE
bool
default n
depends on EC_STARLABS_ITE
help
Select if the mainboard supports limiting the maximum charge of the battery.

config EC_STARLABS_MERLIN
bool "Use open-source Merlin EC Firmware"
default n
Expand Down
4 changes: 2 additions & 2 deletions src/ec/starlabs/merlin/acpi/ac.asl
Expand Up @@ -9,8 +9,8 @@ Device (ADP1)
}
Method (_PSR, 0)
{
PWRS = ECPS & 0x01
Return(PWRS)
PWRS = (ECRD (RefOf(ECPS)) & 0x01)
Return (PWRS)
}
Method (_PCL, 0)
{
Expand Down
25 changes: 14 additions & 11 deletions src/ec/starlabs/merlin/acpi/battery.asl
Expand Up @@ -9,13 +9,13 @@ Device (BAT0)
// Battery Status
// 0x80 BIT1 0x01 = Present
// 0x80 BIT1 0x00 = Not Present
If(ECPS & 0x02)
If (ECPS & 0x02)
{
Return(0x1F)
Return (0x1F)
}
Return(0x0F)
Return (0x0F)
}
Name (BPKG, Package(13)
Name (BPKG, Package (13)
{
1, // 0: Power Unit
0xFFFFFFFF, // 1: Design Capacity
Expand All @@ -34,30 +34,33 @@ Device (BAT0)
Method (_BIF, 0, Serialized)
{
BPKG[1] = B1DC
If (B1FC >= B1DC) {
B1FC = B1DC
}
BPKG[2] = B1FC
BPKG[4] = B1DV
If(B1FC)
If (B1FC)
{
BPKG[5] = B1FC / 10
BPKG[6] = B1FC / 100
BPKG[7] = B1DC / 100
}
Return(BPKG)
Return (BPKG)
}
Name (PKG1, Package (4)
{
0xFFFFFFFF, // Battery State
0xFFFFFFFF, // Battery Present Rate
0xFFFFFFFF, // Battery Remaining Capacity
0xFFFFFFFF, // Battery Present Voltage
0xFFFFFFFF, // Battery State
0xFFFFFFFF, // Battery Present Rate
0xFFFFFFFF, // Battery Remaining Capacity
0xFFFFFFFF, // Battery Present Voltage
})
Method (_BST, 0, NotSerialized)
{
PKG1[0] = (B1ST & 0x07)
PKG1[1] = B1PR
PKG1[2] = B1RC
PKG1[3] = B1PV
Return(PKG1)
Return (PKG1)
}
Method (_PCL, 0, NotSerialized)
{
Expand Down
7 changes: 3 additions & 4 deletions src/ec/starlabs/merlin/acpi/ec.asl
Expand Up @@ -39,16 +39,15 @@ Scope (\_SB.PCI0.LPCB)
Name (PVOL, 0x00)
Mutex (ECMT, 0x00)

Name(BFFR, ResourceTemplate()
Name (BFFR, ResourceTemplate()
{
IO(Decode16, 0x0062, 0x0062, 0x00, 0x01)
IO(Decode16, 0x0066, 0x0066, 0x00, 0x01)
})

Method (_CRS, 0, Serialized)
{

Return(BFFR)
Return (BFFR)
}

Method (_STA, 0, NotSerialized)
Expand Down Expand Up @@ -98,7 +97,7 @@ Scope (\_SB.PCI0.LPCB)
Release (ECMT)
}
}
Return(0) // Return in case Arg0 doesn't exist
Return (0) // Return in case Arg0 doesn't exist
}

// ECWR (Embedded Controller Write Method)
Expand Down
14 changes: 7 additions & 7 deletions src/ec/starlabs/merlin/acpi/hid.asl
Expand Up @@ -26,7 +26,7 @@ Device (HIDD) // HID Device
// Output:
// Package containing a complete HID Descriptor information.
//
Name(DPKG, Package(4)
Name (DPKG, Package(4)
{
0x11111111,
0x22222222,
Expand All @@ -35,7 +35,7 @@ Device (HIDD) // HID Device
})
Method (HDDM, 0, Serialized)
{
Return(DPKG)
Return (DPKG)
}
//
// HID Driver Event Method - Called by HID Driver to get the specific
Expand All @@ -54,9 +54,9 @@ Device (HIDD) // HID Device
// Simple Mode is hardcoded for now. Return Simple Mode HID Index Value.
If (HMDE == 0x00)
{
Return(HIDX)
Return (HIDX)
}
Return(HMDE)
Return (HMDE)
}
//
// HID Driver Mode Method - Called by HID Driver during initialization to get
Expand All @@ -71,7 +71,7 @@ Device (HIDD) // HID Device
//
Method (HDMM, 0, Serialized)
{
Return(HMDE) // Return Mode of operation.
Return (HMDE) // Return Mode of operation.
}
//
// HID Driver Status Method - called by HID Driver to report platform readiness status.
Expand Down Expand Up @@ -196,7 +196,7 @@ Device (HIDD) // HID Device
//
Method (BTNC, 0, Serialized) // HID Button Capabilities Method
{
Return(0x1F)
Return (0x1F)
}

//
Expand Down Expand Up @@ -253,7 +253,7 @@ Device (HIDD) // HID Device
//
Method (HEEC, 0, Serialized) {
// It's possible to return (\HEB2)
Return(0x00)
Return (0x00)
}
//
// HIDD _DSM
Expand Down
59 changes: 0 additions & 59 deletions src/ec/starlabs/merlin/acpi/keyboard.asl

This file was deleted.

4 changes: 2 additions & 2 deletions src/ec/starlabs/merlin/acpi/lid.asl
Expand Up @@ -7,10 +7,10 @@ Device (LID0)
{
Return (0x0F)
}
Method (_LID,0)
Method (_LID, 0)
{
// 0x00 == Closed
// 0x01 == Open
Return (^^LSTE)
Return (ECRD (RefOf (LSTE)))
}
}
135 changes: 123 additions & 12 deletions src/ec/starlabs/merlin/acpi/suspend.asl
@@ -1,26 +1,137 @@
/* SPDX-License-Identifier: GPL-2.0-only */

Method (RPTS, 1, NotSerialized)
Method (RPTS, 1, Serialized)
{
\_SB.PCI0.LPCB.EC.OSFG = 0x00

If ((Arg0 == 0x04) || (Arg0 == 0x05))
/* Store current EC settings in CMOS */
Switch (ToInteger (\_SB.PCI0.LPCB.EC.ECRD (RefOf (\_SB.PCI0.LPCB.EC.TPLE))))
{
// 0x00 == Enabled == 0x00
// 0x11 == Re-enabled == 0x00
// 0x22 == Disabled == 0x01
Case (0x00)
{
\_SB.PCI0.LPCB.TPLC = 0x00
}
Case (0x11)
{
\_SB.PCI0.LPCB.TPLC = 0x00
}
Case (0x22)
{
\_SB.PCI0.LPCB.TPLC = 0x01
}
}

\_SB.PCI0.LPCB.FLKC =
\_SB.PCI0.LPCB.EC.ECRD (RefOf (\_SB.PCI0.LPCB.EC.FLKE))

Switch (ToInteger (\_SB.PCI0.LPCB.EC.ECRD (RefOf (\_SB.PCI0.LPCB.EC.KLSE))))
{
/* Store current EC settings in CMOS */
\_SB.PCI0.LPCB.TPLC = \_SB.PCI0.LPCB.EC.TPLE
\_SB.PCI0.LPCB.FLKC = \_SB.PCI0.LPCB.EC.FLKE
\_SB.PCI0.LPCB.KLSC = \_SB.PCI0.LPCB.EC.KLSE
\_SB.PCI0.LPCB.KLBC = \_SB.PCI0.LPCB.EC.KLBE
// 0x00 == Disabled == 0x00
// 0xdd == Enabled == 0x01
Case (0x00)
{
\_SB.PCI0.LPCB.KLSC = 0x00
}
Case (0xdd)
{
\_SB.PCI0.LPCB.KLSC = 0x01
}
}

Switch (ToInteger (\_SB.PCI0.LPCB.EC.ECRD (RefOf (\_SB.PCI0.LPCB.EC.KLBE))))
{
// 0xdd == On == 0x00
// 0xcc == Off == 0x01
// 0xbb == Low == 0x02
// 0xaa == High == 0x03
Case (0xdd)
{
\_SB.PCI0.LPCB.KLBC = 0x00
}
Case (0xcc)
{
\_SB.PCI0.LPCB.KLBC = 0x01
}
Case (0xbb)
{
\_SB.PCI0.LPCB.KLBC = 0x02
}
Case (0xaa)
{
\_SB.PCI0.LPCB.KLBC = 0x03
}
}

/*
* Disable ACPI support.
* This should always be the last action before entering S4 or S5.
*/
\_SB.PCI0.LPCB.EC.OSFG = 0x00
}

Method (RWAK, 1, Serialized)
{
/*
* Enable ACPI support.
* This should always be the first action when exiting S4 or S5.
*/
\_SB.PCI0.LPCB.EC.OSFG = 0x01

/* Restore EC settings from CMOS */
\_SB.PCI0.LPCB.EC.TPLE = \_SB.PCI0.LPCB.TPLC
\_SB.PCI0.LPCB.EC.FLKE = \_SB.PCI0.LPCB.FLKC
\_SB.PCI0.LPCB.EC.KLSE = \_SB.PCI0.LPCB.KLSC
\_SB.PCI0.LPCB.EC.KLBE = \_SB.PCI0.LPCB.KLBC
Switch (ToInteger (\_SB.PCI0.LPCB.TPLC))
{
// 0x00 == Enabled == 0x00
// 0x00 == Re-enabled == 0x11
// 0x01 == Disabled == 0x22
Case (0x00)
{
\_SB.PCI0.LPCB.EC.ECWR (0x00, RefOf(\_SB.PCI0.LPCB.EC.TPLE))
}
Case (0x01)
{
\_SB.PCI0.LPCB.EC.ECWR (0x22, RefOf(\_SB.PCI0.LPCB.EC.TPLE))
}
}

\_SB.PCI0.LPCB.EC.ECWR (\_SB.PCI0.LPCB.FLKC, RefOf(\_SB.PCI0.LPCB.EC.FLKE))

Switch (ToInteger (\_SB.PCI0.LPCB.KLSC))
{
// 0x00 == Disabled == 0x00
// 0x01 == Enabled == 0xdd
Case (0x00)
{
\_SB.PCI0.LPCB.EC.ECWR (0x00, RefOf(\_SB.PCI0.LPCB.EC.KLSE))
}
Case (0x01)
{
\_SB.PCI0.LPCB.EC.ECWR (0xdd, RefOf(\_SB.PCI0.LPCB.EC.KLSE))
}
}

Switch (ToInteger (\_SB.PCI0.LPCB.KLBC))
{
// 0x00 == On == 0xdd
// 0x01 == Off == 0xcc
// 0x02 == Low == 0xbb
// 0x03 == High == 0xaa
Case (0x00)
{
\_SB.PCI0.LPCB.EC.ECWR (0xdd, RefOf(\_SB.PCI0.LPCB.EC.KLBE))
}
Case (0x01)
{
\_SB.PCI0.LPCB.EC.ECWR (0xcc, RefOf(\_SB.PCI0.LPCB.EC.KLBE))
}
Case (0x02)
{
\_SB.PCI0.LPCB.EC.ECWR (0xbb, RefOf(\_SB.PCI0.LPCB.EC.KLBE))
}
Case (0x03)
{
\_SB.PCI0.LPCB.EC.ECWR (0xaa, RefOf(\_SB.PCI0.LPCB.EC.KLBE))
}
}
}
11 changes: 6 additions & 5 deletions src/ec/starlabs/merlin/ec.c
Expand Up @@ -130,11 +130,12 @@ static void merlin_init(struct device *dev)
CHARGE_60
};

ec_write(ECRAM_MAX_CHARGE,
get_ec_value_from_option("max_charge",
0,
max_charge,
ARRAY_SIZE(max_charge)));
if (CONFIG(EC_STARLABS_MAX_CHARGE))
ec_write(ECRAM_MAX_CHARGE,
get_ec_value_from_option("max_charge",
0,
max_charge,
ARRAY_SIZE(max_charge)));

/*
* Fan Mode
Expand Down
18 changes: 2 additions & 16 deletions src/ec/starlabs/merlin/variants/apl/events.asl
Expand Up @@ -36,22 +36,8 @@ Method (_Q07, 0, NotSerialized) // Event: Backlight Brightness Up

Method (_Q08, 0, NotSerialized) // Event: Function Lock
{
FLKC = FLKE
}
//
// TODO:
// Below Q Events need to be added
//
// Method (_Q04, 0, NotSerialized) // Event: Trackpad Lock
// {
// TPLC = TPLE
// }
//
// Method (_Q__, 0, NotSerialized) // Event: Keyboard Backlight Brightness
// {
// KLBC = KLBE
// }
//
Printf ("EC: Function Lock")
}

Method (_Q99, 0, NotSerialized) // Event: Airplane Mode
{
Expand Down
13 changes: 5 additions & 8 deletions src/ec/starlabs/merlin/variants/cml/events.asl
Expand Up @@ -36,20 +36,17 @@ Method (_Q07, 0, NotSerialized) // Event: Backlight Brightness Up

Method (_Q08, 0, NotSerialized) // Event: Function Lock
{
FLKC = FLKE
Printf ("EC: Function Lock")
}

Method (_Q04, 0, NotSerialized) // Event: Trackpad Lock
{
TPLC = TPLE
Printf ("EC: Trackpad Lock")
}
//
// TODO:
// Below Q Events need to be added
//
Method (_Q11) // Event: Keyboard Backlight Brightness

Method (_Q11, 0, NotSerialized) // Event: Keyboard Backlight Brightness
{
KLBC = KLBE
Printf ("EC: Keyboard Brightness")
}

Method (_Q99, 0, NotSerialized) // Event: Airplane Mode
Expand Down
4 changes: 2 additions & 2 deletions src/ec/starlabs/merlin/variants/glk/ecdefs.h
Expand Up @@ -15,8 +15,8 @@

/* EC RAM offsets. */
#define ECRAM_TRACKPAD_STATE 0x14
#define ECRAM_KBL_STATE 0x18
#define ECRAM_KBL_BRIGHTNESS 0x19
#define ECRAM_KBL_STATE 0x19
#define ECRAM_KBL_BRIGHTNESS 0x18
#define ECRAM_KBL_TIMEOUT 0x1a
#define ECRAM_FN_LOCK_STATE 0x2c
#define ECRAM_FN_CTRL_REVERSE 0x2d
Expand Down
2 changes: 1 addition & 1 deletion src/ec/starlabs/merlin/variants/glk/emem.asl
Expand Up @@ -20,8 +20,8 @@ Field (ECF2, ByteAcc, Lock, Preserve)
AFG3, 8, // After G3
CLTP, 8, // Close Trackpad
WKOL, 8, // Wake on Lid
KLSE, 8, // Keyboard Backlight State
KLBE, 8, // Keyboard Backlight Brightness
KLSE, 8, // Keyboard Backlight State

Offset(0x1a),
KLTE, 8, // Keyboard Backlight Timeout
Expand Down
19 changes: 2 additions & 17 deletions src/ec/starlabs/merlin/variants/glk/events.asl
Expand Up @@ -36,23 +36,8 @@ Method (_Q07, 0, NotSerialized) // Event: Backlight Brightness Up

Method (_Q08, 0, NotSerialized) // Event: Function Lock
{
FLKC = FLKE
}
//
// TODO:
// Below Q Events need to be added
//
// Method (_Q04, 0, NotSerialized) // Event: Trackpad Lock
// {
// TPLC = TPLE
// }
//
// Method (_Q__, 0, NotSerialized) // Event: Keyboard Backlight Brightness
// {
// KLBC = KLBE
// }
//

Printf ("EC: Function Lock")
}
Method (_Q99, 0, NotSerialized) // Event: Airplane Mode
{
^^^^HIDD.HPEM (8)
Expand Down
19 changes: 2 additions & 17 deletions src/ec/starlabs/merlin/variants/kbl/events.asl
Expand Up @@ -34,25 +34,10 @@ Method (_Q07, 0, NotSerialized) // Event: Backlight Brightness Up
^^^^HIDD.HPEM (19)
}

Method (_Q08, 0, NotSerialized) // Event: Function Lock
Method (_Q08, 0, NotSerialized) // Event: Function Lock
{
FLKC = FLKE
Printf ("EC: Function Lock")
}
//
// TODO:
// Below Q Events need to be added
//
// Method (_Q04, 0, NotSerialized) // Event: Trackpad Lock
// {
// TPLC = TPLE
// }
//
// Method (_Q__, 0, NotSerialized) // Event: Keyboard Backlight Brightness
// {
// KLBC = KLBE
// KLSC = KLSE
// }
//

Method (_Q99, 0, NotSerialized) // Event: Airplane Mode
{
Expand Down
7 changes: 3 additions & 4 deletions src/ec/starlabs/merlin/variants/merlin/events.asl
Expand Up @@ -36,17 +36,16 @@ Method (_Q06) // Event: Backlight Brightness Up

Method (_Q87) // Event: Function Lock
{
FLKC = FLKE
Printf ("EC: Function Lock")
}

Method (_Q88) // Event: Trackpad Lock
{
TPLC = TPLE
Printf ("EC: Trackpad Lock")
}
Method (_Q11) // Event: Keyboard Backlight Brightness
{
KLBC = KLBE
KLSC = KLSE
Printf ("EC: Keyboard Brightness")
}

Method (_Q99) // Event: Airplane Mode
Expand Down
9 changes: 4 additions & 5 deletions src/ec/starlabs/merlin/variants/tgl/events.asl
Expand Up @@ -36,17 +36,16 @@ Method (_Q06, 0, NotSerialized) // Event: Backlight Brightness Up

Method (_Q87, 0, NotSerialized) // Event: Function Lock
{
FLKC = FLKE
Printf ("EC: Function Lock")
}

Method (_Q88, 0, NotSerialized) // Event: Trackpad Lock
{
TPLC = TPLE
Printf ("EC: Trackpad Lock")
}
Method (_Q4A) // Event: Keyboard Backlight Brightness
Method (_Q4A, 0, NotSerialized) // Event: Keyboard Backlight Brightness
{
KLSC = KLSE
KLBC = KLBE
Printf ("EC: Keyboard Brightness")
}

Method (_Q99, 0, NotSerialized) // Event: Airplane Mode
Expand Down
1 change: 1 addition & 0 deletions src/include/acpi/acpi.h
Expand Up @@ -1264,6 +1264,7 @@ typedef struct acpi_einj {
} __packed acpi_einj_t;


uintptr_t get_coreboot_rsdp(void);
void acpi_create_einj(acpi_einj_t *einj, uintptr_t addr, u8 actions);

unsigned long fw_cfg_acpi_tables(unsigned long start);
Expand Down
10 changes: 5 additions & 5 deletions src/include/cbfs.h
Expand Up @@ -132,7 +132,7 @@ void cbfs_preload(const char *name);
void cbfs_unmap(void *mapping);

/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
int cbfs_prog_stage_load(struct prog *prog);
enum cb_err cbfs_prog_stage_load(struct prog *prog);

/* Returns the size of a CBFS file, or 0 on error. Avoid using this function to allocate space,
and instead use cbfs_alloc() so the file only needs to be looked up once. */
Expand Down Expand Up @@ -185,15 +185,15 @@ const struct cbfs_boot_device *cbfs_get_boot_device(bool force_ro);
* hash was still verified. Should be called once per *boot* (not once per stage) before the
* first CBFS access.
*/
cb_err_t cbfs_init_boot_device(const struct cbfs_boot_device *cbd,
struct vb2_hash *metadata_hash);
enum cb_err cbfs_init_boot_device(const struct cbfs_boot_device *cbd,
struct vb2_hash *metadata_hash);


/**********************************************************************************************
* INTERNAL HELPERS FOR INLINES, DO NOT USE. *
**********************************************************************************************/
cb_err_t _cbfs_boot_lookup(const char *name, bool force_ro,
union cbfs_mdata *mdata, struct region_device *rdev);
enum cb_err _cbfs_boot_lookup(const char *name, bool force_ro,
union cbfs_mdata *mdata, struct region_device *rdev);

void *_cbfs_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
size_t *size_out, bool force_ro, enum cbfs_type *type);
Expand Down
6 changes: 5 additions & 1 deletion src/include/console/cbmem_console.h
Expand Up @@ -10,7 +10,8 @@ void cbmemc_tx_byte(unsigned char data);

#define __CBMEM_CONSOLE_ENABLE__ (CONFIG(CONSOLE_CBMEM) && \
(ENV_RAMSTAGE || ENV_SEPARATE_VERSTAGE || ENV_POSTCAR || \
ENV_ROMSTAGE || (ENV_BOOTBLOCK && CONFIG(BOOTBLOCK_CONSOLE))))
ENV_ROMSTAGE || (ENV_BOOTBLOCK && CONFIG(BOOTBLOCK_CONSOLE)) || \
(ENV_SMM && CONFIG(DEBUG_SMI))))

#if __CBMEM_CONSOLE_ENABLE__
static inline void __cbmemc_init(void) { cbmemc_init(); }
Expand All @@ -28,3 +29,6 @@ void cbmemc_copy_in(void *buffer, size_t size);
void cbmem_dump_console_to_uart(void);
void cbmem_dump_console(void);
#endif

/* Retrieves the location of the CBMEM Console buffer in SMM mode */
void smm_get_cbmemc_buffer(void **buffer_out, size_t *size_out);
3 changes: 2 additions & 1 deletion src/include/cpu/intel/cpu_ids.h
Expand Up @@ -56,5 +56,6 @@
#define CPUID_ALDERLAKE_A2 0x906a2
#define CPUID_ALDERLAKE_A3 0x906a4
#define CPUID_ALDERLAKE_N_A0 0xb06e0

#define CPUID_METEORLAKE_A0_1 0xa06a0
#define CPUID_METEORLAKE_A0_2 0xa06a1
#endif /* CPU_INTEL_CPU_IDS_H */
3 changes: 3 additions & 0 deletions src/include/cpu/x86/msr.h
Expand Up @@ -86,8 +86,11 @@
#define IA32_VMX_MISC_MSR 0x485

#define IA32_PM_ENABLE 0x770
#define HWP_ENABLE 0x1
#define IA32_HWP_CAPABILITIES 0x771
#define IA32_HWP_REQUEST 0x774
#define IA32_HWP_REQUEST_EPP_MASK 0xff000000
#define IA32_HWP_REQUEST_EPP_SHIFT 24
#define IA32_HWP_STATUS 0x777
#define IA32_L3_PROTECTED_WAYS 0xc85
#define IA32_SF_QOS_INFO 0xc87
Expand Down
5 changes: 5 additions & 0 deletions src/include/cpu/x86/smm.h
Expand Up @@ -51,6 +51,9 @@ int mainboard_smi_apmc(u8 data);
void mainboard_smi_sleep(u8 slp_typ);
void mainboard_smi_finalize(void);

void smm_soc_early_init(void);
void smm_soc_exit(void);

/* This is the SMM handler. */
extern unsigned char _binary_smm_start[];
extern unsigned char _binary_smm_end[];
Expand All @@ -61,6 +64,8 @@ struct smm_runtime {
u32 save_state_size;
u32 num_cpus;
u32 gnvs_ptr;
u32 cbmemc_size;
void *cbmemc;
uintptr_t save_state_top[CONFIG_MAX_CPUS];
} __packed;

Expand Down
40 changes: 40 additions & 0 deletions src/include/device/mmio.h
Expand Up @@ -207,4 +207,44 @@ static inline void buffer_to_fifo32(const void *buffer, size_t size, void *fifo,
#define READ32_BITFIELD(addr, name) \
EXTRACT_BITFIELD(read32(addr), name)

static __always_inline uint8_t read8p(const uintptr_t addr)
{
return read8((void *)addr);
}

static __always_inline uint16_t read16p(const uintptr_t addr)
{
return read16((void *)addr);
}

static __always_inline uint32_t read32p(const uintptr_t addr)
{
return read32((void *)addr);
}

static __always_inline uint64_t read64p(const uintptr_t addr)
{
return read64((void *)addr);
}

static __always_inline void write8p(const uintptr_t addr, const uint8_t value)
{
write8((void *)addr, value);
}

static __always_inline void write16p(const uintptr_t addr, const uint16_t value)
{
write16((void *)addr, value);
}

static __always_inline void write32p(const uintptr_t addr, const uint32_t value)
{
write32((void *)addr, value);
}

static __always_inline void write64p(const uintptr_t addr, const uint64_t value)
{
write64((void *)addr, value);
}

#endif /* __DEVICE_MMIO_H__ */
8,333 changes: 4,211 additions & 4,122 deletions src/include/device/pci_ids.h

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions src/include/efi/efi_datatype.h
Expand Up @@ -4,9 +4,17 @@
#ifndef __EFI_DATATYPE_H__
#define __EFI_DATATYPE_H__
#include <Base.h>
#include <PiPei.h>
#include <Uefi/UefiBaseType.h>

#if CONFIG_UDK_VERSION >= CONFIG_UDK_2017_VERSION
#include <Pi/PiPeiCis.h>

/* Data structure for EFI_PEI_SERVICE. */
typedef EFI_PEI_SERVICES efi_pei_services;
/* Structure that describes information about a logical CPU. */
typedef EFI_PROCESSOR_INFORMATION efi_processor_information;
#endif

/* Basic Data types */
/* 8-byte unsigned value. */
typedef UINT64 efi_uint64_t;
Expand Down Expand Up @@ -36,14 +44,9 @@ typedef UINTN efi_uintn_t;
typedef INTN efi_intn_t;
/* Status codes common to all execution phases */
typedef EFI_STATUS efi_return_status_t;
/* Data structure */
/* Data structure for EFI_PEI_SERVICE. */
typedef EFI_PEI_SERVICES efi_pei_services;
/* Data structure for EFI_PHYSICAL_ADDRESS */
typedef EFI_PHYSICAL_ADDRESS efi_physical_address;

/* Structure that describes information about a logical CPU. */
typedef EFI_PROCESSOR_INFORMATION efi_processor_information;
/*
* The function prototype for invoking a function on an
* Application Processor.
Expand Down
4 changes: 2 additions & 2 deletions src/include/mipi/panel.h
Expand Up @@ -31,10 +31,10 @@ struct panel_serializable_data {
u8 init[]; /* A packed array of panel_init_command */
};

typedef cb_err_t (*mipi_cmd_func_t)(enum mipi_dsi_transaction type, const u8 *data, u8 len);
typedef enum cb_err (*mipi_cmd_func_t)(enum mipi_dsi_transaction type, const u8 *data, u8 len);

/* Parse a command array and call cmd_func() for each entry. Delays get handled internally. */
cb_err_t mipi_panel_parse_init_commands(const void *buf, mipi_cmd_func_t cmd_func);
enum cb_err mipi_panel_parse_init_commands(const void *buf, mipi_cmd_func_t cmd_func);

#define PANEL_DCS(...) \
PANEL_CMD_DCS, \
Expand Down
5 changes: 2 additions & 3 deletions src/include/program_loading.h
Expand Up @@ -5,8 +5,7 @@
#include <bootmem.h>
#include <commonlib/bsd/cbfs_serialized.h>
#include <commonlib/region.h>
#include <stdint.h>
#include <stddef.h>
#include <types.h>

enum {
/* Last segment of program. Can be used to take different actions for
Expand Down Expand Up @@ -139,7 +138,7 @@ void platform_prog_run(struct prog *prog);
void run_romstage(void);

/* Runtime selector for CBFS_PREFIX of romstage. */
int legacy_romstage_select_and_load(struct prog *romstage);
enum cb_err legacy_romstage_select_and_load(struct prog *romstage);

/************************
* RAMSTAGE LOADING *
Expand Down
5 changes: 4 additions & 1 deletion src/lib/Makefile.inc
Expand Up @@ -220,6 +220,9 @@ smm-y += delay.c
smm-y += fmap.c
smm-y += cbfs.c memcmp.c
smm-$(CONFIG_GENERIC_UDELAY) += timer.c
ifeq ($(CONFIG_DEBUG_SMI),y)
smm-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
endif

bootblock-y += version.c
romstage-y += version.c
Expand Down Expand Up @@ -318,7 +321,7 @@ RMODULE_LDFLAGS := -z defs -Bsymbolic
# rmdoule is named $(1).rmod
define rmodule_link
$(strip $(1)): $(strip $(2)) $$(COMPILER_RT_rmodules_$(4)) $(call src-to-obj,rmodules_$(4),src/lib/rmodule.ld) | $$(RMODTOOL)
$$(LD_rmodules_$(4)) $$(LDFLAGS_rmodules_$(4)) $(RMODULE_LDFLAGS) -T $(call src-to-obj,rmodules_$(4),src/lib/rmodule.ld) --defsym=__heap_size=$(strip $(3)) -o $$@ --whole-archive --start-group $(filter-out %.ld,$(2)) --end-group
$$(LD_rmodules_$(4)) $$(LDFLAGS_rmodules_$(4)) $(RMODULE_LDFLAGS) $($(1)-ldflags) -T $(call src-to-obj,rmodules_$(4),src/lib/rmodule.ld) --defsym=__heap_size=$(strip $(3)) -o $$@ --whole-archive --start-group $(filter-out %.ld,$(2)) --end-group
$$(NM_rmodules_$(4)) -n $$@ > $$(basename $$@).map
endef

Expand Down
4 changes: 2 additions & 2 deletions src/lib/bootblock.c
Expand Up @@ -39,7 +39,7 @@ void bootblock_main_with_timestamp(uint64_t base_timestamp,
timestamps[i].entry_stamp);
}

timestamp_add_now(TS_START_BOOTBLOCK);
timestamp_add_now(TS_BOOTBLOCK_START);

bootblock_soc_early_init();
bootblock_mainboard_early_init();
Expand All @@ -63,7 +63,7 @@ void bootblock_main_with_timestamp(uint64_t base_timestamp,
tpm_setup(s3resume);
}

timestamp_add_now(TS_END_BOOTBLOCK);
timestamp_add_now(TS_BOOTBLOCK_END);

run_romstage();
}
Expand Down
26 changes: 13 additions & 13 deletions src/lib/cbfs.c
Expand Up @@ -34,15 +34,15 @@ static void switch_to_postram_cache(int unused)
}
ROMSTAGE_CBMEM_INIT_HOOK(switch_to_postram_cache);

cb_err_t _cbfs_boot_lookup(const char *name, bool force_ro,
union cbfs_mdata *mdata, struct region_device *rdev)
enum cb_err _cbfs_boot_lookup(const char *name, bool force_ro,
union cbfs_mdata *mdata, struct region_device *rdev)
{
const struct cbfs_boot_device *cbd = cbfs_get_boot_device(force_ro);
if (!cbd)
return CB_ERR;

size_t data_offset;
cb_err_t err = CB_CBFS_CACHE_FULL;
enum cb_err err = CB_CBFS_CACHE_FULL;
if (!CONFIG(NO_CBFS_MCACHE) && !ENV_SMM && cbd->mcache_size)
err = cbfs_mcache_lookup(cbd->mcache, cbd->mcache_size,
name, mdata, &data_offset);
Expand Down Expand Up @@ -215,9 +215,9 @@ static size_t cbfs_load_and_decompress(const struct region_device *rdev, void *b
return 0;

if (!cbfs_file_hash_mismatch(map, in_size, mdata, skip_verification)) {
timestamp_add_now(TS_START_ULZ4F);
timestamp_add_now(TS_ULZ4F_START);
out_size = ulz4fn(map, in_size, buffer, buffer_size);
timestamp_add_now(TS_END_ULZ4F);
timestamp_add_now(TS_ULZ4F_END);
}

rdev_munmap(rdev, map);
Expand All @@ -233,9 +233,9 @@ static size_t cbfs_load_and_decompress(const struct region_device *rdev, void *b

if (!cbfs_file_hash_mismatch(map, in_size, mdata, skip_verification)) {
/* Note: timestamp not useful for memory-mapped media (x86) */
timestamp_add_now(TS_START_ULZMA);
timestamp_add_now(TS_ULZMA_START);
out_size = ulzman(map, in_size, buffer, buffer_size);
timestamp_add_now(TS_END_ULZMA);
timestamp_add_now(TS_ULZMA_END);
}

rdev_munmap(rdev, map);
Expand Down Expand Up @@ -520,11 +520,11 @@ void *_cbfs_cbmem_allocator(void *arg, size_t size, const union cbfs_mdata *unus
return cbmem_add((uintptr_t)arg, size);
}

cb_err_t cbfs_prog_stage_load(struct prog *pstage)
enum cb_err cbfs_prog_stage_load(struct prog *pstage)
{
union cbfs_mdata mdata;
struct region_device rdev;
cb_err_t err;
enum cb_err err;

prog_locate_hook(pstage);

Expand Down Expand Up @@ -612,8 +612,8 @@ void cbfs_boot_device_find_mcache(struct cbfs_boot_device *cbd, uint32_t id)
}
}

cb_err_t cbfs_init_boot_device(const struct cbfs_boot_device *cbd,
struct vb2_hash *mdata_hash)
enum cb_err cbfs_init_boot_device(const struct cbfs_boot_device *cbd,
struct vb2_hash *mdata_hash)
{
/* If we have an mcache, mcache_build() will also check mdata hash. */
if (!CONFIG(NO_CBFS_MCACHE) && !ENV_SMM && cbd->mcache_size > 0)
Expand All @@ -625,7 +625,7 @@ cb_err_t cbfs_init_boot_device(const struct cbfs_boot_device *cbd,

/* Verification only: use cbfs_walk() without a walker() function to just run through
the CBFS once, will return NOT_FOUND by default. */
cb_err_t err = cbfs_walk(&cbd->rdev, NULL, NULL, mdata_hash, 0);
enum cb_err err = cbfs_walk(&cbd->rdev, NULL, NULL, mdata_hash, 0);
if (err == CB_CBFS_NOT_FOUND)
err = CB_SUCCESS;
return err;
Expand Down Expand Up @@ -660,7 +660,7 @@ const struct cbfs_boot_device *cbfs_get_boot_device(bool force_ro)
die("Cannot locate primary CBFS");

if (ENV_INITIAL_STAGE) {
cb_err_t err = cbfs_init_boot_device(&ro, metadata_hash_get());
enum cb_err err = cbfs_init_boot_device(&ro, metadata_hash_get());
if (err == CB_CBFS_HASH_MISMATCH)
die("RO CBFS metadata hash verification failure");
else if (CONFIG(TOCTOU_SAFETY) && err == CB_CBFS_CACHE_FULL)
Expand Down
7 changes: 7 additions & 0 deletions src/lib/cbmem_console.c
Expand Up @@ -84,6 +84,13 @@ void cbmemc_init(void)
if (ENV_ROMSTAGE_OR_BEFORE) {
/* Pre-RAM environments use special buffer placed by linker script. */
init_console_ptr(_preram_cbmem_console, REGION_SIZE(preram_cbmem_console));
} else if (ENV_SMM) {
void *cbmemc = NULL;
size_t cbmemc_size = 0;

smm_get_cbmemc_buffer(&cbmemc, &cbmemc_size);

init_console_ptr(cbmemc, cbmemc_size);
} else {
/* Post-RAM uses static (BSS) buffer before CBMEM is reinitialized. */
init_console_ptr(static_console, sizeof(static_console));
Expand Down
14 changes: 14 additions & 0 deletions src/lib/coreboot_table.c
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: GPL-2.0-only */

#include <acpi/acpi.h>
#include <arch/cbconfig.h>
#include <console/console.h>
#include <console/uart.h>
Expand Down Expand Up @@ -421,6 +422,16 @@ static unsigned long lb_table_fini(struct lb_header *head)
return (unsigned long)rec + rec->size;
}

static void lb_add_acpi_rsdp(struct lb_header *head)
{
struct lb_acpi_rsdp *acpi_rsdp;
struct lb_record *rec = lb_new_record(head);
acpi_rsdp = (struct lb_acpi_rsdp *)rec;
acpi_rsdp->tag = LB_TAG_ACPI_RSDP;
acpi_rsdp->size = sizeof(*acpi_rsdp);
acpi_rsdp->rsdp_pointer = pack_lb64(get_coreboot_rsdp());
}

size_t write_coreboot_forwarding_table(uintptr_t entry, uintptr_t target)
{
struct lb_header *head;
Expand Down Expand Up @@ -524,6 +535,9 @@ static uintptr_t write_coreboot_table(uintptr_t rom_table_end)
/* Add all cbmem entries into the coreboot tables. */
cbmem_add_records_to_cbtable(head);

if (CONFIG(HAVE_ACPI_TABLES))
lb_add_acpi_rsdp(head);

/* Remember where my valid memory ranges are */
return lb_table_fini(head);
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/decompressor.c
Expand Up @@ -23,8 +23,8 @@ struct bootblock_arg arg = {
.base_timestamp = 0,
.num_timestamps = 2,
.timestamps = {
{ .entry_id = TS_START_ULZ4F },
{ .entry_id = TS_END_ULZ4F },
{ .entry_id = TS_ULZ4F_START },
{ .entry_id = TS_ULZ4F_END },
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib/device_tree.c
Expand Up @@ -554,7 +554,7 @@ struct device_tree_node *dt_find_node(struct device_tree_node *parent,
if (!create)
return NULL;

found = malloc(sizeof(*found));
found = calloc(1, sizeof(*found));
if (!found)
return NULL;
found->name = strdup(*path);
Expand Down
10 changes: 5 additions & 5 deletions src/lib/fit_payload.c
Expand Up @@ -62,14 +62,14 @@ static bool extract(struct region *region, struct fit_image_node *node)
true_size = node->size;
break;
case CBFS_COMPRESS_LZMA:
timestamp_add_now(TS_START_ULZMA);
timestamp_add_now(TS_ULZMA_START);
true_size = ulzman(node->data, node->size, dst, region->size);
timestamp_add_now(TS_END_ULZMA);
timestamp_add_now(TS_ULZMA_END);
break;
case CBFS_COMPRESS_LZ4:
timestamp_add_now(TS_START_ULZ4F);
timestamp_add_now(TS_ULZ4F_START);
true_size = ulz4fn(node->data, node->size, dst, region->size);
timestamp_add_now(TS_END_ULZ4F);
timestamp_add_now(TS_ULZ4F_END);
break;
default:
return true;
Expand Down Expand Up @@ -240,5 +240,5 @@ void fit_payload(struct prog *payload, void *data)
return;
}

timestamp_add_now(TS_START_KERNEL);
timestamp_add_now(TS_KERNEL_START);
}
2 changes: 1 addition & 1 deletion src/lib/hardwaremain.c
Expand Up @@ -457,7 +457,7 @@ void main(void)
*/
cbmem_initialize();

timestamp_add_now(TS_START_RAMSTAGE);
timestamp_add_now(TS_RAMSTAGE_START);
post_code(POST_ENTRY_HARDWAREMAIN);

/* Handoff sleep type from romstage. */
Expand Down
14 changes: 7 additions & 7 deletions src/lib/prog_loaders.c
Expand Up @@ -24,17 +24,17 @@ void run_romstage(void)

vboot_run_logic();

timestamp_add_now(TS_START_COPYROM);
timestamp_add_now(TS_COPYROM_START);

if (ENV_X86 && CONFIG(BOOTBLOCK_NORMAL)) {
if (legacy_romstage_select_and_load(&romstage))
if (legacy_romstage_select_and_load(&romstage) != CB_SUCCESS)
goto fail;
} else {
if (cbfs_prog_stage_load(&romstage))
goto fail;
}

timestamp_add_now(TS_END_COPYROM);
timestamp_add_now(TS_COPYROM_END);

console_time_report();

Expand Down Expand Up @@ -90,11 +90,11 @@ void run_ramstage(void)
PROG_INIT(PROG_RAMSTAGE, CONFIG_CBFS_PREFIX "/ramstage");

if (ENV_POSTCAR)
timestamp_add_now(TS_END_POSTCAR);
timestamp_add_now(TS_POSTCAR_END);

/* Call "end of romstage" here if postcar stage doesn't exist */
if (ENV_ROMSTAGE)
timestamp_add_now(TS_END_ROMSTAGE);
timestamp_add_now(TS_ROMSTAGE_END);

/*
* Only x86 systems using ramstage stage cache currently take the same
Expand All @@ -105,7 +105,7 @@ void run_ramstage(void)

vboot_run_logic();

timestamp_add_now(TS_START_COPYRAM);
timestamp_add_now(TS_COPYRAM_START);

if (ENV_X86) {
if (load_relocatable_ramstage(&ramstage))
Expand All @@ -117,7 +117,7 @@ void run_ramstage(void)

stage_cache_add(STAGE_RAMSTAGE, &ramstage);

timestamp_add_now(TS_END_COPYRAM);
timestamp_add_now(TS_COPYRAM_END);

console_time_report();

Expand Down
8 changes: 4 additions & 4 deletions src/lib/selfboot.c
Expand Up @@ -72,18 +72,18 @@ static int load_one_segment(uint8_t *dest,
switch (compression) {
case CBFS_COMPRESS_LZMA: {
printk(BIOS_DEBUG, "using LZMA\n");
timestamp_add_now(TS_START_ULZMA);
timestamp_add_now(TS_ULZMA_START);
len = ulzman(src, len, dest, memsz);
timestamp_add_now(TS_END_ULZMA);
timestamp_add_now(TS_ULZMA_END);
if (!len) /* Decompression Error. */
return 0;
break;
}
case CBFS_COMPRESS_LZ4: {
printk(BIOS_DEBUG, "using LZ4\n");
timestamp_add_now(TS_START_ULZ4F);
timestamp_add_now(TS_ULZ4F_START);
len = ulz4fn(src, len, dest, memsz);
timestamp_add_now(TS_END_ULZ4F);
timestamp_add_now(TS_ULZ4F_END);
if (!len) /* Decompression Error. */
return 0;
break;
Expand Down
6 changes: 4 additions & 2 deletions src/lib/spd_bin.c
Expand Up @@ -167,8 +167,10 @@ static void spd_get_name(const uint8_t spd[], int type, const char **spd_name, s
case SPD_DRAM_DDR5:
case SPD_DRAM_LPDDR4:
case SPD_DRAM_LPDDR4X:
*spd_name = (const char *) &spd[DDR4_SPD_PART_OFF];
*len = DDR4_SPD_PART_LEN;
if (spd[DDR4_SPD_PART_OFF]) {
*spd_name = (const char *) &spd[DDR4_SPD_PART_OFF];
*len = DDR4_SPD_PART_LEN;
}
break;
default:
*len = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/mainboard/amd/bilby/dsdt.asl
Expand Up @@ -21,8 +21,8 @@ DefinitionBlock (
/* PCI IRQ mapping for the Southbridge */
#include <pcie.asl>

/* Describe the processor tree (\_PR) */
#include <cpu.asl>
/* Power state notification to ALIB */
#include <pnot.asl>

/* Contains the supported sleep states for this chipset */
#include <soc/amd/common/acpi/sleepstates.asl>
Expand Down
9 changes: 9 additions & 0 deletions src/mainboard/amd/chausie/Kconfig
Expand Up @@ -66,9 +66,18 @@ config VBOOT_VBNV_OFFSET
hex
default 0x2A

config RO_REGION_ONLY
string
depends on VBOOT_SLOTS_RW_AB || VBOOT_SLOTS_RW_A
# Add the EFS and EC to the RO region only
# This is a chausie-specific override of soc/amd/sabrina/Kconfig
default "apu/amdfw apu/ecfw"

config CHROMEOS
# Use default libpayload config
select LP_DEFCONFIG_OVERRIDE if PAYLOAD_DEPTHCHARGE
# We don't have recovery buttons, so we can't manually enable devmode.
select GBB_FLAG_FORCE_DEV_SWITCH_ON

if !EM100 # EM100 defaults in soc/amd/common/blocks/spi/Kconfig
config EFS_SPI_READ_MODE
Expand Down
9 changes: 6 additions & 3 deletions src/mainboard/amd/chausie/Makefile.inc
Expand Up @@ -8,9 +8,12 @@ romstage-y += port_descriptors.c
ramstage-y += chromeos.c
ramstage-y += gpio.c

#TODO: add APCB binaries
#APCB_SOURCES = $(MAINBOARD_BLOBS_DIR)/APCB_CZN_D4.bin
#APCB_SOURCES_RECOVERY = $(MAINBOARD_BLOBS_DIR)/APCB_CZN_D4_DefaultRecovery.bin
ifneq ($(wildcard $(MAINBOARD_BLOBS_DIR)/APCB_FT6_Updatable.bin),)
APCB_SOURCES = $(MAINBOARD_BLOBS_DIR)/APCB_FT6_Updatable.bin
APCB_SOURCES_RECOVERY = $(MAINBOARD_BLOBS_DIR)/APCB_FT6_DefaultRecovery.bin
else
$(info APCB sources not found. Skipping APCB. The resulting image won't boot.)
endif

ifeq ($(CONFIG_CHAUSIE_HAVE_MCHP_FW),y)
$(call add_intermediate, add_mchp_fw)
Expand Down
6 changes: 3 additions & 3 deletions src/mainboard/amd/chausie/chromeos.fmd
Expand Up @@ -2,12 +2,12 @@ FLASH@0xFF000000 16M {
SI_BIOS {
EC 4K
RW_MRC_CACHE(PRESERVE) 96K
RW_SECTION_A 3M {
RW_SECTION_A 4M {
VBLOCK_A 8K
FW_MAIN_A(CBFS)
RW_FWID_A 256
}
RW_SECTION_B 3M {
RW_SECTION_B 4M {
VBLOCK_B 8K
FW_MAIN_B(CBFS)
RW_FWID_B 256
Expand All @@ -21,7 +21,7 @@ FLASH@0xFF000000 16M {
RW_NVRAM(PRESERVE) 20K
SMMSTORE(PRESERVE) 4K
RW_LEGACY(CBFS)
WP_RO@8M 8M {
WP_RO@10M 6M {
RO_VPD(PRESERVE) 16K
RO_SECTION {
FMAP 2K
Expand Down
16 changes: 15 additions & 1 deletion src/mainboard/amd/chausie/devicetree.cb
Expand Up @@ -24,7 +24,7 @@ chip soc/amd/sabrina

register "s0ix_enable" = "true"

register "pspp_policy" = "DXIO_PSPP_BALANCED"
register "pspp_policy" = "DXIO_PSPP_DISABLED" # TODO: reenable when PSPP works

device domain 0 on
device ref iommu on end
Expand All @@ -36,6 +36,7 @@ chip soc/amd/sabrina
device ref gpp_bridge_5 on end
device ref gpp_bridge_a on # Internal GPP Bridge 0 to Bus A
device ref gfx on end # Internal GPU (GFX)
device ref gfx_hda on end # Display HD Audio Controller (GFXAZ)
device ref crypto on end # Crypto Coprocessor
device ref xhci_0 on # USB 3.1 (USB0)
chip drivers/usb/acpi
Expand Down Expand Up @@ -73,6 +74,19 @@ chip soc/amd/sabrina
end
end
end
device ref acp on end # Audio Processor (ACP)
end
device ref gpp_bridge_c on # Internal GPP Bridge 2 to Bus C
device ref xhci_2 on
chip drivers/usb/acpi
register "type" = "UPC_TYPE_HUB"
device usb 0.0 alias xhci_2_root_hub on
chip drivers/usb/acpi
device usb 2.0 alias usb2_port5 on end
end
end
end
end
end
end

Expand Down
4 changes: 2 additions & 2 deletions src/mainboard/amd/gardenia/dsdt.asl
Expand Up @@ -24,8 +24,8 @@ DefinitionBlock (
/* PCI IRQ mapping for the Southbridge */
#include <pcie.asl>

/* Describe the processor tree (\_SB) */
#include <cpu.asl>
/* Power state notification */
#include <pnot.asl>

/* Contains the supported sleep states for this chipset */
#include <soc/amd/common/acpi/sleepstates.asl>
Expand Down
1 change: 1 addition & 0 deletions src/mainboard/amd/majolica/Makefile.inc
Expand Up @@ -6,6 +6,7 @@ bootblock-y += early_gpio.c
romstage-y += port_descriptors.c

ramstage-y += chromeos.c
ramstage-y += port_descriptors.c

APCB_SOURCES = $(MAINBOARD_BLOBS_DIR)/APCB_CZN_D4.bin
APCB_SOURCES_RECOVERY = $(MAINBOARD_BLOBS_DIR)/APCB_CZN_D4_DefaultRecovery.bin
Expand Down
4 changes: 2 additions & 2 deletions src/mainboard/amd/mandolin/dsdt.asl
Expand Up @@ -21,8 +21,8 @@ DefinitionBlock (
/* PCI IRQ mapping for the Southbridge */
#include <pcie.asl>

/* Describe the processor tree (\_PR) */
#include <cpu.asl>
/* Power state notification to ALIB */
#include <pnot.asl>

/* Contains the supported sleep states for this chipset */
#include <soc/amd/common/acpi/sleepstates.asl>
Expand Down
4 changes: 2 additions & 2 deletions src/mainboard/amd/padmelon/dsdt.asl
Expand Up @@ -22,8 +22,8 @@ DefinitionBlock (
/* PCI IRQ mapping for the Southbridge */
#include <pcie.asl>

/* Describe the processor tree (\_SB) */
#include <cpu.asl>
/* Power state notification */
#include <pnot.asl>

/* Contains the supported sleep states for this chipset */
#include <soc/amd/common/acpi/sleepstates.asl>
Expand Down
2 changes: 0 additions & 2 deletions src/mainboard/dell/optiplex_9010/Kconfig.name

This file was deleted.

@@ -1,17 +1,11 @@
if BOARD_DELL_OPTIPLEX_9010

config IGNORE_IASL_MISSING_DEPENDENCY
def_bool y

config BOARD_SPECIFIC_OPTIONS
def_bool y
config BOARD_DELL_SNB_IVB_WORKSTATIONS
def_bool n
select BOARD_ROMSIZE_KB_12288
select HAVE_ACPI_RESUME
select HAVE_ACPI_TABLES
select INTEL_INT15
select NORTHBRIDGE_INTEL_SANDYBRIDGE
select SERIRQ_CONTINUOUS_MODE
select SOUTHBRIDGE_INTEL_C216
select USE_NATIVE_RAMINIT
select MAINBOARD_HAS_LPC_TPM
select MAINBOARD_HAS_TPM1
Expand All @@ -24,11 +18,27 @@ config BOARD_SPECIFIC_OPTIONS
select PCIEXP_L1_SUB_STATE
select DRIVERS_UART_8250IO

if BOARD_DELL_SNB_IVB_WORKSTATIONS

config IGNORE_IASL_MISSING_DEPENDENCY
def_bool y

config MAINBOARD_DIR
default "dell/optiplex_9010"
default "dell/snb_ivb_workstations"

config MAINBOARD_PART_NUMBER
default "OptiPlex 9010"
default "OptiPlex 9010" if BOARD_DELL_OPTIPLEX_9010
default "Precision T1650" if BOARD_DELL_PRECISION_T1650

config VARIANT_DIR
default "optiplex_9010_sff" if BOARD_DELL_OPTIPLEX_9010
default "precision_t1650" if BOARD_DELL_PRECISION_T1650

config DEVICETREE
default "variants/baseboard/devicetree.cb"

config OVERRIDE_DEVICETREE
default "variants/\$(CONFIG_VARIANT_DIR)/overridetree.cb"

config DRAM_RESET_GATE_GPIO
int
Expand Down
9 changes: 9 additions & 0 deletions src/mainboard/dell/snb_ivb_workstations/Kconfig.name
@@ -0,0 +1,9 @@
config BOARD_DELL_OPTIPLEX_9010
bool "OptiPlex 9010 SFF"
select BOARD_DELL_SNB_IVB_WORKSTATIONS
select SOUTHBRIDGE_INTEL_BD82X6X

config BOARD_DELL_PRECISION_T1650
bool "Dell Precision T1650"
select BOARD_DELL_SNB_IVB_WORKSTATIONS
select SOUTHBRIDGE_INTEL_C216
Expand Up @@ -9,12 +9,20 @@ romstage-y += early_init.c
bootblock-y += sch5545_ec_early.c

romstage-y += sch5545_ec.c

ramstage-y += sch5545_ec.c

ramstage-$(CONFIG_MAINBOARD_USE_LIBGFXINIT) += gma-mainboard.ads

ramstage-y += variants/$(VARIANT_DIR)/hda_verb.c

ifeq ($(CONFIG_INCLUDE_SMSC_SCH5545_EC_FW),y)
cbfs-files-y += sch5545_ecfw.bin
sch5545_ecfw.bin-file := $(call strip_quotes,$(CONFIG_SMSC_SCH5545_EC_FW_FILE))
sch5545_ecfw.bin-type := raw
endif

subdirs-y += variants/baseboard
CPPFLAGS_common += -I$(src)/mainboard/$(MAINBOARDDIR)/variants/baseboard/include

subdirs-y += variants/$(VARIANT_DIR)
CPPFLAGS_common += -I$(src)/mainboard/$(MAINBOARDDIR)/variants/$(VARIANT_DIR)/include
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -7,7 +7,7 @@
#include <superio/smsc/sch5545/sch5545.h>
#include <superio/smsc/sch5545/sch5545_emi.h>

#include "sch5545_ec.h"
#include <baseboard/sch5545_ec.h>

const struct southbridge_usb_port mainboard_usb_ports[] = {
{ 1, 6, 0 },
Expand Down
File renamed without changes.
File renamed without changes.
Empty file.
Expand Up @@ -9,7 +9,7 @@
#include <southbridge/intel/common/gpio.h>
#include <superio/smsc/sch5545/sch5545.h>

#include "sch5545_ec.h"
#include <baseboard/sch5545_ec.h>

#define SIO_PORT 0x2e

Expand Down Expand Up @@ -61,7 +61,7 @@ static void mainboard_enable(struct device *dev)
pin_sts |= get_gpio(GPIO_CHASSIS_ID2) << 2;
pin_sts |= get_gpio(GPIO_FRONT_PANEL_CHASSIS_DET_L) << 3;

printk(BIOS_DEBUG, "Chassis type:");
printk(BIOS_DEBUG, "Chassis type: ");
switch (pin_sts) {
case 0:
printk(BIOS_DEBUG, "MT\n");
Expand Down
Expand Up @@ -10,7 +10,7 @@
#include <superio/smsc/sch5545/sch5545.h>
#include <superio/smsc/sch5545/sch5545_emi.h>

#include "sch5545_ec.h"
#include <baseboard/sch5545_ec.h>

void mainboard_late_rcba_config(void)
{
Expand Down