mirror of
https://github.com/ipxe/ipxe
synced 2025-12-20 03:55:46 +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:
@@ -102,20 +102,19 @@ static void acpi_udelay ( unsigned long usecs ) {
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int acpi_timer_probe ( void ) {
|
||||
struct acpi_fadt fadtab;
|
||||
userptr_t fadt;
|
||||
const struct acpi_fadt *fadt;
|
||||
unsigned int pm_tmr_blk;
|
||||
|
||||
/* Locate FADT */
|
||||
fadt = acpi_table ( FADT_SIGNATURE, 0 );
|
||||
fadt = container_of ( acpi_table ( FADT_SIGNATURE, 0 ),
|
||||
struct acpi_fadt, acpi );
|
||||
if ( ! fadt ) {
|
||||
DBGC ( &acpi_timer, "ACPI could not find FADT\n" );
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Read FADT */
|
||||
copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) );
|
||||
pm_tmr_blk = le32_to_cpu ( fadtab.pm_tmr_blk );
|
||||
pm_tmr_blk = le32_to_cpu ( fadt->pm_tmr_blk );
|
||||
if ( ! pm_tmr_blk ) {
|
||||
DBGC ( &acpi_timer, "ACPI has no timer\n" );
|
||||
return -ENOENT;
|
||||
|
||||
@@ -62,8 +62,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
* uglier hacks I have ever implemented, but it's still prettier than
|
||||
* the ACPI specification itself.
|
||||
*/
|
||||
static int acpi_extract_sx ( userptr_t zsdt, size_t len, size_t offset,
|
||||
void *data ) {
|
||||
static int acpi_extract_sx ( const struct acpi_header *zsdt, size_t len,
|
||||
size_t offset, void *data ) {
|
||||
unsigned int *sx = data;
|
||||
uint8_t bytes[4];
|
||||
uint8_t *byte;
|
||||
@@ -77,7 +77,8 @@ static int acpi_extract_sx ( userptr_t zsdt, size_t len, size_t offset,
|
||||
}
|
||||
|
||||
/* Read first four bytes of value */
|
||||
copy_from_user ( bytes, zsdt, offset, sizeof ( bytes ) );
|
||||
memcpy ( bytes, ( ( ( const void * ) zsdt ) + offset ),
|
||||
sizeof ( bytes ) );
|
||||
DBGC ( colour, "ACPI found \\_Sx containing %02x:%02x:%02x:%02x\n",
|
||||
bytes[0], bytes[1], bytes[2], bytes[3] );
|
||||
|
||||
@@ -111,8 +112,7 @@ static int acpi_extract_sx ( userptr_t zsdt, size_t len, size_t offset,
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int acpi_poweroff ( void ) {
|
||||
struct acpi_fadt fadtab;
|
||||
userptr_t fadt;
|
||||
const struct acpi_fadt *fadt;
|
||||
unsigned int pm1a_cnt_blk;
|
||||
unsigned int pm1b_cnt_blk;
|
||||
unsigned int pm1a_cnt;
|
||||
@@ -123,16 +123,16 @@ int acpi_poweroff ( void ) {
|
||||
int rc;
|
||||
|
||||
/* Locate FADT */
|
||||
fadt = acpi_table ( FADT_SIGNATURE, 0 );
|
||||
fadt = container_of ( acpi_table ( FADT_SIGNATURE, 0 ),
|
||||
struct acpi_fadt, acpi );
|
||||
if ( ! fadt ) {
|
||||
DBGC ( colour, "ACPI could not find FADT\n" );
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Read FADT */
|
||||
copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) );
|
||||
pm1a_cnt_blk = le32_to_cpu ( fadtab.pm1a_cnt_blk );
|
||||
pm1b_cnt_blk = le32_to_cpu ( fadtab.pm1b_cnt_blk );
|
||||
pm1a_cnt_blk = le32_to_cpu ( fadt->pm1a_cnt_blk );
|
||||
pm1b_cnt_blk = le32_to_cpu ( fadt->pm1b_cnt_blk );
|
||||
pm1a_cnt = ( pm1a_cnt_blk + ACPI_PM1_CNT );
|
||||
pm1b_cnt = ( pm1b_cnt_blk + ACPI_PM1_CNT );
|
||||
|
||||
|
||||
@@ -53,50 +53,51 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
*
|
||||
* @v start Start address to search
|
||||
* @v len Length to search
|
||||
* @ret rsdt ACPI root system description table, or UNULL
|
||||
* @ret rsdt ACPI root system description table, or NULL
|
||||
*/
|
||||
static userptr_t rsdp_find_rsdt_range ( userptr_t start, size_t len ) {
|
||||
static const struct acpi_rsdt * rsdp_find_rsdt_range ( const void *start,
|
||||
size_t len ) {
|
||||
static const char signature[8] = RSDP_SIGNATURE;
|
||||
struct acpi_rsdp rsdp;
|
||||
userptr_t rsdt;
|
||||
const struct acpi_rsdp *rsdp;
|
||||
const struct acpi_rsdt *rsdt;
|
||||
size_t offset;
|
||||
uint8_t sum;
|
||||
unsigned int i;
|
||||
|
||||
/* Search for RSDP */
|
||||
for ( offset = 0 ; ( ( offset + sizeof ( rsdp ) ) < len ) ;
|
||||
for ( offset = 0 ; ( ( offset + sizeof ( *rsdp ) ) < len ) ;
|
||||
offset += RSDP_STRIDE ) {
|
||||
|
||||
/* Check signature and checksum */
|
||||
copy_from_user ( &rsdp, start, offset, sizeof ( rsdp ) );
|
||||
if ( memcmp ( rsdp.signature, signature,
|
||||
rsdp = ( start + offset );
|
||||
if ( memcmp ( rsdp->signature, signature,
|
||||
sizeof ( signature ) ) != 0 )
|
||||
continue;
|
||||
for ( sum = 0, i = 0 ; i < sizeof ( rsdp ) ; i++ )
|
||||
sum += *( ( ( uint8_t * ) &rsdp ) + i );
|
||||
for ( sum = 0, i = 0 ; i < sizeof ( *rsdp ) ; i++ )
|
||||
sum += *( ( ( uint8_t * ) rsdp ) + i );
|
||||
if ( sum != 0 )
|
||||
continue;
|
||||
|
||||
/* Extract RSDT */
|
||||
rsdt = phys_to_virt ( le32_to_cpu ( rsdp.rsdt ) );
|
||||
rsdt = phys_to_virt ( le32_to_cpu ( rsdp->rsdt ) );
|
||||
DBGC ( rsdt, "RSDT %#08lx found via RSDP %#08lx\n",
|
||||
virt_to_phys ( rsdt ),
|
||||
( virt_to_phys ( start ) + offset ) );
|
||||
return rsdt;
|
||||
}
|
||||
|
||||
return UNULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate ACPI root system description table
|
||||
*
|
||||
* @ret rsdt ACPI root system description table, or UNULL
|
||||
* @ret rsdt ACPI root system description table, or NULL
|
||||
*/
|
||||
static userptr_t rsdp_find_rsdt ( void ) {
|
||||
static userptr_t rsdt;
|
||||
static const struct acpi_rsdt * rsdp_find_rsdt ( void ) {
|
||||
static const struct acpi_rsdt *rsdt;
|
||||
const void *ebda;
|
||||
uint16_t ebda_seg;
|
||||
userptr_t ebda;
|
||||
size_t ebda_len;
|
||||
|
||||
/* Return existing RSDT if already found */
|
||||
@@ -119,7 +120,7 @@ static userptr_t rsdp_find_rsdt ( void ) {
|
||||
if ( rsdt )
|
||||
return rsdt;
|
||||
|
||||
return UNULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PROVIDE_ACPI ( rsdp, acpi_find_rsdt, rsdp_find_rsdt );
|
||||
|
||||
Reference in New Issue
Block a user