/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Jason R. Thorpe.
*
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
switch (bi->bi_tag) {
case BI_VIRT_GF_RTC_BASE:
/*
* There are 2 Goldfish RTC instances on the virt68k
* platform:
*
* 1- This is used as the system timer / hard-clock.
* 2- This is used as the TODR.
*/
for (i = 0; i < 2; i++) {
ma.ma_compatible = (i == 0)
? "netbsd,goldfish-rtc-hardclock"
: "google,goldfish-rtc";
ma.ma_addr = vd->vd_mmio_base + (i * 0x1000);
ma.ma_size = 0x1000;
ma.ma_irq = vd->vd_irq_base + i;
config_found(self, &ma, mainbus_print, CFARGS_NONE);
}
break;
/*
* Probe the virtio slot to see if there's actually something
* there before we claim that it is "found".
*/
if (bus_space_map(ma->ma_st, ma->ma_addr, ma->ma_size, 0, &bsh) != 0) {
aprint_error_dev(self,
"unable to map virtio slot @ 0x%lx\n", ma->ma_addr);
return;
}
val = bus_space_read_4(ma->ma_st, bsh, VIRTIO_MMIO_DEVICE_ID);
bus_space_unmap(ma->ma_st, bsh, ma->ma_size);
switch (bi->bi_tag) {
case BI_VIRT_QEMU_VERSION:
case BI_VIRT_GF_PIC_BASE:
case BI_VIRT_GF_RTC_BASE:
case BI_VIRT_GF_TTY_BASE:
/* Handled elsewhere. */
break;
case BI_VIRT_VIRTIO_BASE:
for (i = 0; i < (32 * 4); i++) {
ma.ma_compatible = "virtio,mmio";
ma.ma_addr = vd->vd_mmio_base + (i * 0x200);
ma.ma_size = 0x200;
ma.ma_irq = vd->vd_irq_base + i;
mainbus_attach_virtio(self, &ma);
}
break;