11.4Sthorpej/* $NetBSD: autoconf.c,v 1.4 2025/10/13 14:49:16 thorpej Exp $ */ 21.1Smacallan 31.1Smacallan/*- 41.1Smacallan * Copyright (c) 2001 The NetBSD Foundation, Inc. 51.1Smacallan * All rights reserved. 61.1Smacallan * 71.1Smacallan * This code is derived from software contributed to The NetBSD Foundation 81.1Smacallan * by Matt Thomas <matt@3am-software.com>. 91.1Smacallan * 101.1Smacallan * Redistribution and use in source and binary forms, with or without 111.1Smacallan * modification, are permitted provided that the following conditions 121.1Smacallan * are met: 131.1Smacallan * 1. Redistributions of source code must retain the above copyright 141.1Smacallan * notice, this list of conditions and the following disclaimer. 151.1Smacallan * 2. Redistributions in binary form must reproduce the above copyright 161.1Smacallan * notice, this list of conditions and the following disclaimer in the 171.1Smacallan * documentation and/or other materials provided with the distribution. 181.1Smacallan * 191.1Smacallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Smacallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Smacallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Smacallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Smacallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Smacallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Smacallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Smacallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Smacallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Smacallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Smacallan * POSSIBILITY OF SUCH DAMAGE. 301.1Smacallan */ 311.1Smacallan 321.1Smacallan#include <sys/cdefs.h> 331.4Sthorpej__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.4 2025/10/13 14:49:16 thorpej Exp $"); 341.1Smacallan 351.1Smacallan#include "opt_md.h" 361.1Smacallan 371.1Smacallan#include <sys/param.h> 381.1Smacallan#include <sys/systm.h> 391.1Smacallan#include <sys/reboot.h> 401.1Smacallan#include <sys/disklabel.h> 411.1Smacallan#include <sys/device.h> 421.1Smacallan#include <sys/conf.h> 431.1Smacallan#include <sys/kernel.h> 441.1Smacallan 451.1Smacallan#include <net/if.h> 461.1Smacallan#include <net/if_ether.h> 471.1Smacallan 481.1Smacallan#include <machine/autoconf.h> 491.1Smacallan#include <machine/intr.h> 501.1Smacallan 511.1Smacallan#include <evbarm/iyonix/iyonixvar.h> 521.1Smacallan 531.1Smacallan#include <acorn32/include/bootconfig.h> 541.1Smacallan 551.1Smacallanextern struct bootconfig bootconfig; 561.1Smacallan 571.1Smacallan/* 581.1Smacallan * Set up the root device from the boot args 591.1Smacallan */ 601.1Smacallanvoid 611.1Smacallancpu_rootconf(void) 621.1Smacallan{ 631.1Smacallan aprint_normal("boot device: %s\n", 641.1Smacallan booted_device != NULL ? device_xname(booted_device) : "<unknown>"); 651.1Smacallan rootconf(); 661.1Smacallan} 671.1Smacallan 681.1Smacallan 691.1Smacallan/* 701.1Smacallan * void cpu_configure() 711.1Smacallan * 721.1Smacallan * Configure all the root devices 731.1Smacallan * The root devices are expected to configure their own children 741.1Smacallan */ 751.1Smacallanvoid 761.1Smacallancpu_configure(void) 771.1Smacallan{ 781.1Smacallan struct mainbus_attach_args maa; 791.1Smacallan 801.1Smacallan (void) splhigh(); 811.1Smacallan (void) splserial(); /* XXX need an splextreme() */ 821.1Smacallan 831.1Smacallan maa.ma_name = "mainbus"; 841.1Smacallan 851.1Smacallan config_rootfound("mainbus", &maa); 861.1Smacallan 871.1Smacallan /* Time to start taking interrupts so lets open the flood gates .... */ 881.1Smacallan spl0(); 891.1Smacallan} 901.1Smacallan 911.1Smacallan#define BUILTIN_ETHERNET_P(pa) \ 921.1Smacallan ((pa)->pa_bus == 0 && (pa)->pa_device == 4 && (pa)->pa_function == 0) 931.1Smacallan 941.1Smacallan#define SETPROP(x, y) \ 951.1Smacallan do { \ 961.1Smacallan if (prop_dictionary_set(device_properties(dev), \ 971.1Smacallan x, y) == false) { \ 981.1Smacallan printf("WARNING: unable to set " x " " \ 991.1Smacallan "property for %s\n", device_xname(dev)); \ 1001.1Smacallan } \ 1011.1Smacallan prop_object_release(y); \ 1021.1Smacallan } while (/*CONSTCOND*/0) 1031.1Smacallan 1041.1Smacallanvoid 1051.1Smacallandevice_register(device_t dev, void *aux) 1061.1Smacallan{ 1071.1Smacallan device_t pdev; 1081.1Smacallan 1091.1Smacallan if ((pdev = device_parent(dev)) != NULL && 1101.1Smacallan device_is_a(pdev, "pci")) { 1111.1Smacallan struct pci_attach_args *pa = aux; 1121.1Smacallan 1131.1Smacallan if (BUILTIN_ETHERNET_P(pa)) { 1141.1Smacallan prop_number_t cfg1, cfg2, swdpin; 1151.1Smacallan 1161.1Smacallan /* 1171.1Smacallan * We set these configuration registers to 0, 1181.1Smacallan * because it's the closest we have to "leave them 1191.1Smacallan * alone". That and, it works. 1201.1Smacallan */ 1211.1Smacallan cfg1 = prop_number_create_integer(0); 1221.1Smacallan KASSERT(cfg1 != NULL); 1231.1Smacallan cfg2 = prop_number_create_integer(0); 1241.1Smacallan KASSERT(cfg2 != NULL); 1251.1Smacallan swdpin = prop_number_create_integer(0); 1261.1Smacallan KASSERT(swdpin != NULL); 1271.1Smacallan 1281.3Sthorpej device_setprop_data(dev, "mac-address", 1291.3Sthorpej iyonix_macaddr, ETHER_ADDR_LEN); 1301.1Smacallan 1311.1Smacallan SETPROP("i82543-cfg1", cfg1); 1321.1Smacallan SETPROP("i82543-cfg2", cfg2); 1331.1Smacallan SETPROP("i82543-swdpin", swdpin); 1341.1Smacallan } 1351.1Smacallan } 1361.1Smacallan 1371.1Smacallan if ((device_is_a(dev, "genfb") || device_is_a(dev, "gffb")) && 1381.1Smacallan device_is_a(device_parent(dev), "pci") ) { 1391.1Smacallan prop_dictionary_t dict = device_properties(dev); 1401.1Smacallan struct pci_attach_args *pa = aux; 1411.1Smacallan pcireg_t bar0, bar1; 1421.1Smacallan uint32_t fbaddr; 1431.1Smacallan bus_space_handle_t vgah; 1441.1Smacallan 1451.1Smacallan bar0 = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_MAPREG_START); 1461.1Smacallan bar1 = pci_conf_read(pa->pa_pc, pa->pa_tag, 1471.1Smacallan PCI_MAPREG_START + 0x04); 1481.1Smacallan 1491.1Smacallan /* 1501.1Smacallan * We need to prod the VGA card to disable interrupts, since 1511.1Smacallan * RISC OS has been using them and we don't know how to 1521.1Smacallan * handle them. This assumes that we have a NVidia 1531.1Smacallan * GeForce 2 MX card as supplied with the Iyonix and 1541.1Smacallan * as (probably) required by RISC OS in order to boot. 1551.1Smacallan * If you write your own RISC OS driver for a different card, 1561.1Smacallan * you're on your own. 1571.1Smacallan */ 1581.1Smacallan 1591.1Smacallan/* We're guessing at the numbers here, guys */ 1601.1Smacallan#define VGASIZE 0x1000 1611.1Smacallan#define IRQENABLE_ADDR 0x140 1621.1Smacallan 1631.1Smacallan bus_space_map(pa->pa_memt, PCI_MAPREG_MEM_ADDR(bar0), 1641.1Smacallan VGASIZE, 0, &vgah); 1651.1Smacallan bus_space_write_4(pa->pa_memt, vgah, 0x140, 0); 1661.1Smacallan bus_space_unmap(pa->pa_memt, vgah, 0x1000); 1671.1Smacallan 1681.1Smacallan fbaddr = PCI_MAPREG_MEM_ADDR(bar1); 1691.1Smacallan 1701.3Sthorpej device_setprop_bool(dev, "is_console", true); 1711.1Smacallan prop_dictionary_set_uint32(dict, "width", 1721.1Smacallan bootconfig.width + 1); 1731.1Smacallan prop_dictionary_set_uint32(dict, "height", 1741.1Smacallan bootconfig.height + 1); 1751.1Smacallan prop_dictionary_set_uint32(dict, "depth", 1761.1Smacallan 1 << bootconfig.log2_bpp); 1771.1Smacallan /* 1781.1Smacallan * XXX 1791.1Smacallan * at least RISC OS 5.28 seems to use the graphics hardware in 1801.1Smacallan * BGR mode when in 32bit colour, so take that into account 1811.1Smacallan */ 1821.1Smacallan if (bootconfig.log2_bpp == 5) 1831.1Smacallan prop_dictionary_set_bool(dict, "is_bgr", 1); 1841.1Smacallan prop_dictionary_set_uint32(dict, "address", fbaddr); 1851.1Smacallan } 1861.1Smacallan if (device_is_a(dev, "dsrtc")) { 1871.4Sthorpej /* RISC OS RTC epoch is 2000. */ 1881.4Sthorpej device_setprop_uint(dev, "start-year", 2000); 1891.1Smacallan } 1901.1Smacallan} 191