ph1_machdep.c revision 1.1 1 1.1 thorpej /* $NetBSD: ph1_machdep.c,v 1.1 2026/07/19 01:48:24 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 2026 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej *
19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
30 1.1 thorpej */
31 1.1 thorpej
32 1.1 thorpej #include <sys/cdefs.h>
33 1.1 thorpej __KERNEL_RCSID(0, "$NetBSD: ph1_machdep.c,v 1.1 2026/07/19 01:48:24 thorpej Exp $");
34 1.1 thorpej
35 1.1 thorpej #include <sys/param.h>
36 1.1 thorpej #include <sys/bus.h>
37 1.1 thorpej #include <sys/device.h>
38 1.1 thorpej
39 1.1 thorpej #include <hb68k/pg68k/pgromcalls.h>
40 1.1 thorpej
41 1.1 thorpej #include <dev/ata/atavar.h>
42 1.1 thorpej
43 1.1 thorpej #include <dev/fdt/fdtvar.h>
44 1.1 thorpej #include <dev/fdt/fdt_platform.h>
45 1.1 thorpej
46 1.1 thorpej #include <dev/ofw/openfirm.h>
47 1.1 thorpej
48 1.1 thorpej /*
49 1.1 thorpej * plat_machine_init --
50 1.1 thorpej * Perform any machine-specific initialization. "nextpa" is
51 1.1 thorpej * the next free physical memory page, from which any memory
52 1.1 thorpej * can be stolen on a whole-page basis as needed. Returns the
53 1.1 thorpej * next free physical memory page.
54 1.1 thorpej */
55 1.1 thorpej static paddr_t
56 1.1 thorpej ph1_plat_machine_init(paddr_t nextpa)
57 1.1 thorpej {
58 1.1 thorpej return nextpa;
59 1.1 thorpej }
60 1.1 thorpej
61 1.1 thorpej /*
62 1.1 thorpej * plat_device_register --
63 1.1 thorpej * device_register() hook -- boot device detection and an
64 1.1 thorpej * opportunity to set any device properties as devices are
65 1.1 thorpej * attached during autoconfiguration.
66 1.1 thorpej */
67 1.1 thorpej static void
68 1.1 thorpej ph1_plat_device_register(device_t dev, void *aux)
69 1.1 thorpej {
70 1.1 thorpej extern device_t machine_booted_device; /* XXX extern */
71 1.1 thorpej device_t parent = device_parent(dev);
72 1.1 thorpej
73 1.1 thorpej static device_t booted_controller;
74 1.1 thorpej static paddr_t booted_controller_phys = (paddr_t)-1;
75 1.1 thorpej static int booted_unit = -1;
76 1.1 thorpej static bool initialized;
77 1.1 thorpej
78 1.1 thorpej /*
79 1.1 thorpej * The Phaethon 1 firmware provides several properties
80 1.1 thorpej * in /chosen to help us find the boot device:
81 1.1 thorpej *
82 1.1 thorpej * pg68k,booted-controller-type -- e.g. "ata"
83 1.1 thorpej * pg68k,booted-controller-phys -- phys addr of device
84 1.1 thorpej * pg68k,booted-unit -- unit (i.e. drive) #
85 1.1 thorpej *
86 1.1 thorpej * We'll be concerned with pg68k,booted-controller-phys and
87 1.1 thorpej * pg68k,booted-unit.
88 1.1 thorpej */
89 1.1 thorpej if (! initialized) {
90 1.1 thorpej int chosen = OF_finddevice("/chosen");
91 1.1 thorpej uint32_t val;
92 1.1 thorpej
93 1.1 thorpej if (chosen != -1) {
94 1.1 thorpej if (of_getprop_uint32(chosen,
95 1.1 thorpej "pg68k,booted-controller-phys",
96 1.1 thorpej &val) == 0) {
97 1.1 thorpej booted_controller_phys = val;
98 1.1 thorpej }
99 1.1 thorpej if (of_getprop_uint32(chosen,
100 1.1 thorpej "pg68k,booted-unit",
101 1.1 thorpej &val) == 0) {
102 1.1 thorpej booted_unit = val;
103 1.1 thorpej }
104 1.1 thorpej }
105 1.1 thorpej initialized = true;
106 1.1 thorpej }
107 1.1 thorpej
108 1.1 thorpej if (booted_controller == NULL) {
109 1.1 thorpej if (device_is_a(parent, "simplebus")) {
110 1.1 thorpej struct fdt_attach_args *faa = aux;
111 1.1 thorpej bus_addr_t addr;
112 1.1 thorpej bus_size_t size;
113 1.1 thorpej
114 1.1 thorpej if (fdtbus_get_reg(faa->faa_phandle,
115 1.1 thorpej 0, &addr, &size) != 0) {
116 1.1 thorpej return;
117 1.1 thorpej }
118 1.1 thorpej
119 1.1 thorpej if (addr == booted_controller_phys) {
120 1.1 thorpej booted_controller = dev;
121 1.1 thorpej }
122 1.1 thorpej }
123 1.1 thorpej return;
124 1.1 thorpej }
125 1.1 thorpej
126 1.1 thorpej if (machine_booted_device == NULL) {
127 1.1 thorpej if (device_is_a(dev, "wd") &&
128 1.1 thorpej device_is_a(parent, "atabus") &&
129 1.1 thorpej device_parent(parent) == booted_controller) {
130 1.1 thorpej struct ata_device *adev = aux;
131 1.1 thorpej
132 1.1 thorpej if (adev->adev_drv_data->drive == booted_unit) {
133 1.1 thorpej machine_booted_device = dev;
134 1.1 thorpej }
135 1.1 thorpej }
136 1.1 thorpej }
137 1.1 thorpej }
138 1.1 thorpej
139 1.1 thorpej /*
140 1.1 thorpej * plat_halt --
141 1.1 thorpej * Halt the machine, returning back to the firmware monitor,
142 1.1 thorpej * if possible.
143 1.1 thorpej */
144 1.1 thorpej static void
145 1.1 thorpej ph1_plat_halt(void)
146 1.1 thorpej {
147 1.1 thorpej printf("Transferring control back to firmware...\n");
148 1.1 thorpej pgromcall_halt();
149 1.1 thorpej }
150 1.1 thorpej
151 1.1 thorpej /*
152 1.1 thorpej * plat_powerdown --
153 1.1 thorpej * Power-down the machine, if possible. If not, then halt.
154 1.1 thorpej */
155 1.1 thorpej static void
156 1.1 thorpej ph1_plat_powerdown(void)
157 1.1 thorpej {
158 1.1 thorpej /*
159 1.1 thorpej * The Phaethon 1 doesn't have software power control. It
160 1.1 thorpej * provides a poweroff vector, but it just halts.
161 1.1 thorpej */
162 1.1 thorpej ph1_plat_halt();
163 1.1 thorpej }
164 1.1 thorpej
165 1.1 thorpej /*
166 1.1 thorpej * plat_reboot --
167 1.1 thorpej * Reboot the system according to "howto". Attempt to
168 1.1 thorpej * use "bootstr" as the arguments for the resulting system
169 1.1 thorpej * boot.
170 1.1 thorpej */
171 1.1 thorpej static void
172 1.1 thorpej ph1_plat_reboot(int howto, char *bootstr)
173 1.1 thorpej {
174 1.1 thorpej printf("Requesting reboot from firmware...\n");
175 1.1 thorpej pgromcall_reboot();
176 1.1 thorpej }
177 1.1 thorpej
178 1.1 thorpej /*
179 1.1 thorpej * plat_uart_freq --
180 1.1 thorpej * Return the console UART clock frequency in Hz. This is
181 1.1 thorpej * called if the information is not available in the device
182 1.1 thorpej * tree.
183 1.1 thorpej */
184 1.1 thorpej static u_int
185 1.1 thorpej ph1_plat_uart_freq(void)
186 1.1 thorpej {
187 1.1 thorpej return 1843200;
188 1.1 thorpej }
189 1.1 thorpej
190 1.1 thorpej static const struct fdt_platform phaethon1_platform = {
191 1.1 thorpej .fp_machine_init = ph1_plat_machine_init,
192 1.1 thorpej .fp_device_register = ph1_plat_device_register,
193 1.1 thorpej .fp_powerdown = ph1_plat_powerdown,
194 1.1 thorpej .fp_halt = ph1_plat_halt,
195 1.1 thorpej .fp_reboot = ph1_plat_reboot,
196 1.1 thorpej .fp_uart_freq = ph1_plat_uart_freq,
197 1.1 thorpej };
198 1.1 thorpej FDT_PLATFORM(phaethon1, "pg68k,cpu010-mk1", &phaethon1_platform);
199