From patchwork Thu Dec 7 21:46:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Minyard X-Patchwork-Id: 845885 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="noa6+qIv"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yt8VD01brz9s83 for ; Fri, 8 Dec 2017 08:57:39 +1100 (AEDT) Received: from localhost ([::1]:34556 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eN4Aj-0006yg-Pf for incoming@patchwork.ozlabs.org; Thu, 07 Dec 2017 16:57:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eN408-00049C-Iw for qemu-devel@nongnu.org; Thu, 07 Dec 2017 16:46:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eN406-0006Ze-JY for qemu-devel@nongnu.org; Thu, 07 Dec 2017 16:46:40 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:39837) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eN406-0006Y4-9N for qemu-devel@nongnu.org; Thu, 07 Dec 2017 16:46:38 -0500 Received: by mail-pg0-x243.google.com with SMTP id w7so5384351pgv.6 for ; Thu, 07 Dec 2017 13:46:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=goAlaAucMUaF2YX8yWhx02RKfDukhVKEstj/kswfqj0=; b=noa6+qIvkVtTLJsy1Wd/wKUqldKyE30reQ90PUERgIca54HQ5Y/hwzwNVgOfkR0XYN glKAGKxfQtVnBKvlUyqazb8liAY558K+vXI54ehIfylf6yMZYE4quBvrb1E3GGTP5t99 kp7SLPMUXyTvD4Pd4dW67ig/dgIfkIP3Y4lJ81QjGwR5/mx8DPE6aKS3tCNmV+lCofYo UsfEXElouEEdJHloAHgpXHv3sFMRS2RBaiBOhFTqkwUlTvjqstVVYD/3BmBARtCUd8Ap FdEQ6G5WFXqV6FQY1gQQ7OdJ2c7e/bP+fJTa4DGO9hLMoPideTtg8m9Y0Md0BzC4Mf7X J+ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=goAlaAucMUaF2YX8yWhx02RKfDukhVKEstj/kswfqj0=; b=TMQE1encdsDbCqumdfno8yYNZmaurjhNmbJC9DNQNUnFaHNuVL9Gi3c+neuAClSB1y j3u6cfM19Z3tVWtm0rCmPqNDJYooFJlCxjqJNLzCp9QYX28j6T4xhOmf7Po0IoGkOr57 soOAEK3lUJtM+rEkyzpsSAoLZZ+JNWItwG4mUCwfa+lFrfT1s+np4hCXa2TFhMdjxU6L CJv0rorIUBNEbQPjs+MO9QJmokbs+ZDySSvQTNghaJJscfkU4XZsUWMJMEvxx95J7fdv E+WsFgeOUSQdu84JF/xv7I7HgaxDqozyXsnw8rVU41yghQKH0pOzTff7wxiFB9SdgjGg 4izA== X-Gm-Message-State: AJaThX45YIvKHX6naRf5zpmXoNcDcJSmfJU4fmfdhp0DLC0Y5w25J9aY SwytwBUgWefEtvAtYHPq+4XSqSE= X-Google-Smtp-Source: AGs4zMYXoHWqzfrt2SE4yuEPV6Xr2uNi2tyiSTx97FK+FFsXEPR4WsVpsECjcIxnWqVfjip8d1RUgQ== X-Received: by 10.99.106.67 with SMTP id f64mr25205322pgc.453.1512683197189; Thu, 07 Dec 2017 13:46:37 -0800 (PST) Received: from serve.minyard.net ([47.184.168.85]) by smtp.gmail.com with ESMTPSA id g2sm10630014pfc.130.2017.12.07.13.46.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Dec 2017 13:46:33 -0800 (PST) Received: from t430.minyard.net (t430m.minyard.net [192.168.27.3]) by serve.minyard.net (Postfix) with ESMTPA id 1DD3C1278; Thu, 7 Dec 2017 15:46:26 -0600 (CST) Received: by t430.minyard.net (Postfix, from userid 1000) id 7AD9830236A; Thu, 7 Dec 2017 15:46:23 -0600 (CST) From: minyard@acm.org To: qemu-devel@nongnu.org Date: Thu, 7 Dec 2017 15:46:18 -0600 Message-Id: <1512683181-8420-12-git-send-email-minyard@acm.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512683181-8420-1-git-send-email-minyard@acm.org> References: <1512683181-8420-1-git-send-email-minyard@acm.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH 11/14] acpi: Add i2c serial bus CRS handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Corey Minyard Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Corey Minyard Signed-off-by: Corey Minyard --- hw/acpi/aml-build.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/aml-build.h | 18 ++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/hw/acpi/aml-build.c b/hw/acpi/aml-build.c index 36a6cc4..36e2263 100644 --- a/hw/acpi/aml-build.c +++ b/hw/acpi/aml-build.c @@ -1662,3 +1662,43 @@ void build_slit(GArray *table_data, BIOSLinker *linker) "SLIT", table_data->len - slit_start, 1, NULL, NULL); } + +/* ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors */ +static Aml *aml_serial_bus_device(uint8_t serial_bus_type, uint8_t flags, + uint16_t type_flags, + uint8_t revid, uint16_t data_length, + uint16_t resource_source_len) +{ + Aml *var = aml_alloc(); + uint16_t length = data_length + resource_source_len + 9; + + build_append_byte(var->buf, 0x8e); /* Serial Bus Connection Descriptor */ + build_append_int_noprefix(var->buf, length, sizeof(length)); + build_append_byte(var->buf, 1); /* Revision ID */ + build_append_byte(var->buf, 0); /* Resource Source Index */ + build_append_byte(var->buf, serial_bus_type); /* Serial Bus Type */ + build_append_byte(var->buf, flags); /* General Flags */ + build_append_int_noprefix(var->buf, type_flags, /* Type Specific Flags */ + sizeof(type_flags)); + build_append_byte(var->buf, revid); /* Type Specification Revision ID */ + build_append_int_noprefix(var->buf, data_length, sizeof(data_length)); + + return var; +} + +/* ACPI 5.0: 6.4.3.8.2.1 I2C Serial Bus Connection Resource Descriptor */ +Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source) +{ + uint16_t resource_source_len = strlen(resource_source) + 1; + Aml *var = aml_serial_bus_device(AML_SERIAL_BUS_TYPE_I2C, 0, 0, 1, + 6, resource_source_len); + + /* Connection Speed. Just set to 100K for now, it doesn't really matter. */ + build_append_int_noprefix(var->buf, 100000, 4); + build_append_int_noprefix(var->buf, address, sizeof(address)); + + /* This is a string, not a name, so just copy it directly in. */ + g_array_append_vals(var->buf, resource_source, resource_source_len); + + return var; +} diff --git a/include/hw/acpi/aml-build.h b/include/hw/acpi/aml-build.h index 88d0738..26fece8 100644 --- a/include/hw/acpi/aml-build.h +++ b/include/hw/acpi/aml-build.h @@ -214,6 +214,23 @@ struct AcpiBuildTables { BIOSLinker *linker; } AcpiBuildTables; +/* + * ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors + * Serial Bus Type + */ +#define AML_SERIAL_BUS_TYPE_I2C 1 +#define AML_SERIAL_BUS_TYPE_SPI 2 +#define AML_SERIAL_BUS_TYPE_UART 3 + +/* + * ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors + * General Flags + */ +/* Slave Mode */ +#define AML_SERIAL_BUS_FLAG_MASTER_DEVICE (1 << 0) +/* Consumer/Producer */ +#define AML_SERIAL_BUS_FLAG_CONSUME_ONLY (1 << 1) + /** * init_aml_allocator: * @@ -338,6 +355,7 @@ Aml *aml_qword_memory(AmlDecode dec, AmlMinFixed min_fixed, Aml *aml_dma(AmlDmaType typ, AmlDmaBusMaster bm, AmlTransferSize sz, uint8_t channel); Aml *aml_sleep(uint64_t msec); +Aml *aml_i2c_serial_bus_device(uint16_t address, const char *resource_source); /* Block AML object primitives */ Aml *aml_scope(const char *name_format, ...) GCC_FMT_ATTR(1, 2);