Home | History | Annotate | Line # | Download | only in efi
      1  1.2  riastrad /* $NetBSD: devpath5.c,v 1.2 2025/03/02 00:23:59 riastradh Exp $ */
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Redistribution and use in source and binary forms, with or without
      5  1.1  christos  * modification, are permitted provided that the following conditions
      6  1.1  christos  * are met:
      7  1.1  christos  * 1. Redistributions of source code must retain the above copyright
      8  1.1  christos  *    notice, this list of conditions and the following disclaimer.
      9  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     10  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     11  1.1  christos  *    documentation and/or other materials provided with the distribution.
     12  1.1  christos  *
     13  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     14  1.1  christos  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     15  1.1  christos  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     16  1.1  christos  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     17  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     18  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     19  1.1  christos  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     20  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     21  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     22  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     23  1.1  christos  * SUCH DAMAGE.
     24  1.1  christos  */
     25  1.1  christos 
     26  1.1  christos #include <sys/cdefs.h>
     27  1.1  christos #ifndef lint
     28  1.2  riastrad __RCSID("$NetBSD: devpath5.c,v 1.2 2025/03/02 00:23:59 riastradh Exp $");
     29  1.1  christos #endif /* not lint */
     30  1.1  christos 
     31  1.1  christos #include <assert.h>
     32  1.1  christos #include <stdio.h>
     33  1.1  christos 
     34  1.1  christos #include "defs.h"
     35  1.1  christos #include "devpath.h"
     36  1.1  christos #include "devpath5.h"
     37  1.1  christos 
     38  1.1  christos #define easprintf	(size_t)easprintf
     39  1.1  christos 
     40  1.1  christos /************************************************************************
     41  1.1  christos  * Type 5 - BIOS Boot Specification Device Path
     42  1.1  christos  ************************************************************************/
     43  1.1  christos 
     44  1.1  christos /*
     45  1.1  christos  * See Appendix A of BIOSBootSpecsV1.01.pdf for typename and statusflag.
     46  1.1  christos  * Available from <http:/www.uefi.org/uefi>
     47  1.1  christos  */
     48  1.1  christos static inline const char *
     49  1.1  christos devpath_bios_typename(uint devtype)
     50  1.1  christos {
     51  1.1  christos 
     52  1.1  christos 	switch (devtype) {
     53  1.1  christos 	case 0x01:	return "Floppy";
     54  1.1  christos 	case 0x02:	return "HardDisk";
     55  1.1  christos 	case 0x03:	return "CDRom";
     56  1.1  christos 	case 0x04:	return "PCMCIA";
     57  1.1  christos 	case 0x05:	return "USB";
     58  1.1  christos 	case 0x06:	return "Network";
     59  1.1  christos 	case 0x80:	return "BEV device";
     60  1.1  christos 	case 0xff:	return "Unknown";
     61  1.1  christos 	default:	return "Reserved";
     62  1.1  christos 	}
     63  1.1  christos }
     64  1.1  christos 
     65  1.1  christos #define BIOS_STATUS_OLD_POSITION	__BITS(3,0)
     66  1.1  christos #define BIOS_STATUS_ENABLED		__BIT(8)
     67  1.1  christos #define BIOS_STATUS_FAILED		__BIT(9)
     68  1.1  christos #define BIOS_STATUS_MEDIA		__BITS(11,10)
     69  1.1  christos #define BIOS_STATUS_MEDIA_NONE		__SHIFTIN(0, BIOS_STATUS_MEDIA)
     70  1.1  christos #define BIOS_STATUS_MEDIA_UNKNOWN	__SHIFTIN(1, BIOS_STATUS_MEDIA)
     71  1.1  christos #define BIOS_STATUS_MEDIA_PRESENT	__SHIFTIN(2, BIOS_STATUS_MEDIA)
     72  1.1  christos #define BIOS_STATUS_MEDIA_RESVD		__SHIFTIN(3, BIOS_STATUS_MEDIA)
     73  1.1  christos #define BIOS_STATUS_RESERVED		(__BITS(15,12) | __BITS(7,4))
     74  1.1  christos #define BIOS_STATUS_BITS \
     75  1.1  christos 	"\177\020"		\
     76  1.1  christos 	"f\x00\x04""POS\0"	\
     77  1.1  christos 	"b\x08""ENBL\0"		\
     78  1.1  christos 	"b\x09""FAIL\0"		\
     79  1.1  christos 	"f\x0a\x02""MEDIA\0"	\
     80  1.1  christos 	"=\0""NONE\0"		\
     81  1.1  christos 	"=\1""UNKNOWN\0"	\
     82  1.1  christos 	"=\2""PRESENT\0"	\
     83  1.1  christos 	"=\3""RSVD\0"
     84  1.1  christos 
     85  1.1  christos /* Bios Boot Specification Device */
     86  1.1  christos static inline void
     87  1.1  christos devpath_bios_BBS(devpath_t *dp, devpath_elm_t *path, devpath_elm_t *dbg)
     88  1.1  christos {	/* See 10.3.6 */
     89  1.1  christos 	struct { /* Sub-Type 1 */
     90  1.1  christos 		devpath_t	hdr;	/* Length = 8 */
     91  1.1  christos 		uint16_t	DeviceType; /* see devpath_bios_typename() */
     92  1.1  christos 		uint16_t	StatusFlag;
     93  1.1  christos 		char		Description[]; /* asciiz */
     94  1.1  christos 	} __packed *p = (void *)dp;
     95  1.1  christos 	__CTASSERT(sizeof(*p) == 8);
     96  1.1  christos 	const char *typename;
     97  1.1  christos 
     98  1.1  christos 	typename = devpath_bios_typename(p->DeviceType);
     99  1.1  christos 
    100  1.2  riastrad 	path->sz = easprintf(&path->cp, "BBS(%s(%#x),0x%04x,%s)",
    101  1.2  riastrad 	    typename, p->DeviceType, p->StatusFlag, p->Description);
    102  1.1  christos 
    103  1.1  christos 	if (dbg != NULL) {
    104  1.1  christos 		char statusflag[128];
    105  1.1  christos 
    106  1.1  christos 		snprintb(statusflag, sizeof(statusflag), BIOS_STATUS_BITS,
    107  1.1  christos 		    p->StatusFlag);
    108  1.1  christos 		dbg->sz = easprintf(&dbg->cp,
    109  1.1  christos 		    DEVPATH_FMT_HDR
    110  1.1  christos 		    DEVPATH_FMT(DeviceType: %x (%s)\n)
    111  1.1  christos 		    DEVPATH_FMT(StatusFlag: %s\n)
    112  1.1  christos 		    DEVPATH_FMT(Description: '%s'\n),
    113  1.1  christos 		    DEVPATH_DAT_HDR(dp),
    114  1.1  christos 		    p->DeviceType,
    115  1.1  christos 		    typename,
    116  1.1  christos 		    statusflag,
    117  1.1  christos 		    p->Description);
    118  1.1  christos 	}
    119  1.1  christos }
    120  1.1  christos 
    121  1.1  christos PUBLIC void
    122  1.1  christos devpath_bios(devpath_t *dp, devpath_elm_t *path, devpath_elm_t *dbg)
    123  1.1  christos {
    124  1.1  christos 
    125  1.1  christos 	assert(dp->Type = 5);
    126  1.1  christos 
    127  1.1  christos 	switch (dp->SubType) {
    128  1.1  christos 	case 1:   devpath_bios_BBS(dp, path, dbg);	return;
    129  1.1  christos 	default:  devpath_unsupported(dp, path, dbg);	return;
    130  1.1  christos 	}
    131  1.1  christos }
    132