Initial commit; kernel source import

This commit is contained in:
Nathan
2025-04-06 23:50:55 -05:00
commit 25c6d769f4
45093 changed files with 18199410 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
#
# ARM Platform Specific Drivers
#
menuconfig ARM_PLATFORM_DEVICES
bool "ARM Specific Device Drivers"
default n
---help---
Say Y here to get to see options for device drivers for various
ARM platforms. This option alone does not add any kernel code.
If you say N, all options in this submenu will be skipped and disabled.
if ARM_PLATFORM_DEVICES
config ARM_CHROMEOS_FIRMWARE
bool "ChromeOS firmware interface driver"
select CHROMEOS
select CHROMEOS_VBC_BLK
select CHROMEOS_VBC_EC
---help---
This driver provides an interface to ChromeOS firmware.
Say Y here if you are building for a ChromeOS device.
endif # CROS_PLATFORM_DEVICES

View File

@@ -0,0 +1,5 @@
#
# Makefile for linux/drivers/platform/arm
# arm Platform-Specific Drivers
#
obj-$(CONFIG_ARM_CHROMEOS_FIRMWARE) += chromeos_arm.o

View File

@@ -0,0 +1,265 @@
/*
* Copyright (C) 2011 The Chromium OS Authors
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#define pr_fmt(fmt) "chromeos_arm: " fmt
#include <linux/bcd.h>
#include <linux/gpio.h>
#include <linux/notifier.h>
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/platform_device.h>
#include <linux/slab.h>
#include "../chromeos.h"
#include "elog.h"
struct chromeos_arm_elog_panic_buffer {
uint32_t start;
uint32_t size;
void __iomem *virt_addr;
struct notifier_block nb;
};
/*
* Update the checksum at the last byte
*/
static void elog_update_checksum(struct event_header *event, u8 checksum)
{
u8 *event_data = (u8 *)event;
event_data[event->length - 1] = checksum;
}
/*
* Simple byte checksum for events
*/
static u8 elog_checksum_event(struct event_header *event)
{
u8 index, checksum = 0;
u8 *data = (u8 *)event;
for (index = 0; index < event->length; index++)
checksum += data[index];
return checksum;
}
/*
* Populate timestamp in event header with current time
*/
static void elog_fill_timestamp(struct event_header *event)
{
struct timeval timeval;
struct tm time;
do_gettimeofday(&timeval);
time_to_tm(timeval.tv_sec, 0, &time);
event->second = bin2bcd(time.tm_sec);
event->minute = bin2bcd(time.tm_min);
event->hour = bin2bcd(time.tm_hour);
event->day = bin2bcd(time.tm_mday);
event->month = bin2bcd(time.tm_mon + 1);
event->year = bin2bcd(time.tm_year % 100);
}
/*
* Fill out an event structure with space for the data and checksum.
*/
void elog_prepare_event(struct event_header *event, u8 event_type, void *data,
u8 data_size)
{
event->type = event_type;
event->length = sizeof(*event) + data_size + 1;
elog_fill_timestamp(event);
if (data_size)
memcpy(&event[1], data, data_size);
/* Zero the checksum byte and then compute checksum */
elog_update_checksum(event, 0);
elog_update_checksum(event, -(elog_checksum_event(event)));
}
static int chromeos_arm_elog_panic(struct notifier_block *this,
unsigned long p_event, void *ptr)
{
struct chromeos_arm_elog_panic_buffer *buf;
uint32_t reason = ELOG_SHUTDOWN_PANIC;
const u8 data_size = sizeof(reason);
union {
struct event_header hdr;
u8 bytes[sizeof(struct event_header) + data_size + 1];
} event;
buf = container_of(this, struct chromeos_arm_elog_panic_buffer, nb);
elog_prepare_event(&event.hdr, ELOG_TYPE_OS_EVENT, &reason, data_size);
memcpy_toio(buf->virt_addr, event.bytes, sizeof(event.bytes));
return NOTIFY_DONE;
}
static int chromeos_arm_panic_init(struct platform_device *pdev, u32 start,
u32 size)
{
int ret = -EINVAL;
struct chromeos_arm_elog_panic_buffer *buf;
buf = kmalloc(sizeof(*buf), GFP_KERNEL);
if (!buf) {
dev_err(&pdev->dev, "failed to allocate panic notifier.\n");
ret = -ENOMEM;
goto fail1;
}
buf->start = start;
buf->size = size;
buf->nb.notifier_call = chromeos_arm_elog_panic;
if (!request_mem_region(start, size, "elog panic event")) {
dev_err(&pdev->dev, "failed to request panic event buffer.\n");
goto fail2;
}
buf->virt_addr = ioremap(start, size);
if (!buf->virt_addr) {
dev_err(&pdev->dev, "failed to map panic event buffer.\n");
goto fail3;
}
atomic_notifier_chain_register(&panic_notifier_list, &buf->nb);
platform_set_drvdata(pdev, buf);
return 0;
fail3:
release_mem_region(start, size);
fail2:
kfree(buf);
fail1:
return ret;
}
static int chromeos_arm_probe(struct platform_device *pdev)
{
int gpio, err, active_low;
enum of_gpio_flags flags;
u32 elog_panic_event[2];
struct device_node *np = pdev->dev.of_node;
if (!np) {
err = -ENODEV;
goto err;
}
gpio = of_get_named_gpio_flags(np, "write-protect-gpio", 0, &flags);
if (!gpio_is_valid(gpio)) {
dev_err(&pdev->dev, "invalid write-protect gpio descriptor\n");
err = -EINVAL;
goto err;
}
active_low = !!(flags & OF_GPIO_ACTIVE_LOW);
err = gpio_request_one(gpio, GPIOF_DIR_IN, "firmware-write-protect");
if (err)
goto err;
err = gpio_sysfs_set_active_low(gpio, active_low);
if (err)
goto err;
gpio_export(gpio, 0);
gpio_export_link(&pdev->dev, "write-protect", gpio);
gpio = of_get_named_gpio_flags(np, "recovery-gpio", 0, &flags);
if (!gpio_is_valid(gpio)) {
dev_err(&pdev->dev, "invalid recovery gpio descriptor\n");
err = -EINVAL;
goto err;
}
active_low = !!(flags & OF_GPIO_ACTIVE_LOW);
err = gpio_request_one(gpio, GPIOF_DIR_IN, "firmware-recovery");
if (err)
goto err;
err = gpio_sysfs_set_active_low(gpio, active_low);
if (err)
goto err;
gpio_export(gpio, 0);
gpio_export_link(&pdev->dev, "recovery", gpio);
if (!of_property_read_u32_array(np, "elog-panic-event",
elog_panic_event,
ARRAY_SIZE(elog_panic_event))) {
err = chromeos_arm_panic_init(pdev, elog_panic_event[0],
elog_panic_event[1]);
if (err)
goto err;
}
dev_info(&pdev->dev, "chromeos system detected\n");
err = 0;
err:
of_node_put(np);
return err;
}
static int chromeos_arm_remove(struct platform_device *pdev)
{
struct chromeos_arm_elog_panic_buffer *buf;
buf = platform_get_drvdata(pdev);
platform_set_drvdata(pdev, NULL);
if (buf) {
atomic_notifier_chain_unregister(&panic_notifier_list,
&buf->nb);
release_mem_region(buf->start, buf->size);
iounmap(buf->virt_addr);
kfree(buf);
}
return 0;
}
static struct platform_driver chromeos_arm_driver = {
.probe = chromeos_arm_probe,
.remove = chromeos_arm_remove,
.driver = {
.name = "chromeos_arm",
},
};
static int __init chromeos_arm_init(void)
{
struct device_node *fw_dn;
struct platform_device *pdev;
fw_dn = of_find_compatible_node(NULL, NULL, "chromeos-firmware");
if (!fw_dn)
return -ENODEV;
pdev = platform_device_register_simple("chromeos_arm", -1, NULL, 0);
pdev->dev.of_node = fw_dn;
platform_driver_register(&chromeos_arm_driver);
return 0;
}
subsys_initcall(chromeos_arm_init);

