#ifndef _DEV_PCI_PCIIDEVAR_H_
#define _DEV_PCI_PCIIDEVAR_H_
#ifdef _KERNEL_OPT
#include "opt_pciide.h"
#endif
#include <dev/ata/atavar.h>
#include <dev/ic/wdcreg.h>
#include <dev/ic/wdcvar.h>
#include <sys/device_if.h>
#define PCIIDE_OPTIONS_DMA 0x01
#define PCIIDE_OPTIONS_NODMA 0x02
#ifndef ATADEBUG
#define ATADEBUG
#endif
#define DEBUG_DMA 0x01
#define DEBUG_XFERS 0x02
#define DEBUG_FUNCS 0x08
#define DEBUG_PROBE 0x10
#ifdef ATADEBUG
extern int atadebug_pciide_mask;
#define ATADEBUG_PRINT(args, level) \
if (atadebug_pciide_mask & (level)) printf args
#else
#define ATADEBUG_PRINT(args, level)
#endif
#define PCIIDE_MAX_CHANNELS 4
struct pciide_softc {
struct wdc_softc sc_wdcdev;
pci_chipset_tag_t sc_pc;
pcitag_t sc_tag;
void *sc_pci_ih;
#if NATA_DMA
int sc_dma_ok;
bus_space_tag_t sc_dma_iot;
bus_space_handle_t sc_dma_ioh;
bus_size_t sc_dma_ios;
bus_dma_tag_t sc_dmat;
bus_size_t sc_dma_maxsegsz;
bus_size_t sc_dma_boundary;
bus_addr_t sc_apo_regbase;
const struct cy82c693_handle *sc_cy_handle;
int sc_cy_compatchan;
u_int8_t sis_type;
bus_space_tag_t sc_ba5_st;
bus_space_handle_t sc_ba5_sh;
bus_size_t sc_ba5_ss;
int sc_ba5_en;
#endif
uint sc_cmd_act_channel;
pcireg_t sc_pci_id;
const struct pciide_product_desc *sc_pp;
struct ata_channel *wdc_chanarray[PCIIDE_MAX_CHANNELS];
struct pciide_channel {
struct ata_channel ata_channel;
const char *name;
int compat;
void *ih;
bus_space_handle_t ctl_baseioh;
bus_size_t ctl_ios;
#if NATA_DMA
struct pciide_dma_maps {
bus_dma_segment_t dmamap_table_seg;
int dmamap_table_nseg;
bus_dmamap_t dmamap_table;
struct idedma_table *dma_table;
bus_dmamap_t dmamap_xfer;
int dma_flags;
} dma_maps[WDC_MAXDRIVES];
bus_space_handle_t dma_iohs[IDEDMA_NREGS];
uint8_t idedma_cmd;
#endif
} pciide_channels[PCIIDE_MAX_CHANNELS];
pcireg_t sc_pm_reg[4];
};
#define CHAN_TO_PCIIDE(chp) ((struct pciide_softc *) (chp)->ch_atac)
#define CHAN_TO_PCHAN(chp) ((struct pciide_channel *) (chp))
struct pciide_product_desc {
u_int32_t ide_product;
int ide_flags;
const char *ide_name;
void (*chip_map)(struct pciide_softc*, const struct pci_attach_args*);
};
#define IDE_16BIT_IOSPACE 0x0002
#define IDE_SHARED_CHANNELS 0x0004
static __inline u_int8_t pciide_pci_read(pci_chipset_tag_t, pcitag_t, int);
static __inline void pciide_pci_write(pci_chipset_tag_t, pcitag_t,
int, u_int8_t);
static __inline u_int8_t
pciide_pci_read(pci_chipset_tag_t pc, pcitag_t pa, int reg)
{
return (pci_conf_read(pc, pa, (reg & ~0x03)) >>
((reg & 0x03) * 8) & 0xff);
}
static __inline void
pciide_pci_write(pci_chipset_tag_t pc, pcitag_t pa, int reg, uint8_t val)
{
pcireg_t pcival;
pcival = pci_conf_read(pc, pa, (reg & ~0x03));
pcival &= ~(0xff << ((reg & 0x03) * 8));
pcival |= (val << ((reg & 0x03) * 8));
pci_conf_write(pc, pa, (reg & ~0x03), pcival);
}
void default_chip_map(struct pciide_softc*, const struct pci_attach_args*);
void sata_setup_channel(struct ata_channel*);
void pciide_channel_dma_setup(struct pciide_channel *);
int pciide_dma_table_setup(struct pciide_softc*, int, int);
void pciide_dma_table_teardown(struct pciide_softc *, int, int);
int pciide_dma_dmamap_setup(struct pciide_softc *, int, int,
void *, size_t, int);
int pciide_dma_init(void*, int, int, void *, size_t, int);
void pciide_dma_start(void*, int, int);
int pciide_dma_finish(void*, int, int, int);
void pciide_irqack(struct ata_channel *);
#ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
void *pciide_machdep_compat_intr_establish(device_t,
const struct pci_attach_args *, int, int (*)(void *), void *);
#endif
#ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_DISESTABLISH
void pciide_machdep_compat_intr_disestablish(device_t,
pci_chipset_tag_t, int, void *);
#endif
const struct pciide_product_desc* pciide_lookup_product
(u_int32_t, const struct pciide_product_desc *);
void pciide_common_attach(struct pciide_softc *,
const struct pci_attach_args *,
const struct pciide_product_desc *);
int pciide_common_detach(struct pciide_softc *, int);
int pciide_detach(device_t, int);
int pciide_chipen(struct pciide_softc *, const struct pci_attach_args *);
void pciide_mapregs_compat(const struct pci_attach_args *,
struct pciide_channel *, int);
void pciide_mapregs_native(const struct pci_attach_args *,
struct pciide_channel *, int (*pci_intr)(void *));
void pciide_mapreg_dma(struct pciide_softc *,
const struct pci_attach_args *);
int pciide_chansetup(struct pciide_softc *, int, pcireg_t);
void pciide_mapchan(const struct pci_attach_args *,
struct pciide_channel *, pcireg_t, int (*pci_intr)(void *));
void pciide_map_compat_intr(const struct pci_attach_args *,
struct pciide_channel *, int);
void pciide_unmap_compat_intr(pci_chipset_tag_t,
struct pciide_channel *, int);
int pciide_compat_intr(void *);
int pciide_pci_intr(void *);
#endif