Commit Graph

8 Commits

Author SHA1 Message Date
Michael D Kinney
73ecd7d8b2 MdeModulePkg/SpiNorFlashJedecSfdp: Initialize AddressSize
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-06-13 15:47:59 +00:00
Dongyan Qian
58d3345d8c MdeModulePkg/SpiBus: Free handle buffers after LocateHandleBuffer
Fix memory leaks by adding missing FreePool calls:
release SpiHcHandles in SpiBusEntry exit path.

REF: https://uefi.org/sites/default/files/resources/UEFI_Spec_Final_2.11.pdf
Chapter 7.3.15: "Services - Boot Services.LocateHandleBuffer":
It is the caller's responsibility to call the Boot Service.FreePool when
the caller no longer requires the contents of Buffer.

Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
2025-06-12 14:09:13 +00:00
PaddyDeng
93aeaa0812 MdeModulePkg/Spi: Allow NULL WriteBuffer in FillWriteBuffer()
Fix false positive assert added in #10924
Functon `FillWriteBuffer()` should able to accept NULL WriteBuffer when
WriteBytes equals 0.

Use case:
```
  // Read Status register
  TransactionBufferLength = FillWriteBuffer (
                              Instance,
                              SPI_FLASH_RDSR,
                              SPI_FLASH_RDSR_DUMMY,
                              SPI_FLASH_RDSR_ADDR_BYTES,
                              FALSE,
                              0,
                              0, // WriteBytes = 0
                              NULL // WriteBuffer can be NULL
                              );

```

Signed-off-by: Paddy Deng <v-paddydeng@microsoft.com>
2025-05-26 05:45:37 +00:00
PaddyDeng
2cff8743ce MdeModulePkg/Spi: Solving potential null ptr deref. in SpiNorFlashJedecSfdp
The pointer `Instance->SfdpBasicFlash` can be used before initializing.

Example code flow:
- CreateSpiNorFlashSfdpInstance: Allocate pool for `Instance`
    - InitialSpiNorFlashSfdpInstance
        - ReadSfdp
            - ReadSfdpHeader
                - FillWriteBuffer: Dereferencing
`Instance->SfdpBasicFlash`
            - ReadSfdpBasicParameterTable: Allocate pool for
`Instance->SfdpBasicFlash`

Check both `Instance` and `Instance->SfdpBasicFlash` should have
a non null value before dereferencing it. Otherwise use the defaut
value 0.

Also terminate the function if `Instance` or `WriteBuffer` is NULL.

Signed-off-by: Paddy Deng <v-paddydeng@microsoft.com>
2025-05-05 14:26:16 +08:00
Jack Hsieh
e1dee2bcfa MdeModulePkg SpiBus: Use correct GUID
Fix incorrect guid in SpiBusDxe and add null checking for AllocateZeroPool in the SpiBus driver.

Signed-off-by: Jack Hsieh <v-chhsieh@microsoft.com>
2025-04-30 14:55:42 +08:00
Brit Chesley
82b0358e3f MdeModulePkg: SpiHc: SpiHc Drivers
Added SpiHc DXE and SMM drivers. This code receives bus transactions
from the SpiBus layer and passes them onto the SpiHcPlatformLib

Platform Initialization Spec 1.7 volume 5 section 18.1.7

Bugzilla #4753

Cc: Abner Chang <abner.chang@amd.com>
Cc: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
Signed-off-by: Brit Chesley <brit.chesley@amd.com>
Reviewed-by: Abner Chang <abner.chang@amd.com>
2024-05-08 04:43:58 +00:00
Brit Chesley
efc7ccf906 MdeModulePkg/Bus/Spi/SpiBus: Adding SpiBus Drivers
Added SpiBus DXE and SMM drivers. This code translates SPI requests from
the application layer into SPI Bus transactions on the SPI host
controller. The code is responsible for checking if the transaction is
valid, then setting up the SPI clock and chip select properly before
passing the bus transaction to the host controller.

Platform Initialization Spec 1.7 volume 5 section 18.1.6

Bugzilla #4753

Cc: Abner Chang <abner.chang@amd.com>
Cc: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
Signed-off-by: Brit Chesley <brit.chesley@amd.com>
Reviewed-by: Abner Chang <abner.chang@amd.com>
2024-05-08 04:43:58 +00:00
abnchang
8b02ecc5f0 MdeModulePkg/SpiNorFlashJedecSfdp: SPI NOR Flash JEDEC SFDP
BZ#: 4471
SPI NOR Flash JEDEC Serial Flash Discoverable Driver
implementation.

Signed-off-by: Abner Chang <abner.chang@amd.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Abdul Lateef Attar <abdattar@amd.com>
Cc: Brit Chesley <brit.chesley@amd.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
2024-04-20 08:26:40 +00:00