From patchwork Wed Apr 27 13:04:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 66790 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2176758qge; Wed, 27 Apr 2016 06:05:30 -0700 (PDT) X-Received: by 10.98.36.12 with SMTP id r12mr11677491pfj.86.1461762330493; Wed, 27 Apr 2016 06:05:30 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id os10si5336199pab.228.2016.04.27.06.05.29; Wed, 27 Apr 2016 06:05:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752997AbcD0NF0 (ORCPT + 29 others); Wed, 27 Apr 2016 09:05:26 -0400 Received: from mail-pa0-f67.google.com ([209.85.220.67]:36501 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752280AbcD0NEd (ORCPT ); Wed, 27 Apr 2016 09:04:33 -0400 Received: by mail-pa0-f67.google.com with SMTP id i5so4754219pag.3 for ; Wed, 27 Apr 2016 06:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=xFFSvGSCjZvUfPcgI1OGOXk9cLComCSKwVims/GzRcM=; b=oAh9jQnU1LQWANkdx1YIY/J3d6MioamTfgTqnRUNAhgWo2OwtPTfDgpJyAOXJCUvGh DBVSt9G4iyNsZg2yykg+baEsPIg0i6eNbs0Im/IhwgxZ/E9YjT3GBL5U23pdZ6KPKSrS W5aezPOeru1E5Pig2x58e3/BnhwDn8wMiSJ8f/uOWCIZh0exlnjZ3wvn5yaPN0hofZsP yUt0Hz4vkckclMLBpAw8hnROy/F9lmgapOIj5v4QvlBIL3rJB5seyVFenUzLCJ6NKODC 7+qqE+NPPKDrY4DLD8uM8FOs4971rv6Xw5eX1NyHtNZeQh3loTB1D57L4kSnhlp/sSNJ C0Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=xFFSvGSCjZvUfPcgI1OGOXk9cLComCSKwVims/GzRcM=; b=HakTrxTKkZntA2W6UPYcXY13SLWBt4/Rhj1P54Y3mgpllbvSDNuMmMqDmKAorL3pYi cTdueJ5TKW5hN1fKRAgRQNJGyuTNZxiTxSH0YD/tbXjMj3u8nsdI5u5NvKf7KeWxQq0e My6sNQHKbo6DQkDT2kFCzLA2FVn5J5sNes6XwRTt8oGuEd1dfuHkP+y6khG0GtkNoiyK eJroWVQxY/j8Gg1AS6h2fLl5gWiyrcxsPB9e7lFCQp6mvPQth+bt0yfTWDTbFLLT9JjG z3suuLUETvQ7xWSztNM80+2KOfAmB92z+MewRtQOZbqC0W05GbY8YHHJWSigxWHsYLhO dBEQ== X-Gm-Message-State: AOPr4FUh85x3eXCVp1Xd6styX0QfGTeZJ5LJOcvdc8z2B2rkdM4B5TEWqMlPbmsrshkmAA== X-Received: by 10.66.190.131 with SMTP id gq3mr11558262pac.42.1461762272919; Wed, 27 Apr 2016 06:04:32 -0700 (PDT) Received: from serve.minyard.net ([173.71.13.195]) by smtp.gmail.com with ESMTPSA id zn12sm6778953pab.14.2016.04.27.06.04.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Apr 2016 06:04:30 -0700 (PDT) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 5B5B396F; Wed, 27 Apr 2016 08:04:29 -0500 (CDT) Received: by t430.minyard.net (Postfix, from userid 1000) id E036830052C; Wed, 27 Apr 2016 08:04:27 -0500 (CDT) From: minyard@acm.org To: openipmi-developer@lists.sourceforge.net, linux-kernel@vger.kernel.org, Jean Delvare Cc: Corey Minyard , Andy Lutomirski Subject: [PATCH v3 3/5] dmi: Add IPMI DMI scanning to the DMI code Date: Wed, 27 Apr 2016 08:04:18 -0500 Message-Id: <1461762260-32454-4-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1461762260-32454-1-git-send-email-minyard@acm.org> References: <1461762260-32454-1-git-send-email-minyard@acm.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Corey Minyard It makes more sense to be there, and it's cleaner with the upcoming conversion of IPMI DMI to a platform device. Signed-off-by: Corey Minyard Cc: Jean Delvare Cc: Andy Lutomirski Tested-by: Andy Lutomirski --- drivers/firmware/dmi_scan.c | 108 ++++++++++++++++++++++++++++++++++++++++++-- include/linux/dmi.h | 26 +++++++++++ 2 files changed, 129 insertions(+), 5 deletions(-) -- 2.7.4 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c index 5519b4f..16e5174 100644 --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -303,9 +303,105 @@ static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm) } } +#define DMI_IPMI_MIN_LENGTH 0x10 +#define DMI_IPMI_VER2_LENGTH 0x12 +#define DMI_IPMI_TYPE 4 +#define DMI_IPMI_SLAVEADDR 6 +#define DMI_IPMI_ADDR 8 +#define DMI_IPMI_ACCESS 0x10 +#define DMI_IPMI_IRQ 0x11 +#define DMI_IPMI_IO_MASK 0xfffe + +static void __init dmi_decode_ipmi(struct dmi_dev_ipmi *dev, + const struct dmi_header *dm) +{ + const u8 *data = (const u8 *) dm; + unsigned long base_addr; + u8 len = dm->length; + bool slave_addr_set; + + if (len < DMI_IPMI_MIN_LENGTH) + return; + + dev->type = data[DMI_IPMI_TYPE]; + + memcpy(&base_addr, data + DMI_IPMI_ADDR, sizeof(unsigned long)); + if (len >= DMI_IPMI_VER2_LENGTH) { + if (dev->type == IPMI_DMI_TYPE_SSIF) { + if ((data[DMI_IPMI_ADDR] >> 1) == 0) { + /* + * Some broken systems put the I2C address in + * the slave address field. We try to + * accommodate them here. + */ + dev->base_addr = data[DMI_IPMI_SLAVEADDR] >> 1; + dev->slave_addr = 0; + slave_addr_set = true; + } else { + dev->base_addr = data[DMI_IPMI_ADDR] >> 1; + } + } else { + if (base_addr & 1) { + /* I/O */ + base_addr &= DMI_IPMI_IO_MASK; + dev->is_io_space = 1; + } else { + /* Memory */ + dev->is_io_space = 0; + } + + /* + * If bit 4 of byte 0x10 is set, then the lsb + * for the address is odd. + */ + base_addr |= (data[DMI_IPMI_ACCESS] >> 4) & 1; + + dev->base_addr = base_addr; + dev->irq = data[DMI_IPMI_IRQ]; + + /* + * The top two bits of byte 0x10 hold the + * register spacing. + */ + switch ((data[DMI_IPMI_ACCESS] >> 6) & 3) { + case 0: /* Byte boundaries */ + dev->offset = 1; + break; + case 1: /* 32-bit boundaries */ + dev->offset = 4; + break; + case 2: /* 16-byte boundaries */ + dev->offset = 16; + break; + default: + /* Leave 0 for undefined. */ + return; + } + } + } else { + /* Old DMI spec. */ + /* + * Note that technically, the lower bit of the base + * address should be 1 if the address is I/O and 0 if + * the address is in memory. So many systems get that + * wrong (and all that I have seen are I/O) so we just + * ignore that bit and assume I/O. Systems that use + * memory should use the newer spec, anyway. + */ + dev->base_addr = base_addr & DMI_IPMI_IO_MASK; + dev->is_io_space = 1; + dev->offset = 1; + } + + if (!slave_addr_set) + dev->slave_addr = data[DMI_IPMI_SLAVEADDR]; + + dev->good_data = 1; +} + static void __init dmi_save_ipmi_device(const struct dmi_header *dm) { - struct dmi_device *dev; + struct dmi_dev_ipmi *dev; void *data; data = dmi_alloc(dm->length); @@ -318,11 +414,13 @@ static void __init dmi_save_ipmi_device(const struct dmi_header *dm) if (!dev) return; - dev->type = DMI_DEV_TYPE_IPMI; - dev->name = "IPMI controller"; - dev->device_data = data; + dev->dev.type = DMI_DEV_TYPE_IPMI; + dev->dev.name = "IPMI controller"; + dev->dev.device_data = data; - dmi_devices_list_add(dev); + dmi_decode_ipmi(dev, dm); + + dmi_devices_list_add(&dev->dev); } static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus, diff --git a/include/linux/dmi.h b/include/linux/dmi.h index c8dd5b8..96dc644 100644 --- a/include/linux/dmi.h +++ b/include/linux/dmi.h @@ -97,6 +97,24 @@ struct dmi_dev_onboard { int devfn; }; +/* Device data for an IPMI entry. */ +struct dmi_dev_ipmi { + struct dmi_device dev; + u8 good_data; + u8 type; + u8 is_io_space; + u8 irq; + u8 offset; + u8 slave_addr; + unsigned long base_addr; +}; + +/* dmi_ipmi_data type field */ +#define IPMI_DMI_TYPE_KCS 0x01 +#define IPMI_DMI_TYPE_SMIC 0x02 +#define IPMI_DMI_TYPE_BT 0x03 +#define IPMI_DMI_TYPE_SSIF 0x04 + extern struct kobject *dmi_kobj; extern int dmi_check_system(const struct dmi_system_id *list); const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list); @@ -127,6 +145,14 @@ static inline struct dmi_device *to_dmi_device(struct fwnode_handle *fwnode) return NULL; } +static inline struct dmi_dev_ipmi *to_dmi_dev_ipmi(struct dmi_device *dev) +{ + if (!dev || dev->type != DMI_DEV_TYPE_IPMI) + return NULL; + + return container_of(dev, struct dmi_dev_ipmi, dev); +} + #else static inline int dmi_check_system(const struct dmi_system_id *list) { return 0; }