RE: [PATCH] dcdbas: Add support for WSMT ACPI table
-Original Message- > From: Stuart Hayes [mailto:stuart.w.ha...@gmail.com] > Sent: Monday, April 16, 2018 10:08 AM > To: Warzecha, Douglas > Cc: Limonciello, Mario; Dominguez, Jared; linux-kernel@vger.kernel.org > Subject: [PATCH] dcdbas: Add support for WSMT ACPI table > > > If the WSMT ACPI table is present and indicates that a fixed communication > buffer should be used, use the firmware-specified buffer instead of > allocating a buffer in memory for communications between the dcdbas driver > and firmware. > > Signed-off-by: Stuart Hayes <stuart.w.ha...@gmail.com> > Reviewed-by: Mario Limonciello <mario.limoncie...@dell.com> > --- > drivers/firmware/Kconfig | 2 +- > drivers/firmware/dcdbas.c | 100 > -- > drivers/firmware/dcdbas.h | 11 + > 3 files changed, 108 insertions(+), 5 deletions(-) > > diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig > index b7c748248e53..a2bd6092bfa1 100644 > --- a/drivers/firmware/Kconfig > +++ b/drivers/firmware/Kconfig > @@ -125,7 +125,7 @@ config DELL_RBU > > config DCDBAS > tristate "Dell Systems Management Base Driver" > - depends on X86 > + depends on X86 && ACPI > help > The Dell Systems Management Base Driver provides a sysfs interface > for systems management software to perform System Management > diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c > index 0bdea60c65dd..cdcc10d5f04b 100644 > --- a/drivers/firmware/dcdbas.c > +++ b/drivers/firmware/dcdbas.c > @@ -36,6 +36,7 @@ > #include > #include > #include > +#include > #include > > #include "dcdbas.h" > @@ -49,19 +50,23 @@ static struct platform_device *dcdbas_pdev; > static u8 *smi_data_buf; > static dma_addr_t smi_data_buf_handle; > static unsigned long smi_data_buf_size; > +static unsigned long max_smi_data_buf_size = MAX_SMI_DATA_BUF_SIZE; > static u32 smi_data_buf_phys_addr; > static DEFINE_MUTEX(smi_data_lock); > +static u8 *eps_buffer; > > static unsigned int host_control_action; > static unsigned int host_control_smi_type; > static unsigned int host_control_on_shutdown; > > +static bool wsmt_enabled; > + > /** > * smi_data_buf_free: free SMI data buffer > */ > static void smi_data_buf_free(void) > { > - if (!smi_data_buf) > + if (!smi_data_buf || wsmt_enabled) > return; > > dev_dbg(_pdev->dev, "%s: phys: %x size: %lu\n", > @@ -86,7 +91,7 @@ static int smi_data_buf_realloc(unsigned long size) > if (smi_data_buf_size >= size) > return 0; > > - if (size > MAX_SMI_DATA_BUF_SIZE) > + if (size > max_smi_data_buf_size) > return -EINVAL; > > /* new buffer is needed */ > @@ -169,7 +174,7 @@ static ssize_t smi_data_write(struct file *filp, struct > kobject > *kobj, > { > ssize_t ret; > > - if ((pos + count) > MAX_SMI_DATA_BUF_SIZE) > + if ((pos + count) > max_smi_data_buf_size) > return -EINVAL; > > mutex_lock(_data_lock); > @@ -323,7 +328,8 @@ static ssize_t smi_request_store(struct device *dev, > break; > case 1: > /* Calling Interface SMI */ > - smi_cmd->ebx = (u32) virt_to_phys(smi_cmd->command_buffer); > + smi_cmd->ebx = smi_data_buf_phys_addr > + + offsetof(struct smi_cmd, command_buffer); > ret = dcdbas_smi_request(smi_cmd); > if (!ret) > ret = count; > @@ -482,6 +488,85 @@ static void dcdbas_host_control(void) > } > } > > +/* WSMT */ > + > +static u8 checksum(u8 *buffer, u8 length) > +{ > + u8 sum = 0; > + u8 *end = buffer + length; > + > + while (buffer < end) > + sum = (u8)(sum + *(buffer++)); > + return sum; > +} > + > +static inline struct smm_eps_table *check_eps_table(u8 *addr) > +{ > + struct smm_eps_table *eps = (struct smm_eps_table *)addr; > + > + if (strncmp(SMM_EPS_SIG, eps->smm_comm_buff_anchor, 4) != 0) > + return NULL; > + > + if (checksum(addr, eps->length) != 0) > + return NULL; > + > + return eps; > +} > + > +static int dcdbas_check_wsmt(void) > +{ > + struct acpi_table_wsmt *wsmt = NULL; > + struct smm_eps_table *eps = NULL; > + u8 *addr; > + > + acpi_get_table(ACPI_SIG_WSMT, 0, (struct acpi_table_header **)); > + if (!wsmt) > + return 0; > + > + /* Check if WSMT ACPI
RE: [PATCH] dcdbas: Add support for WSMT ACPI table
-Original Message- > From: Stuart Hayes [mailto:stuart.w.ha...@gmail.com] > Sent: Monday, April 16, 2018 10:08 AM > To: Warzecha, Douglas > Cc: Limonciello, Mario; Dominguez, Jared; linux-kernel@vger.kernel.org > Subject: [PATCH] dcdbas: Add support for WSMT ACPI table > > > If the WSMT ACPI table is present and indicates that a fixed communication > buffer should be used, use the firmware-specified buffer instead of > allocating a buffer in memory for communications between the dcdbas driver > and firmware. > > Signed-off-by: Stuart Hayes > Reviewed-by: Mario Limonciello > --- > drivers/firmware/Kconfig | 2 +- > drivers/firmware/dcdbas.c | 100 > -- > drivers/firmware/dcdbas.h | 11 + > 3 files changed, 108 insertions(+), 5 deletions(-) > > diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig > index b7c748248e53..a2bd6092bfa1 100644 > --- a/drivers/firmware/Kconfig > +++ b/drivers/firmware/Kconfig > @@ -125,7 +125,7 @@ config DELL_RBU > > config DCDBAS > tristate "Dell Systems Management Base Driver" > - depends on X86 > + depends on X86 && ACPI > help > The Dell Systems Management Base Driver provides a sysfs interface > for systems management software to perform System Management > diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c > index 0bdea60c65dd..cdcc10d5f04b 100644 > --- a/drivers/firmware/dcdbas.c > +++ b/drivers/firmware/dcdbas.c > @@ -36,6 +36,7 @@ > #include > #include > #include > +#include > #include > > #include "dcdbas.h" > @@ -49,19 +50,23 @@ static struct platform_device *dcdbas_pdev; > static u8 *smi_data_buf; > static dma_addr_t smi_data_buf_handle; > static unsigned long smi_data_buf_size; > +static unsigned long max_smi_data_buf_size = MAX_SMI_DATA_BUF_SIZE; > static u32 smi_data_buf_phys_addr; > static DEFINE_MUTEX(smi_data_lock); > +static u8 *eps_buffer; > > static unsigned int host_control_action; > static unsigned int host_control_smi_type; > static unsigned int host_control_on_shutdown; > > +static bool wsmt_enabled; > + > /** > * smi_data_buf_free: free SMI data buffer > */ > static void smi_data_buf_free(void) > { > - if (!smi_data_buf) > + if (!smi_data_buf || wsmt_enabled) > return; > > dev_dbg(_pdev->dev, "%s: phys: %x size: %lu\n", > @@ -86,7 +91,7 @@ static int smi_data_buf_realloc(unsigned long size) > if (smi_data_buf_size >= size) > return 0; > > - if (size > MAX_SMI_DATA_BUF_SIZE) > + if (size > max_smi_data_buf_size) > return -EINVAL; > > /* new buffer is needed */ > @@ -169,7 +174,7 @@ static ssize_t smi_data_write(struct file *filp, struct > kobject > *kobj, > { > ssize_t ret; > > - if ((pos + count) > MAX_SMI_DATA_BUF_SIZE) > + if ((pos + count) > max_smi_data_buf_size) > return -EINVAL; > > mutex_lock(_data_lock); > @@ -323,7 +328,8 @@ static ssize_t smi_request_store(struct device *dev, > break; > case 1: > /* Calling Interface SMI */ > - smi_cmd->ebx = (u32) virt_to_phys(smi_cmd->command_buffer); > + smi_cmd->ebx = smi_data_buf_phys_addr > + + offsetof(struct smi_cmd, command_buffer); > ret = dcdbas_smi_request(smi_cmd); > if (!ret) > ret = count; > @@ -482,6 +488,85 @@ static void dcdbas_host_control(void) > } > } > > +/* WSMT */ > + > +static u8 checksum(u8 *buffer, u8 length) > +{ > + u8 sum = 0; > + u8 *end = buffer + length; > + > + while (buffer < end) > + sum = (u8)(sum + *(buffer++)); > + return sum; > +} > + > +static inline struct smm_eps_table *check_eps_table(u8 *addr) > +{ > + struct smm_eps_table *eps = (struct smm_eps_table *)addr; > + > + if (strncmp(SMM_EPS_SIG, eps->smm_comm_buff_anchor, 4) != 0) > + return NULL; > + > + if (checksum(addr, eps->length) != 0) > + return NULL; > + > + return eps; > +} > + > +static int dcdbas_check_wsmt(void) > +{ > + struct acpi_table_wsmt *wsmt = NULL; > + struct smm_eps_table *eps = NULL; > + u8 *addr; > + > + acpi_get_table(ACPI_SIG_WSMT, 0, (struct acpi_table_header **)); > + if (!wsmt) > + return 0; > + > + /* Check if WSMT ACPI table shows that protection is enabled */ > + if (!(wsm
[PATCH] dcdbas: Add support for WSMT ACPI table
If the WSMT ACPI table is present and indicates that a fixed communication buffer should be used, use the firmware-specified buffer instead of allocating a buffer in memory for communications between the dcdbas driver and firmware. Signed-off-by: Stuart HayesReviewed-by: Mario Limonciello --- drivers/firmware/Kconfig | 2 +- drivers/firmware/dcdbas.c | 100 -- drivers/firmware/dcdbas.h | 11 + 3 files changed, 108 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index b7c748248e53..a2bd6092bfa1 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -125,7 +125,7 @@ config DELL_RBU config DCDBAS tristate "Dell Systems Management Base Driver" - depends on X86 + depends on X86 && ACPI help The Dell Systems Management Base Driver provides a sysfs interface for systems management software to perform System Management diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c index 0bdea60c65dd..cdcc10d5f04b 100644 --- a/drivers/firmware/dcdbas.c +++ b/drivers/firmware/dcdbas.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "dcdbas.h" @@ -49,19 +50,23 @@ static struct platform_device *dcdbas_pdev; static u8 *smi_data_buf; static dma_addr_t smi_data_buf_handle; static unsigned long smi_data_buf_size; +static unsigned long max_smi_data_buf_size = MAX_SMI_DATA_BUF_SIZE; static u32 smi_data_buf_phys_addr; static DEFINE_MUTEX(smi_data_lock); +static u8 *eps_buffer; static unsigned int host_control_action; static unsigned int host_control_smi_type; static unsigned int host_control_on_shutdown; +static bool wsmt_enabled; + /** * smi_data_buf_free: free SMI data buffer */ static void smi_data_buf_free(void) { - if (!smi_data_buf) + if (!smi_data_buf || wsmt_enabled) return; dev_dbg(_pdev->dev, "%s: phys: %x size: %lu\n", @@ -86,7 +91,7 @@ static int smi_data_buf_realloc(unsigned long size) if (smi_data_buf_size >= size) return 0; - if (size > MAX_SMI_DATA_BUF_SIZE) + if (size > max_smi_data_buf_size) return -EINVAL; /* new buffer is needed */ @@ -169,7 +174,7 @@ static ssize_t smi_data_write(struct file *filp, struct kobject *kobj, { ssize_t ret; - if ((pos + count) > MAX_SMI_DATA_BUF_SIZE) + if ((pos + count) > max_smi_data_buf_size) return -EINVAL; mutex_lock(_data_lock); @@ -323,7 +328,8 @@ static ssize_t smi_request_store(struct device *dev, break; case 1: /* Calling Interface SMI */ - smi_cmd->ebx = (u32) virt_to_phys(smi_cmd->command_buffer); + smi_cmd->ebx = smi_data_buf_phys_addr + + offsetof(struct smi_cmd, command_buffer); ret = dcdbas_smi_request(smi_cmd); if (!ret) ret = count; @@ -482,6 +488,85 @@ static void dcdbas_host_control(void) } } +/* WSMT */ + +static u8 checksum(u8 *buffer, u8 length) +{ + u8 sum = 0; + u8 *end = buffer + length; + + while (buffer < end) + sum = (u8)(sum + *(buffer++)); + return sum; +} + +static inline struct smm_eps_table *check_eps_table(u8 *addr) +{ + struct smm_eps_table *eps = (struct smm_eps_table *)addr; + + if (strncmp(SMM_EPS_SIG, eps->smm_comm_buff_anchor, 4) != 0) + return NULL; + + if (checksum(addr, eps->length) != 0) + return NULL; + + return eps; +} + +static int dcdbas_check_wsmt(void) +{ + struct acpi_table_wsmt *wsmt = NULL; + struct smm_eps_table *eps = NULL; + u8 *addr; + + acpi_get_table(ACPI_SIG_WSMT, 0, (struct acpi_table_header **)); + if (!wsmt) + return 0; + + /* Check if WSMT ACPI table shows that protection is enabled */ + if (!(wsmt->protection_flags & ACPI_WSMT_FIXED_COMM_BUFFERS) + || !(wsmt->protection_flags +& ACPI_WSMT_COMM_BUFFER_NESTED_PTR_PROTECTION)) + return 0; + + /* Scan for EPS (entry point structure) */ + for (addr = (u8 *)__va(0xf); +addr < (u8 *)__va(0x10 - sizeof(struct smm_eps_table)) && !eps; +addr += 1) + eps = check_eps_table(addr); + + if (!eps) { + dev_dbg(_pdev->dev, "found WSMT, but no EPS found\n"); + return -ENODEV; + } + + /* +* Get physical address of buffer and map to virtual address. +* Table gives size in 4K pages, regardless of actual system page size. +*/ + if (eps->smm_comm_buff_addr + 8 > U32_MAX) { + dev_warn(_pdev->dev, "found WSMT, but EPS buffer address is above 4GB\n"); +
[PATCH] dcdbas: Add support for WSMT ACPI table
If the WSMT ACPI table is present and indicates that a fixed communication buffer should be used, use the firmware-specified buffer instead of allocating a buffer in memory for communications between the dcdbas driver and firmware. Signed-off-by: Stuart Hayes Reviewed-by: Mario Limonciello --- drivers/firmware/Kconfig | 2 +- drivers/firmware/dcdbas.c | 100 -- drivers/firmware/dcdbas.h | 11 + 3 files changed, 108 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index b7c748248e53..a2bd6092bfa1 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig @@ -125,7 +125,7 @@ config DELL_RBU config DCDBAS tristate "Dell Systems Management Base Driver" - depends on X86 + depends on X86 && ACPI help The Dell Systems Management Base Driver provides a sysfs interface for systems management software to perform System Management diff --git a/drivers/firmware/dcdbas.c b/drivers/firmware/dcdbas.c index 0bdea60c65dd..cdcc10d5f04b 100644 --- a/drivers/firmware/dcdbas.c +++ b/drivers/firmware/dcdbas.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "dcdbas.h" @@ -49,19 +50,23 @@ static struct platform_device *dcdbas_pdev; static u8 *smi_data_buf; static dma_addr_t smi_data_buf_handle; static unsigned long smi_data_buf_size; +static unsigned long max_smi_data_buf_size = MAX_SMI_DATA_BUF_SIZE; static u32 smi_data_buf_phys_addr; static DEFINE_MUTEX(smi_data_lock); +static u8 *eps_buffer; static unsigned int host_control_action; static unsigned int host_control_smi_type; static unsigned int host_control_on_shutdown; +static bool wsmt_enabled; + /** * smi_data_buf_free: free SMI data buffer */ static void smi_data_buf_free(void) { - if (!smi_data_buf) + if (!smi_data_buf || wsmt_enabled) return; dev_dbg(_pdev->dev, "%s: phys: %x size: %lu\n", @@ -86,7 +91,7 @@ static int smi_data_buf_realloc(unsigned long size) if (smi_data_buf_size >= size) return 0; - if (size > MAX_SMI_DATA_BUF_SIZE) + if (size > max_smi_data_buf_size) return -EINVAL; /* new buffer is needed */ @@ -169,7 +174,7 @@ static ssize_t smi_data_write(struct file *filp, struct kobject *kobj, { ssize_t ret; - if ((pos + count) > MAX_SMI_DATA_BUF_SIZE) + if ((pos + count) > max_smi_data_buf_size) return -EINVAL; mutex_lock(_data_lock); @@ -323,7 +328,8 @@ static ssize_t smi_request_store(struct device *dev, break; case 1: /* Calling Interface SMI */ - smi_cmd->ebx = (u32) virt_to_phys(smi_cmd->command_buffer); + smi_cmd->ebx = smi_data_buf_phys_addr + + offsetof(struct smi_cmd, command_buffer); ret = dcdbas_smi_request(smi_cmd); if (!ret) ret = count; @@ -482,6 +488,85 @@ static void dcdbas_host_control(void) } } +/* WSMT */ + +static u8 checksum(u8 *buffer, u8 length) +{ + u8 sum = 0; + u8 *end = buffer + length; + + while (buffer < end) + sum = (u8)(sum + *(buffer++)); + return sum; +} + +static inline struct smm_eps_table *check_eps_table(u8 *addr) +{ + struct smm_eps_table *eps = (struct smm_eps_table *)addr; + + if (strncmp(SMM_EPS_SIG, eps->smm_comm_buff_anchor, 4) != 0) + return NULL; + + if (checksum(addr, eps->length) != 0) + return NULL; + + return eps; +} + +static int dcdbas_check_wsmt(void) +{ + struct acpi_table_wsmt *wsmt = NULL; + struct smm_eps_table *eps = NULL; + u8 *addr; + + acpi_get_table(ACPI_SIG_WSMT, 0, (struct acpi_table_header **)); + if (!wsmt) + return 0; + + /* Check if WSMT ACPI table shows that protection is enabled */ + if (!(wsmt->protection_flags & ACPI_WSMT_FIXED_COMM_BUFFERS) + || !(wsmt->protection_flags +& ACPI_WSMT_COMM_BUFFER_NESTED_PTR_PROTECTION)) + return 0; + + /* Scan for EPS (entry point structure) */ + for (addr = (u8 *)__va(0xf); +addr < (u8 *)__va(0x10 - sizeof(struct smm_eps_table)) && !eps; +addr += 1) + eps = check_eps_table(addr); + + if (!eps) { + dev_dbg(_pdev->dev, "found WSMT, but no EPS found\n"); + return -ENODEV; + } + + /* +* Get physical address of buffer and map to virtual address. +* Table gives size in 4K pages, regardless of actual system page size. +*/ + if (eps->smm_comm_buff_addr + 8 > U32_MAX) { + dev_warn(_pdev->dev, "found WSMT, but EPS buffer address is above 4GB\n"); + return -EINVAL; + } + eps_buffer = (u8