2018-03-21 22:23:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Hisilicon Limited, All Rights Reserved.
|
|
|
|
* Author: Zhichang Yuan <yuanzhichang@hisilicon.com>
|
|
|
|
* Author: Zou Rongrong <zourongrong@huawei.com>
|
|
|
|
* Author: John Garry <john.garry@huawei.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/logic_pio.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/pci.h>
|
2023-08-03 22:42:56 +00:00
|
|
|
#include <linux/platform_device.h>
|
2018-05-08 10:27:32 +00:00
|
|
|
#include <linux/serial_8250.h>
|
2018-03-21 22:23:02 +00:00
|
|
|
#include <linux/slab.h>
|
|
|
|
|
|
|
|
#define DRV_NAME "hisi-lpc"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setting this bit means each IO operation will target a different port
|
|
|
|
* address; 0 means repeated IO operations will use the same port,
|
|
|
|
* such as BT.
|
|
|
|
*/
|
|
|
|
#define FG_INCRADDR_LPC 0x02
|
|
|
|
|
|
|
|
struct lpc_cycle_para {
|
|
|
|
unsigned int opflags;
|
|
|
|
unsigned int csize; /* data length of each operation */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct hisi_lpc_dev {
|
|
|
|
spinlock_t cycle_lock;
|
|
|
|
void __iomem *membase;
|
|
|
|
struct logic_pio_hwaddr *io_host;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The max IO cycle counts supported is four per operation at maximum */
|
|
|
|
#define LPC_MAX_DWIDTH 4
|
|
|
|
|
|
|
|
#define LPC_REG_STARTUP_SIGNAL 0x00
|
|
|
|
#define LPC_REG_STARTUP_SIGNAL_START BIT(0)
|
|
|
|
#define LPC_REG_OP_STATUS 0x04
|
|
|
|
#define LPC_REG_OP_STATUS_IDLE BIT(0)
|
|
|
|
#define LPC_REG_OP_STATUS_FINISHED BIT(1)
|
|
|
|
#define LPC_REG_OP_LEN 0x10 /* LPC cycles count per start */
|
|
|
|
#define LPC_REG_CMD 0x14
|
|
|
|
#define LPC_REG_CMD_OP BIT(0) /* 0: read, 1: write */
|
|
|
|
#define LPC_REG_CMD_SAMEADDR BIT(3)
|
|
|
|
#define LPC_REG_ADDR 0x20 /* target address */
|
|
|
|
#define LPC_REG_WDATA 0x24 /* write FIFO */
|
|
|
|
#define LPC_REG_RDATA 0x28 /* read FIFO */
|
|
|
|
|
|
|
|
/* The minimal nanosecond interval for each query on LPC cycle status */
|
|
|
|
#define LPC_NSEC_PERWAIT 100
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The maximum waiting time is about 128us. It is specific for stream I/O,
|
|
|
|
* such as ins.
|
|
|
|
*
|
|
|
|
* The fastest IO cycle time is about 390ns, but the worst case will wait
|
|
|
|
* for extra 256 lpc clocks, so (256 + 13) * 30ns = 8 us. The maximum burst
|
|
|
|
* cycles is 16. So, the maximum waiting time is about 128us under worst
|
|
|
|
* case.
|
|
|
|
*
|
|
|
|
* Choose 1300 as the maximum.
|
|
|
|
*/
|
|
|
|
#define LPC_MAX_WAITCNT 1300
|
|
|
|
|
|
|
|
/* About 10us. This is specific for single IO operations, such as inb */
|
|
|
|
#define LPC_PEROP_WAITCNT 100
|
|
|
|
|
2019-11-04 17:22:17 +00:00
|
|
|
static int wait_lpc_idle(void __iomem *mbase, unsigned int waitcnt)
|
2018-03-21 22:23:02 +00:00
|
|
|
{
|
|
|
|
u32 status;
|
|
|
|
|
|
|
|
do {
|
|
|
|
status = readl(mbase + LPC_REG_OP_STATUS);
|
|
|
|
if (status & LPC_REG_OP_STATUS_IDLE)
|
|
|
|
return (status & LPC_REG_OP_STATUS_FINISHED) ? 0 : -EIO;
|
|
|
|
ndelay(LPC_NSEC_PERWAIT);
|
|
|
|
} while (--waitcnt);
|
|
|
|
|
2022-09-05 08:23:04 +00:00
|
|
|
return -ETIMEDOUT;
|
2018-03-21 22:23:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hisi_lpc_target_in - trigger a series of LPC cycles for read operation
|
|
|
|
* @lpcdev: pointer to hisi lpc device
|
|
|
|
* @para: some parameters used to control the lpc I/O operations
|
|
|
|
* @addr: the lpc I/O target port address
|
|
|
|
* @buf: where the read back data is stored
|
|
|
|
* @opcnt: how many I/O operations required, i.e. data width
|
|
|
|
*
|
|
|
|
* Returns 0 on success, non-zero on fail.
|
|
|
|
*/
|
|
|
|
static int hisi_lpc_target_in(struct hisi_lpc_dev *lpcdev,
|
|
|
|
struct lpc_cycle_para *para, unsigned long addr,
|
|
|
|
unsigned char *buf, unsigned long opcnt)
|
|
|
|
{
|
|
|
|
unsigned int cmd_word;
|
|
|
|
unsigned int waitcnt;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!buf || !opcnt || !para || !para->csize || !lpcdev)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
cmd_word = 0; /* IO mode, Read */
|
|
|
|
waitcnt = LPC_PEROP_WAITCNT;
|
|
|
|
if (!(para->opflags & FG_INCRADDR_LPC)) {
|
|
|
|
cmd_word |= LPC_REG_CMD_SAMEADDR;
|
|
|
|
waitcnt = LPC_MAX_WAITCNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* whole operation must be atomic */
|
|
|
|
spin_lock_irqsave(&lpcdev->cycle_lock, flags);
|
|
|
|
|
|
|
|
writel_relaxed(opcnt, lpcdev->membase + LPC_REG_OP_LEN);
|
|
|
|
writel_relaxed(cmd_word, lpcdev->membase + LPC_REG_CMD);
|
|
|
|
writel_relaxed(addr, lpcdev->membase + LPC_REG_ADDR);
|
|
|
|
|
|
|
|
writel(LPC_REG_STARTUP_SIGNAL_START,
|
|
|
|
lpcdev->membase + LPC_REG_STARTUP_SIGNAL);
|
|
|
|
|
|
|
|
/* whether the operation is finished */
|
|
|
|
ret = wait_lpc_idle(lpcdev->membase, waitcnt);
|
|
|
|
if (ret) {
|
|
|
|
spin_unlock_irqrestore(&lpcdev->cycle_lock, flags);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
readsb(lpcdev->membase + LPC_REG_RDATA, buf, opcnt);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&lpcdev->cycle_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hisi_lpc_target_out - trigger a series of LPC cycles for write operation
|
|
|
|
* @lpcdev: pointer to hisi lpc device
|
|
|
|
* @para: some parameters used to control the lpc I/O operations
|
|
|
|
* @addr: the lpc I/O target port address
|
|
|
|
* @buf: where the data to be written is stored
|
|
|
|
* @opcnt: how many I/O operations required, i.e. data width
|
|
|
|
*
|
|
|
|
* Returns 0 on success, non-zero on fail.
|
|
|
|
*/
|
|
|
|
static int hisi_lpc_target_out(struct hisi_lpc_dev *lpcdev,
|
|
|
|
struct lpc_cycle_para *para, unsigned long addr,
|
|
|
|
const unsigned char *buf, unsigned long opcnt)
|
|
|
|
{
|
|
|
|
unsigned int waitcnt;
|
|
|
|
unsigned long flags;
|
|
|
|
u32 cmd_word;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!buf || !opcnt || !para || !lpcdev)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* default is increasing address */
|
|
|
|
cmd_word = LPC_REG_CMD_OP; /* IO mode, write */
|
|
|
|
waitcnt = LPC_PEROP_WAITCNT;
|
|
|
|
if (!(para->opflags & FG_INCRADDR_LPC)) {
|
|
|
|
cmd_word |= LPC_REG_CMD_SAMEADDR;
|
|
|
|
waitcnt = LPC_MAX_WAITCNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&lpcdev->cycle_lock, flags);
|
|
|
|
|
|
|
|
writel_relaxed(opcnt, lpcdev->membase + LPC_REG_OP_LEN);
|
|
|
|
writel_relaxed(cmd_word, lpcdev->membase + LPC_REG_CMD);
|
|
|
|
writel_relaxed(addr, lpcdev->membase + LPC_REG_ADDR);
|
|
|
|
|
|
|
|
writesb(lpcdev->membase + LPC_REG_WDATA, buf, opcnt);
|
|
|
|
|
|
|
|
writel(LPC_REG_STARTUP_SIGNAL_START,
|
|
|
|
lpcdev->membase + LPC_REG_STARTUP_SIGNAL);
|
|
|
|
|
|
|
|
/* whether the operation is finished */
|
|
|
|
ret = wait_lpc_idle(lpcdev->membase, waitcnt);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&lpcdev->cycle_lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned long hisi_lpc_pio_to_addr(struct hisi_lpc_dev *lpcdev,
|
|
|
|
unsigned long pio)
|
|
|
|
{
|
|
|
|
return pio - lpcdev->io_host->io_start + lpcdev->io_host->hw_start;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hisi_lpc_comm_in - input the data in a single operation
|
|
|
|
* @hostdata: pointer to the device information relevant to LPC controller
|
|
|
|
* @pio: the target I/O port address
|
|
|
|
* @dwidth: the data length required to read from the target I/O port
|
|
|
|
*
|
|
|
|
* When success, data is returned. Otherwise, ~0 is returned.
|
|
|
|
*/
|
|
|
|
static u32 hisi_lpc_comm_in(void *hostdata, unsigned long pio, size_t dwidth)
|
|
|
|
{
|
|
|
|
struct hisi_lpc_dev *lpcdev = hostdata;
|
|
|
|
struct lpc_cycle_para iopara;
|
|
|
|
unsigned long addr;
|
2019-11-04 17:22:17 +00:00
|
|
|
__le32 rd_data = 0;
|
2018-03-21 22:23:02 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!lpcdev || !dwidth || dwidth > LPC_MAX_DWIDTH)
|
|
|
|
return ~0;
|
|
|
|
|
|
|
|
addr = hisi_lpc_pio_to_addr(lpcdev, pio);
|
|
|
|
|
|
|
|
iopara.opflags = FG_INCRADDR_LPC;
|
|
|
|
iopara.csize = dwidth;
|
|
|
|
|
|
|
|
ret = hisi_lpc_target_in(lpcdev, &iopara, addr,
|
|
|
|
(unsigned char *)&rd_data, dwidth);
|
|
|
|
if (ret)
|
|
|
|
return ~0;
|
|
|
|
|
|
|
|
return le32_to_cpu(rd_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hisi_lpc_comm_out - output the data in a single operation
|
|
|
|
* @hostdata: pointer to the device information relevant to LPC controller
|
|
|
|
* @pio: the target I/O port address
|
|
|
|
* @val: a value to be output from caller, maximum is four bytes
|
|
|
|
* @dwidth: the data width required writing to the target I/O port
|
|
|
|
*
|
|
|
|
* This function corresponds to out(b,w,l) only.
|
|
|
|
*/
|
|
|
|
static void hisi_lpc_comm_out(void *hostdata, unsigned long pio,
|
|
|
|
u32 val, size_t dwidth)
|
|
|
|
{
|
|
|
|
struct hisi_lpc_dev *lpcdev = hostdata;
|
|
|
|
struct lpc_cycle_para iopara;
|
|
|
|
const unsigned char *buf;
|
|
|
|
unsigned long addr;
|
2019-11-04 17:22:17 +00:00
|
|
|
__le32 _val = cpu_to_le32(val);
|
2018-03-21 22:23:02 +00:00
|
|
|
|
|
|
|
if (!lpcdev || !dwidth || dwidth > LPC_MAX_DWIDTH)
|
|
|
|
return;
|
|
|
|
|
2019-11-04 17:22:17 +00:00
|
|
|
buf = (const unsigned char *)&_val;
|
2018-03-21 22:23:02 +00:00
|
|
|
addr = hisi_lpc_pio_to_addr(lpcdev, pio);
|
|
|
|
|
|
|
|
iopara.opflags = FG_INCRADDR_LPC;
|
|
|
|
iopara.csize = dwidth;
|
|
|
|
|
|
|
|
hisi_lpc_target_out(lpcdev, &iopara, addr, buf, dwidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hisi_lpc_comm_ins - input the data in the buffer in multiple operations
|
|
|
|
* @hostdata: pointer to the device information relevant to LPC controller
|
|
|
|
* @pio: the target I/O port address
|
|
|
|
* @buffer: a buffer where read/input data bytes are stored
|
|
|
|
* @dwidth: the data width required writing to the target I/O port
|
|
|
|
* @count: how many data units whose length is dwidth will be read
|
|
|
|
*
|
|
|
|
* When success, the data read back is stored in buffer pointed by buffer.
|
|
|
|
* Returns 0 on success, -errno otherwise.
|
|
|
|
*/
|
|
|
|
static u32 hisi_lpc_comm_ins(void *hostdata, unsigned long pio, void *buffer,
|
|
|
|
size_t dwidth, unsigned int count)
|
|
|
|
{
|
|
|
|
struct hisi_lpc_dev *lpcdev = hostdata;
|
|
|
|
unsigned char *buf = buffer;
|
|
|
|
struct lpc_cycle_para iopara;
|
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
if (!lpcdev || !buf || !count || !dwidth || dwidth > LPC_MAX_DWIDTH)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
iopara.opflags = 0;
|
|
|
|
if (dwidth > 1)
|
|
|
|
iopara.opflags |= FG_INCRADDR_LPC;
|
|
|
|
iopara.csize = dwidth;
|
|
|
|
|
|
|
|
addr = hisi_lpc_pio_to_addr(lpcdev, pio);
|
|
|
|
|
|
|
|
do {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = hisi_lpc_target_in(lpcdev, &iopara, addr, buf, dwidth);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
buf += dwidth;
|
|
|
|
} while (--count);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hisi_lpc_comm_outs - output the data in the buffer in multiple operations
|
|
|
|
* @hostdata: pointer to the device information relevant to LPC controller
|
|
|
|
* @pio: the target I/O port address
|
|
|
|
* @buffer: a buffer where write/output data bytes are stored
|
|
|
|
* @dwidth: the data width required writing to the target I/O port
|
|
|
|
* @count: how many data units whose length is dwidth will be written
|
|
|
|
*/
|
|
|
|
static void hisi_lpc_comm_outs(void *hostdata, unsigned long pio,
|
|
|
|
const void *buffer, size_t dwidth,
|
|
|
|
unsigned int count)
|
|
|
|
{
|
|
|
|
struct hisi_lpc_dev *lpcdev = hostdata;
|
|
|
|
struct lpc_cycle_para iopara;
|
|
|
|
const unsigned char *buf = buffer;
|
|
|
|
unsigned long addr;
|
|
|
|
|
|
|
|
if (!lpcdev || !buf || !count || !dwidth || dwidth > LPC_MAX_DWIDTH)
|
|
|
|
return;
|
|
|
|
|
|
|
|
iopara.opflags = 0;
|
|
|
|
if (dwidth > 1)
|
|
|
|
iopara.opflags |= FG_INCRADDR_LPC;
|
|
|
|
iopara.csize = dwidth;
|
|
|
|
|
|
|
|
addr = hisi_lpc_pio_to_addr(lpcdev, pio);
|
|
|
|
do {
|
|
|
|
if (hisi_lpc_target_out(lpcdev, &iopara, addr, buf, dwidth))
|
|
|
|
break;
|
|
|
|
buf += dwidth;
|
|
|
|
} while (--count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct logic_pio_host_ops hisi_lpc_ops = {
|
|
|
|
.in = hisi_lpc_comm_in,
|
|
|
|
.out = hisi_lpc_comm_out,
|
|
|
|
.ins = hisi_lpc_comm_ins,
|
|
|
|
.outs = hisi_lpc_comm_outs,
|
|
|
|
};
|
|
|
|
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
#ifdef CONFIG_ACPI
|
|
|
|
static int hisi_lpc_acpi_xlat_io_res(struct acpi_device *adev,
|
|
|
|
struct acpi_device *host,
|
|
|
|
struct resource *res)
|
|
|
|
{
|
|
|
|
unsigned long sys_port;
|
|
|
|
resource_size_t len = resource_size(res);
|
|
|
|
|
2022-09-05 08:23:02 +00:00
|
|
|
sys_port = logic_pio_trans_hwaddr(acpi_fwnode_handle(host), res->start, len);
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
if (sys_port == ~0UL)
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
res->start = sys_port;
|
|
|
|
res->end = sys_port + len;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-16 18:48:34 +00:00
|
|
|
/*
|
|
|
|
* Released firmware describes the IO port max address as 0x3fff, which is
|
|
|
|
* the max host bus address. Fixup to a proper range. This will probably
|
|
|
|
* never be fixed in firmware.
|
|
|
|
*/
|
|
|
|
static void hisi_lpc_acpi_fixup_child_resource(struct device *hostdev,
|
|
|
|
struct resource *r)
|
|
|
|
{
|
|
|
|
if (r->end != 0x3fff)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (r->start == 0xe4)
|
|
|
|
r->end = 0xe4 + 0x04 - 1;
|
|
|
|
else if (r->start == 0x2f8)
|
|
|
|
r->end = 0x2f8 + 0x08 - 1;
|
|
|
|
else
|
|
|
|
dev_warn(hostdev, "unrecognised resource %pR to fixup, ignoring\n",
|
|
|
|
r);
|
|
|
|
}
|
|
|
|
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
/*
|
2018-05-08 10:27:30 +00:00
|
|
|
* hisi_lpc_acpi_set_io_res - set the resources for a child
|
2022-06-30 18:13:52 +00:00
|
|
|
* @adev: ACPI companion of the device node to be updated the I/O resource
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
* @hostdev: the device node associated with host controller
|
|
|
|
* @res: double pointer to be set to the address of translated resources
|
|
|
|
* @num_res: pointer to variable to hold the number of translated resources
|
|
|
|
*
|
|
|
|
* Returns 0 when successful, and a negative value for failure.
|
|
|
|
*
|
|
|
|
* For a given host controller, each child device will have an associated
|
|
|
|
* host-relative address resource. This function will return the translated
|
|
|
|
* logical PIO addresses for each child devices resources.
|
|
|
|
*/
|
2022-06-30 18:13:52 +00:00
|
|
|
static int hisi_lpc_acpi_set_io_res(struct acpi_device *adev,
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
struct device *hostdev,
|
|
|
|
const struct resource **res, int *num_res)
|
|
|
|
{
|
2022-06-30 18:13:52 +00:00
|
|
|
struct acpi_device *host = to_acpi_device(adev->dev.parent);
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
struct resource_entry *rentry;
|
|
|
|
LIST_HEAD(resource_list);
|
|
|
|
struct resource *resources;
|
|
|
|
int count;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!adev->status.present) {
|
2022-06-30 18:13:52 +00:00
|
|
|
dev_dbg(&adev->dev, "device is not present\n");
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (acpi_device_enumerated(adev)) {
|
2022-06-30 18:13:52 +00:00
|
|
|
dev_dbg(&adev->dev, "has been enumerated\n");
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following code segment to retrieve the resources is common to
|
|
|
|
* acpi_create_platform_device(), so consider a common helper function
|
|
|
|
* in future.
|
|
|
|
*/
|
|
|
|
count = acpi_dev_get_resources(adev, &resource_list, NULL, NULL);
|
|
|
|
if (count <= 0) {
|
2022-06-30 18:13:52 +00:00
|
|
|
dev_dbg(&adev->dev, "failed to get resources\n");
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
return count ? count : -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
resources = devm_kcalloc(hostdev, count, sizeof(*resources),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!resources) {
|
|
|
|
dev_warn(hostdev, "could not allocate memory for %d resources\n",
|
|
|
|
count);
|
|
|
|
acpi_dev_free_resource_list(&resource_list);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
count = 0;
|
2020-01-16 18:48:34 +00:00
|
|
|
list_for_each_entry(rentry, &resource_list, node) {
|
|
|
|
resources[count] = *rentry->res;
|
|
|
|
hisi_lpc_acpi_fixup_child_resource(hostdev, &resources[count]);
|
|
|
|
count++;
|
|
|
|
}
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
|
|
|
|
acpi_dev_free_resource_list(&resource_list);
|
|
|
|
|
|
|
|
/* translate the I/O resources */
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(resources[i].flags & IORESOURCE_IO))
|
|
|
|
continue;
|
|
|
|
ret = hisi_lpc_acpi_xlat_io_res(adev, host, &resources[i]);
|
|
|
|
if (ret) {
|
2022-06-30 18:13:52 +00:00
|
|
|
dev_err(&adev->dev, "translate IO range %pR failed (%d)\n",
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
&resources[i], ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*res = resources;
|
|
|
|
*num_res = count;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-08 10:27:31 +00:00
|
|
|
static int hisi_lpc_acpi_remove_subdev(struct device *dev, void *unused)
|
|
|
|
{
|
|
|
|
platform_device_unregister(to_platform_device(dev));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-30 18:13:52 +00:00
|
|
|
static int hisi_lpc_acpi_clear_enumerated(struct acpi_device *adev, void *not_used)
|
|
|
|
{
|
|
|
|
acpi_device_clear_enumerated(adev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-08 10:27:31 +00:00
|
|
|
struct hisi_lpc_acpi_cell {
|
|
|
|
const char *hid;
|
2022-09-05 08:23:06 +00:00
|
|
|
const struct platform_device_info *pdevinfo;
|
2018-05-08 10:27:31 +00:00
|
|
|
};
|
|
|
|
|
bus: hisi_lpc: Add .remove method to avoid driver unbind crash
The original driver author seemed to be under the impression that a driver
cannot be removed if it does not have a .remove method. Or maybe if it is
a built-in platform driver.
This is not true. This crash can be created:
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# echo HISI0191\:00 > unbind
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# ipmitool raw 6 1
Unable to handle kernel paging request at virtual address ffff000010035010
Mem abort info:
ESR = 0x96000047
Exception class = DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
Data abort info:
ISV = 0, ISS = 0x00000047
CM = 0, WnR = 1
swapper pgtable: 4k pages, 48-bit VAs, pgdp=000000000118b000
[ffff000010035010] pgd=0000041ffbfff003, pud=0000041ffbffe003, pmd=0000041ffbffd003, pte=0000000000000000
Internal error: Oops: 96000047 [#1] PREEMPT SMP
Modules linked in:
CPU: 17 PID: 1473 Comm: ipmitool Not tainted 5.2.0-rc5-00003-gf68c53b414a3-dirty #198
Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT21 Nemo 2.0 RC0 04/18/2018
pstate: 20000085 (nzCv daIf -PAN -UAO)
pc : hisi_lpc_target_in+0x7c/0x120
lr : hisi_lpc_target_in+0x70/0x120
sp : ffff00001efe3930
x29: ffff00001efe3930 x28: ffff841f9f599200
x27: 0000000000000002 x26: 0000000000000000
x25: 0000000000000080 x24: 00000000000000e4
x23: 0000000000000000 x22: 0000000000000064
x21: ffff801fb667d280 x20: 0000000000000001
x19: ffff00001efe39ac x18: 0000000000000000
x17: 0000000000000000 x16: 0000000000000000
x15: 0000000000000000 x14: 0000000000000000
x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000000
x9 : 0000000000000000 x8 : ffff841febe60340
x7 : ffff801fb55c52e8 x6 : 0000000000000000
x5 : 0000000000ffc0e3 x4 : 0000000000000001
x3 : ffff801fb667d280 x2 : 0000000000000001
x1 : ffff000010035010 x0 : ffff000010035000
Call trace:
hisi_lpc_target_in+0x7c/0x120
hisi_lpc_comm_in+0x88/0x98
logic_inb+0x5c/0xb8
port_inb+0x18/0x20
bt_event+0x38/0x808
smi_event_handler+0x4c/0x5a0
check_start_timer_thread.part.4+0x40/0x58
sender+0x78/0x88
smi_send.isra.6+0x94/0x108
i_ipmi_request+0x2c4/0x8f8
ipmi_request_settime+0x124/0x160
handle_send_req+0x19c/0x208
ipmi_ioctl+0x2c0/0x990
do_vfs_ioctl+0xb8/0x8f8
ksys_ioctl+0x80/0xb8
__arm64_sys_ioctl+0x1c/0x28
el0_svc_common.constprop.0+0x64/0x160
el0_svc_handler+0x28/0x78
el0_svc+0x8/0xc
Code: 941d1511 aa0003f9 f94006a0 91004001 (b9000034)
---[ end trace aa842b86af7069e4 ]---
The problem here is that the host goes away but the associated logical PIO
region remains registered, as do the children devices.
Fix by adding a .remove method to tidy-up by removing the child devices
and unregistering the logical PIO region.
Cc: stable@vger.kernel.org
Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
2019-07-30 13:29:56 +00:00
|
|
|
static void hisi_lpc_acpi_remove(struct device *hostdev)
|
|
|
|
{
|
|
|
|
device_for_each_child(hostdev, NULL, hisi_lpc_acpi_remove_subdev);
|
2022-06-30 18:13:52 +00:00
|
|
|
acpi_dev_for_each_child(ACPI_COMPANION(hostdev),
|
|
|
|
hisi_lpc_acpi_clear_enumerated, NULL);
|
bus: hisi_lpc: Add .remove method to avoid driver unbind crash
The original driver author seemed to be under the impression that a driver
cannot be removed if it does not have a .remove method. Or maybe if it is
a built-in platform driver.
This is not true. This crash can be created:
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# echo HISI0191\:00 > unbind
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# ipmitool raw 6 1
Unable to handle kernel paging request at virtual address ffff000010035010
Mem abort info:
ESR = 0x96000047
Exception class = DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
Data abort info:
ISV = 0, ISS = 0x00000047
CM = 0, WnR = 1
swapper pgtable: 4k pages, 48-bit VAs, pgdp=000000000118b000
[ffff000010035010] pgd=0000041ffbfff003, pud=0000041ffbffe003, pmd=0000041ffbffd003, pte=0000000000000000
Internal error: Oops: 96000047 [#1] PREEMPT SMP
Modules linked in:
CPU: 17 PID: 1473 Comm: ipmitool Not tainted 5.2.0-rc5-00003-gf68c53b414a3-dirty #198
Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT21 Nemo 2.0 RC0 04/18/2018
pstate: 20000085 (nzCv daIf -PAN -UAO)
pc : hisi_lpc_target_in+0x7c/0x120
lr : hisi_lpc_target_in+0x70/0x120
sp : ffff00001efe3930
x29: ffff00001efe3930 x28: ffff841f9f599200
x27: 0000000000000002 x26: 0000000000000000
x25: 0000000000000080 x24: 00000000000000e4
x23: 0000000000000000 x22: 0000000000000064
x21: ffff801fb667d280 x20: 0000000000000001
x19: ffff00001efe39ac x18: 0000000000000000
x17: 0000000000000000 x16: 0000000000000000
x15: 0000000000000000 x14: 0000000000000000
x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000000
x9 : 0000000000000000 x8 : ffff841febe60340
x7 : ffff801fb55c52e8 x6 : 0000000000000000
x5 : 0000000000ffc0e3 x4 : 0000000000000001
x3 : ffff801fb667d280 x2 : 0000000000000001
x1 : ffff000010035010 x0 : ffff000010035000
Call trace:
hisi_lpc_target_in+0x7c/0x120
hisi_lpc_comm_in+0x88/0x98
logic_inb+0x5c/0xb8
port_inb+0x18/0x20
bt_event+0x38/0x808
smi_event_handler+0x4c/0x5a0
check_start_timer_thread.part.4+0x40/0x58
sender+0x78/0x88
smi_send.isra.6+0x94/0x108
i_ipmi_request+0x2c4/0x8f8
ipmi_request_settime+0x124/0x160
handle_send_req+0x19c/0x208
ipmi_ioctl+0x2c0/0x990
do_vfs_ioctl+0xb8/0x8f8
ksys_ioctl+0x80/0xb8
__arm64_sys_ioctl+0x1c/0x28
el0_svc_common.constprop.0+0x64/0x160
el0_svc_handler+0x28/0x78
el0_svc+0x8/0xc
Code: 941d1511 aa0003f9 f94006a0 91004001 (b9000034)
---[ end trace aa842b86af7069e4 ]---
The problem here is that the host goes away but the associated logical PIO
region remains registered, as do the children devices.
Fix by adding a .remove method to tidy-up by removing the child devices
and unregistering the logical PIO region.
Cc: stable@vger.kernel.org
Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
2019-07-30 13:29:56 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 18:13:52 +00:00
|
|
|
static int hisi_lpc_acpi_add_child(struct acpi_device *child, void *data)
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
{
|
2022-06-30 18:13:52 +00:00
|
|
|
const char *hid = acpi_device_hid(child);
|
|
|
|
struct device *hostdev = data;
|
|
|
|
const struct hisi_lpc_acpi_cell *cell;
|
2022-07-01 09:43:52 +00:00
|
|
|
struct platform_device *pdev;
|
2022-06-30 18:13:52 +00:00
|
|
|
const struct resource *res;
|
|
|
|
bool found = false;
|
|
|
|
int num_res;
|
2018-05-08 10:27:30 +00:00
|
|
|
int ret;
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
|
2022-06-30 18:13:52 +00:00
|
|
|
ret = hisi_lpc_acpi_set_io_res(child, hostdev, &res, &num_res);
|
|
|
|
if (ret) {
|
|
|
|
dev_warn(hostdev, "set resource fail (%d)\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2018-05-08 10:27:31 +00:00
|
|
|
|
2022-06-30 18:13:52 +00:00
|
|
|
cell = (struct hisi_lpc_acpi_cell []){
|
|
|
|
/* ipmi */
|
|
|
|
{
|
|
|
|
.hid = "IPI0001",
|
2022-09-05 08:23:06 +00:00
|
|
|
.pdevinfo = (struct platform_device_info []) {
|
|
|
|
{
|
|
|
|
.parent = hostdev,
|
|
|
|
.fwnode = acpi_fwnode_handle(child),
|
|
|
|
.name = "hisi-lpc-ipmi",
|
|
|
|
.id = PLATFORM_DEVID_AUTO,
|
|
|
|
.res = res,
|
|
|
|
.num_res = num_res,
|
|
|
|
},
|
|
|
|
},
|
2022-06-30 18:13:52 +00:00
|
|
|
},
|
|
|
|
/* 8250-compatible uart */
|
|
|
|
{
|
|
|
|
.hid = "HISI1031",
|
2022-09-05 08:23:06 +00:00
|
|
|
.pdevinfo = (struct platform_device_info []) {
|
2022-06-30 18:13:52 +00:00
|
|
|
{
|
2022-09-05 08:23:06 +00:00
|
|
|
.parent = hostdev,
|
|
|
|
.fwnode = acpi_fwnode_handle(child),
|
|
|
|
.name = "serial8250",
|
|
|
|
.id = PLATFORM_DEVID_AUTO,
|
|
|
|
.res = res,
|
|
|
|
.num_res = num_res,
|
|
|
|
.data = (struct plat_serial8250_port []) {
|
|
|
|
{
|
|
|
|
.iobase = res->start,
|
|
|
|
.uartclk = 1843200,
|
|
|
|
.iotype = UPIO_PORT,
|
|
|
|
.flags = UPF_BOOT_AUTOCONF,
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
},
|
|
|
|
.size_data = 2 * sizeof(struct plat_serial8250_port),
|
2018-05-08 10:27:32 +00:00
|
|
|
},
|
|
|
|
},
|
2022-06-30 18:13:52 +00:00
|
|
|
},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2022-09-05 08:23:06 +00:00
|
|
|
for (; cell && cell->hid; cell++) {
|
2022-06-30 18:13:52 +00:00
|
|
|
if (!strcmp(cell->hid, hid)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
2018-05-08 10:27:31 +00:00
|
|
|
}
|
2022-06-30 18:13:52 +00:00
|
|
|
}
|
2018-05-08 10:27:31 +00:00
|
|
|
|
2022-06-30 18:13:52 +00:00
|
|
|
if (!found) {
|
|
|
|
dev_warn(hostdev,
|
|
|
|
"could not find cell for child device (%s), discarding\n",
|
|
|
|
hid);
|
|
|
|
return 0;
|
|
|
|
}
|
2018-05-08 10:27:31 +00:00
|
|
|
|
2022-09-05 08:23:06 +00:00
|
|
|
pdev = platform_device_register_full(cell->pdevinfo);
|
|
|
|
if (IS_ERR(pdev))
|
|
|
|
return PTR_ERR(pdev);
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
|
2022-06-30 18:13:52 +00:00
|
|
|
acpi_device_set_enumerated(child);
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
return 0;
|
2022-06-30 18:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hisi_lpc_acpi_probe - probe children for ACPI FW
|
|
|
|
* @hostdev: LPC host device pointer
|
|
|
|
*
|
|
|
|
* Returns 0 when successful, and a negative value for failure.
|
|
|
|
*
|
|
|
|
* Create a platform device per child, fixing up the resources
|
|
|
|
* from bus addresses to Logical PIO addresses.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int hisi_lpc_acpi_probe(struct device *hostdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Only consider the children of the host */
|
|
|
|
ret = acpi_dev_for_each_child(ACPI_COMPANION(hostdev),
|
|
|
|
hisi_lpc_acpi_add_child, hostdev);
|
|
|
|
if (ret)
|
|
|
|
hisi_lpc_acpi_remove(hostdev);
|
|
|
|
|
2018-05-08 10:27:31 +00:00
|
|
|
return ret;
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int hisi_lpc_acpi_probe(struct device *dev)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
bus: hisi_lpc: Add .remove method to avoid driver unbind crash
The original driver author seemed to be under the impression that a driver
cannot be removed if it does not have a .remove method. Or maybe if it is
a built-in platform driver.
This is not true. This crash can be created:
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# echo HISI0191\:00 > unbind
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# ipmitool raw 6 1
Unable to handle kernel paging request at virtual address ffff000010035010
Mem abort info:
ESR = 0x96000047
Exception class = DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
Data abort info:
ISV = 0, ISS = 0x00000047
CM = 0, WnR = 1
swapper pgtable: 4k pages, 48-bit VAs, pgdp=000000000118b000
[ffff000010035010] pgd=0000041ffbfff003, pud=0000041ffbffe003, pmd=0000041ffbffd003, pte=0000000000000000
Internal error: Oops: 96000047 [#1] PREEMPT SMP
Modules linked in:
CPU: 17 PID: 1473 Comm: ipmitool Not tainted 5.2.0-rc5-00003-gf68c53b414a3-dirty #198
Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT21 Nemo 2.0 RC0 04/18/2018
pstate: 20000085 (nzCv daIf -PAN -UAO)
pc : hisi_lpc_target_in+0x7c/0x120
lr : hisi_lpc_target_in+0x70/0x120
sp : ffff00001efe3930
x29: ffff00001efe3930 x28: ffff841f9f599200
x27: 0000000000000002 x26: 0000000000000000
x25: 0000000000000080 x24: 00000000000000e4
x23: 0000000000000000 x22: 0000000000000064
x21: ffff801fb667d280 x20: 0000000000000001
x19: ffff00001efe39ac x18: 0000000000000000
x17: 0000000000000000 x16: 0000000000000000
x15: 0000000000000000 x14: 0000000000000000
x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000000
x9 : 0000000000000000 x8 : ffff841febe60340
x7 : ffff801fb55c52e8 x6 : 0000000000000000
x5 : 0000000000ffc0e3 x4 : 0000000000000001
x3 : ffff801fb667d280 x2 : 0000000000000001
x1 : ffff000010035010 x0 : ffff000010035000
Call trace:
hisi_lpc_target_in+0x7c/0x120
hisi_lpc_comm_in+0x88/0x98
logic_inb+0x5c/0xb8
port_inb+0x18/0x20
bt_event+0x38/0x808
smi_event_handler+0x4c/0x5a0
check_start_timer_thread.part.4+0x40/0x58
sender+0x78/0x88
smi_send.isra.6+0x94/0x108
i_ipmi_request+0x2c4/0x8f8
ipmi_request_settime+0x124/0x160
handle_send_req+0x19c/0x208
ipmi_ioctl+0x2c0/0x990
do_vfs_ioctl+0xb8/0x8f8
ksys_ioctl+0x80/0xb8
__arm64_sys_ioctl+0x1c/0x28
el0_svc_common.constprop.0+0x64/0x160
el0_svc_handler+0x28/0x78
el0_svc+0x8/0xc
Code: 941d1511 aa0003f9 f94006a0 91004001 (b9000034)
---[ end trace aa842b86af7069e4 ]---
The problem here is that the host goes away but the associated logical PIO
region remains registered, as do the children devices.
Fix by adding a .remove method to tidy-up by removing the child devices
and unregistering the logical PIO region.
Cc: stable@vger.kernel.org
Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
2019-07-30 13:29:56 +00:00
|
|
|
|
|
|
|
static void hisi_lpc_acpi_remove(struct device *hostdev)
|
|
|
|
{
|
|
|
|
}
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
#endif // CONFIG_ACPI
|
|
|
|
|
2018-03-21 22:23:02 +00:00
|
|
|
/*
|
|
|
|
* hisi_lpc_probe - the probe callback function for hisi lpc host,
|
|
|
|
* will finish all the initialization.
|
|
|
|
* @pdev: the platform device corresponding to hisi lpc host
|
|
|
|
*
|
|
|
|
* Returns 0 on success, non-zero on fail.
|
|
|
|
*/
|
|
|
|
static int hisi_lpc_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct logic_pio_hwaddr *range;
|
|
|
|
struct hisi_lpc_dev *lpcdev;
|
|
|
|
resource_size_t io_end;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
lpcdev = devm_kzalloc(dev, sizeof(*lpcdev), GFP_KERNEL);
|
|
|
|
if (!lpcdev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
spin_lock_init(&lpcdev->cycle_lock);
|
|
|
|
|
2022-09-05 08:23:03 +00:00
|
|
|
lpcdev->membase = devm_platform_ioremap_resource(pdev, 0);
|
2018-03-21 22:23:02 +00:00
|
|
|
if (IS_ERR(lpcdev->membase))
|
|
|
|
return PTR_ERR(lpcdev->membase);
|
|
|
|
|
|
|
|
range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL);
|
|
|
|
if (!range)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2022-09-05 08:23:02 +00:00
|
|
|
range->fwnode = dev_fwnode(dev);
|
2018-03-21 22:23:02 +00:00
|
|
|
range->flags = LOGIC_PIO_INDIRECT;
|
|
|
|
range->size = PIO_INDIRECT_SIZE;
|
2019-07-30 13:29:55 +00:00
|
|
|
range->hostdata = lpcdev;
|
|
|
|
range->ops = &hisi_lpc_ops;
|
|
|
|
lpcdev->io_host = range;
|
2018-03-21 22:23:02 +00:00
|
|
|
|
|
|
|
ret = logic_pio_register_range(range);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "register IO range failed (%d)!\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* register the LPC host PIO resources */
|
2022-09-05 08:23:02 +00:00
|
|
|
if (is_acpi_device_node(range->fwnode))
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
ret = hisi_lpc_acpi_probe(dev);
|
|
|
|
else
|
2018-03-21 22:23:02 +00:00
|
|
|
ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
|
2019-07-30 13:29:55 +00:00
|
|
|
if (ret) {
|
|
|
|
logic_pio_unregister_range(range);
|
HISI LPC: Add ACPI support
Based on the previous patches, this patch supports the LPC host on
Hip06/Hip07 for ACPI FW.
It is the responsibility of the LPC host driver to enumerate the child
devices, as the ACPI scan code will not enumerate children of "indirect IO"
hosts.
The ACPI table for the LPC host controller and the child devices is in the
following format:
Device (LPC0) {
Name (_HID, "HISI0191") // HiSi LPC
Name (_CRS, ResourceTemplate () {
Memory32Fixed (ReadWrite, 0xa01b0000, 0x1000)
})
}
Device (LPC0.IPMI) {
Name (_HID, "IPI0001")
Name (LORS, ResourceTemplate() {
QWordIO (
ResourceConsumer,
MinNotFixed, // _MIF
MaxNotFixed, // _MAF
PosDecode,
EntireRange,
0x0, // _GRA
0xe4, // _MIN
0x3fff, // _MAX
0x0, // _TRA
0x04, // _LEN
, ,
BTIO
)
})
Since the IO resources of the child devices need to be translated from LPC
bus addresses to logical PIO addresses, and we shouldn't modify the
resources of the devices generated in the FW scan, a per-child MFD is
created as a substitute. The MFD IO resources will be the translated bus
addresses of the ACPI child.
Tested-by: dann frazier <dann.frazier@canonical.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Zhichang Yuan <yuanzhichang@hisilicon.com>
Signed-off-by: Gabriele Paoloni <gabriele.paoloni@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
2018-03-14 18:15:58 +00:00
|
|
|
return ret;
|
2019-07-30 13:29:55 +00:00
|
|
|
}
|
2018-03-21 22:23:02 +00:00
|
|
|
|
bus: hisi_lpc: Add .remove method to avoid driver unbind crash
The original driver author seemed to be under the impression that a driver
cannot be removed if it does not have a .remove method. Or maybe if it is
a built-in platform driver.
This is not true. This crash can be created:
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# echo HISI0191\:00 > unbind
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# ipmitool raw 6 1
Unable to handle kernel paging request at virtual address ffff000010035010
Mem abort info:
ESR = 0x96000047
Exception class = DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
Data abort info:
ISV = 0, ISS = 0x00000047
CM = 0, WnR = 1
swapper pgtable: 4k pages, 48-bit VAs, pgdp=000000000118b000
[ffff000010035010] pgd=0000041ffbfff003, pud=0000041ffbffe003, pmd=0000041ffbffd003, pte=0000000000000000
Internal error: Oops: 96000047 [#1] PREEMPT SMP
Modules linked in:
CPU: 17 PID: 1473 Comm: ipmitool Not tainted 5.2.0-rc5-00003-gf68c53b414a3-dirty #198
Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT21 Nemo 2.0 RC0 04/18/2018
pstate: 20000085 (nzCv daIf -PAN -UAO)
pc : hisi_lpc_target_in+0x7c/0x120
lr : hisi_lpc_target_in+0x70/0x120
sp : ffff00001efe3930
x29: ffff00001efe3930 x28: ffff841f9f599200
x27: 0000000000000002 x26: 0000000000000000
x25: 0000000000000080 x24: 00000000000000e4
x23: 0000000000000000 x22: 0000000000000064
x21: ffff801fb667d280 x20: 0000000000000001
x19: ffff00001efe39ac x18: 0000000000000000
x17: 0000000000000000 x16: 0000000000000000
x15: 0000000000000000 x14: 0000000000000000
x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000000
x9 : 0000000000000000 x8 : ffff841febe60340
x7 : ffff801fb55c52e8 x6 : 0000000000000000
x5 : 0000000000ffc0e3 x4 : 0000000000000001
x3 : ffff801fb667d280 x2 : 0000000000000001
x1 : ffff000010035010 x0 : ffff000010035000
Call trace:
hisi_lpc_target_in+0x7c/0x120
hisi_lpc_comm_in+0x88/0x98
logic_inb+0x5c/0xb8
port_inb+0x18/0x20
bt_event+0x38/0x808
smi_event_handler+0x4c/0x5a0
check_start_timer_thread.part.4+0x40/0x58
sender+0x78/0x88
smi_send.isra.6+0x94/0x108
i_ipmi_request+0x2c4/0x8f8
ipmi_request_settime+0x124/0x160
handle_send_req+0x19c/0x208
ipmi_ioctl+0x2c0/0x990
do_vfs_ioctl+0xb8/0x8f8
ksys_ioctl+0x80/0xb8
__arm64_sys_ioctl+0x1c/0x28
el0_svc_common.constprop.0+0x64/0x160
el0_svc_handler+0x28/0x78
el0_svc+0x8/0xc
Code: 941d1511 aa0003f9 f94006a0 91004001 (b9000034)
---[ end trace aa842b86af7069e4 ]---
The problem here is that the host goes away but the associated logical PIO
region remains registered, as do the children devices.
Fix by adding a .remove method to tidy-up by removing the child devices
and unregistering the logical PIO region.
Cc: stable@vger.kernel.org
Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
2019-07-30 13:29:56 +00:00
|
|
|
dev_set_drvdata(dev, lpcdev);
|
|
|
|
|
2018-03-21 22:23:02 +00:00
|
|
|
io_end = lpcdev->io_host->io_start + lpcdev->io_host->size;
|
|
|
|
dev_info(dev, "registered range [%pa - %pa]\n",
|
|
|
|
&lpcdev->io_host->io_start, &io_end);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-11-09 20:28:31 +00:00
|
|
|
static void hisi_lpc_remove(struct platform_device *pdev)
|
bus: hisi_lpc: Add .remove method to avoid driver unbind crash
The original driver author seemed to be under the impression that a driver
cannot be removed if it does not have a .remove method. Or maybe if it is
a built-in platform driver.
This is not true. This crash can be created:
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# echo HISI0191\:00 > unbind
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# ipmitool raw 6 1
Unable to handle kernel paging request at virtual address ffff000010035010
Mem abort info:
ESR = 0x96000047
Exception class = DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
Data abort info:
ISV = 0, ISS = 0x00000047
CM = 0, WnR = 1
swapper pgtable: 4k pages, 48-bit VAs, pgdp=000000000118b000
[ffff000010035010] pgd=0000041ffbfff003, pud=0000041ffbffe003, pmd=0000041ffbffd003, pte=0000000000000000
Internal error: Oops: 96000047 [#1] PREEMPT SMP
Modules linked in:
CPU: 17 PID: 1473 Comm: ipmitool Not tainted 5.2.0-rc5-00003-gf68c53b414a3-dirty #198
Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT21 Nemo 2.0 RC0 04/18/2018
pstate: 20000085 (nzCv daIf -PAN -UAO)
pc : hisi_lpc_target_in+0x7c/0x120
lr : hisi_lpc_target_in+0x70/0x120
sp : ffff00001efe3930
x29: ffff00001efe3930 x28: ffff841f9f599200
x27: 0000000000000002 x26: 0000000000000000
x25: 0000000000000080 x24: 00000000000000e4
x23: 0000000000000000 x22: 0000000000000064
x21: ffff801fb667d280 x20: 0000000000000001
x19: ffff00001efe39ac x18: 0000000000000000
x17: 0000000000000000 x16: 0000000000000000
x15: 0000000000000000 x14: 0000000000000000
x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000000
x9 : 0000000000000000 x8 : ffff841febe60340
x7 : ffff801fb55c52e8 x6 : 0000000000000000
x5 : 0000000000ffc0e3 x4 : 0000000000000001
x3 : ffff801fb667d280 x2 : 0000000000000001
x1 : ffff000010035010 x0 : ffff000010035000
Call trace:
hisi_lpc_target_in+0x7c/0x120
hisi_lpc_comm_in+0x88/0x98
logic_inb+0x5c/0xb8
port_inb+0x18/0x20
bt_event+0x38/0x808
smi_event_handler+0x4c/0x5a0
check_start_timer_thread.part.4+0x40/0x58
sender+0x78/0x88
smi_send.isra.6+0x94/0x108
i_ipmi_request+0x2c4/0x8f8
ipmi_request_settime+0x124/0x160
handle_send_req+0x19c/0x208
ipmi_ioctl+0x2c0/0x990
do_vfs_ioctl+0xb8/0x8f8
ksys_ioctl+0x80/0xb8
__arm64_sys_ioctl+0x1c/0x28
el0_svc_common.constprop.0+0x64/0x160
el0_svc_handler+0x28/0x78
el0_svc+0x8/0xc
Code: 941d1511 aa0003f9 f94006a0 91004001 (b9000034)
---[ end trace aa842b86af7069e4 ]---
The problem here is that the host goes away but the associated logical PIO
region remains registered, as do the children devices.
Fix by adding a .remove method to tidy-up by removing the child devices
and unregistering the logical PIO region.
Cc: stable@vger.kernel.org
Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
2019-07-30 13:29:56 +00:00
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct hisi_lpc_dev *lpcdev = dev_get_drvdata(dev);
|
|
|
|
struct logic_pio_hwaddr *range = lpcdev->io_host;
|
|
|
|
|
2022-09-05 08:23:02 +00:00
|
|
|
if (is_acpi_device_node(range->fwnode))
|
bus: hisi_lpc: Add .remove method to avoid driver unbind crash
The original driver author seemed to be under the impression that a driver
cannot be removed if it does not have a .remove method. Or maybe if it is
a built-in platform driver.
This is not true. This crash can be created:
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# echo HISI0191\:00 > unbind
root@ubuntu:/sys/bus/platform/drivers/hisi-lpc# ipmitool raw 6 1
Unable to handle kernel paging request at virtual address ffff000010035010
Mem abort info:
ESR = 0x96000047
Exception class = DABT (current EL), IL = 32 bits
SET = 0, FnV = 0
EA = 0, S1PTW = 0
Data abort info:
ISV = 0, ISS = 0x00000047
CM = 0, WnR = 1
swapper pgtable: 4k pages, 48-bit VAs, pgdp=000000000118b000
[ffff000010035010] pgd=0000041ffbfff003, pud=0000041ffbffe003, pmd=0000041ffbffd003, pte=0000000000000000
Internal error: Oops: 96000047 [#1] PREEMPT SMP
Modules linked in:
CPU: 17 PID: 1473 Comm: ipmitool Not tainted 5.2.0-rc5-00003-gf68c53b414a3-dirty #198
Hardware name: Huawei Taishan 2280 /D05, BIOS Hisilicon D05 IT21 Nemo 2.0 RC0 04/18/2018
pstate: 20000085 (nzCv daIf -PAN -UAO)
pc : hisi_lpc_target_in+0x7c/0x120
lr : hisi_lpc_target_in+0x70/0x120
sp : ffff00001efe3930
x29: ffff00001efe3930 x28: ffff841f9f599200
x27: 0000000000000002 x26: 0000000000000000
x25: 0000000000000080 x24: 00000000000000e4
x23: 0000000000000000 x22: 0000000000000064
x21: ffff801fb667d280 x20: 0000000000000001
x19: ffff00001efe39ac x18: 0000000000000000
x17: 0000000000000000 x16: 0000000000000000
x15: 0000000000000000 x14: 0000000000000000
x13: 0000000000000000 x12: 0000000000000000
x11: 0000000000000000 x10: 0000000000000000
x9 : 0000000000000000 x8 : ffff841febe60340
x7 : ffff801fb55c52e8 x6 : 0000000000000000
x5 : 0000000000ffc0e3 x4 : 0000000000000001
x3 : ffff801fb667d280 x2 : 0000000000000001
x1 : ffff000010035010 x0 : ffff000010035000
Call trace:
hisi_lpc_target_in+0x7c/0x120
hisi_lpc_comm_in+0x88/0x98
logic_inb+0x5c/0xb8
port_inb+0x18/0x20
bt_event+0x38/0x808
smi_event_handler+0x4c/0x5a0
check_start_timer_thread.part.4+0x40/0x58
sender+0x78/0x88
smi_send.isra.6+0x94/0x108
i_ipmi_request+0x2c4/0x8f8
ipmi_request_settime+0x124/0x160
handle_send_req+0x19c/0x208
ipmi_ioctl+0x2c0/0x990
do_vfs_ioctl+0xb8/0x8f8
ksys_ioctl+0x80/0xb8
__arm64_sys_ioctl+0x1c/0x28
el0_svc_common.constprop.0+0x64/0x160
el0_svc_handler+0x28/0x78
el0_svc+0x8/0xc
Code: 941d1511 aa0003f9 f94006a0 91004001 (b9000034)
---[ end trace aa842b86af7069e4 ]---
The problem here is that the host goes away but the associated logical PIO
region remains registered, as do the children devices.
Fix by adding a .remove method to tidy-up by removing the child devices
and unregistering the logical PIO region.
Cc: stable@vger.kernel.org
Fixes: adf38bb0b595 ("HISI LPC: Support the LPC host on Hip06/Hip07 with DT bindings")
Signed-off-by: John Garry <john.garry@huawei.com>
Signed-off-by: Wei Xu <xuwei5@hisilicon.com>
2019-07-30 13:29:56 +00:00
|
|
|
hisi_lpc_acpi_remove(dev);
|
|
|
|
else
|
|
|
|
of_platform_depopulate(dev);
|
|
|
|
|
|
|
|
logic_pio_unregister_range(range);
|
|
|
|
}
|
|
|
|
|
2018-03-21 22:23:02 +00:00
|
|
|
static const struct of_device_id hisi_lpc_of_match[] = {
|
|
|
|
{ .compatible = "hisilicon,hip06-lpc", },
|
|
|
|
{ .compatible = "hisilicon,hip07-lpc", },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2022-09-05 08:23:05 +00:00
|
|
|
static const struct acpi_device_id hisi_lpc_acpi_match[] = {
|
|
|
|
{"HISI0191"},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2018-03-21 22:23:02 +00:00
|
|
|
static struct platform_driver hisi_lpc_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = DRV_NAME,
|
|
|
|
.of_match_table = hisi_lpc_of_match,
|
2022-09-05 08:23:05 +00:00
|
|
|
.acpi_match_table = hisi_lpc_acpi_match,
|
2018-03-21 22:23:02 +00:00
|
|
|
},
|
|
|
|
.probe = hisi_lpc_probe,
|
2024-11-12 08:35:19 +00:00
|
|
|
.remove = hisi_lpc_remove,
|
2018-03-21 22:23:02 +00:00
|
|
|
};
|
|
|
|
builtin_platform_driver(hisi_lpc_driver);
|