From 4535548cba255c220719a55d02535e06da82ba47 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Mon, 21 Apr 2025 00:15:52 +0100 Subject: [uaccess] Remove redundant user_to_virt() The user_to_virt() function is now a straightforward wrapper around addition, with the addend almost invariably being zero. Remove this redundant wrapper. Signed-off-by: Michael Brown --- src/interface/linux/linux_acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/interface/linux/linux_acpi.c') diff --git a/src/interface/linux/linux_acpi.c b/src/interface/linux/linux_acpi.c index e658936f2..846db2f1f 100644 --- a/src/interface/linux/linux_acpi.c +++ b/src/interface/linux/linux_acpi.c @@ -101,7 +101,7 @@ static userptr_t linux_acpi_find ( uint32_t signature, unsigned int index ) { filename, strerror ( rc ) ); goto err_read; } - header = user_to_virt ( table->data, 0 ); + header = table->data; if ( ( ( ( size_t ) len ) < sizeof ( *header ) ) || ( ( ( size_t ) len ) < le32_to_cpu ( header->length ) ) ) { rc = -ENOENT; -- cgit v1.2.3-55-g7522 From 0b3fc48fefd311b17b666fecf3a34688717727e8 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 22 Apr 2025 14:13:45 +0100 Subject: [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 --- src/arch/x86/include/ipxe/rsdp.h | 4 +- src/arch/x86/interface/pcbios/acpi_timer.c | 9 +-- src/arch/x86/interface/pcbios/acpipwr.c | 18 ++--- src/arch/x86/interface/pcbios/rsdp.c | 33 ++++---- src/core/acpi.c | 116 +++++++++++++---------------- src/core/acpi_settings.c | 21 +++--- src/core/acpimac.c | 17 +++-- src/drivers/bus/ecam.c | 34 ++++----- src/include/ipxe/acpi.h | 24 +++--- src/include/ipxe/efi/efi_acpi.h | 4 +- src/include/ipxe/null_acpi.h | 6 +- src/interface/efi/efi_acpi.c | 7 +- src/interface/linux/linux_acpi.c | 9 ++- src/tests/acpi_test.c | 12 +-- 14 files changed, 152 insertions(+), 162 deletions(-) (limited to 'src/interface/linux/linux_acpi.c') diff --git a/src/arch/x86/include/ipxe/rsdp.h b/src/arch/x86/include/ipxe/rsdp.h index 14afcd774..daaa43077 100644 --- a/src/arch/x86/include/ipxe/rsdp.h +++ b/src/arch/x86/include/ipxe/rsdp.h @@ -20,9 +20,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -static inline __attribute__ (( always_inline )) userptr_t +static inline __attribute__ (( always_inline )) const struct acpi_header * ACPI_INLINE ( rsdp, acpi_find ) ( uint32_t signature, unsigned int index ) { return acpi_find_via_rsdt ( signature, index ); diff --git a/src/arch/x86/interface/pcbios/acpi_timer.c b/src/arch/x86/interface/pcbios/acpi_timer.c index 2e4047e38..e1523578b 100644 --- a/src/arch/x86/interface/pcbios/acpi_timer.c +++ b/src/arch/x86/interface/pcbios/acpi_timer.c @@ -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; diff --git a/src/arch/x86/interface/pcbios/acpipwr.c b/src/arch/x86/interface/pcbios/acpipwr.c index f08b4af25..bff53806b 100644 --- a/src/arch/x86/interface/pcbios/acpipwr.c +++ b/src/arch/x86/interface/pcbios/acpipwr.c @@ -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 ); diff --git a/src/arch/x86/interface/pcbios/rsdp.c b/src/arch/x86/interface/pcbios/rsdp.c index c2534c7f6..6bcf19b18 100644 --- a/src/arch/x86/interface/pcbios/rsdp.c +++ b/src/arch/x86/interface/pcbios/rsdp.c @@ -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 ); diff --git a/src/core/acpi.c b/src/core/acpi.c index d7da0ccc1..6c5d1e079 100644 --- a/src/core/acpi.c +++ b/src/core/acpi.c @@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include #include #include #include @@ -54,25 +55,17 @@ typeof ( acpi_find ) *acpi_finder __attribute__ (( weak )) = acpi_find; /** * Compute ACPI table checksum * - * @v table Any ACPI table + * @v acpi Any ACPI table header * @ret checksum 0 if checksum is good */ -static uint8_t acpi_checksum ( userptr_t table ) { - struct acpi_header acpi; +static uint8_t acpi_checksum ( const struct acpi_header *acpi ) { + const uint8_t *byte = ( ( const void * ) acpi ); + size_t len = le32_to_cpu ( acpi->length ); uint8_t sum = 0; - uint8_t data = 0; - unsigned int i; - - /* Read table length */ - copy_from_user ( &acpi.length, table, - offsetof ( typeof ( acpi ), length ), - sizeof ( acpi.length ) ); /* Compute checksum */ - for ( i = 0 ; i < le32_to_cpu ( acpi.length ) ; i++ ) { - copy_from_user ( &data, table, i, sizeof ( data ) ); - sum += data; - } + while ( len-- ) + sum += *(byte++); return sum; } @@ -85,7 +78,7 @@ static uint8_t acpi_checksum ( userptr_t table ) { void acpi_fix_checksum ( struct acpi_header *acpi ) { /* Update checksum */ - acpi->checksum -= acpi_checksum ( virt_to_user ( acpi ) ); + acpi->checksum -= acpi_checksum ( acpi ); } /** @@ -93,9 +86,10 @@ void acpi_fix_checksum ( struct acpi_header *acpi ) { * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -userptr_t acpi_table ( uint32_t signature, unsigned int index ) { +const struct acpi_header * acpi_table ( uint32_t signature, + unsigned int index ) { return ( *acpi_finder ) ( signature, index ); } @@ -105,14 +99,12 @@ userptr_t acpi_table ( uint32_t signature, unsigned int index ) { * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { - struct acpi_header acpi; - struct acpi_rsdt *rsdtab; - typeof ( rsdtab->entry[0] ) entry; - userptr_t rsdt; - userptr_t table; +const struct acpi_header * acpi_find_via_rsdt ( uint32_t signature, + unsigned int index ) { + const struct acpi_rsdt *rsdt; + const struct acpi_header *table; size_t len; unsigned int count; unsigned int i; @@ -121,45 +113,38 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { rsdt = acpi_find_rsdt(); if ( ! rsdt ) { DBG ( "RSDT not found\n" ); - return UNULL; + return NULL; } /* Read RSDT header */ - copy_from_user ( &acpi, rsdt, 0, sizeof ( acpi ) ); - if ( acpi.signature != cpu_to_le32 ( RSDT_SIGNATURE ) ) { + if ( rsdt->acpi.signature != cpu_to_le32 ( RSDT_SIGNATURE ) ) { DBGC ( colour, "RSDT %#08lx has invalid signature:\n", virt_to_phys ( rsdt ) ); - DBGC_HDA ( colour, virt_to_phys ( rsdt ), &acpi, - sizeof ( acpi ) ); - return UNULL; + DBGC_HDA ( colour, virt_to_phys ( rsdt ), &rsdt->acpi, + sizeof ( rsdt->acpi ) ); + return NULL; } - len = le32_to_cpu ( acpi.length ); - if ( len < sizeof ( rsdtab->acpi ) ) { + len = le32_to_cpu ( rsdt->acpi.length ); + if ( len < sizeof ( rsdt->acpi ) ) { DBGC ( colour, "RSDT %#08lx has invalid length:\n", virt_to_phys ( rsdt ) ); - DBGC_HDA ( colour, virt_to_phys ( rsdt ), &acpi, - sizeof ( acpi ) ); - return UNULL; + DBGC_HDA ( colour, virt_to_phys ( rsdt ), &rsdt->acpi, + sizeof ( rsdt->acpi ) ); + return NULL; } /* Calculate number of entries */ - count = ( ( len - sizeof ( rsdtab->acpi ) ) / sizeof ( entry ) ); + count = ( ( len - sizeof ( rsdt->acpi ) ) / + sizeof ( rsdt->entry[0] ) ); /* Search through entries */ for ( i = 0 ; i < count ; i++ ) { - /* Get table address */ - copy_from_user ( &entry, rsdt, - offsetof ( typeof ( *rsdtab ), entry[i] ), - sizeof ( entry ) ); - /* Read table header */ - table = phys_to_virt ( entry ); - copy_from_user ( &acpi.signature, table, 0, - sizeof ( acpi.signature ) ); + table = phys_to_virt ( rsdt->entry[i] ); /* Check table signature */ - if ( acpi.signature != cpu_to_le32 ( signature ) ) + if ( table->signature != cpu_to_le32 ( signature ) ) continue; /* Check index */ @@ -169,13 +154,13 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { /* Check table integrity */ if ( acpi_checksum ( table ) != 0 ) { DBGC ( colour, "RSDT %#08lx found %s with bad " - "checksum at %08lx\n", virt_to_phys ( rsdt ), + "checksum at %#08lx\n", virt_to_phys ( rsdt ), acpi_name ( signature ), virt_to_phys ( table ) ); break; } - DBGC ( colour, "RSDT %#08lx found %s at %08lx\n", + DBGC ( colour, "RSDT %#08lx found %s at %#08lx\n", virt_to_phys ( rsdt ), acpi_name ( signature ), virt_to_phys ( table ) ); return table; @@ -183,7 +168,7 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { DBGC ( colour, "RSDT %#08lx could not find %s\n", virt_to_phys ( rsdt ), acpi_name ( signature ) ); - return UNULL; + return NULL; } /** @@ -195,26 +180,27 @@ userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ) { * @v extract Extraction method * @ret rc Return status code */ -static int acpi_zsdt ( userptr_t zsdt, uint32_t signature, void *data, - int ( * extract ) ( userptr_t zsdt, size_t len, - size_t offset, void *data ) ) { - struct acpi_header acpi; +static int acpi_zsdt ( const struct acpi_header *zsdt, + uint32_t signature, void *data, + int ( * extract ) ( const struct acpi_header *zsdt, + size_t len, size_t offset, + void *data ) ) { uint32_t buf; size_t offset; size_t len; int rc; /* Read table header */ - copy_from_user ( &acpi, zsdt, 0, sizeof ( acpi ) ); - len = le32_to_cpu ( acpi.length ); + len = le32_to_cpu ( zsdt->length ); /* Locate signature */ - for ( offset = sizeof ( acpi ) ; + for ( offset = sizeof ( *zsdt ) ; ( ( offset + sizeof ( buf ) /* signature */ ) < len ) ; offset++ ) { /* Check signature */ - copy_from_user ( &buf, zsdt, offset, sizeof ( buf ) ); + memcpy ( &buf, ( ( ( const void * ) zsdt ) + offset ), + sizeof ( buf ) ); if ( buf != cpu_to_le32 ( signature ) ) continue; DBGC ( zsdt, "DSDT/SSDT %#08lx found %s at offset %#zx\n", @@ -238,20 +224,20 @@ static int acpi_zsdt ( userptr_t zsdt, uint32_t signature, void *data, * @ret rc Return status code */ int acpi_extract ( uint32_t signature, void *data, - int ( * extract ) ( userptr_t zsdt, size_t len, - size_t offset, void *data ) ) { - struct acpi_fadt fadtab; - userptr_t fadt; - userptr_t dsdt; - userptr_t ssdt; + int ( * extract ) ( const struct acpi_header *zsdt, + size_t len, size_t offset, + void *data ) ) { + const struct acpi_fadt *fadt; + const struct acpi_header *dsdt; + const struct acpi_header *ssdt; unsigned int i; int rc; /* Try DSDT first */ - fadt = acpi_table ( FADT_SIGNATURE, 0 ); + fadt = container_of ( acpi_table ( FADT_SIGNATURE, 0 ), + struct acpi_fadt, acpi ); if ( fadt ) { - copy_from_user ( &fadtab, fadt, 0, sizeof ( fadtab ) ); - dsdt = phys_to_virt ( fadtab.dsdt ); + dsdt = phys_to_virt ( fadt->dsdt ); if ( ( rc = acpi_zsdt ( dsdt, signature, data, extract ) ) == 0 ) return 0; diff --git a/src/core/acpi_settings.c b/src/core/acpi_settings.c index b9e2b7f61..cdee1f865 100644 --- a/src/core/acpi_settings.c +++ b/src/core/acpi_settings.c @@ -64,14 +64,15 @@ static int acpi_settings_applies ( struct settings *settings __unused, static int acpi_settings_fetch ( struct settings *settings, struct setting *setting, void *data, size_t len ) { - struct acpi_header acpi; + const struct acpi_header *acpi; + const uint8_t *src; + uint8_t *dst; uint32_t tag_high; uint32_t tag_low; uint32_t tag_signature; unsigned int tag_index; size_t tag_offset; size_t tag_len; - userptr_t table; size_t offset; size_t max_len; int delta; @@ -88,15 +89,12 @@ static int acpi_settings_fetch ( struct settings *settings, acpi_name ( tag_signature ), tag_index, tag_offset, tag_len ); /* Locate ACPI table */ - table = acpi_table ( tag_signature, tag_index ); - if ( ! table ) + acpi = acpi_table ( tag_signature, tag_index ); + if ( ! acpi ) return -ENOENT; - /* Read table header */ - copy_from_user ( &acpi, table, 0, sizeof ( acpi ) ); - /* Calculate starting offset and maximum available length */ - max_len = le32_to_cpu ( acpi.length ); + max_len = le32_to_cpu ( acpi->length ); if ( tag_offset > max_len ) return -ENOENT; offset = tag_offset; @@ -115,10 +113,11 @@ static int acpi_settings_fetch ( struct settings *settings, } /* Read data */ + src = ( ( ( const void * ) acpi ) + offset ); + dst = data; for ( i = 0 ; ( ( i < max_len ) && ( i < len ) ) ; i++ ) { - copy_from_user ( data, table, offset, 1 ); - data++; - offset += delta; + *(dst++) = *src; + src += delta; } /* Set type if not already specified */ diff --git a/src/core/acpimac.c b/src/core/acpimac.c index e0074ba43..11ac3243e 100644 --- a/src/core/acpimac.c +++ b/src/core/acpimac.c @@ -142,8 +142,9 @@ static struct acpimac_extractor acpimac_rtxmac = { * string that appears shortly after an "AMAC" or "MACA" signature. * This should work for most implementations encountered in practice. */ -static int acpimac_extract ( userptr_t zsdt, size_t len, size_t offset, - void *data, struct acpimac_extractor *extractor ){ +static int acpimac_extract ( const struct acpi_header *zsdt, size_t len, + size_t offset, void *data, + struct acpimac_extractor *extractor ) { size_t prefix_len = strlen ( extractor->prefix ); uint8_t *hw_addr = data; size_t skip = 0; @@ -161,8 +162,8 @@ static int acpimac_extract ( userptr_t zsdt, size_t len, size_t offset, skip++ ) { /* Read value */ - copy_from_user ( buf, zsdt, ( offset + skip ), - sizeof ( buf ) ); + memcpy ( buf, ( ( ( const void * ) zsdt ) + offset + skip ), + sizeof ( buf ) ); /* Check for expected format */ if ( memcmp ( buf, extractor->prefix, prefix_len ) != 0 ) @@ -203,8 +204,8 @@ static int acpimac_extract ( userptr_t zsdt, size_t len, size_t offset, * @v data Data buffer * @ret rc Return status code */ -static int acpimac_extract_auxmac ( userptr_t zsdt, size_t len, size_t offset, - void *data ) { +static int acpimac_extract_auxmac ( const struct acpi_header *zsdt, + size_t len, size_t offset, void *data ) { return acpimac_extract ( zsdt, len, offset, data, &acpimac_auxmac ); } @@ -218,8 +219,8 @@ static int acpimac_extract_auxmac ( userptr_t zsdt, size_t len, size_t offset, * @v data Data buffer * @ret rc Return status code */ -static int acpimac_extract_rtxmac ( userptr_t zsdt, size_t len, size_t offset, - void *data ) { +static int acpimac_extract_rtxmac ( const struct acpi_header *zsdt, + size_t len, size_t offset, void *data ) { return acpimac_extract ( zsdt, len, offset, data, &acpimac_rtxmac ); } diff --git a/src/drivers/bus/ecam.c b/src/drivers/bus/ecam.c index cde5952b8..58d513e88 100644 --- a/src/drivers/bus/ecam.c +++ b/src/drivers/bus/ecam.c @@ -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; diff --git a/src/include/ipxe/acpi.h b/src/include/ipxe/acpi.h index c34681238..40a44cffc 100644 --- a/src/include/ipxe/acpi.h +++ b/src/include/ipxe/acpi.h @@ -14,7 +14,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include #include @@ -355,7 +354,8 @@ struct acpi_model { #define PROVIDE_ACPI_INLINE( _subsys, _api_func ) \ PROVIDE_SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func ) -extern userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ); +extern const struct acpi_header * acpi_find_via_rsdt ( uint32_t signature, + unsigned int index ); /* Include all architecture-independent ACPI API headers */ #include @@ -368,31 +368,35 @@ extern userptr_t acpi_find_via_rsdt ( uint32_t signature, unsigned int index ); /** * Locate ACPI root system description table * - * @ret rsdt ACPI root system description table, or UNULL + * @ret rsdt ACPI root system description table, or NULL */ -userptr_t acpi_find_rsdt ( void ); +const struct acpi_rsdt * acpi_find_rsdt ( void ); /** * Locate ACPI table * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -userptr_t acpi_find ( uint32_t signature, unsigned int index ); +const struct acpi_header * acpi_find ( uint32_t signature, + unsigned int index ); extern struct acpi_descriptor * acpi_describe ( struct interface *interface ); #define acpi_describe_TYPE( object_type ) \ typeof ( struct acpi_descriptor * ( object_type ) ) -extern userptr_t ( * acpi_finder ) ( uint32_t signature, unsigned int index ); +extern const struct acpi_header * ( * acpi_finder ) ( uint32_t signature, + unsigned int index ); extern void acpi_fix_checksum ( struct acpi_header *acpi ); -extern userptr_t acpi_table ( uint32_t signature, unsigned int index ); +extern const struct acpi_header * acpi_table ( uint32_t signature, + unsigned int index ); extern int acpi_extract ( uint32_t signature, void *data, - int ( * extract ) ( userptr_t zsdt, size_t len, - size_t offset, void *data ) ); + int ( * extract ) ( const struct acpi_header *zsdt, + size_t len, size_t offset, + void *data ) ); extern void acpi_add ( struct acpi_descriptor *desc ); extern void acpi_del ( struct acpi_descriptor *desc ); extern int acpi_install ( int ( * install ) ( struct acpi_header *acpi ) ); diff --git a/src/include/ipxe/efi/efi_acpi.h b/src/include/ipxe/efi/efi_acpi.h index a698863a6..68f9c5be7 100644 --- a/src/include/ipxe/efi/efi_acpi.h +++ b/src/include/ipxe/efi/efi_acpi.h @@ -20,9 +20,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -static inline __attribute__ (( always_inline )) userptr_t +static inline __attribute__ (( always_inline )) const struct acpi_header * ACPI_INLINE ( efi, acpi_find ) ( uint32_t signature, unsigned int index ) { return acpi_find_via_rsdt ( signature, index ); diff --git a/src/include/ipxe/null_acpi.h b/src/include/ipxe/null_acpi.h index cedb02839..18f059964 100644 --- a/src/include/ipxe/null_acpi.h +++ b/src/include/ipxe/null_acpi.h @@ -9,17 +9,19 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include + #ifdef ACPI_NULL #define ACPI_PREFIX_null #else #define ACPI_PREFIX_null __null_ #endif -static inline __attribute__ (( always_inline )) userptr_t +static inline __attribute__ (( always_inline )) const struct acpi_header * ACPI_INLINE ( null, acpi_find ) ( uint32_t signature __unused, unsigned int index __unused ) { - return UNULL; + return NULL; } #endif /* _IPXE_NULL_ACPI_H */ diff --git a/src/interface/efi/efi_acpi.c b/src/interface/efi/efi_acpi.c index c1046c01a..a2021a4f6 100644 --- a/src/interface/efi/efi_acpi.c +++ b/src/interface/efi/efi_acpi.c @@ -31,6 +31,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ #include +#include #include #include #include @@ -42,15 +43,15 @@ EFI_USE_TABLE ( ACPI_10_TABLE, &rsdp, 0 ); /** * 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 efi_find_rsdt ( void ) { +static const struct acpi_rsdt * efi_find_rsdt ( void ) { /* Locate RSDT via ACPI configuration table, if available */ if ( rsdp ) return phys_to_virt ( rsdp->RsdtAddress ); - return UNULL; + return NULL; } PROVIDE_ACPI ( efi, acpi_find_rsdt, efi_find_rsdt ); diff --git a/src/interface/linux/linux_acpi.c b/src/interface/linux/linux_acpi.c index 846db2f1f..a2a8bf12e 100644 --- a/src/interface/linux/linux_acpi.c +++ b/src/interface/linux/linux_acpi.c @@ -42,7 +42,7 @@ struct linux_acpi_table { /** Index */ unsigned int index; /** Cached data */ - userptr_t data; + void *data; }; /** List of cached ACPI tables */ @@ -53,9 +53,10 @@ static LIST_HEAD ( linux_acpi_tables ); * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -static userptr_t linux_acpi_find ( uint32_t signature, unsigned int index ) { +static const struct acpi_header * linux_acpi_find ( uint32_t signature, + unsigned int index ) { struct linux_acpi_table *table; struct acpi_header *header; union { @@ -121,7 +122,7 @@ static userptr_t linux_acpi_find ( uint32_t signature, unsigned int index ) { err_read: free ( table ); err_alloc: - return UNULL; + return NULL; } /** diff --git a/src/tests/acpi_test.c b/src/tests/acpi_test.c index 1ca5befaf..6e8840217 100644 --- a/src/tests/acpi_test.c +++ b/src/tests/acpi_test.c @@ -32,6 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /* Forcibly enable assertions */ #undef NDEBUG +#include #include #include #include @@ -185,26 +186,27 @@ static struct acpi_test_tables *acpi_test_tables; * * @v signature Requested table signature * @v index Requested index of table with this signature - * @ret table Table, or UNULL if not found + * @ret table Table, or NULL if not found */ -static userptr_t acpi_test_find ( uint32_t signature, unsigned int index ) { +static const struct acpi_header * acpi_test_find ( uint32_t signature, + unsigned int index ) { struct acpi_test_table *table; unsigned int i; /* Fail if no test tables are installed */ if ( ! acpi_test_tables ) - return UNULL; + return NULL; /* Scan through test tables */ for ( i = 0 ; i < acpi_test_tables->count ; i++ ) { table = acpi_test_tables->table[i]; if ( ( signature == le32_to_cpu ( table->signature.raw ) ) && ( index-- == 0 ) ) { - return virt_to_user ( table->data ); + return table->data; } } - return UNULL; + return NULL; } /** Override ACPI table finder */ -- cgit v1.2.3-55-g7522 From e8ffe2cd644000c1cca51c40ba14edb546ca769b Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Thu, 24 Apr 2025 01:30:50 +0100 Subject: [uaccess] Remove trivial uses of userptr_t Signed-off-by: Michael Brown --- src/arch/x86/core/vram_settings.c | 5 +++-- src/arch/x86/image/pxe_image.c | 2 +- src/arch/x86/include/realmode.h | 4 ++-- src/arch/x86/interface/pxe/pxe_preboot.c | 5 ++--- src/arch/x86/interface/pxe/pxe_tftp.c | 12 +++++------- src/arch/x86/interface/pxe/pxe_udp.c | 9 ++++----- src/core/cachedhcp.c | 4 ++-- src/core/dma.c | 2 +- src/core/fdt.c | 6 +++--- src/drivers/infiniband/arbel.c | 2 +- src/drivers/infiniband/arbel.h | 5 ++--- src/drivers/infiniband/golan.c | 12 ++++++------ src/drivers/infiniband/golan.h | 2 +- src/drivers/infiniband/hermon.c | 2 +- src/drivers/infiniband/hermon.h | 5 ++--- src/drivers/net/efi/nii.c | 2 +- src/drivers/net/netvsc.c | 2 +- src/drivers/net/netvsc.h | 2 +- src/drivers/usb/xhci.h | 3 +-- src/image/segment.c | 2 +- src/include/ipxe/cachedhcp.h | 3 +-- src/include/ipxe/linux_sysfs.h | 4 +--- src/include/ipxe/memblock.h | 3 +-- src/include/ipxe/segment.h | 4 ++-- src/include/ipxe/vmbus.h | 3 +-- src/interface/efi/efi_block.c | 3 +-- src/interface/efi/efi_bofm.c | 3 +-- src/interface/efi/efi_cachedhcp.c | 10 ++++------ src/interface/efi/efi_file.c | 17 +++++++---------- src/interface/hyperv/vmbus.c | 4 ++-- src/interface/linux/linux_acpi.c | 1 + src/interface/linux/linux_smbios.c | 1 + src/interface/linux/linux_sysfs.c | 6 +++--- src/tests/bofm_test.c | 5 ++--- 34 files changed, 69 insertions(+), 86 deletions(-) (limited to 'src/interface/linux/linux_acpi.c') diff --git a/src/arch/x86/core/vram_settings.c b/src/arch/x86/core/vram_settings.c index ceeada467..a97a463fe 100644 --- a/src/arch/x86/core/vram_settings.c +++ b/src/arch/x86/core/vram_settings.c @@ -23,6 +23,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); +#include #include #include @@ -47,12 +48,12 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); * @ret len Length of setting data, or negative error */ static int vram_fetch ( void *data, size_t len ) { - userptr_t vram = phys_to_virt ( VRAM_BASE ); + const void *vram = phys_to_virt ( VRAM_BASE ); /* Copy video RAM */ if ( len > VRAM_LEN ) len = VRAM_LEN; - copy_from_user ( data, vram, 0, len ); + memcpy ( data, vram, len ); return VRAM_LEN; } diff --git a/src/arch/x86/image/pxe_image.c b/src/arch/x86/image/pxe_image.c index 5472ea594..9f8044fa1 100644 --- a/src/arch/x86/image/pxe_image.c +++ b/src/arch/x86/image/pxe_image.c @@ -54,7 +54,7 @@ const char *pxe_cmdline; * @ret rc Return status code */ static int pxe_exec ( struct image *image ) { - userptr_t buffer = real_to_virt ( 0, 0x7c00 ); + void *buffer = real_to_virt ( 0, 0x7c00 ); struct net_device *netdev; int rc; diff --git a/src/arch/x86/include/realmode.h b/src/arch/x86/include/realmode.h index 0017b42c0..75f7d16e7 100644 --- a/src/arch/x86/include/realmode.h +++ b/src/arch/x86/include/realmode.h @@ -87,7 +87,7 @@ real_to_virt ( unsigned int segment, unsigned int offset ) { static inline __always_inline void copy_to_real ( unsigned int dest_seg, unsigned int dest_off, void *src, size_t n ) { - copy_to_user ( real_to_virt ( dest_seg, dest_off ), 0, src, n ); + memcpy ( real_to_virt ( dest_seg, dest_off ), src, n ); } /** @@ -101,7 +101,7 @@ copy_to_real ( unsigned int dest_seg, unsigned int dest_off, static inline __always_inline void copy_from_real ( void *dest, unsigned int src_seg, unsigned int src_off, size_t n ) { - copy_from_user ( dest, real_to_virt ( src_seg, src_off ), 0, n ); + memcpy ( dest, real_to_virt ( src_seg, src_off ), n ); } /** diff --git a/src/arch/x86/interface/pxe/pxe_preboot.c b/src/arch/x86/interface/pxe/pxe_preboot.c index 727d8e1ea..77dcf66e7 100644 --- a/src/arch/x86/interface/pxe/pxe_preboot.c +++ b/src/arch/x86/interface/pxe/pxe_preboot.c @@ -33,7 +33,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include #include @@ -184,7 +183,7 @@ pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO *get_cached_info ) { union pxe_cached_info *info; unsigned int idx; size_t len; - userptr_t buffer; + void *buffer; DBGC ( &pxe_netdev, "PXENV_GET_CACHED_INFO %s to %04x:%04x+%x", pxenv_get_cached_info_name ( get_cached_info->PacketType ), @@ -245,7 +244,7 @@ pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO *get_cached_info ) { DBGC ( &pxe_netdev, " buffer may be too short" ); buffer = real_to_virt ( get_cached_info->Buffer.segment, get_cached_info->Buffer.offset ); - copy_to_user ( buffer, 0, info, len ); + memcpy ( buffer, info, len ); get_cached_info->BufferSize = len; } diff --git a/src/arch/x86/interface/pxe/pxe_tftp.c b/src/arch/x86/interface/pxe/pxe_tftp.c index 073414dce..aa675fd13 100644 --- a/src/arch/x86/interface/pxe/pxe_tftp.c +++ b/src/arch/x86/interface/pxe/pxe_tftp.c @@ -33,7 +33,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include #include @@ -49,7 +48,7 @@ struct pxe_tftp_connection { /** Data transfer interface */ struct interface xfer; /** Data buffer */ - userptr_t buffer; + void *buffer; /** Size of data buffer */ size_t size; /** Starting offset of data buffer */ @@ -121,9 +120,8 @@ static int pxe_tftp_xfer_deliver ( struct pxe_tftp_connection *pxe_tftp, ( pxe_tftp->start + pxe_tftp->size ) ); rc = -ENOBUFS; } else { - copy_to_user ( pxe_tftp->buffer, - ( pxe_tftp->offset - pxe_tftp->start ), - iobuf->data, len ); + memcpy ( ( pxe_tftp->buffer + pxe_tftp->offset - + pxe_tftp->start ), iobuf->data, len ); } /* Calculate new buffer position */ @@ -385,7 +383,7 @@ static PXENV_EXIT_t pxenv_tftp_read ( struct s_PXENV_TFTP_READ *tftp_read ) { while ( ( ( rc = pxe_tftp.rc ) == -EINPROGRESS ) && ( pxe_tftp.offset == pxe_tftp.start ) ) step(); - pxe_tftp.buffer = UNULL; + pxe_tftp.buffer = NULL; tftp_read->BufferSize = ( pxe_tftp.offset - pxe_tftp.start ); tftp_read->PacketNumber = ++pxe_tftp.blkidx; @@ -496,7 +494,7 @@ PXENV_EXIT_t pxenv_tftp_read_file ( struct s_PXENV_TFTP_READ_FILE pxe_tftp.size = tftp_read_file->BufferSize; while ( ( rc = pxe_tftp.rc ) == -EINPROGRESS ) step(); - pxe_tftp.buffer = UNULL; + pxe_tftp.buffer = NULL; tftp_read_file->BufferSize = pxe_tftp.max_offset; /* Close TFTP file */ diff --git a/src/arch/x86/interface/pxe/pxe_udp.c b/src/arch/x86/interface/pxe/pxe_udp.c index 47abb7df4..61c858dde 100644 --- a/src/arch/x86/interface/pxe/pxe_udp.c +++ b/src/arch/x86/interface/pxe/pxe_udp.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -296,7 +295,7 @@ pxenv_udp_write ( struct s_PXENV_UDP_WRITE *pxenv_udp_write ) { }; size_t len; struct io_buffer *iobuf; - userptr_t buffer; + const void *buffer; int rc; DBG ( "PXENV_UDP_WRITE" ); @@ -330,7 +329,7 @@ pxenv_udp_write ( struct s_PXENV_UDP_WRITE *pxenv_udp_write ) { } buffer = real_to_virt ( pxenv_udp_write->buffer.segment, pxenv_udp_write->buffer.offset ); - copy_from_user ( iob_put ( iobuf, len ), buffer, 0, len ); + memcpy ( iob_put ( iobuf, len ), buffer, len ); DBG ( " %04x:%04x+%x %d->%s:%d\n", pxenv_udp_write->buffer.segment, pxenv_udp_write->buffer.offset, pxenv_udp_write->buffer_size, @@ -400,7 +399,7 @@ static PXENV_EXIT_t pxenv_udp_read ( struct s_PXENV_UDP_READ *pxenv_udp_read ) { struct pxe_udp_pseudo_header *pshdr; uint16_t d_port_wanted = pxenv_udp_read->d_port; uint16_t d_port; - userptr_t buffer; + void *buffer; size_t len; /* Try receiving a packet, if the queue is empty */ @@ -443,7 +442,7 @@ static PXENV_EXIT_t pxenv_udp_read ( struct s_PXENV_UDP_READ *pxenv_udp_read ) { len = iob_len ( iobuf ); if ( len > pxenv_udp_read->buffer_size ) len = pxenv_udp_read->buffer_size; - copy_to_user ( buffer, 0, iobuf->data, len ); + memcpy ( buffer, iobuf->data, len ); pxenv_udp_read->buffer_size = len; /* Fill in source/dest information */ diff --git a/src/core/cachedhcp.c b/src/core/cachedhcp.c index 07589f0b8..0d400db16 100644 --- a/src/core/cachedhcp.c +++ b/src/core/cachedhcp.c @@ -198,7 +198,7 @@ static int cachedhcp_apply ( struct cached_dhcp_packet *cache, * @ret rc Return status code */ int cachedhcp_record ( struct cached_dhcp_packet *cache, unsigned int vlan, - userptr_t data, size_t max_len ) { + const void *data, size_t max_len ) { struct dhcp_packet *dhcppkt; struct dhcp_packet *tmp; struct dhcphdr *dhcphdr; @@ -216,7 +216,7 @@ int cachedhcp_record ( struct cached_dhcp_packet *cache, unsigned int vlan, return -ENOMEM; } dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( *dhcppkt ) ); - copy_from_user ( dhcphdr, data, 0, max_len ); + memcpy ( dhcphdr, data, max_len ); dhcppkt_init ( dhcppkt, dhcphdr, max_len ); /* Shrink packet to required length. If reallocation fails, diff --git a/src/core/dma.c b/src/core/dma.c index 1f3c1d8a6..cf4b20379 100644 --- a/src/core/dma.c +++ b/src/core/dma.c @@ -136,7 +136,7 @@ static void * dma_op_umalloc ( struct dma_device *dma, struct dma_operations *op = dma->op; if ( ! op ) - return UNULL; + return NULL; return op->umalloc ( dma, map, len, align ); } diff --git a/src/core/fdt.c b/src/core/fdt.c index 4c709b342..7c7127aed 100644 --- a/src/core/fdt.c +++ b/src/core/fdt.c @@ -1037,7 +1037,7 @@ static int fdt_urealloc ( struct fdt *fdt, size_t len ) { assert ( len >= fdt->used ); /* Attempt reallocation */ - new = urealloc ( virt_to_user ( fdt->raw ), len ); + new = urealloc ( fdt->raw, len ); if ( ! new ) { DBGC ( fdt, "FDT could not reallocate from +%#04zx to " "+%#04zx\n", fdt->len, len ); @@ -1129,7 +1129,7 @@ int fdt_create ( struct fdt_header **hdr, const char *cmdline ) { return 0; err_bootargs: - ufree ( virt_to_user ( fdt.raw ) ); + ufree ( fdt.raw ); err_alloc: err_image: return rc; @@ -1143,7 +1143,7 @@ int fdt_create ( struct fdt_header **hdr, const char *cmdline ) { void fdt_remove ( struct fdt_header *hdr ) { /* Free modifiable copy */ - ufree ( virt_to_user ( hdr ) ); + ufree ( hdr ); } /* Drag in objects via fdt_describe() */ diff --git a/src/drivers/infiniband/arbel.c b/src/drivers/infiniband/arbel.c index 4cb4167e0..0789ea593 100644 --- a/src/drivers/infiniband/arbel.c +++ b/src/drivers/infiniband/arbel.c @@ -2119,7 +2119,7 @@ static void arbel_stop_firmware ( struct arbel *arbel ) { DBGC ( arbel, "Arbel %p FATAL could not stop firmware: %s\n", arbel, strerror ( rc ) ); /* Leak memory and return; at least we avoid corruption */ - arbel->firmware_area = UNULL; + arbel->firmware_area = NULL; return; } } diff --git a/src/drivers/infiniband/arbel.h b/src/drivers/infiniband/arbel.h index 8a5a996a3..a31e59934 100644 --- a/src/drivers/infiniband/arbel.h +++ b/src/drivers/infiniband/arbel.h @@ -10,7 +10,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include -#include #include #include "mlx_bitops.h" #include "MT25218_PRM.h" @@ -492,7 +491,7 @@ struct arbel { * final teardown, in order to avoid memory map changes at * runtime. */ - userptr_t firmware_area; + void *firmware_area; /** ICM size */ size_t icm_len; /** ICM AUX size */ @@ -503,7 +502,7 @@ struct arbel { * final teardown, in order to avoid memory map changes at * runtime. */ - userptr_t icm; + void *icm; /** Offset within ICM of doorbell records */ size_t db_rec_offset; /** Doorbell records */ diff --git a/src/drivers/infiniband/golan.c b/src/drivers/infiniband/golan.c index a33bad9ff..ffa78fabf 100755 --- a/src/drivers/infiniband/golan.c +++ b/src/drivers/infiniband/golan.c @@ -52,7 +52,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); struct golan_page { struct list_head list; - userptr_t addr; + void *addr; }; static void golan_free_fw_areas ( struct golan *golan ) { @@ -61,7 +61,7 @@ static void golan_free_fw_areas ( struct golan *golan ) { for (i = 0; i < GOLAN_FW_AREAS_NUM; i++) { if ( golan->fw_areas[i].area ) { ufree ( golan->fw_areas[i].area ); - golan->fw_areas[i].area = UNULL; + golan->fw_areas[i].area = NULL; } } } @@ -75,7 +75,7 @@ static int golan_init_fw_areas ( struct golan *golan ) { } for (i = 0; i < GOLAN_FW_AREAS_NUM; i++) - golan->fw_areas[i].area = UNULL; + golan->fw_areas[i].area = NULL; return rc; @@ -448,12 +448,12 @@ static inline int golan_provide_pages ( struct golan *golan , uint32_t pages int size_ibox = 0; int size_obox = 0; int rc = 0; - userptr_t next_page_addr = UNULL; + void *next_page_addr = NULL; DBGC(golan, "%s\n", __FUNCTION__); if ( ! fw_area->area ) { fw_area->area = umalloc ( GOLAN_PAGE_SIZE * pages ); - if ( fw_area->area == UNULL ) { + if ( fw_area->area == NULL ) { rc = -ENOMEM; DBGC (golan ,"Failed to allocated %d pages \n",pages); goto err_golan_alloc_fw_area; @@ -467,7 +467,7 @@ static inline int golan_provide_pages ( struct golan *golan , uint32_t pages unsigned i, j; struct golan_cmd_layout *cmd; struct golan_manage_pages_inbox *in; - userptr_t addr = 0; + void *addr = NULL; mailbox = GET_INBOX(golan, MEM_MBOX); size_ibox = sizeof(struct golan_manage_pages_inbox) + (pas_num * GOLAN_PAS_SIZE); diff --git a/src/drivers/infiniband/golan.h b/src/drivers/infiniband/golan.h index f7da1e960..8122f8d38 100755 --- a/src/drivers/infiniband/golan.h +++ b/src/drivers/infiniband/golan.h @@ -121,7 +121,7 @@ struct golan_firmware_area { * final teardown, in order to avoid memory map changes at * runtime. */ - userptr_t area; + void *area; }; /* Queue Pair */ #define GOLAN_SEND_WQE_BB_SIZE 64 diff --git a/src/drivers/infiniband/hermon.c b/src/drivers/infiniband/hermon.c index 3138d8bfb..d25f4f011 100644 --- a/src/drivers/infiniband/hermon.c +++ b/src/drivers/infiniband/hermon.c @@ -2422,7 +2422,7 @@ static void hermon_stop_firmware ( struct hermon *hermon ) { DBGC ( hermon, "Hermon %p FATAL could not stop firmware: %s\n", hermon, strerror ( rc ) ); /* Leak memory and return; at least we avoid corruption */ - hermon->firmware_area = UNULL; + hermon->firmware_area = NULL; return; } } diff --git a/src/drivers/infiniband/hermon.h b/src/drivers/infiniband/hermon.h index a952bbd81..be79ff9d0 100644 --- a/src/drivers/infiniband/hermon.h +++ b/src/drivers/infiniband/hermon.h @@ -10,7 +10,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include -#include #include #include #include @@ -887,7 +886,7 @@ struct hermon { * final teardown, in order to avoid memory map changes at * runtime. */ - userptr_t firmware_area; + void *firmware_area; /** ICM map */ struct hermon_icm_map icm_map[HERMON_ICM_NUM_REGIONS]; /** ICM size */ @@ -900,7 +899,7 @@ struct hermon { * final teardown, in order to avoid memory map changes at * runtime. */ - userptr_t icm; + void *icm; /** Event queue */ struct hermon_event_queue eq; diff --git a/src/drivers/net/efi/nii.c b/src/drivers/net/efi/nii.c index 6381fb2dd..c60d4ca18 100644 --- a/src/drivers/net/efi/nii.c +++ b/src/drivers/net/efi/nii.c @@ -177,7 +177,7 @@ struct nii_nic { size_t mtu; /** Hardware transmit/receive buffer */ - userptr_t buffer; + void *buffer; /** Hardware transmit/receive buffer length */ size_t buffer_len; diff --git a/src/drivers/net/netvsc.c b/src/drivers/net/netvsc.c index 5be52fb8e..4bdf7b517 100644 --- a/src/drivers/net/netvsc.c +++ b/src/drivers/net/netvsc.c @@ -622,7 +622,7 @@ static int netvsc_buffer_copy ( struct vmbus_xfer_pages *pages, void *data, return -ERANGE; /* Copy data from buffer */ - copy_from_user ( data, buffer->data, offset, len ); + memcpy ( data, ( buffer->data + offset ), len ); return 0; } diff --git a/src/drivers/net/netvsc.h b/src/drivers/net/netvsc.h index 93192357f..41db49af7 100644 --- a/src/drivers/net/netvsc.h +++ b/src/drivers/net/netvsc.h @@ -305,7 +305,7 @@ struct netvsc_buffer { /** Buffer length */ size_t len; /** Buffer */ - userptr_t data; + void *data; /** GPADL ID */ unsigned int gpadl; }; diff --git a/src/drivers/usb/xhci.h b/src/drivers/usb/xhci.h index a3c8888af..22bc115c2 100644 --- a/src/drivers/usb/xhci.h +++ b/src/drivers/usb/xhci.h @@ -11,7 +11,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include -#include #include /** Minimum alignment required for data structures @@ -1054,7 +1053,7 @@ struct xhci_scratchpad { /** Number of page-sized scratchpad buffers */ unsigned int count; /** Scratchpad buffer area */ - userptr_t buffer; + void *buffer; /** Buffer DMA mapping */ struct dma_mapping buffer_map; /** Scratchpad array */ diff --git a/src/image/segment.c b/src/image/segment.c index ebc2b703d..2cb637dc2 100644 --- a/src/image/segment.c +++ b/src/image/segment.c @@ -57,7 +57,7 @@ struct errortab segment_errors[] __errortab = { * @v memsz Size of the segment * @ret rc Return status code */ -int prep_segment ( userptr_t segment, size_t filesz, size_t memsz ) { +int prep_segment ( void *segment, size_t filesz, size_t memsz ) { struct memory_map memmap; physaddr_t start = virt_to_phys ( segment ); physaddr_t mid = ( start + filesz ); diff --git a/src/include/ipxe/cachedhcp.h b/src/include/ipxe/cachedhcp.h index 8ebee3b7b..5b19bc59e 100644 --- a/src/include/ipxe/cachedhcp.h +++ b/src/include/ipxe/cachedhcp.h @@ -10,7 +10,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include -#include struct net_device; struct cached_dhcp_packet; @@ -20,7 +19,7 @@ extern struct cached_dhcp_packet cached_proxydhcp; extern struct cached_dhcp_packet cached_pxebs; extern int cachedhcp_record ( struct cached_dhcp_packet *cache, - unsigned int vlan, userptr_t data, + unsigned int vlan, const void *data, size_t max_len ); extern void cachedhcp_recycle ( struct net_device *netdev ); diff --git a/src/include/ipxe/linux_sysfs.h b/src/include/ipxe/linux_sysfs.h index d97b649c0..fbe1e6e8a 100644 --- a/src/include/ipxe/linux_sysfs.h +++ b/src/include/ipxe/linux_sysfs.h @@ -9,8 +9,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); -#include - -extern int linux_sysfs_read ( const char *filename, userptr_t *data ); +extern int linux_sysfs_read ( const char *filename, void **data ); #endif /* _IPXE_LINUX_SYSFS_H */ diff --git a/src/include/ipxe/memblock.h b/src/include/ipxe/memblock.h index 2bb38c460..4b6c64156 100644 --- a/src/include/ipxe/memblock.h +++ b/src/include/ipxe/memblock.h @@ -10,8 +10,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include -#include -extern size_t largest_memblock ( userptr_t *start ); +extern size_t largest_memblock ( void **start ); #endif /* _IPXE_MEMBLOCK_H */ diff --git a/src/include/ipxe/segment.h b/src/include/ipxe/segment.h index 9d5ecbd9b..b37c93c93 100644 --- a/src/include/ipxe/segment.h +++ b/src/include/ipxe/segment.h @@ -10,8 +10,8 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); -#include +#include -extern int prep_segment ( userptr_t segment, size_t filesz, size_t memsz ); +extern int prep_segment ( void *segment, size_t filesz, size_t memsz ); #endif /* _IPXE_SEGMENT_H */ diff --git a/src/include/ipxe/vmbus.h b/src/include/ipxe/vmbus.h index 682441857..5eee230fe 100644 --- a/src/include/ipxe/vmbus.h +++ b/src/include/ipxe/vmbus.h @@ -13,7 +13,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include @@ -634,7 +633,7 @@ vmbus_gpadl_is_obsolete ( unsigned int gpadl ) { return ( gpadl <= vmbus_obsolete_gpadl ); } -extern int vmbus_establish_gpadl ( struct vmbus_device *vmdev, userptr_t data, +extern int vmbus_establish_gpadl ( struct vmbus_device *vmdev, void *data, size_t len ); extern int vmbus_gpadl_teardown ( struct vmbus_device *vmdev, unsigned int gpadl ); diff --git a/src/interface/efi/efi_block.c b/src/interface/efi/efi_block.c index 5165bd804..94e2aae06 100644 --- a/src/interface/efi/efi_block.c +++ b/src/interface/efi/efi_block.c @@ -110,8 +110,7 @@ static int efi_block_rw ( struct san_device *sandev, uint64_t lba, } /* Read from / write to block device */ - if ( ( rc = sandev_rw ( sandev, lba, count, - virt_to_user ( data ) ) ) != 0 ) { + if ( ( rc = sandev_rw ( sandev, lba, count, data ) ) != 0 ) { DBGC ( sandev->drive, "EFIBLK %#02x I/O failed: %s\n", sandev->drive, strerror ( rc ) ); return rc; diff --git a/src/interface/efi/efi_bofm.c b/src/interface/efi/efi_bofm.c index b64770d8a..7d1d3619f 100644 --- a/src/interface/efi/efi_bofm.c +++ b/src/interface/efi/efi_bofm.c @@ -284,8 +284,7 @@ static int efi_bofm_start ( struct efi_device *efidev ) { efi_handle_name ( device ) ); DBGC2_HD ( device, bofmtab2, bofmtab2->Parameters.Length ); } - bofmrc = bofm ( virt_to_user ( bofmtab2 ? bofmtab2 : bofmtab ), - &efipci.pci ); + bofmrc = bofm ( ( bofmtab2 ? bofmtab2 : bofmtab ), &efipci.pci ); DBGC ( device, "EFIBOFM %s status %08x\n", efi_handle_name ( device ), bofmrc ); DBGC2 ( device, "EFIBOFM %s version 1 after processing:\n", diff --git a/src/interface/efi/efi_cachedhcp.c b/src/interface/efi/efi_cachedhcp.c index eb41a8e43..6bba4173a 100644 --- a/src/interface/efi/efi_cachedhcp.c +++ b/src/interface/efi/efi_cachedhcp.c @@ -72,8 +72,7 @@ int efi_cachedhcp_record ( EFI_HANDLE device, /* Record DHCPACK, if present */ if ( mode->DhcpAckReceived && - ( ( rc = cachedhcp_record ( &cached_dhcpack, vlan, - virt_to_user ( &mode->DhcpAck ), + ( ( rc = cachedhcp_record ( &cached_dhcpack, vlan, &mode->DhcpAck, sizeof ( mode->DhcpAck ) ) ) != 0 ) ) { DBGC ( device, "EFI %s could not record DHCPACK: %s\n", efi_handle_name ( device ), strerror ( rc ) ); @@ -83,7 +82,7 @@ int efi_cachedhcp_record ( EFI_HANDLE device, /* Record ProxyDHCPOFFER, if present */ if ( mode->ProxyOfferReceived && ( ( rc = cachedhcp_record ( &cached_proxydhcp, vlan, - virt_to_user ( &mode->ProxyOffer ), + &mode->ProxyOffer, sizeof ( mode->ProxyOffer ) ) ) != 0)){ DBGC ( device, "EFI %s could not record ProxyDHCPOFFER: %s\n", efi_handle_name ( device ), strerror ( rc ) ); @@ -92,9 +91,8 @@ int efi_cachedhcp_record ( EFI_HANDLE device, /* Record PxeBSACK, if present */ if ( mode->PxeReplyReceived && - ( ( rc = cachedhcp_record ( &cached_pxebs, vlan, - virt_to_user ( &mode->PxeReply ), - sizeof ( mode->PxeReply ) ) ) != 0)){ + ( ( rc = cachedhcp_record ( &cached_pxebs, vlan, &mode->PxeReply, + sizeof ( mode->PxeReply ) ) ) != 0 )){ DBGC ( device, "EFI %s could not record PXEBSACK: %s\n", efi_handle_name ( device ), strerror ( rc ) ); return rc; diff --git a/src/interface/efi/efi_file.c b/src/interface/efi/efi_file.c index b7b97aee7..79330641d 100644 --- a/src/interface/efi/efi_file.c +++ b/src/interface/efi/efi_file.c @@ -177,12 +177,12 @@ static size_t efi_file_len ( struct efi_file *file ) { * Read chunk of EFI file * * @v reader EFI file reader - * @v data Input data, or UNULL to zero-fill + * @v data Input data, or NULL to zero-fill * @v len Length of input data * @ret len Length of output data */ static size_t efi_file_read_chunk ( struct efi_file_reader *reader, - userptr_t data, size_t len ) { + const void *data, size_t len ) { struct efi_file *file = reader->file; size_t offset; @@ -203,7 +203,7 @@ static size_t efi_file_read_chunk ( struct efi_file_reader *reader, /* Copy or zero output data */ if ( data ) { - copy_from_user ( reader->data, data, offset, len ); + memcpy ( reader->data, ( data + offset ), len ); } else { memset ( reader->data, 0, len ); } @@ -262,7 +262,7 @@ static size_t efi_file_read_initrd ( struct efi_file_reader *reader ) { efi_file_name ( file ), reader->pos, ( reader->pos + pad_len ) ); } - len += efi_file_read_chunk ( reader, UNULL, pad_len ); + len += efi_file_read_chunk ( reader, NULL, pad_len ); /* Read CPIO header(s), if applicable */ name = cpio_name ( image ); @@ -274,13 +274,10 @@ static size_t efi_file_read_initrd ( struct efi_file_reader *reader ) { efi_file_name ( file ), reader->pos, ( reader->pos + cpio_len + pad_len ), image->name ); - len += efi_file_read_chunk ( reader, - virt_to_user ( &cpio ), + len += efi_file_read_chunk ( reader, &cpio, sizeof ( cpio ) ); - len += efi_file_read_chunk ( reader, - virt_to_user ( name ), - name_len ); - len += efi_file_read_chunk ( reader, UNULL, pad_len ); + len += efi_file_read_chunk ( reader, name, name_len ); + len += efi_file_read_chunk ( reader, NULL, pad_len ); } /* Read file data */ diff --git a/src/interface/hyperv/vmbus.c b/src/interface/hyperv/vmbus.c index 49ccf69c8..1c44cab5e 100644 --- a/src/interface/hyperv/vmbus.c +++ b/src/interface/hyperv/vmbus.c @@ -273,7 +273,7 @@ static int vmbus_negotiate_version ( struct hv_hypervisor *hv ) { * @v len Length of data buffer * @ret gpadl GPADL ID, or negative error */ -int vmbus_establish_gpadl ( struct vmbus_device *vmdev, userptr_t data, +int vmbus_establish_gpadl ( struct vmbus_device *vmdev, void *data, size_t len ) { struct hv_hypervisor *hv = vmdev->hv; struct vmbus *vmbus = hv->vmbus; @@ -442,7 +442,7 @@ int vmbus_open ( struct vmbus_device *vmdev, memset ( ring, 0, len ); /* Establish GPADL for ring buffer */ - gpadl = vmbus_establish_gpadl ( vmdev, virt_to_user ( ring ), len ); + gpadl = vmbus_establish_gpadl ( vmdev, ring, len ); if ( gpadl < 0 ) { rc = gpadl; goto err_establish; diff --git a/src/interface/linux/linux_acpi.c b/src/interface/linux/linux_acpi.c index a2a8bf12e..21a2e27cc 100644 --- a/src/interface/linux/linux_acpi.c +++ b/src/interface/linux/linux_acpi.c @@ -21,6 +21,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include +#include #include #include #include diff --git a/src/interface/linux/linux_smbios.c b/src/interface/linux/linux_smbios.c index a12c936ed..1450fcf1b 100644 --- a/src/interface/linux/linux_smbios.c +++ b/src/interface/linux/linux_smbios.c @@ -19,6 +19,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); +#include #include #include #include diff --git a/src/interface/linux/linux_sysfs.c b/src/interface/linux/linux_sysfs.c index cbb23d81d..321824ba9 100644 --- a/src/interface/linux/linux_sysfs.c +++ b/src/interface/linux/linux_sysfs.c @@ -42,8 +42,8 @@ FILE_LICENCE ( GPL2_OR_LATER ); * @v data Data to fill in * @ret len Length read, or negative error */ -int linux_sysfs_read ( const char *filename, userptr_t *data ) { - userptr_t tmp; +int linux_sysfs_read ( const char *filename, void **data ) { + void *tmp; ssize_t read; size_t len; int fd; @@ -59,7 +59,7 @@ int linux_sysfs_read ( const char *filename, userptr_t *data ) { } /* Read file */ - for ( *data = UNULL, len = 0 ; ; len += read ) { + for ( *data = NULL, len = 0 ; ; len += read ) { /* (Re)allocate space */ tmp = urealloc ( *data, ( len + LINUX_SYSFS_BLKSIZE ) ); diff --git a/src/tests/bofm_test.c b/src/tests/bofm_test.c index 829924887..dbef1eb90 100644 --- a/src/tests/bofm_test.c +++ b/src/tests/bofm_test.c @@ -26,7 +26,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); #include #include #include -#include #include #include #include @@ -111,7 +110,7 @@ void bofm_test ( struct pci_device *pci ) { printf ( "BOFMTEST performing harvest\n" ); bofmtab_harvest.en.busdevfn = pci->busdevfn; DBG_HDA ( 0, &bofmtab_harvest, sizeof ( bofmtab_harvest ) ); - bofmrc = bofm ( virt_to_user ( &bofmtab_harvest ), pci ); + bofmrc = bofm ( &bofmtab_harvest, pci ); printf ( "BOFMTEST harvest result %08x\n", bofmrc ); if ( bofmtab_harvest.en.options & BOFM_EN_HVST ) { printf ( "BOFMTEST harvested MAC address %s\n", @@ -125,7 +124,7 @@ void bofm_test ( struct pci_device *pci ) { printf ( "BOFMTEST performing update\n" ); bofmtab_update.en.busdevfn = pci->busdevfn; DBG_HDA ( 0, &bofmtab_update, sizeof ( bofmtab_update ) ); - bofmrc = bofm ( virt_to_user ( &bofmtab_update ), pci ); + bofmrc = bofm ( &bofmtab_update, pci ); printf ( "BOFMTEST update result %08x\n", bofmrc ); if ( bofmtab_update.en.options & BOFM_EN_CSM_SUCCESS ) { printf ( "BOFMTEST updated MAC address to %s\n", -- cgit v1.2.3-55-g7522