From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F40DEC4332F for ; Tue, 13 Dec 2022 07:15:57 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8B4E385424; Tue, 13 Dec 2022 08:15:55 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="P6HJb/GZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D6AD985450; Tue, 13 Dec 2022 08:15:53 +0100 (CET) Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2374185420 for ; Tue, 13 Dec 2022 08:15:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x632.google.com with SMTP id x22so34282264ejs.11 for ; Mon, 12 Dec 2022 23:15:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=EOKE5Px9ObHlkQgnjXXWKoeoAqNTW4iAYJ1TsIEOWzE=; b=P6HJb/GZ2nmSEVXmhEXstt+qzsGmNL/p/+Zgkdf2keKE/KyJb3x9jayTeMLuq1EY/n KWBsEHZzmM+zhwDUklQ8xXrLyNdfYox2wa2fdnX12BNatPGWm2lLYCcctvwIVz+a+vwZ +0/ZvFm7qF1aiJc+vVw8iN52wpdO53dsbFpPA1rVjx9/rvxhQ3Q+RnorDcEyyXUXV+Yb HhPrdJvcZ2u63in5b2Qa3WMSos4iXls5F5XE9y3fyzYIy+74gtytJAvaa2AeAk5pTe+p s600PqSvRm/6JNRCiX/PbFYna4LP/BkUDdEIa3nRIm2Rt6FRFaIG3u7XibSuz1tAHItY 0jyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=EOKE5Px9ObHlkQgnjXXWKoeoAqNTW4iAYJ1TsIEOWzE=; b=YKbjrt64dVbTxJZwBOg3IGMS18dT2jfjZcd+8VjYmh59P2iWwoK+T7kQngYMZuND01 7Nhp0ERY9yL75aW8FR8wwcvCQZCfmMSY604WiDwI3hojP9vEaL7JSXng0X+PJ6Jxb1pV jBsQL6Y9fADdYd0PgBd4+QZRNmiWw2J4y3pxYHEe07U7+xYNPfIWR0rBO75xTlsd4V9w uR7nGxs4ezlUzFa/ha87ebiYc0/C60zrCJjUKA39bV64GTyac3RgK0yNk9LCUKehKqDv 6XUC82V8wmwECSM9ZLVkEiiS3FmiLy4FXVZoOV3ya6vrnEHfF1+vKmYGXQ7HsbWH1v8D /LeQ== X-Gm-Message-State: ANoB5pmvUgMQMH1eB7fRoBAGwshkCwGqIuq45jvmOoLjw+ClaJieqJQ5 LGxy1lNJ0Sdqq0UGCGxqOUWtfg== X-Google-Smtp-Source: AA0mqf4Jl9fdEwRf/JgfXAhpUsPBgtJJCDlB6NLTfsf7RdtIzYxG0bJM+3ZDSAXVRsN+I2BM7lvXzA== X-Received: by 2002:a17:906:2a85:b0:7b2:7181:2489 with SMTP id l5-20020a1709062a8500b007b271812489mr19776857eje.13.1670915750713; Mon, 12 Dec 2022 23:15:50 -0800 (PST) Received: from hera (ppp078087234022.access.hol.gr. [78.87.234.22]) by smtp.gmail.com with ESMTPSA id gg9-20020a170906e28900b0078db5bddd9csm4132555ejb.22.2022.12.12.23.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 23:15:50 -0800 (PST) Date: Tue, 13 Dec 2022 09:15:47 +0200 From: Ilias Apalodimas To: Paul Barker Cc: u-boot@lists.denx.de, Simon Glass , Tom Rini , Heinrich Schuchardt , Jagan Teki Subject: Re: [PATCH v5 1/3] efi_loader: Add SPI I/O protocol support Message-ID: References: <20221123175006.4080122-1-paul.barker@sancloud.com> <20221123175006.4080122-2-paul.barker@sancloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221123175006.4080122-2-paul.barker@sancloud.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Hi Paul, Apologies for the delayed reply. [...] > +static efi_status_t > +export_spi_peripheral(struct efi_spi_bus *bus, struct udevice *dev) > +{ > + efi_string_t name_utf16, vendor_utf16, part_number_utf16; > + struct efi_spi_peripheral_priv *priv; > + efi_status_t status; > + efi_handle_t handle = NULL; > + struct udevice *dev_bus = dev->parent; > + struct spi_slave *target; > + const char *name = dev_read_name(dev); > + const char *vendor = dev_read_string(dev, "u-boot,uefi-spi-vendor"); > + const char *part_number = dev_read_string(dev, > + "u-boot,uefi-spi-part-number"); > + efi_guid_t *guid = (efi_guid_t *)dev_read_u8_array_ptr(dev, > + "u-boot,uefi-spi-io-guid", 16); > + > + if (device_get_uclass_id(dev) == UCLASS_SPI_EMUL) { > + debug("Skipping emulated SPI peripheral %s\n", name); > + goto fail_1; > + } > + > + if (!vendor || !part_number || !guid) { > + debug("Skipping SPI peripheral %s\n", name); > + status = EFI_UNSUPPORTED; > + goto fail_1; > + } > + > + if (!device_active(dev)) { > + int ret = device_probe(dev); > + if (ret) { > + debug("Skipping SPI peripheral %s, probe failed\n", > + name); > + goto fail_1; > + } > + } > + > + target = dev_get_parent_priv(dev); > + if (!target) { > + debug("Skipping uninitialized SPI peripheral %s\n", name); > + status = EFI_UNSUPPORTED; > + goto fail_1; > + } > + > + debug("Registering SPI dev %d:%d, name %s\n", > + dev_bus->seq_, spi_chip_select(dev), name); > + > + priv = calloc(1, sizeof(*priv)); > + if (!priv) { > + status = EFI_OUT_OF_RESOURCES; > + goto fail_1; > + } > + > + vendor_utf16 = efi_convert_string(vendor); > + if (!vendor_utf16) { > + status = EFI_OUT_OF_RESOURCES; > + goto fail_2; > + } > + > + part_number_utf16 = efi_convert_string(part_number); > + if (!part_number_utf16) { > + status = EFI_OUT_OF_RESOURCES; > + goto fail_3; > + } > + > + name_utf16 = efi_convert_string(name); > + if (!name_utf16) { > + status = EFI_OUT_OF_RESOURCES; > + goto fail_4; > + } > + > + priv->target = target; > + > + efi_spi_init_part(&priv->part, target, vendor_utf16, part_number_utf16); > + > + efi_spi_init_peripheral(&priv->peripheral, &priv->part, > + bus, target, guid, name_utf16); > + > + efi_spi_append_peripheral(&priv->peripheral, bus); > + > + efi_spi_init_io_protocol(&priv->io_protocol, &priv->peripheral, target); > + > + status = efi_install_multiple_protocol_interfaces(&handle, guid, > + &priv->io_protocol, > + NULL); There's a protocols installed here as well as in efi_spi_protocol_register(). But I don't see those being uninstalled somewhere. Shouldn't destroy_efi_spi_bus() call efi_uninstall_multiple_protocol_interfaces() as well ? > + if (status != EFI_SUCCESS) > + goto fail_5; > + > + debug("Added EFI_SPI_IO_PROTOCOL for %s with guid %pUl\n", name, guid); > + return EFI_SUCCESS; > + > +fail_5: > + free(name_utf16); > +fail_4: > + free(part_number_utf16); > +fail_3: > + free(vendor_utf16); > +fail_2: > + free(priv); > +fail_1: > + return status; > +} > + > +static struct efi_spi_bus *export_spi_bus(int i) > +{ > + struct efi_spi_bus *bus; > + struct udevice *dev, *child; > + const char *name; > + int r; > + > + r = uclass_get_device(UCLASS_SPI, i, &dev); > + if (r < 0) { > + debug("Failed to get SPI bus %d\n", i); > + goto fail_1; > + } > + > + name = dev_read_name(dev); > + debug("Registering SPI bus %d, name %s\n", i, name); > + > + bus = calloc(1, sizeof(*bus)); > + if (!bus) > + goto fail_1; > + > + bus->friendly_name = efi_convert_string(name); > + if (!bus->friendly_name) > + goto fail_2; > + > + bus->peripheral_list = NULL; > + bus->clock = efi_spi_bus_clock; > + bus->clock_parameter = NULL; > + > + /* For the purposes of the current implementation, we do not need to > + * expose the hardware device path to users of the SPI I/O protocol. > + */ > + bus->controller_path = &null_device_path; > + > + device_foreach_child(child, dev) { > + efi_status_t status = export_spi_peripheral(bus, child); > + > + if (status == EFI_OUT_OF_RESOURCES) > + goto fail_3; > + } > + > + return bus; > + > +fail_3: > + destroy_efi_spi_bus(bus); > +fail_2: > + free(bus); > +fail_1: > + return NULL; > +} > + > +efi_status_t efi_spi_protocol_register(void) > +{ > + efi_status_t status; > + efi_handle_t handle = NULL; > + struct efi_spi_configuration_protocol *proto; > + uint i; > + > + debug("Registering EFI_SPI_CONFIGURATION_PROTOCOL\n"); > + > + proto = calloc(1, sizeof(*proto)); > + if (!proto) { > + status = EFI_OUT_OF_RESOURCES; > + goto fail_1; > + } > + > + proto->bus_count = uclass_id_count(UCLASS_SPI); > + proto->bus_list = calloc(proto->bus_count, sizeof(*proto->bus_list)); > + if (!proto->bus_list) { > + status = EFI_OUT_OF_RESOURCES; > + goto fail_2; > + } > + > + for (i = 0; i < proto->bus_count; i++) { > + proto->bus_list[i] = export_spi_bus(i); > + if (!proto->bus_list[i]) > + goto fail_3; > + } > + > + status = efi_install_multiple_protocol_interfaces(&handle, > + &efi_spi_configuration_guid, > + proto, NULL); > + if (status != EFI_SUCCESS) > + goto fail_3; > + > + return EFI_SUCCESS; > + > +fail_3: > + for (i = 0; i < proto->bus_count; i++) { > + if (proto->bus_list[i]) > + destroy_efi_spi_bus(proto->bus_list[i]); > + } > + free(proto->bus_list); > +fail_2: > + free(proto); > +fail_1: > + return status; > +} > diff --git a/lib/uuid.c b/lib/uuid.c > index 465e1ac38f57..3f723b732588 100644 > --- a/lib/uuid.c > +++ b/lib/uuid.c > @@ -187,6 +187,10 @@ static const struct { > "TCG2", > EFI_TCG2_PROTOCOL_GUID, > }, > + { > + "SPI Protocol Stack", > + EFI_SPI_CONFIGURATION_GUID > + }, > { > "System Partition", > PARTITION_SYSTEM_GUID > -- > 2.25.1 > Regards /Ilias