2 * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 FILE_LICENCE ( GPL2_OR_LATER );
23 #include <linux_api.h>
24 #include <ipxe/linux.h>
25 #include <ipxe/smbios.h>
27 /** SMBIOS filename */
28 static const char smbios_filename[] = "/dev/mem";
30 /** SMBIOS entry point scan region start address */
31 #define SMBIOS_ENTRY_START 0xf0000
33 /** SMBIOS entry point scan region length */
34 #define SMBIOS_ENTRY_LEN 0x10000
36 /** SMBIOS mapping alignment */
37 #define SMBIOS_ALIGN 0x1000
42 * @v smbios SMBIOS entry point descriptor structure to fill in
43 * @ret rc Return status code
45 static int linux_find_smbios ( struct smbios *smbios ) {
46 struct smbios_entry entry;
55 /* Open SMBIOS file */
56 fd = linux_open ( smbios_filename, O_RDONLY );
58 rc = -ELINUX ( linux_errno );
59 DBGC ( smbios, "SMBIOS could not open %s: %s\n",
60 smbios_filename, linux_strerror ( linux_errno ) );
64 /* Map the region potentially containing the SMBIOS entry point */
65 entry_mem = linux_mmap ( NULL, SMBIOS_ENTRY_LEN, PROT_READ, MAP_SHARED,
66 fd, SMBIOS_ENTRY_START );
67 if ( entry_mem == MAP_FAILED ) {
68 rc = -ELINUX ( linux_errno );
69 DBGC ( smbios, "SMBIOS could not mmap %s (%#x+%#x): %s\n",
70 smbios_filename, SMBIOS_ENTRY_START, SMBIOS_ENTRY_LEN,
71 linux_strerror ( linux_errno ) );
75 /* Scan for the SMBIOS entry point */
76 if ( ( rc = find_smbios_entry ( virt_to_user ( entry_mem ),
77 SMBIOS_ENTRY_LEN, &entry ) ) != 0 )
80 /* Map the region containing the SMBIOS structures */
81 smbios_indent = ( entry.smbios_address & ( SMBIOS_ALIGN - 1 ) );
82 smbios_offset = ( entry.smbios_address - smbios_indent );
83 smbios_len = ( entry.smbios_len + smbios_indent );
84 smbios_mem = linux_mmap ( NULL, smbios_len, PROT_READ, MAP_SHARED,
86 if ( smbios_mem == MAP_FAILED ) {
87 rc = -ELINUX ( linux_errno );
88 DBGC ( smbios, "SMBIOS could not mmap %s (%#zx+%#zx): %s\n",
89 smbios_filename, smbios_offset, smbios_len,
90 linux_strerror ( linux_errno ) );
94 /* Fill in entry point descriptor structure */
95 smbios->address = virt_to_user ( smbios_mem + smbios_indent );
96 smbios->len = entry.smbios_len;
97 smbios->count = entry.smbios_count;
98 smbios->version = SMBIOS_VERSION ( entry.major, entry.minor );
100 /* Unmap the entry point region (no longer required) */
101 linux_munmap ( entry_mem, SMBIOS_ENTRY_LEN );
105 linux_munmap ( smbios_mem, smbios_len );
108 linux_munmap ( entry_mem, SMBIOS_ENTRY_LEN );
115 PROVIDE_SMBIOS ( linux, find_smbios, linux_find_smbios );