📄 config.c
字号:
}
if (status != CERR_SUCCESS) {
DEBUGMSG(ZONE_WARNING,
(TEXT("CardRequestConfiguration CardReadAttrByte failed %d\r\n"),
status));
}
req_cfg_exit:
#ifdef DEBUG
if (status) {
DEBUGMSG(ZONE_FUNCTION|ZONE_ERROR,
(TEXT("PCMCIA:CardRequestConfiguration failed %d\r\n"), status));
} else {
DEBUGMSG(ZONE_FUNCTION,
(TEXT("PCMCIA:CardRequestConfiguration succeeded\r\n")));
}
#endif
return status;
} // CardRequestConfiguration
//
// CardReleaseConfiguration
//
// @func STATUS | CardReleaseConfiguration | Place socket and PC card into memory only interface.
// @rdesc Returns one of CERR_SUCCESS, CERR_BAD_HANDLE, CERR_BAD_SOCKET, CERR_IN_USE
// or CERR_WRITE_FAILURE.
//
// @comm Configure socket and PC card for memory only and also remove power if no other
// clients are currently using the card.
// @xref <f CardModifyConfiguration> <f CardRequestConfiguration> <t CARD_SOCKET_HANDLE>
//
STATUS
CardReleaseConfiguration(
CARD_CLIENT_HANDLE hCardClient, // @parm Handle from <f CardRegisterClient>
CARD_SOCKET_HANDLE hSock // @parm Socket/function identifier
)
{
PCLIENT_DRIVER pClient;
PLOG_SOCKET pLsock, pTmp;
PDCARD_SOCKET_STATE State;
PDCARD_ADAPTER_STATE AdapterState;
STATUS status;
BYTE uReg;
UINT16 fAttributes = 0;
DEBUGMSG(ZONE_FUNCTION,
(TEXT("PCMCIA:CardReleaseConfiguration entered\r\n")));
//
// Check the parameters
//
if ((pClient = FindClient(hCardClient, TRUE, TRUE)) == NULL) {
status = CERR_BAD_HANDLE;
goto rel_cfg_exit;
}
pLsock = I_FindSocket(hSock);
if (pLsock == NULL) {
status = CERR_BAD_SOCKET;
goto rel_cfg_exit;
}
if (pLsock->hOwner != pClient) {
status = CERR_IN_USE;
goto rel_cfg_exit;
}
// Card is not configured, so we're done
if (!(pLsock->fFlags & OWNER_FLAG_CONFIG)) {
status = CERR_SUCCESS;
goto rel_cfg_exit;
}
CardModifyConfiguration(hCardClient, pLsock->hSock, &fAttributes);
pLsock->fFlags &= ~(OWNER_FLAG_CONFIG);
if ((pLsock->fFlags & OWNER_FLAGS) == 0) {
pLsock->hOwner = 0;
}
//
// Turn off IREQ interrupts, if no other configured functions
//
EnterCriticalSection(&v_SocketCrit);
for (pTmp = v_Sockets[pLsock->hSock.uSocket].pLsock; pTmp != NULL; pTmp = pTmp->Next) {
if (pTmp->fFlags & OWNER_FLAG_CONFIG) break;
}
LeaveCriticalSection(&v_SocketCrit);
if (pTmp == NULL) {
status = PDCardGetSocket(hSock.uSocket, &State);
if (status == CERR_SUCCESS) {
State.fInterruptEvents = INITIAL_SOCKET_EVENTS;
State.fInterfaceType = CFG_IFACE_MEMORY;
State.fIREQRouting &= ~SOCK_IREQ_ENABLE;
State.fControlCaps &= ~SOCK_ENABLE_SPEAKER;
status = PDCardSetSocket(hSock.uSocket, &State);
}
if (status) {
goto rel_cfg_poweroff;
}
}
//
// Avoid accessing PCMCIA space when the bus is not powered.
//
if (v_Sockets[hSock.uSocket].PowerState != POWER_NORMAL) {
goto rel_cfg_poweroff;
}
AdapterState = 0;
PDCardGetAdapter(hSock.uSocket, &AdapterState);
if (AdapterState & (ADP_STATE_POWERDOWN|ADP_STATE_POWEROFF)) {
goto rel_cfg_exit;
}
//
// Set card to memory only interface (Use configuration 0)
//
if (pLsock->pRegWin == NULL) {
status = CERR_WRITE_FAILURE;
goto rel_cfg_poweroff;
}
//
// Place card in power down mode
//
status = CardReadAttrByte(pLsock->pRegWin, FCR_OFFSET_FCSR, &uReg);
if (status != CERR_SUCCESS) goto rel_cfg_poweroff;
uReg |= FCR_FCSR_PWR_DOWN;
status = CardWriteAttrByte(pLsock->pRegWin, FCR_OFFSET_FCSR, uReg);
rel_cfg_poweroff:
//
// Power off the adapter if this client is the only one with any windows on
// this socket.
//
PcmciaPowerOff(hSock.uSocket, FALSE, hCardClient);
rel_cfg_exit:
#ifdef DEBUG
if (status) {
DEBUGMSG(ZONE_FUNCTION|ZONE_ERROR,
(TEXT("PCMCIA:CardReleaseConfiguration failed %d\r\n"), status));
} else {
DEBUGMSG(ZONE_FUNCTION,
(TEXT("PCMCIA:CardReleaseConfiguration succeeded\r\n")));
}
#endif
return status;
} // CardReleaseConfiguration
//
// This function gets called by the kernel (RegisterDevice installs it)
// and cannot block or yield or cause any kind of traps.
//
STATUS
PowerUp(
DWORD dwData
)
{
PDCARD_ADAPTER_STATE AdapterState;
// PLOG_SOCKET pLsock;
UINT i;
for (i = 0; i < (UINT8)v_cSockets; i++) {
AdapterState = ADP_STATE_KERNEL_MODE;
PDCardGetAdapter(i, &AdapterState);
//
// Put the PCMCIA system in low power mode
//
AdapterState |= ADP_STATE_KERNEL_MODE;
/*
for (pLsock = v_Sockets[i].pLsock; pLsock != NULL; pLsock = pLsock->Next) {
if (pLsock->fFlags & LOG_SOCK_FLAG_KEEP_POWERED)
break;
}
if (pLsock == NULL || (AdapterState & ADP_STATE_POWEROFF)) {
AdapterState |= ADP_STATE_POWERDOWN;
}
*/
AdapterState &= ~(ADP_STATE_POWEROFF|ADP_STATE_NODETECT|ADP_STATE_NOIRQ);
PDCardSetAdapter(i, &AdapterState);
}
//
// Cause NK to signal our StatusChangeThread
//
SetInterruptEvent(gIntrPcmciaState);
return CERR_SUCCESS;
} // PowerUp
//
// This function gets called by the kernel (RegisterDevice installs it)
// and cannot block or yield or cause any kind of traps.
//
STATUS
PowerDown(
DWORD dwData
)
{
PDCARD_ADAPTER_STATE AdapterState;
UINT i;
PLOG_SOCKET pLsock;
for (i = 0; i < (UINT8)v_cSockets; i++) {
AdapterState = ADP_STATE_KERNEL_MODE;
PDCardGetAdapter(i, &AdapterState);
AdapterState |= ADP_STATE_KERNEL_MODE;
// If a log sock wants to keep powered and has not already been powered down
// We won't need to set ADP_STATE_POWEROFF
for (pLsock = v_Sockets[i].pLsock; pLsock != NULL; pLsock = pLsock->Next) {
if ((pLsock->fFlags & LOG_SOCK_FLAG_KEEP_POWERED) &&
!(pLsock->FCSR_val & FCR_FCSR_PWR_DOWN))
break;
}
if (pLsock == NULL) {
AdapterState |= ADP_STATE_POWEROFF;
v_Sockets[i].PowerState = POWER_OFF;
} else {
v_Sockets[i].PowerState = POWER_KEPT;
}
// If socket does want to be unloaded and no IRQ wakeups
// disable insertion/removal interrupts
for (pLsock = v_Sockets[i].pLsock; pLsock != NULL; pLsock = pLsock->Next) {
if ((pLsock->fFlags & LOG_SOCK_FLAG_NO_SUSPEND_UNLOAD) ||
(pLsock->fFlags & LOG_SOCK_FLAG_IRQ_WAKEUP))
break;
}
if (pLsock == NULL) {
AdapterState |= ADP_STATE_NODETECT;
}
// disable IRQs if we don't want IRQ wakeups, or we're powered down
for (pLsock = v_Sockets[i].pLsock; pLsock != NULL; pLsock = pLsock->Next) {
if ((pLsock->fFlags & LOG_SOCK_FLAG_IRQ_WAKEUP) &&
!(pLsock->FCSR_val & FCR_FCSR_PWR_DOWN))
break;
}
if (pLsock == NULL) {
AdapterState |= ADP_STATE_NOIRQ;
}
PDCardSetAdapter(i, &AdapterState);
}
return CERR_SUCCESS;
} // PowerDown
//
// PcmciaPowerOn - cause PCMCIA system to be placed in full power mode to
// enable PC card access.
//
VOID
PcmciaPowerOn(UINT uSocket)
{
PDCARD_ADAPTER_STATE AdapterState;
DWORD status;
DEBUGMSG(ZONE_FUNCTION|ZONE_POWER,
(TEXT("PCMCIA:Entering PcmciaPowerOn (socket: %u)\n\r"),uSocket));
//
// Avoid powering an empty socket
//
if (!IsCardInserted(uSocket)) {
DEBUGMSG(ZONE_FUNCTION|ZONE_POWER,
(TEXT("PCMCIA:Leaving PcmciaPowerOn (no pccard)\n\r")));
return;
}
//
// Fully power on the PCMCIA system
//
EnterCriticalSection(&v_PowerCrit);
AdapterState = 0;
PDCardGetAdapter(uSocket, &AdapterState);
if (AdapterState & (ADP_STATE_POWERDOWN|ADP_STATE_POWEROFF)) {
AdapterState &= ~(ADP_STATE_POWERDOWN|ADP_STATE_POWEROFF);
if ((status = PDCardSetAdapter(uSocket, &AdapterState)) == CERR_SUCCESS)
DEBUGMSG(ZONE_WARNING|ZONE_POWER,
(TEXT("PCMCIA:PcmciaPowerOn: socket %u powered up\n\r"),
uSocket));
else
DEBUGMSG(ZONE_WARNING|ZONE_ERROR|ZONE_POWER,
(TEXT("PCMCIA:Error %d powering up PCMCIA socket %u\n\r"),
status,uSocket));
PDCardResetSocket(uSocket);
}
LeaveCriticalSection(&v_PowerCrit);
DEBUGMSG(ZONE_FUNCTION|ZONE_POWER,
(TEXT("PCMCIA:Leaving PcmciaPowerOn\n\r")));
} // PcmciaPowerOn
//
// PcmciaPowerOff - Power off PCMCIA adapter. Unless force parameter is
// set, only powerdown adapter if there are no active client windows. Use
// the ADP_STATE_POWERDOWN setting, so that card insertions/removals are
// still detected.
//
VOID
PcmciaPowerOff(
UINT uSocket,
BOOL Force,
CARD_CLIENT_HANDLE hClient
)
{
PDCARD_ADAPTER_STATE AdapterState;
PDCARD_SOCKET_STATE State;
DWORD status;
PLOG_SOCKET pLsock;
PLOG_WINDOW pLog;
PPHYS_WINDOW pPhys = v_pWinList;
PCALLBACK_STRUCT pEvent;
PCLIENT_DRIVER pClient;
BOOL bFound;
DEBUGMSG(ZONE_FUNCTION|ZONE_POWER,
(TEXT("PCMCIA:Entering PcmciaPowerOff (sock: %u, force: %u)\n\r"),
uSocket,Force));
//
// Unless we are forced, check to make sure no client windows are
// present before we shut down.
//
EnterCriticalSection(&v_PowerCrit);
if (Force == FALSE) {
if (v_Sockets[uSocket].fFlags & PHYS_SOCK_FLAG_ACTIVE) {
DEBUGMSG(ZONE_POWER|ZONE_WARNING,
(TEXT("PCMCIA:PcmciaPowerOff(%u) -- socket is active, not powering down\n\r"),
uSocket));
LeaveCriticalSection(&v_PowerCrit);
return;
}
EnterCriticalSection(&v_SocketCrit);
EnterCriticalSection(&v_WindowCrit);
pClient = FindClient(hClient, TRUE, TRUE);
// Check if the client has any functions in the socket that are configured and not powered down
if (pClient != CARDSERV_CLIENT_HANDLE) {
for (pLsock = v_Sockets[uSocket].pLsock; pLsock != NULL; pLsock = pLsock->Next) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -