rsaddr.c 12.1 KB
Newer Older
L
Linus Torvalds 已提交
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
/*******************************************************************************
 *
 * Module Name: rsaddr - Address resource descriptors (16/32/64)
 *
 ******************************************************************************/

/*
 * Copyright (C) 2000 - 2005, R. Byron Moore
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
#include <acpi/acresrc.h>

#define _COMPONENT          ACPI_RESOURCES
L
Len Brown 已提交
48
ACPI_MODULE_NAME("rsaddr")
L
Linus Torvalds 已提交
49

R
Robert Moore 已提交
50 51
/*******************************************************************************
 *
B
Bob Moore 已提交
52
 * acpi_rs_convert_address16 - All WORD (16-bit) address resources
R
Robert Moore 已提交
53 54
 *
 ******************************************************************************/
B
Bob Moore 已提交
55 56 57 58
struct acpi_rsconvert_info acpi_rs_convert_address16[5] = {
	{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS16,
	 ACPI_RS_SIZE(struct acpi_resource_address16),
	 ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address16)},
R
Robert Moore 已提交
59

B
Bob Moore 已提交
60 61 62
	{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS16,
	 sizeof(struct aml_resource_address16),
	 0},
R
Robert Moore 已提交
63

B
Bob Moore 已提交
64
	/* Resource Type, General Flags, and Type-Specific Flags */
R
Robert Moore 已提交
65

B
Bob Moore 已提交
66
	{ACPI_RSC_ADDRESS, 0, 0, 0},
L
Linus Torvalds 已提交
67 68

	/*
B
Bob Moore 已提交
69
	 * These fields are contiguous in both the source and destination:
B
Bob Moore 已提交
70 71 72 73 74
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
L
Linus Torvalds 已提交
75
	 */
B
Bob Moore 已提交
76 77 78
	{ACPI_RSC_MOVE16, ACPI_RS_OFFSET(data.address16.granularity),
	 AML_OFFSET(address16.granularity),
	 5},
L
Linus Torvalds 已提交
79

B
Bob Moore 已提交
80
	/* Optional resource_source (Index and String) */
L
Linus Torvalds 已提交
81

B
Bob Moore 已提交
82 83 84 85
	{ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address16.resource_source),
	 0,
	 sizeof(struct aml_resource_address16)}
};
L
Linus Torvalds 已提交
86 87 88

/*******************************************************************************
 *
B
Bob Moore 已提交
89
 * acpi_rs_convert_address32 - All DWORD (32-bit) address resources
L
Linus Torvalds 已提交
90 91 92
 *
 ******************************************************************************/

B
Bob Moore 已提交
93 94 95 96
struct acpi_rsconvert_info acpi_rs_convert_address32[5] = {
	{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS32,
	 ACPI_RS_SIZE(struct acpi_resource_address32),
	 ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address32)},
R
Robert Moore 已提交
97

B
Bob Moore 已提交
98 99 100
	{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS32,
	 sizeof(struct aml_resource_address32),
	 0},
L
Linus Torvalds 已提交
101

B
Bob Moore 已提交
102
	/* Resource Type, General Flags, and Type-Specific Flags */
R
Robert Moore 已提交
103

B
Bob Moore 已提交
104
	{ACPI_RSC_ADDRESS, 0, 0, 0},
R
Robert Moore 已提交
105

B
Bob Moore 已提交
106
	/*
B
Bob Moore 已提交
107
	 * These fields are contiguous in both the source and destination:
B
Bob Moore 已提交
108 109 110 111 112 113
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
	 */
B
Bob Moore 已提交
114 115 116
	{ACPI_RSC_MOVE32, ACPI_RS_OFFSET(data.address32.granularity),
	 AML_OFFSET(address32.granularity),
	 5},
R
Robert Moore 已提交
117

B
Bob Moore 已提交
118
	/* Optional resource_source (Index and String) */
L
Linus Torvalds 已提交
119

B
Bob Moore 已提交
120 121 122 123
	{ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address32.resource_source),
	 0,
	 sizeof(struct aml_resource_address32)}
};
L
Linus Torvalds 已提交
124 125 126

/*******************************************************************************
 *
B
Bob Moore 已提交
127
 * acpi_rs_convert_address64 - All QWORD (64-bit) address resources
L
Linus Torvalds 已提交
128 129 130
 *
 ******************************************************************************/

B
Bob Moore 已提交
131 132 133 134
struct acpi_rsconvert_info acpi_rs_convert_address64[5] = {
	{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_ADDRESS64,
	 ACPI_RS_SIZE(struct acpi_resource_address64),
	 ACPI_RSC_TABLE_SIZE(acpi_rs_convert_address64)},
L
Linus Torvalds 已提交
135

B
Bob Moore 已提交
136 137 138
	{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_ADDRESS64,
	 sizeof(struct aml_resource_address64),
	 0},
L
Linus Torvalds 已提交
139

B
Bob Moore 已提交
140
	/* Resource Type, General Flags, and Type-Specific Flags */
L
Linus Torvalds 已提交
141

B
Bob Moore 已提交
142
	{ACPI_RSC_ADDRESS, 0, 0, 0},
L
Linus Torvalds 已提交
143 144

	/*
B
Bob Moore 已提交
145
	 * These fields are contiguous in both the source and destination:
B
Bob Moore 已提交
146 147 148 149 150
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
L
Linus Torvalds 已提交
151
	 */
B
Bob Moore 已提交
152 153 154
	{ACPI_RSC_MOVE64, ACPI_RS_OFFSET(data.address64.granularity),
	 AML_OFFSET(address64.granularity),
	 5},
L
Linus Torvalds 已提交
155

B
Bob Moore 已提交
156
	/* Optional resource_source (Index and String) */
L
Linus Torvalds 已提交
157

B
Bob Moore 已提交
158 159 160 161
	{ACPI_RSC_SOURCE, ACPI_RS_OFFSET(data.address64.resource_source),
	 0,
	 sizeof(struct aml_resource_address64)}
};
L
Linus Torvalds 已提交
162 163 164

/*******************************************************************************
 *
B
Bob Moore 已提交
165
 * acpi_rs_convert_ext_address64 - All Extended (64-bit) address resources
L
Linus Torvalds 已提交
166 167 168
 *
 ******************************************************************************/

B
Bob Moore 已提交
169 170 171 172 173 174 175 176
struct acpi_rsconvert_info acpi_rs_convert_ext_address64[5] = {
	{ACPI_RSC_INITGET, ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64,
	 ACPI_RS_SIZE(struct acpi_resource_extended_address64),
	 ACPI_RSC_TABLE_SIZE(acpi_rs_convert_ext_address64)},

	{ACPI_RSC_INITSET, ACPI_RESOURCE_NAME_EXTENDED_ADDRESS64,
	 sizeof(struct aml_resource_extended_address64),
	 0},
L
Linus Torvalds 已提交
177

B
Bob Moore 已提交
178
	/* Resource Type, General Flags, and Type-Specific Flags */
R
Robert Moore 已提交
179

B
Bob Moore 已提交
180
	{ACPI_RSC_ADDRESS, 0, 0, 0},
L
Linus Torvalds 已提交
181

B
Bob Moore 已提交
182
	/* Revision ID */
R
Robert Moore 已提交
183

B
Bob Moore 已提交
184 185 186
	{ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.ext_address64.revision_iD),
	 AML_OFFSET(ext_address64.revision_iD),
	 1},
B
Bob Moore 已提交
187
	/*
B
Bob Moore 已提交
188
	 * These fields are contiguous in both the source and destination:
B
Bob Moore 已提交
189 190 191 192 193
	 * Address Granularity
	 * Address Range Minimum
	 * Address Range Maximum
	 * Address Translation Offset
	 * Address Length
B
Bob Moore 已提交
194
	 * Type-Specific Attribute
B
Bob Moore 已提交
195
	 */
B
Bob Moore 已提交
196 197 198 199
	{ACPI_RSC_MOVE64, ACPI_RS_OFFSET(data.ext_address64.granularity),
	 AML_OFFSET(ext_address64.granularity),
	 6}
};
L
Linus Torvalds 已提交
200 201 202

/*******************************************************************************
 *
B
Bob Moore 已提交
203
 * acpi_rs_convert_general_flags - Flags common to all address descriptors
L
Linus Torvalds 已提交
204 205 206
 *
 ******************************************************************************/

B
Bob Moore 已提交
207 208 209
static struct acpi_rsconvert_info acpi_rs_convert_general_flags[6] = {
	{ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.flags),
	 ACPI_RSC_TABLE_SIZE(acpi_rs_convert_general_flags)},
R
Robert Moore 已提交
210

B
Bob Moore 已提交
211
	/* Resource Type (Memory, Io, bus_number, etc.) */
L
Linus Torvalds 已提交
212

