rsaddr.c 12.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/*******************************************************************************
 *
 * Module Name: rsaddr - Address resource descriptors (16/32/64)
 *
 ******************************************************************************/

/*
L
Len Brown 已提交
8
 * Copyright (C) 2000 - 2008, Intel Corp.
L
Linus Torvalds 已提交
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
 * 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>
45
#include <acpi/accommon.h>
L
Linus Torvalds 已提交
46 47 48
#include <acpi/acresrc.h>

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

R
Robert Moore 已提交
51 52
/*******************************************************************************
 *
B
Bob Moore 已提交
53
 * acpi_rs_convert_address16 - All WORD (16-bit) address resources
R
Robert Moore 已提交
54 55
 *
 ******************************************************************************/
B
Bob Moore 已提交
56 57 58 59
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 已提交
60

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

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

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

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

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

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

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

B
Bob Moore 已提交
94 95 96 97
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 已提交
98

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

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

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

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

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

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

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

B
Bob Moore 已提交
132 133 134 135
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 已提交
136

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

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

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

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

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

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

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

B
Bob Moore 已提交
170 171 172 173 174 175 176 177
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 已提交
178

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

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

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

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

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

B
Bob Moore 已提交
208 209 210
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 已提交
211

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

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

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

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

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

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

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

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

B
Bob Moore 已提交
243 244 245
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 已提交
246

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

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

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

B
Bob Moore 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270
	{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 已提交
271

B
Bob Moore 已提交
272 273 274
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 已提交
275

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

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

B
Bob Moore 已提交
282 283 284 285 286 287 288 289 290
	{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 已提交
291

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

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

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

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

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

B
Bob Moore 已提交
321 322 323 324
	(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 已提交
325

B
Bob Moore 已提交
326 327 328 329 330 331 332 333
	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 已提交
334

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

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

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

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

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

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

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

B
Bob Moore 已提交
369 370 371 372 373 374 375 376
	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 已提交
377

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