-
Notifications
You must be signed in to change notification settings - Fork 5
/
topology.cpp
255 lines (196 loc) · 6.33 KB
/
topology.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/* 1010 PCI/PCIe Audio Driver
Copyright (c) Eugene Gavrilov, 2002-2016
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "common.h"
#include "debug.h"
#include "adapter.h"
#include "topology.h"
#include "guids.h"
#include "property.h"
#include "topo_descriptors.h"
#include "hal.h"
#pragma code_seg("PAGE")
NTSTATUS Topology::Create(OUT PUNKNOWN *Unknown,IN REFCLSID,IN PUNKNOWN UnknownOuter OPTIONAL,IN POOL_TYPE PoolType)
{
PAGED_CODE();
ASSERT(Unknown);
STD_CREATE_BODY_(Topology,Unknown,UnknownOuter,PoolType,PMINIPORTTOPOLOGY);
}
#pragma code_seg("PAGE")
Topology::~Topology()
{
PAGED_CODE();
ASSERT(valid_object(this,Topology));
debug("Topology::~Topology\n");
magic=NULL;
if(adapter)
{
adapter->topology=NULL;
adapter->Release();
adapter=NULL;
}
}
#pragma code_seg("PAGE")
STDMETHODIMP Topology::NonDelegatingQueryInterface(IN REFIID Interface,OUT PVOID * Object)
{
PAGED_CODE();
ASSERT(Object);
if (IsEqualGUIDAligned(Interface,IID_IUnknown))
{
*Object = PVOID(PUNKNOWN(PMINIPORTTOPOLOGY(this)));
}
else
if (IsEqualGUIDAligned(Interface,IID_IMiniport))
{
*Object = PVOID(PMINIPORT(this));
}
else
if (IsEqualGUIDAligned(Interface,IID_IMiniportTopology))
{
*Object = PVOID(PMINIPORTTOPOLOGY(this));
}
else
if (IsEqualGUIDAligned(Interface,IID_IPowerNotify))
{
*Object = PVOID(PPOWERNOTIFY(this));
}
else
{
*Object = NULL;
}
if (*Object)
{
//
// We reference the interface for the caller.
//
PUNKNOWN(*Object)->AddRef();
return STATUS_SUCCESS;
}
return STATUS_INVALID_PARAMETER;
}
#pragma code_seg("PAGE")
STDMETHODIMP Topology::Init(IN PUNKNOWN UnknownAdapter,IN PRESOURCELIST ResourceList,IN PPORTTOPOLOGY Port_)
{
PAGED_CODE();
ASSERT(UnknownAdapter);
ASSERT(ResourceList);
ASSERT(Port_);
debug("Topology::Init [%p]\n",this);
adapter=NULL;
magic=object_magic;
PowerState=PowerDeviceD0;
UnknownAdapter->QueryInterface( IID_IAdapterCommon,(PVOID *)&adapter );
adapter->topology=this;
for(int i=0;i<MAX_CHANNELS;i++)
{
WaveOutMute[i]=false;
WaveOutVolume[i]=0UL;
}
return STATUS_SUCCESS;
}
#pragma code_seg("PAGE")
STDMETHODIMP Topology::GetDescription(OUT PPCFILTER_DESCRIPTOR * OutFilterDescriptor)
{
PAGED_CODE();
ASSERT(OutFilterDescriptor);
if(OutFilterDescriptor)
*OutFilterDescriptor = &MiniportFilterDescriptor;
return STATUS_SUCCESS;
}
#pragma code_seg("PAGE")
STDMETHODIMP Topology::DataRangeIntersection
( IN ULONG /*PinId*/
, IN PKSDATARANGE /*DataRange*/
, IN PKSDATARANGE /*MatchingDataRange*/
, IN ULONG /*OutputBufferLength*/
, OUT PVOID /*ResultantFormat*/ OPTIONAL
, OUT PULONG /*ResultantFormatLength*/
)
{
PAGED_CODE();
return STATUS_NOT_IMPLEMENTED;
}
#pragma code_seg("PAGE")
NTSTATUS Topology::SetMute(ULONG /*node*/,LONG channel,BOOL value)
{
PAGED_CODE();
// debug("Topo:SetMute: node: %d, chn: %d, vol: %d\n",node,channel,value);
if(channel>=0 && channel<MAX_CHANNELS) WaveOutMute[channel]=value; else return STATUS_INVALID_PARAMETER;
update_volume();
return STATUS_SUCCESS;
}
#pragma code_seg("PAGE")
NTSTATUS Topology::GetMute(ULONG /*node*/,LONG channel,BOOL *value)
{
PAGED_CODE();
// debug("Topo:GetMute: node: %d, chn: %d\n",node,channel);
if(channel>=0 && channel<MAX_CHANNELS && value) *value=WaveOutMute[channel]; else return STATUS_INVALID_PARAMETER;
return STATUS_SUCCESS;
}
#pragma code_seg("PAGE")
NTSTATUS Topology::SetVolume(ULONG /*node*/,LONG channel,ULONG volume)
{
PAGED_CODE();
// debug("Topo:SetVol: node: %d, chn: %d, vol: %d\n",node,channel,(LONG)volume);
if(channel>=0 && channel<MAX_CHANNELS) WaveOutVolume[channel]=volume; else return STATUS_INVALID_PARAMETER;
update_volume();
return STATUS_SUCCESS;
}
#pragma code_seg("PAGE")
NTSTATUS Topology::GetVolume(ULONG /*node*/,LONG channel,ULONG *volume)
{
PAGED_CODE();
// debug("Topo:GetVolume: node: %d, chn: %d\n",node,channel);
if(channel>=0 && channel<MAX_CHANNELS && volume) *volume=WaveOutVolume[channel]; else return STATUS_INVALID_PARAMETER;
return STATUS_SUCCESS;
}
#pragma code_seg("PAGE")
void Topology::update_volume(void)
{
PAGED_CODE();
adapter->apply_volume(WaveOutMute[0]?0x80000000:WaveOutVolume[0],WaveOutMute[1]?0x80000000:WaveOutVolume[1],false);
}
#pragma code_seg("PAGE")
NTSTATUS Topology::PropertyPrivate(IN PPCPROPERTY_REQUEST PropertyRequest)
{
PAGED_CODE();
ASSERT(PropertyRequest);
Topology *topo=(Topology *)PMINIPORTTOPOLOGY(PropertyRequest->MajorTarget);
if(valid_object(topo,Topology))
{
return topo->adapter->PropertyPrivate(PropertyRequest,NULL,NULL);
}
debug("!! Topology::PropertyPrivate: invalid target: %p\n",topo);
return STATUS_INVALID_PARAMETER;
}
#pragma code_seg("PAGE")
int Topology::get_n_channels(void)
{
PAGED_CODE();
if(valid_object(adapter,Adapter) && valid_object(adapter->hal,Hal))
return adapter->hal->get_current_n_channels();
else
{
debug("!! Topology::get_n_channels: objects not yet constructed\n");
return 0;
}
}
#pragma code_seg()
STDMETHODIMP_(void) Topology::PowerChangeNotify(IN POWER_STATE NewState)
{
debug("Topology::PowerChangeState - do nothing\n");
PowerState = NewState.DeviceState;
}