1218885Sdim/* $NetBSD: booted_dev.c,v 1.4 2016/10/13 16:18:20 flxd Exp $ */
2218885Sdim
3218885Sdim/*
4218885Sdim * Copyright (c) 1999 Christopher G. Demetriou.  All rights reserved.
5218885Sdim *
6218885Sdim * Redistribution and use in source and binary forms, with or without
7218885Sdim * modification, are permitted provided that the following conditions
8218885Sdim * are met:
9218885Sdim * 1. Redistributions of source code must retain the above copyright
10218885Sdim *    notice, this list of conditions and the following disclaimer.
11218885Sdim * 2. Redistributions in binary form must reproduce the above copyright
12218885Sdim *    notice, this list of conditions and the following disclaimer in the
13218885Sdim *    documentation and/or other materials provided with the distribution.
14218885Sdim * 3. All advertising materials mentioning features or use of this software
15249423Sdim *    must display the following acknowledgement:
16249423Sdim *      This product includes software developed by Christopher G. Demetriou
17249423Sdim *	for the NetBSD Project.
18218885Sdim * 4. The name of the author may not be used to endorse or promote products
19218885Sdim *    derived from this software without specific prior written permission
20218885Sdim *
21218885Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22218885Sdim * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23218885Sdim * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24218885Sdim * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25218885Sdim * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26218885Sdim * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27218885Sdim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28218885Sdim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29218885Sdim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30218885Sdim * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31218885Sdim */
32218885Sdim
33218885Sdim#include <lib/libsa/stand.h>
34218885Sdim#include <lib/libkern/libkern.h>
35218885Sdim
36218885Sdim#include <machine/prom.h>
37218885Sdim#include "common.h"
38249423Sdim
39218885Sdimlong	booted_dev_fd;
40218885Sdim#if defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK)
41249423Sdimchar	booted_dev_name[BOOTED_DEV_MAXNAMELEN];
42249423Sdim#endif /* defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK) */
43249423Sdim
44249423Sdim#if defined(PRIMARY_BOOTBLOCK) || defined(UNIFIED_BOOTBLOCK)
45249423Sdimint
46249423Sdimbooted_dev_open(void)
47249423Sdim{
48249423Sdim	prom_return_t ret;
49249423Sdim	int devlen;
50249423Sdim
51249423Sdim	/*
52249423Sdim	 * XXX
53249423Sdim	 * We don't know what device names look like yet,
54249423Sdim	 * so we can't change them.
55249423Sdim	 */
56249423Sdim	devlen = prom_getenv(PROM_E_BOOTED_DEV, booted_dev_name,
57249423Sdim	    sizeof(booted_dev_name));
58249423Sdim
59249423Sdim	ret.bits = prom_open(booted_dev_name, devlen);
60249423Sdim
61249423Sdim	if (ret.u.status)
62249423Sdim		return 0;
63249423Sdim	booted_dev_fd = ret.u.retval;
64249423Sdim
65249423Sdim	return 1;
66249423Sdim}
67249423Sdim#endif
68249423Sdim