1/*-
2 * Copyright (C) 2014 Nathan Whitehorn
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
21 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
22 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
23 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#include <sys/cdefs.h>
27__FBSDID("$FreeBSD: stable/11/stand/powerpc/kboot/hostdisk.c 329183 2018-02-12 20:51:28Z kevans $");
28
29#include <sys/types.h>
30#include <stdarg.h>
31#include "bootstrap.h"
32#include "host_syscall.h"
33
34static int hostdisk_init(void);
35static int hostdisk_strategy(void *devdata, int flag, daddr_t dblk,
36    size_t size, char *buf, size_t *rsize);
37static int hostdisk_open(struct open_file *f, ...);
38static int hostdisk_close(struct open_file *f);
39static int hostdisk_ioctl(struct open_file *f, u_long cmd, void *data);
40static int hostdisk_print(int verbose);
41
42struct devsw hostdisk = {
43	"/dev",
44	DEVT_DISK,
45	hostdisk_init,
46	hostdisk_strategy,
47	hostdisk_open,
48	hostdisk_close,
49	hostdisk_ioctl,
50	hostdisk_print,
51};
52
53static int
54hostdisk_init(void)
55{
56
57	return (0);
58}
59
60static int
61hostdisk_strategy(void *devdata, int flag, daddr_t dblk, size_t size,
62    char *buf, size_t *rsize)
63{
64	struct devdesc *desc = devdata;
65	daddr_t pos;
66	int n;
67	uint64_t res;
68	uint32_t posl, posh;
69
70	pos = dblk * 512;
71
72	posl = pos & 0xffffffff;
73	posh = (pos >> 32) & 0xffffffff;
74	if (host_llseek(desc->d_unit, posh, posl, &res, 0) < 0) {
75		printf("Seek error\n");
76		return (EIO);
77	}
78	n = host_read(desc->d_unit, buf, size);
79
80	if (n < 0)
81		return (EIO);
82
83	*rsize = n;
84	return (0);
85}
86
87static int
88hostdisk_open(struct open_file *f, ...)
89{
90	struct devdesc *desc;
91	va_list vl;
92
93	va_start(vl, f);
94	desc = va_arg(vl, struct devdesc *);
95	va_end(vl);
96
97	desc->d_unit = host_open(desc->d_opendata, O_RDONLY, 0);
98
99	if (desc->d_unit <= 0) {
100		printf("hostdisk_open: couldn't open %s: %d\n",
101		    (char *)desc->d_opendata, desc->d_unit);
102		return (ENOENT);
103	}
104
105	return (0);
106}
107
108static int
109hostdisk_close(struct open_file *f)
110{
111	struct devdesc *desc = f->f_devdata;
112
113	host_close(desc->d_unit);
114	return (0);
115}
116
117static int
118hostdisk_ioctl(struct open_file *f, u_long cmd, void *data)
119{
120
121	return (EINVAL);
122}
123
124static int
125hostdisk_print(int verbose)
126{
127	return (0);
128}
129
130