186
drivers/platform/arm/elog.h Normal file
View File

@@ -0,0 +1,186 @@
/*
* This file is part of the coreboot project.
*
* Copyright (C) 2012 The ChromiumOS Authors. All rights reserved.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
*/
#ifndef ELOG_H_
#define ELOG_H_
/* SMI command code for GSMI event logging */
#define ELOG_GSMI_APM_CNT 0xEF
#define MAX_EVENT_SIZE 0x7F
/* End of log */
#define ELOG_TYPE_EOL 0xFF
/*
* Standard SMBIOS event log types below 0x80
*/
#define ELOG_TYPE_UNDEFINED_EVENT 0x00
#define ELOG_TYPE_SINGLE_BIT_ECC_MEM_ERR 0x01
#define ELOG_TYPE_MULTI_BIT_ECC_MEM_ERR 0x02
#define ELOG_TYPE_MEM_PARITY_ERR 0x03
#define ELOG_TYPE_BUS_TIMEOUT 0x04
#define ELOG_TYPE_IO_CHECK 0x05
#define ELOG_TYPE_SW_NMI 0x06
#define ELOG_TYPE_POST_MEM_RESIZE 0x07
#define ELOG_TYPE_POST_ERR 0x08
#define ELOG_TYPE_PCI_PERR 0x09
#define ELOG_TYPE_PCI_SERR 0x0A
#define ELOG_TYPE_CPU_FAIL 0x0B
#define ELOG_TYPE_EISA_TIMEOUT 0x0C
#define ELOG_TYPE_CORRECTABLE_MEMLOG_DIS 0x0D
#define ELOG_TYPE_LOG_DISABLED 0x0E
#define ELOG_TYPE_UNDEFINED_EVENT2 0x0F
#define ELOG_TYPE_SYS_LIMIT_EXCEED 0x10
#define ELOG_TYPE_ASYNC_HW_TIMER_EXPIRED 0x11
#define ELOG_TYPE_SYS_CONFIG_INFO 0x12
#define ELOG_TYPE_HDD_INFO 0x13
#define ELOG_TYPE_SYS_RECONFIG 0x14
#define ELOG_TYPE_CPU_ERROR 0x15
#define ELOG_TYPE_LOG_CLEAR 0x16
#define ELOG_TYPE_BOOT 0x17
/*
* Extended defined OEM event types start at 0x80
*/
/* OS/kernel events */
#define ELOG_TYPE_OS_EVENT 0x81
#define ELOG_SHUTDOWN_CLEAN 0 /* Clean Shutdown */
#define ELOG_SHUTDOWN_NMIWDT 1 /* NMI Watchdog */
#define ELOG_SHUTDOWN_PANIC 2 /* Panic */
#define ELOG_SHUTDOWN_OOPS 3 /* Oops */
#define ELOG_SHUTDOWN_DIE 4 /* Die - No longer meaningful */
#define ELOG_SHUTDOWN_MCE 5 /* Machine Check */
#define ELOG_SHUTDOWN_SOFTWDT 6 /* Software Watchdog */
#define ELOG_SHUTDOWN_MBE 7 /* Uncorrected ECC */
#define ELOG_SHUTDOWN_TRIPLE 8 /* Triple Fault */
#define ELOG_SHUTDOWN_THERMAL 9 /* Critical Thermal Threshold */
/* Last event from coreboot */
#define ELOG_TYPE_OS_BOOT 0x90
/* Embedded controller event */
#define ELOG_TYPE_EC_EVENT 0x91
#define EC_EVENT_LID_CLOSED 0x01
#define EC_EVENT_LID_OPEN 0x02
#define EC_EVENT_POWER_BUTTON 0x03
#define EC_EVENT_AC_CONNECTED 0x04
#define EC_EVENT_AC_DISCONNECTED 0x05
#define EC_EVENT_BATTERY_LOW 0x06
#define EC_EVENT_BATTERY_CRITICAL 0x07
#define EC_EVENT_BATTERY 0x08
#define EC_EVENT_THERMAL_THRESHOLD 0x09
#define EC_EVENT_THERMAL_OVERLOAD 0x0a
#define EC_EVENT_THERMAL 0x0b
#define EC_EVENT_USB_CHARGER 0x0c
#define EC_EVENT_KEY_PRESSED 0x0d
#define EC_EVENT_INTERFACE_READY 0x0e
#define EC_EVENT_KEYBOARD_RECOVERY 0x0f
#define EC_EVENT_THERMAL_SHUTDOWN 0x10
#define EC_EVENT_BATTERY_SHUTDOWN 0x11
#define EC_EVENT_FAN_ERROR 0x12
/* Power */
#define ELOG_TYPE_POWER_FAIL 0x92
#define ELOG_TYPE_SUS_POWER_FAIL 0x93
#define ELOG_TYPE_PWROK_FAIL 0x94
#define ELOG_TYPE_SYS_PWROK_FAIL 0x95
#define ELOG_TYPE_POWER_ON 0x96
#define ELOG_TYPE_POWER_BUTTON 0x97
#define ELOG_TYPE_POWER_BUTTON_OVERRIDE 0x98
/* Reset */
#define ELOG_TYPE_RESET_BUTTON 0x99
#define ELOG_TYPE_SYSTEM_RESET 0x9a
#define ELOG_TYPE_RTC_RESET 0x9b
#define ELOG_TYPE_TCO_RESET 0x9c
/* Sleep/Wake */
#define ELOG_TYPE_ACPI_ENTER 0x9d
#define ELOG_TYPE_ACPI_WAKE 0x9e
#define ELOG_TYPE_WAKE_SOURCE 0x9f
#define ELOG_WAKE_SOURCE_PCIE 0x00
#define ELOG_WAKE_SOURCE_PME 0x01
#define ELOG_WAKE_SOURCE_PME_INTERNAL 0x02
#define ELOG_WAKE_SOURCE_RTC 0x03
#define ELOG_WAKE_SOURCE_GPIO 0x04
#define ELOG_WAKE_SOURCE_SMBUS 0x05
#define ELOG_WAKE_SOURCE_PWRBTN 0x06
struct elog_event_data_wake {
u8 source;
u32 instance;
} __packed;
/* Chrome OS related events */
#define ELOG_TYPE_CROS_DEVELOPER_MODE 0xa0
#define ELOG_TYPE_CROS_RECOVERY_MODE 0xa1
#define ELOG_CROS_RECOVERY_MODE_BUTTON 0x02
/* Management Engine Events */
#define ELOG_TYPE_MANAGEMENT_ENGINE 0xa2
#define ELOG_TYPE_MANAGEMENT_ENGINE_EXT 0xa4
struct elog_event_data_me_extended {
u8 current_working_state;
u8 operation_state;
u8 operation_mode;
u8 error_code;
u8 progress_code;
u8 current_pmevent;
u8 current_state;
} __packed;
/* Last post code from previous boot */
#define ELOG_TYPE_LAST_POST_CODE 0xa3
/* EC Shutdown Reason */
#define ELOG_TYPE_EC_SHUTDOWN 0xa5
/* ARM/generic versions of sleep/wake */
#define ELOG_TYPE_SLEEP 0xa7
#define ELOG_TYPE_WAKE 0xa8
/* ELOG header */
struct elog_header {
u32 magic;
u8 version;
u8 header_size;
u8 reserved[2];
} __packed;
/* ELOG related constants */
#define ELOG_SIGNATURE 0x474f4c45 /* 'ELOG' */
#define ELOG_VERSION 1
/* SMBIOS event log header */
struct event_header {
u8 type;
u8 length;
u8 year;
u8 month;
u8 day;
u8 hour;
u8 minute;
u8 second;
} __packed;
extern void elog_prepare_event(struct event_header *event, u8 event_type,
void *data, u8 data_size);
#endif /* ELOG_H_ */