B
Bob Moore 已提交
213 214 215
	{ACPI_RSC_MOVE8, ACPI_RS_OFFSET(data.address.resource_type),
	 AML_OFFSET(address.resource_type),
	 1},
L
Linus Torvalds 已提交
216

B
Bob Moore 已提交
217
	/* General Flags - Consume, Decode, min_fixed, max_fixed */
R
Robert Moore 已提交
218

B
Bob Moore 已提交
219 220 221
	{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.producer_consumer),
	 AML_OFFSET(address.flags),
	 0},
L
Linus Torvalds 已提交
222

B
Bob Moore 已提交
223 224 225
	{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.decode),
	 AML_OFFSET(address.flags),
	 1},
L
Linus Torvalds 已提交
226

B
Bob Moore 已提交
227 228 229
	{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.min_address_fixed),
	 AML_OFFSET(address.flags),
	 2},
L
Linus Torvalds 已提交
230

B
Bob Moore 已提交
231 232 233 234
	{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.max_address_fixed),
	 AML_OFFSET(address.flags),
	 3}
};
L
Linus Torvalds 已提交
235

B
Bob Moore 已提交
236 237
/*******************************************************************************
 *
B
Bob Moore 已提交
238
 * acpi_rs_convert_mem_flags - Flags common to Memory address descriptors
B
Bob Moore 已提交
239 240
 *
 ******************************************************************************/
L
Linus Torvalds 已提交
241

B
Bob Moore 已提交
242 243 244
static struct acpi_rsconvert_info acpi_rs_convert_mem_flags[5] = {
	{ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.specific_flags),
	 ACPI_RSC_TABLE_SIZE(acpi_rs_convert_mem_flags)},
R
Robert Moore 已提交
245

B
Bob Moore 已提交
246
	/* Memory-specific flags */
L
Linus Torvalds 已提交
247

B
Bob Moore 已提交
248 249 250
	{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.write_protect),
	 AML_OFFSET(address.specific_flags),
	 0},
L
Linus Torvalds 已提交
251

B
Bob Moore 已提交
252 253 254
	{ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.caching),
	 AML_OFFSET(address.specific_flags),
	 1},
L
Linus Torvalds 已提交
255

B
Bob Moore 已提交
256 257 258 259 260 261 262 263 264 265 266 267 268 269
	{ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.range_type),
	 AML_OFFSET(address.specific_flags),
	 3},

	{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.mem.translation),
	 AML_OFFSET(address.specific_flags),
	 5}
};

/*******************************************************************************
 *
 * acpi_rs_convert_io_flags - Flags common to I/O address descriptors
 *
 ******************************************************************************/
L
Linus Torvalds 已提交
270

B
Bob Moore 已提交
271 272 273
static struct acpi_rsconvert_info acpi_rs_convert_io_flags[4] = {
	{ACPI_RSC_FLAGINIT, 0, AML_OFFSET(address.specific_flags),
	 ACPI_RSC_TABLE_SIZE(acpi_rs_convert_io_flags)},
L
Linus Torvalds 已提交
274

B
Bob Moore 已提交
275
	/* I/O-specific flags */
L
Linus Torvalds 已提交
276

B
Bob Moore 已提交
277 278 279
	{ACPI_RSC_2BITFLAG, ACPI_RS_OFFSET(data.address.info.io.range_type),
	 AML_OFFSET(address.specific_flags),
	 0},
L
Linus Torvalds 已提交
280

B
Bob Moore 已提交
281 282 283 284 285 286 287 288 289
	{ACPI_RSC_1BITFLAG, ACPI_RS_OFFSET(data.address.info.io.translation),
	 AML_OFFSET(address.specific_flags),
	 4},

	{ACPI_RSC_1BITFLAG,
	 ACPI_RS_OFFSET(data.address.info.io.translation_type),
	 AML_OFFSET(address.specific_flags),
	 5}
};
L
Linus Torvalds 已提交
290

B
Bob Moore 已提交
291 292
/*******************************************************************************
 *
B
Bob Moore 已提交
293
 * FUNCTION:    acpi_rs_get_address_common
B
Bob Moore 已提交
294
 *
B
Bob Moore 已提交
295 296
 * PARAMETERS:  Resource            - Pointer to the internal resource struct
 *              Aml                 - Pointer to the AML resource descriptor
B
Bob Moore 已提交
297
 *
B
Bob Moore 已提交
298
 * RETURN:      TRUE if the resource_type field is OK, FALSE otherwise
B
Bob Moore 已提交
299
 *
B
Bob Moore 已提交
300 301
 * DESCRIPTION: Convert common flag fields from a raw AML resource descriptor
 *              to an internal resource descriptor
B
Bob Moore 已提交
302 303
 *
 ******************************************************************************/
