ahcisata_ahb.c revision 1.1
11.1Sjmcneill/* $NetBSD: ahcisata_ahb.c,v 1.1 2026/01/09 22:54:29 jmcneill Exp $ */ 21.1Sjmcneill 31.1Sjmcneill/*- 41.1Sjmcneill * Copyright (c) 2025 Jared McNeill <jmcneill@invisible.ca> 51.1Sjmcneill * All rights reserved. 61.1Sjmcneill * 71.1Sjmcneill * Redistribution and use in source and binary forms, with or without 81.1Sjmcneill * modification, are permitted provided that the following conditions 91.1Sjmcneill * are met: 101.1Sjmcneill * 1. Redistributions of source code must retain the above copyright 111.1Sjmcneill * notice, this list of conditions and the following disclaimer. 121.1Sjmcneill * 2. Redistributions in binary form must reproduce the above copyright 131.1Sjmcneill * notice, this list of conditions and the following disclaimer in the 141.1Sjmcneill * documentation and/or other materials provided with the distribution. 151.1Sjmcneill * 161.1Sjmcneill * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 171.1Sjmcneill * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 181.1Sjmcneill * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 191.1Sjmcneill * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 201.1Sjmcneill * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 211.1Sjmcneill * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 221.1Sjmcneill * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231.1Sjmcneill * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241.1Sjmcneill * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251.1Sjmcneill * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261.1Sjmcneill * POSSIBILITY OF SUCH DAMAGE. 271.1Sjmcneill */ 281.1Sjmcneill 291.1Sjmcneill#include <sys/cdefs.h> 301.1Sjmcneill 311.1Sjmcneill__KERNEL_RCSID(0, "$NetBSD: ahcisata_ahb.c,v 1.1 2026/01/09 22:54:29 jmcneill Exp $"); 321.1Sjmcneill 331.1Sjmcneill#include <sys/param.h> 341.1Sjmcneill#include <sys/bus.h> 351.1Sjmcneill#include <sys/device.h> 361.1Sjmcneill#include <sys/intr.h> 371.1Sjmcneill#include <sys/systm.h> 381.1Sjmcneill 391.1Sjmcneill#include <dev/ata/atavar.h> 401.1Sjmcneill#include <dev/ic/ahcisatavar.h> 411.1Sjmcneill 421.1Sjmcneill#include <machine/wii.h> 431.1Sjmcneill#include <machine/wiiu.h> 441.1Sjmcneill 451.1Sjmcneill#include "ahb.h" 461.1Sjmcneill 471.1Sjmcneill#define SATA_HCCFG_INT_REG 0x400 481.1Sjmcneill#define SATA_HCCFG_INT_PORT1 __BIT(5) 491.1Sjmcneill#define SATA_HCCFG_INT_PORT0 __BIT(3) 501.1Sjmcneill#define SATA_HCCFG_INTMSK_REG 0x404 511.1Sjmcneill 521.1Sjmcneill#define RD4(sc, reg) \ 531.1Sjmcneill bus_space_read_4((sc)->sc_ahcit, (sc)->sc_ahcih, (reg)) 541.1Sjmcneill#define WR4(sc, reg, val) \ 551.1Sjmcneill bus_space_write_4((sc)->sc_ahcit, (sc)->sc_ahcih, (reg), (val)) 561.1Sjmcneill 571.1Sjmcneillstatic int 581.1Sjmcneillahcisata_ahb_intr(void *arg) 591.1Sjmcneill{ 601.1Sjmcneill struct ahci_softc * const sc = arg; 611.1Sjmcneill uint32_t val, mask; 621.1Sjmcneill int ret = 0; 631.1Sjmcneill 641.1Sjmcneill val = RD4(sc, SATA_HCCFG_INT_REG); 651.1Sjmcneill mask = RD4(sc, SATA_HCCFG_INTMSK_REG); 661.1Sjmcneill 671.1Sjmcneill if ((val & mask) != 0) { 681.1Sjmcneill ret = ahci_intr(sc); 691.1Sjmcneill } 701.1Sjmcneill 711.1Sjmcneill WR4(sc, SATA_HCCFG_INT_REG, val); 721.1Sjmcneill 731.1Sjmcneill return ret; 741.1Sjmcneill} 751.1Sjmcneill 761.1Sjmcneillstatic int 771.1Sjmcneillahcisata_ahb_match(device_t parent, cfdata_t cf, void *aux) 781.1Sjmcneill{ 791.1Sjmcneill return wiiu_native; 801.1Sjmcneill} 811.1Sjmcneill 821.1Sjmcneillstatic void 831.1Sjmcneillahcisata_ahb_attach(device_t parent, device_t self, void *aux) 841.1Sjmcneill{ 851.1Sjmcneill struct ahb_attach_args * const aaa = aux; 861.1Sjmcneill struct ahci_softc * const sc = device_private(self); 871.1Sjmcneill 881.1Sjmcneill sc->sc_atac.atac_dev = self; 891.1Sjmcneill sc->sc_dmat = aaa->aaa_dmat; 901.1Sjmcneill sc->sc_ahcit = aaa->aaa_bst; 911.1Sjmcneill sc->sc_ahcis = 0x408; 921.1Sjmcneill if (bus_space_map(sc->sc_ahcit, aaa->aaa_addr, sc->sc_ahcis, 0, 931.1Sjmcneill &sc->sc_ahcih) != 0) { 941.1Sjmcneill aprint_error(": couldn't map registers\n"); 951.1Sjmcneill return; 961.1Sjmcneill } 971.1Sjmcneill sc->sc_ahci_ports = 1; 981.1Sjmcneill sc->sc_save_init_data = true; 991.1Sjmcneill sc->sc_ahci_quirks |= AHCI_QUIRK_BADPMP; 1001.1Sjmcneill 1011.1Sjmcneill aprint_naive("\n"); 1021.1Sjmcneill aprint_normal(": AHCI SATA controller\n"); 1031.1Sjmcneill 1041.1Sjmcneill WR4(sc, SATA_HCCFG_INTMSK_REG, SATA_HCCFG_INT_PORT0); 1051.1Sjmcneill WR4(sc, SATA_HCCFG_INT_REG, ~0U); 1061.1Sjmcneill 1071.1Sjmcneill ahb_intr_establish(aaa->aaa_irq, IPL_BIO, ahcisata_ahb_intr, sc, 1081.1Sjmcneill device_xname(self)); 1091.1Sjmcneill 1101.1Sjmcneill ahci_attach(sc); 1111.1Sjmcneill} 1121.1Sjmcneill 1131.1SjmcneillCFATTACH_DECL_NEW(ahcisata_ahb, sizeof(struct ahci_softc), 1141.1Sjmcneill ahcisata_ahb_match, ahcisata_ahb_attach, NULL, NULL); 115