summaryrefslogtreecommitdiff
path: root/sys/arch/socppc/stand/boot/machdep.c
blob: e75baca1147ec827c341be9505c3aa7869ca7db1 (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
/*	$OpenBSD: machdep.c,v 1.2 2009/09/07 21:16:57 dms Exp $	*/

/*
 * Copyright (c) 2008 Mark Kettenis
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/types.h>

#include "libsa.h"
#include "wdvar.h"
#include "fdt.h"

#define RPR	0xe0000918
#define  RPR_RSTE	0x52535445
#define RCR	0xe000091c
#define  RCR_SWSR	0x00000001
#define  RCR_SWHR	0x00000002

/* defines from pciide.c and wdc_obio.c */
int     pciide_init             (struct wdc_channel*, u_int);
int     wdc_obio_init           (struct wdc_channel*, u_int);

void
machdep(void)
{
	char soc[32];
	void *node;
	char *tmp;
	int len;

	extern int consfreq;
	extern uint8_t *consaddr;
	
	/* set default values */
	consfreq = NS16550_FREQ;
	consaddr = (uint8_t *)CONADDR;

	/* lookup FTD for informations about conole */
	node = fdt_find_node("/chosen");
	if (node) {
		char *console;
		fdt_node_property(node, "linux,stdout-path", &console);
		node = fdt_find_node(console);
		if (node) {
			len = fdt_node_property(node, "clock-frequency", &tmp);
			if (len == 4)
				consfreq = *(int *)tmp;

			len = fdt_node_property(node, "reg", &tmp);
			if (len == 8)
				consaddr = (uint8_t *)*(int *)tmp;
		}
		memcpy(soc, console, 32);
		if (strchr(soc + 1, '/')!=0) {
			/* we are on a soc */
			*strchr(soc + 1, '/') = 0;
			node = fdt_find_node(soc);
			if (node) {
				len = fdt_node_property(node, "reg", &tmp);
				if (len == 8)
					consaddr += *(int *)tmp;
			}
		}
	}

	cninit();
{
	extern int (*controller_init)(struct wdc_channel *chp, u_int chan);
	extern u_int32_t pciide_base_addr;
	extern u_int32_t wdc_base_addr[];
	int *addr;
	int chnum;

	/* Thecus defaults */
	controller_init = pciide_init;
	pciide_base_addr = 0xe2000000;

	/* lookup the FDT, may have some CF there */
	chnum = 0;
	wdc_base_addr[0] = 0;
	wdc_base_addr[1] = 0;
	node = fdt_find_node("/");
	for (node = fdt_child_node(node); node; node = fdt_next_node(node)) {
		len = fdt_node_property(node, "device_type", &tmp);
		if (len && (strcmp(tmp, "rb,cf") == 0) && (chnum < 2)) {
			len = fdt_node_property(node, "reg", (char **)&addr);
			if (len == 8) {
				wdc_base_addr[chnum] = *addr;
				chnum++;
			}
		}
	}
	if (chnum)
		controller_init = wdc_obio_init;
}

}

int
main(void)
{
	extern char __bss_start[], _end[];
	bzero(__bss_start, _end-__bss_start);

	/* initialize FDT if the blob is available */
	extern int fdtaddrsave;
	if (fdtaddrsave) {
		if (fdt_init((void *)fdtaddrsave) == 0)
			fdtaddrsave = 0; /* no usable blob there */
	}

	boot(0);
	return 0;
}

void
_rtt(void)
{
	uint32_t v;

	*((volatile uint32_t *)(RPR)) = RPR_RSTE;
	__asm __volatile("eieio");
	*((volatile uint32_t *)(RCR)) = RCR_SWHR;

	printf("RESET FAILED\n");
	for (;;) ;
}