mirror of
https://github.com/ipxe/ipxe
synced 2026-04-16 03:00:10 +03:00
[acpi] Remove userptr_t from ACPI table parsing
Simplify the ACPI table parsing code by assuming that all table content is fully accessible via pointer dereferences. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
+14
-20
@@ -46,49 +46,43 @@ static struct ecam_mapping ecam;
|
||||
*/
|
||||
static int ecam_find ( uint32_t busdevfn, struct pci_range *range,
|
||||
struct ecam_allocation *alloc ) {
|
||||
struct ecam_allocation tmp;
|
||||
struct ecam_table *mcfg;
|
||||
struct ecam_allocation *tmp;
|
||||
unsigned int best = 0;
|
||||
unsigned int offset;
|
||||
unsigned int count;
|
||||
unsigned int index;
|
||||
userptr_t mcfg;
|
||||
uint32_t length;
|
||||
unsigned int i;
|
||||
uint32_t start;
|
||||
|
||||
/* Return empty range on error */
|
||||
range->count = 0;
|
||||
|
||||
/* Locate MCFG table */
|
||||
mcfg = acpi_table ( ECAM_SIGNATURE, 0 );
|
||||
mcfg = container_of ( acpi_table ( ECAM_SIGNATURE, 0 ),
|
||||
struct ecam_table, acpi );
|
||||
if ( ! mcfg ) {
|
||||
DBGC ( &ecam, "ECAM found no MCFG table\n" );
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
/* Get length of table */
|
||||
copy_from_user ( &length, mcfg,
|
||||
offsetof ( struct ecam_table, acpi.length ),
|
||||
sizeof ( length ) );
|
||||
|
||||
/* Iterate over allocations */
|
||||
for ( offset = offsetof ( struct ecam_table, alloc ) ;
|
||||
( offset + sizeof ( tmp ) ) <= le32_to_cpu ( length ) ;
|
||||
offset += sizeof ( tmp ) ) {
|
||||
for ( i = 0 ; ( offsetof ( typeof ( *mcfg ), alloc[ i + 1 ] ) <=
|
||||
le32_to_cpu ( mcfg->acpi.length ) ) ; i++ ) {
|
||||
|
||||
/* Read allocation */
|
||||
copy_from_user ( &tmp, mcfg, offset, sizeof ( tmp ) );
|
||||
tmp = &mcfg->alloc[i];
|
||||
DBGC2 ( &ecam, "ECAM %04x:[%02x-%02x] has base %08llx\n",
|
||||
le16_to_cpu ( tmp.segment ), tmp.start, tmp.end,
|
||||
( ( unsigned long long ) le64_to_cpu ( tmp.base ) ) );
|
||||
start = PCI_BUSDEVFN ( le16_to_cpu ( tmp.segment ),
|
||||
tmp.start, 0, 0 );
|
||||
count = PCI_BUSDEVFN ( 0, ( tmp.end - tmp.start + 1 ), 0, 0 );
|
||||
le16_to_cpu ( tmp->segment ), tmp->start, tmp->end,
|
||||
( ( unsigned long long ) le64_to_cpu ( tmp->base ) ) );
|
||||
start = PCI_BUSDEVFN ( le16_to_cpu ( tmp->segment ),
|
||||
tmp->start, 0, 0 );
|
||||
count = PCI_BUSDEVFN ( 0, ( tmp->end - tmp->start + 1 ), 0, 0 );
|
||||
|
||||
/* Check for a matching or new closest allocation */
|
||||
index = ( busdevfn - start );
|
||||
if ( ( index < count ) || ( index > best ) ) {
|
||||
if ( alloc )
|
||||
memcpy ( alloc, &tmp, sizeof ( *alloc ) );
|
||||
memcpy ( alloc, tmp, sizeof ( *alloc ) );
|
||||
range->start = start;
|
||||
range->count = count;
|
||||
best = index;
|
||||
|
||||
Reference in New Issue
Block a user