summaryrefslogtreecommitdiffstats
path: root/sys/ia64/ia64/ski.c
blob: a387000d371468efad25eb53cdb79fe45876095d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*-
 * Copyright (c) 2001 Doug Rabson
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

/*
 * Fake out bits of EFI and SAL when running under SKI.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <machine/efi.h>
#include <machine/sal.h>
#include <machine/md_var.h>

struct ssc_time {
	int	year;
	int	month;
	int	day;
	int	hour;
	int	minute;
	int	second;
	int	msec;
	int	wday;
};

#define SSC_GET_RTC			65

static u_int64_t
ssc(u_int64_t in0, u_int64_t in1, u_int64_t in2, u_int64_t in3, int which)
{
	register u_int64_t ret0 __asm("r8");

	__asm __volatile("mov r15=%1\n\t"
			 "break 0x80001"
			 : "=r"(ret0)
			 : "r"(which), "r"(in0), "r"(in1), "r"(in2), "r"(in3));

	/*
	 * Ugh... Work around a bug in the Linux version of ski for
	 * SSC_GET_RTC. The PSR.dt register is not preserved properly
	 * and causes further memory references to be done without
	 * translation. All we need to do is set PSR.dt again. Note
	 * that dependency violations do not exist in ski, so we
	 * don't have to serialize.
	 */
	__asm __volatile("ssm	psr.dt");

	return ret0;
}

extern u_int64_t ski_fake_pal[];	/* *not* a function decl */
extern void ia64_ski_init(void);
extern u_int64_t ia64_pal_entry;

static EFI_STATUS ski_fake_efi_proc(void);
static EFI_STATUS ski_fake_efi_get_time(EFI_TIME *time,
					EFI_TIME_CAPABILITIES *caps);

static EFI_RUNTIME_SERVICES ski_fake_efi = {
	{ EFI_RUNTIME_SERVICES_SIGNATURE,
	  EFI_RUNTIME_SERVICES_REVISION,
	  0, 0, 0 },

	(EFI_GET_TIME)			ski_fake_efi_get_time,
	(EFI_SET_TIME)			ski_fake_efi_proc,
	(EFI_GET_WAKEUP_TIME)		ski_fake_efi_proc,
	(EFI_SET_WAKEUP_TIME)		ski_fake_efi_proc,
	
	(EFI_SET_VIRTUAL_ADDRESS_MAP)	ski_fake_efi_proc,
	(EFI_CONVERT_POINTER)		ski_fake_efi_proc,

	(EFI_GET_VARIABLE)		ski_fake_efi_proc,
	(EFI_GET_NEXT_VARIABLE_NAME)	ski_fake_efi_proc,
	(EFI_SET_VARIABLE)		ski_fake_efi_proc,

	(EFI_GET_NEXT_HIGH_MONO_COUNT)	ski_fake_efi_proc,
	(EFI_RESET_SYSTEM)		ski_fake_efi_proc
};

static EFI_STATUS
ski_fake_efi_get_time(EFI_TIME *time, EFI_TIME_CAPABILITIES *caps)
{
	struct ssc_time ssctime;

	ssc(ia64_tpa((vm_offset_t) &ssctime), 0, 0, 0, SSC_GET_RTC);

	time->Second = ssctime.second;
	time->Minute = ssctime.minute;
	time->Hour = ssctime.hour;
	time->Day = ssctime.day;
	time->Month = ssctime.month + 1;
	time->Year = ssctime.year + 1900;

	return EFI_SUCCESS;
}

static EFI_STATUS
ski_fake_efi_proc(void)
{
	return EFI_UNSUPPORTED;
}

static struct ia64_sal_result
ski_fake_sal(u_int64_t a1, u_int64_t a2, u_int64_t a3, u_int64_t a4,
	     u_int64_t a5, u_int64_t a6, u_int64_t a7, u_int64_t a8)
{
	struct ia64_sal_result res;

	if (a1 == SAL_FREQ_BASE) {
		/*
		 * Fake the values from my SDV.
		 */
		res.sal_status = 0;
		res.sal_result[0] = 133347096;
		res.sal_result[1] = 0;
		res.sal_result[2] = 0;
		return res;
	}

	/*
	 * Return an error for anything we don't care about.
	 */
	res.sal_status = -3;
	res.sal_result[0] = 0;
	res.sal_result[1] = 0;
	res.sal_result[2] = 0;
	return res;
}

void
ia64_ski_init(void)
{
	if (!ia64_running_in_simulator())
		return;

	ia64_efi_runtime = &ski_fake_efi;
	ia64_pal_entry = (u_int64_t) ski_fake_pal;
	ia64_sal_entry = ski_fake_sal;
}
OpenPOWER on IntegriCloud