//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:  

Abstract:

Platform dependent PCMCIA initialization functions

Notes: 
--*/

#ifndef __PCIB_H_
#define __PCIB_H_
#include <devload.h>
#include <pcibus.h>
#include <CRegEdit.h>
#include "CBCardEn.h"
#include "debug.h"

// CardBus Special Registry Entry.
#define CARDBUS_IGNORE_TUPLE_VALNAME TEXT("IgnoreTuple")
#define CARDBUS_IGNORE_TUPLE_VALTYPE REG_DWORD
class CCfgEntry
{
public:
                    CCfgEntry( LPCTSTR lpConfigEntry,
                               LPCTSTR lpConfigDll,
                               DWORD dwDevFlag );
                    ~CCfgEntry();
    DWORD           CallEntry( DWORD dwOp,
                               struct _PCI_DEV_INFO* pInfo,
                               PPCI_RSRC pRrcMem,
                               PPCI_RSRC pResIo,
                               PDWORD pMemSize,
                               PDWORD pIoSize );
private:
    PFN_CONFIGENTRY m_ConfigEntryFn;
    HINSTANCE       m_hDll;
};

class CPCIEnum
{
public:
            CPCIEnum( DWORD dwBus,
                      PCI_SLOT_NUMBER slotNumber,
                      PCBCARD_INFO pInfo,
                      CPCEnableCBCard* pEnabler );
            ~CPCIEnum();
    BOOL    Init();
    BOOL    ConfigDevice();
    BOOL    LauchDriver();
    BOOL    ConfigGetUserResource();
    BOOL    ConfigSetUserResource();
    LPCTSTR GetInstanceRegPath()
    {
        return m_InstRegPath ;
    };
    BOOL    GetRegValue( LPCWSTR lpcName, LPBYTE lpData, DWORD dwDataLen );
private:
    HANDLE              m_hDriver;
    CPCEnableCBCard*    m_pEnabler;
    DWORD               m_Irq, m_SysIntr;
    TCHAR               m_InstRegPath[DEVKEY_LEN];
    DWORD               m_dwBus;
    PCI_SLOT_NUMBER     m_SlotNumber;
    CCfgEntry*          m_pConfigEntry;
    CBCARD_INFO         m_CardInfo;
    PCI_DEV_INFO        m_Info;
    PCI_COMMON_CONFIG   m_pciConfig;
    CARD_WINDOW_HANDLE  m_IoWindow[PCI_TYPE0_ADDRESSES];
    CARD_WINDOW_HANDLE  m_MemWindow[PCI_TYPE0_ADDRESSES];

    // Resource
    PPCI_RSRC           m_pMemHead;
    PPCI_RSRC           m_pIoHead;
    BOOL                PCIRequestResources();
    BOOL                PCIReleaseResources() ;
    // COnfig BAR
    BOOL                PCIReadBARs();
    BOOL                PCIGetBARs();
    // Registry Info
    BOOL                RegGetFlags();

    BOOL                RegGetInfo();
    BOOL                PCICfgFindMatch();
    BOOL                RegFindPnpKey();

    BOOL                RegSetConfig();
    BOOL                RegCopy( PPCI_COMMON_CONFIG pPciConfig,
                                 LPCTSTR lpSrcReg,
                                 LPCTSTR lpInsReg );
    BOOL                RegCopyKey( CRegistryEdit& TKey, CRegistryEdit& IKey );
    DWORD               RegMatch( LPTSTR KeyRegPath ) ;
    DWORD               RegMatchOne( CRegistryEdit& Key, LPCWSTR DevName );

    // Initialization
    void                PCIInitInfo( LPCWSTR RegPath );
    BOOL                LoadDriver();
    BOOL                ActivateDevice();
};

#endif
