📄 mmcpci.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*****************************************************************************
* FileName: MMCPCI.C
*
* SanDisk Host Developer's Toolkit
*
* Copyright (c) 1997 - 1999 SanDisk Corporation
* All rights reserved.
*
* Description:
*
* MMC platform specific routines.
*
******************************************************************************/
#include <windows.h>
#include <types.h>
#include <tchar.h>
#include <windev.h>
#include <ceddk.h>
#include <ntcompat.h>
#include "sdapi.h"
#include "plx9054.h"
#define PCI_CONFIG_TYPE(_CfgData) \
((_CfgData)->HeaderType & ~(UCHAR)PCI_MULTIFUNCTION)
SDBOOL scan_PCI_config(void);
NTSTATUS
PciAssignSlotResources(
IN ULONG BusNumber,
IN PUNICODE_STRING RegistryPath,
IN PUNICODE_STRING DriverClassName OPTIONAL,
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT DeviceObject OPTIONAL,
IN PCI_SLOT_NUMBER SlotNumber,
IN OUT PCM_RESOURCE_LIST *AllocatedResources
);
ULONG
PciReadConfig(
IN ULONG BusNumber,
IN PCI_SLOT_NUMBER SlotNumber,
OUT PVOID Buffer,
IN ULONG Offset,
IN ULONG Length
);
ULONG
PciWriteConfig(
IN ULONG BusNumber,
IN PCI_SLOT_NUMBER SlotNumber,
IN PVOID Buffer,
IN ULONG Offset,
IN ULONG Length
);
ADAPTER myAdapters[N_CONTROLLERS];
/************************************************************************/
/* PCI Internal variables */
/************************************************************************/
SDLOCAL INT16 noController = 0;
SDBOOL scan_PCI_config(SDVOID);
UCHAR TranslatePCIAddress(DWORD dwPCIAddress, int nSize, LPVOID* ppIoAddress)
{
ULONG AddressSpaceFlag;
PHYSICAL_ADDRESS PhysicalAddress;
PHYSICAL_ADDRESS TranslatedAddress;
if (!dwPCIAddress) {
*ppIoAddress = (LPVOID) dwPCIAddress;
return 1;
}
PhysicalAddress.HighPart = 0;
PhysicalAddress.LowPart = dwPCIAddress & 0xFFFFFFFC;
AddressSpaceFlag = dwPCIAddress & 0x00000001;
// translate PCI address to local address
if (HalTranslateBusAddress(PCIBus, 0, PhysicalAddress, &AddressSpaceFlag, &TranslatedAddress))
{
if (!AddressSpaceFlag)
{
// Obtain a virtual address for the I/O port or register.
*ppIoAddress = (PUCHAR)MmMapIoSpace(TranslatedAddress, nSize, FALSE);
if (*ppIoAddress == NULL) return 0; // Indicate Failed
// Return 2 if originally memory, 3 if originally port but mapped
return ((UCHAR)(dwPCIAddress & 0x00000001) | 2);
}else{
*ppIoAddress = (PUCHAR)TranslatedAddress.LowPart;
return 1; // Indicate originally port and not mapped
}
} else {
return 0;
}
return 0;
}
SDBOOL scan_PCI_config(SDVOID)
{
int bus;
int device;
int func;
int i;
PCI_SLOT_NUMBER slotnumber;
PCM_RESOURCE_LIST AllocatedResources;
PCM_RESOURCE_LIST * pAllocatedResources;
ULONG length;
PCI_COMMON_CONFIG ConfigInfo;
UINT32 mmc_port;
INT16 mmc_intr;
PHYSICAL_ADDRESS PhysicalAddress;
DWORD AddressSpace;
pAllocatedResources=&AllocatedResources;
mmc_port = 0;
mmc_intr = 0;
for (bus = 0; bus < PCI_MAX_BUS; bus++)
{
for (device = 0; device < PCI_MAX_DEVICES; device++)
{
for (func = 0; func < PCI_MAX_FUNCTION; func++)
{
slotnumber.u.bits.Reserved=0;
slotnumber.u.bits.DeviceNumber=device;
slotnumber.u.bits.FunctionNumber=func;
//
//
//Get the configuration space for the adapter in this slot
//
//
length= HalGetBusData(PCIConfiguration,
bus, slotnumber.u.AsULONG, &ConfigInfo,
sizeof(PCI_COMMON_CONFIG));
if ((length == 0) || (ConfigInfo.VendorID == 0xFFFF))
{
// Device doesn't exist
break;
}
// if slot is empty or is not SanDisk adapter
if (ConfigInfo.VendorID != SD_VENDOR_ID) continue;
// if SanDisk adapter found in slot
if (ConfigInfo.DeviceID == SD_DEVICE_ID)
{
/*
For CEPC, the BIOS assigns the I/O base address, so we can just
pull it out of the base address registers. For other platforms,
PciAssignSlotResources (or other simlilar code) will need to be used
*/
mmc_intr = (int) ConfigInfo.u.type0.InterruptLine;
for (i=0; i<PCI_TYPE0_ADDRESSES; i++)
{
if (ConfigInfo.u.type0.BaseAddresses[i] & 1)
mmc_port=(UINT32) ConfigInfo.u.type0.BaseAddresses[i] & PCI_ADDRESS_IO_ADDRESS_MASK;
}
if (mmc_port == 0) return FALSE;
// TranslatePCIAddress((DWORD)mmc_port, 32, (LPVOID *)&myAdapters[noController].portIO);
PhysicalAddress.HighPart = 0;
PhysicalAddress.LowPart = mmc_port;
AddressSpace = 1;
TransBusAddrToVirtual( PCIBus, 0, PhysicalAddress, 0x40, &AddressSpace, (LPVOID *)&myAdapters[noController].portIO);
// myAdapters[noController].portIO = mmc_port;
myAdapters[noController].intr = mmc_intr;
return TRUE;
} //If SanDisk adapter found
} // for functions
// Move on to next device
if (length == 0) break;
} // for devices
// Bus doesn't exist
if (length == 0 && device == 0) break;
} // for buses
return FALSE;
}
SDBOOL mmcAdapterInfo(INT16 controller, UINT32 *pPort, INT16 *pIntr);
SDBOOL mmcAdapterInfo(INT16 controller, UINT32 *pPort, INT16 *pIntr)
{
if (controller > noController)
return NO;
*pPort = myAdapters[controller].portIO;
*pIntr = myAdapters[controller].intr;
return YES;
}
ULONG
PciReadConfig(
IN ULONG BusNumber,
IN PCI_SLOT_NUMBER SlotNumber,
OUT PVOID Buffer,
IN ULONG Offset,
IN ULONG Length
)
{
DBGCHK(TEXT("NTCOMPAT"), (Offset & 3) == 0);
DBGCHK(TEXT("NTCOMPAT"), (Length & 3) == 0);
DBGCHK(TEXT("NTCOMPAT"), Offset + Length <= sizeof(PCI_COMMON_CONFIG));
return HalGetBusDataByOffset(
PCIConfiguration,
BusNumber,
SlotNumber.u.AsULONG,
Buffer,
Offset,
Length
);
}
ULONG
PciWriteConfig(
IN ULONG BusNumber,
IN PCI_SLOT_NUMBER SlotNumber,
IN PVOID Buffer,
IN ULONG Offset,
IN ULONG Length
)
{
DBGCHK(TEXT("NTCOMPAT"), (Offset & 3) == 0);
DBGCHK(TEXT("NTCOMPAT"), (Length & 3) == 0);
DBGCHK(TEXT("NTCOMPAT"), Offset + Length <= 128);
return HalSetBusDataByOffset(
PCIConfiguration,
BusNumber,
SlotNumber.u.AsULONG,
Buffer,
Offset,
Length
);
}
NTSTATUS
PciAssignSlotResources(
IN ULONG BusNumber,
IN PUNICODE_STRING RegistryPath,
IN PUNICODE_STRING DriverClassName OPTIONAL,
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT DeviceObject OPTIONAL,
IN PCI_SLOT_NUMBER SlotNumber,
IN OUT PCM_RESOURCE_LIST *AllocatedResources
)
{
PUCHAR WorkingPool;
PCI_COMMON_CONFIG CfgData;
PCI_COMMON_CONFIG OrigCfgData;
ULONG i;
ULONG NoBaseAddress;
ULONG RomIndex;
PIO_RESOURCE_REQUIREMENTS_LIST CompleteList;
PIO_RESOURCE_DESCRIPTOR IoDescriptor;
PCM_PARTIAL_RESOURCE_DESCRIPTOR CmDescriptor;
PULONG BaseAddress[PCI_TYPE0_ADDRESSES + 1];
PULONG OrigAddress[PCI_TYPE0_ADDRESSES + 1];
BOOLEAN EnableRomBase;
BOOLEAN RequestedInterrupt;
*AllocatedResources = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -