andreiw / RaspberryPiPkg

DEPRECATED - DO NOT USE | Go here instead ->
https://github.com/tianocore/edk2-platforms/tree/master/Platform/RaspberryPi/RPi3
746 stars 143 forks source link

Enable SPI1 for AUXSPI driver to load properly #106

Closed driver1998 closed 4 years ago

driver1998 commented 5 years ago

The current Windows bcmauxspi driver checks if SPI1 is enabled in the registers, if not, then the load fails, unless ForceEnable is set in the Windows registry. (if set, the driver enables SPI1 and continue)

bcmauxspi.cpp


    ULONG enableMask;
    volatile BCM_AUXSPI_REGISTERS* registersPtr;
    switch (peripheralOffset) {
    case FIELD_OFFSET(BCM_AUX_REGISTERS, Spi1):
        enableMask = 0x2;   // Spi1Enable
        registersPtr = &thisPtr->auxRegistersPtr->Spi1;
        break;
    case FIELD_OFFSET(BCM_AUX_REGISTERS, Spi2):
        enableMask = 0x4;   // Spi2Enable
        registersPtr = &thisPtr->auxRegistersPtr->Spi2;
        break;
    default:
        NT_ASSERT(!"peripheralOffset should have been validated above");
        return STATUS_INTERNAL_ERROR;
    }

    //
    // Ensure device is enabled. This is a shared register for all devices
    // on the AUX peripheral, so we cannot safely modify it without
    // synchronizing with all the other AUX devices. If the peripheral is not
    // enabled, fail the load of the driver.
    //
    BCM_AUX_ENABLES_REG enablesReg =
        {READ_REGISTER_NOFENCE_ULONG(&thisPtr->auxRegistersPtr->Enables)};

    if (!(enablesReg.AsUlong & enableMask)) {
        NTSTATUS status = queryForceEnableSetting(WdfDeviceGetDriver(WdfDevice));
        if (!NT_SUCCESS(status)) {
            AUXSPI_LOG_ERROR(
                "The device is not enabled. The device must be enabled in the "
                "AUX_ENABLES register prior to driver load. "
                "(enablesReg.AsUlong = 0x%x, enableMask = 0x%x)",
                enablesReg.AsUlong,
                enableMask);
            WdfDeviceSetFailed(WdfDevice, WdfDeviceFailedNoRestart);
            return STATUS_DEVICE_HARDWARE_ERROR;
        }
        //.....

And it seems currently SPI1 is not enabled by default, requiring ForceEnable=1 in the registry. Also, if you decided to add a switch to enable/disable SPI1 in the UEFI settings, remove the AUXSPI (SPI1) entry in RHPX when disabling SPI1 for rhproxy.sys to load properly. (Otherwise it will complain about required drivers are not started).

driver1998 commented 5 years ago

I can patch out the check for sure, but it will be better to do the job on UEFI side.

andreiw commented 5 years ago

Ok, will do.

On Tue, Jan 15, 2019 at 12:56 PM driver1998 notifications@github.com wrote:

I can patch out the check for sure, but it will be better to do the job on UEFI side.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/andreiw/RaspberryPiPkg/issues/106#issuecomment-454488393, or mute the thread https://github.com/notifications/unsubscribe-auth/AAstaxl6ZG1VQf8XfuYv3nWWxThn-r3iks5vDhZhgaJpZM4aBdqp .

-- A

driver1998 commented 4 years ago

I ended up added the ForceEnable DWORD in the bcmauxspi INF file anyway, so it should be fine to close this.