L
Linus Torvalds 已提交
304

B
Bob Moore 已提交
305 306 307
u8
acpi_rs_get_address_common(struct acpi_resource *resource,
			   union aml_resource *aml)
B
Bob Moore 已提交
308
{
B
Bob Moore 已提交
309
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
310

B
Bob Moore 已提交
311
	/* Validate the Resource Type */
L
Linus Torvalds 已提交
312

B
Bob Moore 已提交
313 314 315
	if ((aml->address.resource_type > 2)
	    && (aml->address.resource_type < 0xC0)) {
		return (FALSE);
L
Linus Torvalds 已提交
316 317
	}

B
Bob Moore 已提交
318
	/* Get the Resource Type and General Flags */
R
Robert Moore 已提交
319

B
Bob Moore 已提交
320 321 322 323
	(void)acpi_rs_convert_aml_to_resource(resource, aml,
					      acpi_rs_convert_general_flags);

	/* Get the Type-Specific Flags (Memory and I/O descriptors only) */
L
Linus Torvalds 已提交
324

B
Bob Moore 已提交
325 326 327 328 329 330 331 332
	if (resource->data.address.resource_type == ACPI_MEMORY_RANGE) {
		(void)acpi_rs_convert_aml_to_resource(resource, aml,
						      acpi_rs_convert_mem_flags);
	} else if (resource->data.address.resource_type == ACPI_IO_RANGE) {
		(void)acpi_rs_convert_aml_to_resource(resource, aml,
						      acpi_rs_convert_io_flags);
	} else {
		/* Generic resource type, just grab the type_specific byte */
R
Robert Moore 已提交
333

B
Bob Moore 已提交
334 335 336 337 338
		resource->data.address.info.type_specific =
		    aml->address.specific_flags;
	}

	return (TRUE);
L
Linus Torvalds 已提交
339 340 341 342
}

/*******************************************************************************
 *
B
Bob Moore 已提交
343
 * FUNCTION:    acpi_rs_set_address_common
L
Linus Torvalds 已提交
344
 *
B
Bob Moore 已提交
345 346
 * PARAMETERS:  Aml                 - Pointer to the AML resource descriptor
 *              Resource            - Pointer to the internal resource struct
L
Linus Torvalds 已提交
347
 *
B
Bob Moore 已提交
348
 * RETURN:      None
L
Linus Torvalds 已提交
349
 *
B
Bob Moore 已提交
350 351
 * DESCRIPTION: Convert common flag fields from a resource descriptor to an
 *              AML descriptor
L
Linus Torvalds 已提交
352 353 354
 *
 ******************************************************************************/

B
Bob Moore 已提交
355 356 357
void
acpi_rs_set_address_common(union aml_resource *aml,
			   struct acpi_resource *resource)
L
Linus Torvalds 已提交
358
{
B
Bob Moore 已提交
359
	ACPI_FUNCTION_ENTRY();
R
Robert Moore 已提交
360

B
Bob Moore 已提交
361
	/* Set the Resource Type and General Flags */
L
Linus Torvalds 已提交
362

B
Bob Moore 已提交
363 364
	(void)acpi_rs_convert_resource_to_aml(resource, aml,
					      acpi_rs_convert_general_flags);
R
Robert Moore 已提交
365

B
Bob Moore 已提交
366
	/* Set the Type-Specific Flags (Memory and I/O descriptors only) */
L
Linus Torvalds 已提交
367

B
Bob Moore 已提交
368 369 370 371 372 373 374 375
	if (resource->data.address.resource_type == ACPI_MEMORY_RANGE) {
		(void)acpi_rs_convert_resource_to_aml(resource, aml,
						      acpi_rs_convert_mem_flags);
	} else if (resource->data.address.resource_type == ACPI_IO_RANGE) {
		(void)acpi_rs_convert_resource_to_aml(resource, aml,
						      acpi_rs_convert_io_flags);
	} else {
		/* Generic resource type, just copy the type_specific byte */
L
Linus Torvalds 已提交
376

B
Bob Moore 已提交
377 378 379
		aml->address.specific_flags =
		    resource->data.address.info.type_specific;
	}
L
Linus Torvalds 已提交
380
}