1 /* 2 Copyright (c) 2006-2008 dogbert <dogber1@gmail.com> 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions 7 are met: 8 1. Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 2. Redistributions in binary form must reproduce the above copyright 11 notice, this list of conditions and the following disclaimer in the 12 documentation and/or other materials provided with the distribution. 13 3. The name of the author may not be used to endorse or promote products 14 derived from this software without specific prior written permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef _COMMON_HPP_ 29 #define _COMMON_HPP_ 30 31 #include "stdunk.h" 32 #include "portcls.h" 33 #include "dmusicks.h" 34 #include "ksdebug.h" 35 #include "kcom.h" 36 37 #include "interfaces.hpp" 38 #include "debug.hpp" 39 #include "cmireg.hpp" 40 41 42 PVOID 43 __cdecl 44 operator new( 45 size_t size, 46 POOL_TYPE pool_type, 47 ULONG tag); 48 49 class CCMIAdapter : public ICMIAdapter, 50 public IAdapterPowerManagement, 51 public CUnknown 52 { 53 private: 54 PDEVICE_OBJECT DeviceObject; 55 PINTERRUPTSYNC InterruptSync; 56 DEVICE_POWER_STATE CurrentPowerState; 57 UInt8 mixerCache[0xFF]; 58 59 CMI8738Info cm; 60 61 bool queryChip(); 62 void resetController(); 63 64 public: 65 DECLARE_STD_UNKNOWN(); 66 DEFINE_STD_CONSTRUCTOR(CCMIAdapter); 67 ~CCMIAdapter(); 68 69 IMP_IAdapterPowerManagement; 70 71 STDMETHODIMP_(NTSTATUS) init(PRESOURCELIST ResourceList, PDEVICE_OBJECT aDeviceObject); 72 STDMETHODIMP_(NTSTATUS) activateMPU(ULONG* MPUBase); 73 STDMETHODIMP_(NTSTATUS) loadSBMixerFromMemory(); 74 75 STDMETHODIMP_(UInt8) readUInt8(UInt8 reg); 76 STDMETHODIMP_(void) writeUInt8(UInt8 reg, UInt8 value); 77 78 STDMETHODIMP_(void) setUInt8Bit(UInt8 reg, UInt8 flag); 79 STDMETHODIMP_(void) clearUInt8Bit(UInt8 reg, UInt8 flag); 80 81 STDMETHODIMP_(UInt16) readUInt16(UInt8 reg); 82 STDMETHODIMP_(void) writeUInt16(UInt8 reg, UInt16 value); 83 84 STDMETHODIMP_(UInt32) readUInt32(UInt8 reg); 85 STDMETHODIMP_(void) writeUInt32(UInt8 reg, UInt32 value); 86 87 STDMETHODIMP_(void) setUInt32Bit(UInt8 reg, UInt32 flag); 88 STDMETHODIMP_(void) clearUInt32Bit(UInt8 reg, UInt32 flag); 89 90 STDMETHODIMP_(UInt8) readMixer(UInt8 index); 91 STDMETHODIMP_(void) writeMixer(UInt8 index, UInt8 value); 92 STDMETHODIMP_(void) setMixerBit(UInt8 index, UInt8 flag); 93 STDMETHODIMP_(void) clearMixerBit(UInt8 index, UInt8 flag); 94 95 STDMETHODIMP_(void) resetMixer(); 96 97 static NTSTATUS NTAPI InterruptServiceRoutine(PINTERRUPTSYNC InterruptSync, PVOID StaticContext); 98 getCMI8738Info(void)99 STDMETHODIMP_(PCMI8738Info) getCMI8738Info(void) 100 { 101 return &cm; 102 }; 103 getInterruptSync(void)104 STDMETHODIMP_(PINTERRUPTSYNC) getInterruptSync(void) 105 { 106 return InterruptSync; 107 }; getDeviceObject(void)108 STDMETHODIMP_(PDEVICE_OBJECT) getDeviceObject(void) 109 { 110 return DeviceObject; 111 }; 112 113 friend NTSTATUS NewCCMIAdapter(PCMIADAPTER* OutCMIAdapter, PRESOURCELIST ResourceList); 114 }; 115 116 NTSTATUS NewCMIAdapter(PUNKNOWN* Unknown, REFCLSID, PUNKNOWN UnknownOuter, POOL_TYPE PoolType); 117 118 #endif //_COMMON_HPP_ 119