Path: blob/main/sys/dev/ata/chipsets/ata-marvell.c
39536 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 1998 - 2008 Søren Schmidt <[email protected]>4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer,11* without modification, immediately at the beginning of the file.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR17* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES18* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.19* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,20* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT21* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,22* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY23* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF25* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26*/2728#include <sys/param.h>29#include <sys/module.h>30#include <sys/systm.h>31#include <sys/kernel.h>32#include <sys/ata.h>33#include <sys/bus.h>34#include <sys/endian.h>35#include <sys/malloc.h>36#include <sys/lock.h>37#include <sys/mutex.h>38#include <sys/sema.h>39#include <sys/stdarg.h>40#include <sys/taskqueue.h>41#include <vm/uma.h>42#include <machine/resource.h>43#include <machine/bus.h>44#include <sys/rman.h>45#include <dev/pci/pcivar.h>46#include <dev/pci/pcireg.h>47#include <dev/ata/ata-all.h>48#include <dev/ata/ata-pci.h>49#include <ata_if.h>5051/* local prototypes */52static int ata_marvell_chipinit(device_t dev);53static int ata_marvell_ch_attach(device_t dev);54static int ata_marvell_setmode(device_t dev, int target, int mode);55static int ata_marvell_dummy_chipinit(device_t dev);5657/* misc defines */58#define MV_61XX 6159#define MV_91XX 916061/*62* Marvell chipset support functions63*/64#define ATA_MV_HOST_BASE(ch) \65((ch->unit & 3) * 0x0100) + (ch->unit > 3 ? 0x30000 : 0x20000)66#define ATA_MV_EDMA_BASE(ch) \67((ch->unit & 3) * 0x2000) + (ch->unit > 3 ? 0x30000 : 0x20000)6869struct ata_marvell_response {70u_int16_t tag;71u_int8_t edma_status;72u_int8_t dev_status;73u_int32_t timestamp;74};7576struct ata_marvell_dma_prdentry {77u_int32_t addrlo;78u_int32_t count;79u_int32_t addrhi;80u_int32_t reserved;81};8283static int84ata_marvell_probe(device_t dev)85{86struct ata_pci_controller *ctlr = device_get_softc(dev);87static const struct ata_chip_id ids[] =88{{ ATA_M88SE6101, 0, 0, MV_61XX, ATA_UDMA6, "88SE6101" },89{ ATA_M88SE6102, 0, 0, MV_61XX, ATA_UDMA6, "88SE6102" },90{ ATA_M88SE6111, 0, 1, MV_61XX, ATA_UDMA6, "88SE6111" },91{ ATA_M88SE6121, 0, 2, MV_61XX, ATA_UDMA6, "88SE6121" },92{ ATA_M88SE6141, 0, 4, MV_61XX, ATA_UDMA6, "88SE6141" },93{ ATA_M88SE6145, 0, 4, MV_61XX, ATA_UDMA6, "88SE6145" },94{ 0x91a41b4b, 0, 0, MV_91XX, ATA_UDMA6, "88SE912x" },95{ 0, 0, 0, 0, 0, 0}};9697if (pci_get_vendor(dev) != ATA_MARVELL_ID &&98pci_get_vendor(dev) != ATA_MARVELL2_ID)99return ENXIO;100101if (!(ctlr->chip = ata_match_chip(dev, ids)))102return ENXIO;103104ata_set_desc(dev);105106switch (ctlr->chip->cfg2) {107case MV_61XX:108ctlr->chipinit = ata_marvell_chipinit;109break;110case MV_91XX:111ctlr->chipinit = ata_marvell_dummy_chipinit;112break;113}114return (BUS_PROBE_LOW_PRIORITY);115}116117static int118ata_marvell_chipinit(device_t dev)119{120struct ata_pci_controller *ctlr = device_get_softc(dev);121device_t child;122123if (ata_setup_interrupt(dev, ata_generic_intr))124return ENXIO;125/* Create AHCI subdevice if AHCI part present. */126if (ctlr->chip->cfg1) {127child = device_add_child(dev, NULL, DEVICE_UNIT_ANY);128if (child != NULL) {129device_set_ivars(child, (void *)(intptr_t)-1);130bus_attach_children(dev);131}132}133ctlr->ch_attach = ata_marvell_ch_attach;134ctlr->ch_detach = ata_pci_ch_detach;135ctlr->reset = ata_generic_reset;136ctlr->setmode = ata_marvell_setmode;137ctlr->channels = 1;138return (0);139}140141static int142ata_marvell_ch_attach(device_t dev)143{144struct ata_channel *ch = device_get_softc(dev);145int error;146147error = ata_pci_ch_attach(dev);148/* dont use 32 bit PIO transfers */149ch->flags |= ATA_USE_16BIT;150ch->flags |= ATA_CHECKS_CABLE;151return (error);152}153154static int155ata_marvell_setmode(device_t dev, int target, int mode)156{157struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));158struct ata_channel *ch = device_get_softc(dev);159160mode = min(mode, ctlr->chip->max_dma);161/* Check for 80pin cable present. */162if (ata_dma_check_80pin && mode > ATA_UDMA2 &&163ATA_IDX_INB(ch, ATA_BMDEVSPEC_0) & 0x01) {164ata_print_cable(dev, "controller");165mode = ATA_UDMA2;166}167/* Nothing to do to setup mode, the controller snoop SET_FEATURE cmd. */168return (mode);169}170171static int172ata_marvell_dummy_chipinit(device_t dev)173{174struct ata_pci_controller *ctlr = device_get_softc(dev);175176ctlr->channels = 0;177return (0);178}179180ATA_DECLARE_DRIVER(ata_marvell);181182183