2018-06-28 13:58:36 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2018-09-26 11:58:14 +02:00
|
|
|
#include <arch/acpi.h>
|
2018-06-28 13:58:36 +02:00
|
|
|
#include <arch/io.h>
|
2020-02-24 16:08:35 +01:00
|
|
|
#include <bootmode.h>
|
2019-03-01 12:43:02 +01:00
|
|
|
#include <device/pci_ops.h>
|
2018-06-28 13:58:36 +02:00
|
|
|
#include <device/device.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "pmbase.h"
|
2018-09-26 11:58:14 +02:00
|
|
|
#include "pmutil.h"
|
2018-06-28 13:58:36 +02:00
|
|
|
|
|
|
|
/* LPC PM Base Address Register */
|
|
|
|
#define PMBASE 0x40
|
|
|
|
#define PMSIZE 0x80
|
|
|
|
|
|
|
|
/* PCI Configuration Space (D31:F0): LPC */
|
|
|
|
#if defined(__SIMPLE_DEVICE__)
|
|
|
|
#define PCH_LPC_DEV PCI_DEV(0, 0x1f, 0)
|
|
|
|
#else
|
2018-05-22 01:18:00 +02:00
|
|
|
#define PCH_LPC_DEV pcidev_on_root(0x1f, 0)
|
2018-06-28 13:58:36 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
u16 lpc_get_pmbase(void)
|
|
|
|
{
|
2019-11-05 17:50:38 +01:00
|
|
|
#ifdef __SIMPLE_DEVICE__
|
2018-06-28 13:58:36 +02:00
|
|
|
/* Don't assume PMBASE is still the same */
|
|
|
|
return pci_read_config16(PCH_LPC_DEV, PMBASE) & 0xfffc;
|
|
|
|
#else
|
2018-12-29 13:35:26 +01:00
|
|
|
static u16 pmbase;
|
2018-06-28 13:58:36 +02:00
|
|
|
|
|
|
|
if (pmbase)
|
|
|
|
return pmbase;
|
|
|
|
|
|
|
|
pmbase = pci_read_config16(PCH_LPC_DEV, PMBASE) & 0xfffc;
|
|
|
|
|
|
|
|
return pmbase;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_pmbase32(const u8 addr, const u32 val)
|
|
|
|
{
|
|
|
|
ASSERT(addr <= (PMSIZE - sizeof(u32)));
|
|
|
|
|
|
|
|
outl(val, lpc_get_pmbase() + addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_pmbase16(const u8 addr, const u16 val)
|
|
|
|
{
|
|
|
|
ASSERT(addr <= (PMSIZE - sizeof(u16)));
|
|
|
|
|
|
|
|
outw(val, lpc_get_pmbase() + addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_pmbase8(const u8 addr, const u8 val)
|
|
|
|
{
|
|
|
|
ASSERT(addr <= (PMSIZE - sizeof(u8)));
|
|
|
|
|
|
|
|
outb(val, lpc_get_pmbase() + addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 read_pmbase32(const u8 addr)
|
|
|
|
{
|
|
|
|
ASSERT(addr <= (PMSIZE - sizeof(u32)));
|
|
|
|
|
|
|
|
return inl(lpc_get_pmbase() + addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
u16 read_pmbase16(const u8 addr)
|
|
|
|
{
|
|
|
|
ASSERT(addr <= (PMSIZE - sizeof(u16)));
|
|
|
|
|
|
|
|
return inw(lpc_get_pmbase() + addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 read_pmbase8(const u8 addr)
|
|
|
|
{
|
|
|
|
ASSERT(addr <= (PMSIZE - sizeof(u8)));
|
|
|
|
|
|
|
|
return inb(lpc_get_pmbase() + addr);
|
|
|
|
}
|
2018-09-26 11:58:14 +02:00
|
|
|
|
2020-02-24 16:08:35 +01:00
|
|
|
int platform_is_resuming(void)
|
2018-09-26 11:58:14 +02:00
|
|
|
{
|
|
|
|
u16 reg16 = read_pmbase16(PM1_STS);
|
|
|
|
|
|
|
|
if (!(reg16 & WAK_STS))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return acpi_sleep_from_pm1(reg16) == ACPI_S3;
|
|
|
|
}
|