From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web10.355.1591643392666331687 for ; Mon, 08 Jun 2020 12:09:53 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=GXdazZVn; spf=pass (domain: nuviainc.com, ip: 209.85.221.66, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f66.google.com with SMTP id j10so18653666wrw.8 for ; Mon, 08 Jun 2020 12:09:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Ayh+MhOibEhwqRKLUMFpW3bdp82gdS6ErAmULdPTnDI=; b=GXdazZVnsbj5gDx6fMpnr95y1O+wygF3eFai801OEReaJdBR6ogJPRdp2419E9kgK5 /bw6ffnWC6Kr/UKIZnxvXfUjTrczsBoN0hcB/hDUTASU2GmVVsMGElCgWkSTVynCyTgx h61uArkpZDmnCIQmdFahLjrFLF3/Mq4qBTaDzb048zOVQVDwLfr2U9hnKNyTLK9e82BH UP1w1Uci+jsRIc9S/uUtREJyPfKML0/RCZdLWTwXUFmjwPYXIJhRb4a+8Xx1hPiXWszx EkFqXF9Xn9x6V29ngfnbO/6QnxFAxKZ+kU+P0OAqeOFB8MNs7ze9uFn6iqIACec8mIw2 XnHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Ayh+MhOibEhwqRKLUMFpW3bdp82gdS6ErAmULdPTnDI=; b=BS1Y0hD2DyMIDaFzVsjLEscdcTUDjZTEgjH8aiunjWWsMNo10qcPKpfEK2Y4F+6G8w l04/rNfEChzNY7l1kjrFfcU71qY4+FOr2PvpYVynvpYSy727jXW4tEKhPsDh0fwgpes4 sSAjG4aAsbZ92jyCqFQ7IlXW0dQsWyPQDPnkVEy0Gu9PrN2h4A4sDuPZ3kaQ/3rqEN8U UKqfrnNrToTdndFEO/533ggKCJkrXM5dJyEqYS3t5J/hqEgdSOK8dIHrS+F6dTfWLk4T IYqaWGuCv/fBedtUXf4cjnzMKWIkWUpQM3q8GNp4IB+Oga08BOEOjPyp/JhxS2sKf+6h gb2A== X-Gm-Message-State: AOAM533UJg1ktldN5j3wRor4HaDwous+QFVaqQo2WF7FzV1j+/vY/Gtt +MGiKG7yX+Xa96ckatfF1W/8LA== X-Google-Smtp-Source: ABdhPJzqgCdxoTx8JTgP586vKpOTzIvPgZ8XdqQ7ODcfZD0uS9XfSl/bHmBS5ADejzQCXIkQmfzWlw== X-Received: by 2002:a5d:45c2:: with SMTP id b2mr236890wrs.323.1591643391229; Mon, 08 Jun 2020 12:09:51 -0700 (PDT) Return-Path: Received: from vanye ([2001:470:1f09:12f0:b26e:bfff:fea9:f1b8]) by smtp.gmail.com with ESMTPSA id o18sm460617wme.19.2020.06.08.12.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jun 2020 12:09:50 -0700 (PDT) Date: Mon, 8 Jun 2020 20:09:48 +0100 From: "Leif Lindholm" To: Ming Huang Cc: devel@edk2.groups.io, ard.biesheuvel@linaro.org, lidongzhan@huawei.com, songdongkuang@huawei.com, wanghuiqiang@huawei.com, qiuliangen@huawei.com, shenlimei@huawei.com, xiewenyi2@huawei.com Subject: Re: [PATCH edk2-platforms v1 2/2] Silicon/Hisilicon/Smbios: Optimize type 9 Message-ID: <20200608190948.GX28566@vanye> References: <1591625397-82711-1-git-send-email-huangming23@huawei.com> <1591625397-82711-3-git-send-email-huangming23@huawei.com> MIME-Version: 1.0 In-Reply-To: <1591625397-82711-3-git-send-email-huangming23@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Jun 08, 2020 at 22:09:57 +0800, Ming Huang wrote: > Break down AddSmbiosType9Entry to three funtions for optimizing > Smbios type 9. > > Signed-off-by: Ming Huang Reviewed-by: Leif Lindholm > --- > Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c | 173 +++++++++++--------- > 1 file changed, 95 insertions(+), 78 deletions(-) > > diff --git a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c > index 2398c6b..57e049a 100644 > --- a/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c > +++ b/Silicon/Hisilicon/Drivers/Smbios/AddSmbiosType9/AddSmbiosType9.c > @@ -75,38 +75,16 @@ UpdateSmbiosType9Info ( > return; > } > > -EFI_STATUS > -EFIAPI > -AddSmbiosType9Entry ( > - IN EFI_HANDLE ImageHandle, > - IN EFI_SYSTEM_TABLE *SystemTable > +STATIC > +VOID > +EmptySmbiosType9 ( > + EFI_SMBIOS_PROTOCOL *Smbios > ) > { > EFI_STATUS Status; > EFI_SMBIOS_TYPE SmbiosType; > EFI_SMBIOS_HANDLE SmbiosHandle; > - EFI_SMBIOS_PROTOCOL *Smbios; > EFI_SMBIOS_TABLE_HEADER *Record; > - SMBIOS_TABLE_TYPE9 *Type9Record; > - SMBIOS_TABLE_TYPE9 *SmbiosRecord = NULL; > - CHAR8 *OptionalStrStart; > - > - UINT8 SmbiosAddType9Number; > - UINT8 Index; > - > - CHAR16 *SlotDesignation = NULL; > - UINTN SlotDesignationStrLen; > - > - Status = gBS->LocateProtocol ( > - &gEfiSmbiosProtocolGuid, > - NULL, > - (VOID **) &Smbios > - ); > - if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "[%a]:[%dL] LocateProtocol Failed. Status : %r\n", > - __FUNCTION__, __LINE__, Status)); > - return Status; > - } > > do { > SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; > @@ -122,76 +100,115 @@ AddSmbiosType9Entry ( > } > } while (SmbiosHandle != SMBIOS_HANDLE_PI_RESERVED); > > - SmbiosAddType9Number = OemGetPcieSlotNumber (); > + return; > +} > > - for (Index = 0; Index < SmbiosAddType9Number; Index++) { > - if (gPcieSlotInfo[Index].Hdr.Type != EFI_SMBIOS_TYPE_SYSTEM_SLOTS) { > - continue; > - } > +STATIC > +EFI_STATUS > +AddSmbiosType9Record ( > + EFI_SMBIOS_PROTOCOL *Smbios, > + SMBIOS_TABLE_TYPE9 *Type9Record > + ) > +{ > + EFI_STATUS Status; > + EFI_SMBIOS_HANDLE SmbiosHandle; > + SMBIOS_TABLE_TYPE9 *SmbiosRecord; > + CHAR8 *OptionalStrStart; > + CHAR16 SlotDesignation[SMBIOS_STRING_MAX_LENGTH]; > + UINTN SlotStrLen; > + > + SlotStrLen = UnicodeSPrint ( > + SlotDesignation, > + SMBIOS_STRING_MAX_LENGTH * 2, > + L"PCIE Slot%d", > + Type9Record->SlotID); > + > + // > + // Two zeros following the last string. > + // > + SmbiosRecord = AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE9) + SlotStrLen + 1 + 1); > + if (SmbiosRecord == NULL) { > + DEBUG ((DEBUG_ERROR, "AllocateZeroPool Failed for SmbiosRecord.\n")); > + return EFI_OUT_OF_RESOURCES; > + } > > - Type9Record = &gPcieSlotInfo[Index]; > + (VOID)CopyMem (SmbiosRecord, Type9Record, sizeof (SMBIOS_TABLE_TYPE9)); > + SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE9); > + OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1); > + (VOID)UnicodeStrToAsciiStr (SlotDesignation, OptionalStrStart); > > - UpdateSmbiosType9Info (Type9Record); > - SlotDesignation = AllocateZeroPool ((sizeof (CHAR16)) * SMBIOS_STRING_MAX_LENGTH); > - if (SlotDesignation == NULL) { > - Status = EFI_OUT_OF_RESOURCES; > - DEBUG ((DEBUG_ERROR, "[%a]:[%dL] AllocateZeroPool Failed. Status : %r\n", > - __FUNCTION__, __LINE__, Status)); > + // > + // Now we have got the full smbios record, call smbios protocol to add this record. > + // > + SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; > + Status = Smbios->Add (Smbios, NULL, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *)SmbiosRecord); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "Add Smbios Type09 Failed! %r\n", Status)); > + } > > - goto Exit; > - } > + FreePool (SmbiosRecord); > + return Status; > +} > > - SlotDesignationStrLen = UnicodeSPrint ( > - SlotDesignation, > - SMBIOS_STRING_MAX_LENGTH - 1, > - L"PCIE Slot%d", > - Type9Record->SlotID); > - > - // > - // Two zeros following the last string. > - // > - SmbiosRecord = AllocateZeroPool (sizeof (SMBIOS_TABLE_TYPE9) + SlotDesignationStrLen + 1 + 1); > - if (SmbiosRecord == NULL) { > - Status = EFI_OUT_OF_RESOURCES; > - DEBUG ((DEBUG_ERROR, "[%a]:[%dL] AllocateZeroPool Failed. Status : %r\n", > - __FUNCTION__, __LINE__, Status)); > +STATIC > +VOID > +HandleSmbiosType9 ( > + EFI_SMBIOS_PROTOCOL *Smbios > + ) > +{ > + EFI_STATUS Status; > + SMBIOS_TABLE_TYPE9 *Type9Record; > + UINT8 RecordCount; > + UINT8 Index; > > - goto Exit; > - } > + RecordCount = OemGetPcieSlotNumber (); > + if (RecordCount == 0) { > + return; > + } > > - (VOID)CopyMem (SmbiosRecord, Type9Record, sizeof (SMBIOS_TABLE_TYPE9)); > + EmptySmbiosType9 (Smbios); > + Status = EFI_SUCCESS; > + for (Index = 0; Index < RecordCount; Index++) { > + if (gPcieSlotInfo[Index].Hdr.Type != EFI_SMBIOS_TYPE_SYSTEM_SLOTS) { > + continue; > + } > > - SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE9); > + Type9Record = &gPcieSlotInfo[Index]; > > - OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1); > - UnicodeStrToAsciiStr (SlotDesignation, OptionalStrStart); > + UpdateSmbiosType9Info (Type9Record); > > - // > - // Now we have got the full smbios record, call smbios protocol to add this record. > - // > - SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; > - Status = Smbios->Add (Smbios, NULL, &SmbiosHandle, (EFI_SMBIOS_TABLE_HEADER *)SmbiosRecord); > + Status = AddSmbiosType9Record (Smbios, Type9Record); > if (EFI_ERROR (Status)) { > - DEBUG ((DEBUG_ERROR, "[%a]:[%dL] Smbios Type09 Table Log Failed! %r \n", > - __FUNCTION__, __LINE__, Status)); > - goto Exit; > + break; > } > - > - FreePool (SmbiosRecord); > - FreePool (SlotDesignation); > } > > - return EFI_SUCCESS; > + return; > +} > > -Exit: > - if(SmbiosRecord != NULL) { > - FreePool (SmbiosRecord); > - } > +EFI_STATUS > +EFIAPI > +AddSmbiosType9Entry ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + EFI_SMBIOS_PROTOCOL *Smbios; > > - if(SlotDesignation != NULL) { > - FreePool (SlotDesignation); > + Status = gBS->LocateProtocol ( > + &gEfiSmbiosProtocolGuid, > + NULL, > + (VOID **) &Smbios > + ); > + if (EFI_ERROR (Status)) { > + DEBUG ((DEBUG_ERROR, "[%a]:[%dL] LocateProtocol Failed. Status : %r\n", > + __FUNCTION__, __LINE__, Status)); > + return Status; > } > > + HandleSmbiosType9 (Smbios); > + > return Status; > } > > -- > 2.8.1 >