summaryrefslogtreecommitdiff
path: root/sys/dev/pci
diff options
context:
space:
mode:
authorDavid Gwynne <dlg@cvs.openbsd.org>2007-07-02 14:01:15 +0000
committerDavid Gwynne <dlg@cvs.openbsd.org>2007-07-02 14:01:15 +0000
commit63ed4de470c61a8b706398104d73eae11ed12624 (patch)
tree1648015e151371da0c9140e11555e440ae604488 /sys/dev/pci
parentb791c508bea0b43ae972e64ba85de4e7fb2a88c9 (diff)
kettenis suggested that i can use pci_intr_map twice on the same device
safely, so i tried it and it worked great. i can reuse the pci_attach_args to attach ahci and now pciide to jmb without really modifying either of them. lots of code shrinks. ok jsg@
Diffstat (limited to 'sys/dev/pci')
-rw-r--r--sys/dev/pci/ahci.c6
-rw-r--r--sys/dev/pci/files.pci20
-rw-r--r--sys/dev/pci/jmb.c91
-rw-r--r--sys/dev/pci/pciide.c24
4 files changed, 62 insertions, 79 deletions
diff --git a/sys/dev/pci/ahci.c b/sys/dev/pci/ahci.c
index bfce1cb469b..390483770db 100644
--- a/sys/dev/pci/ahci.c
+++ b/sys/dev/pci/ahci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ahci.c,v 1.125 2007/07/02 01:29:54 dlg Exp $ */
+/* $OpenBSD: ahci.c,v 1.126 2007/07/02 14:01:13 dlg Exp $ */
/*
* Copyright (c) 2006 David Gwynne <dlg@openbsd.org>
@@ -402,6 +402,10 @@ struct cfattach ahci_pci_ca = {
sizeof(struct ahci_softc), ahci_pci_match, ahci_pci_attach
};
+struct cfattach ahci_jmb_ca = {
+ sizeof(struct ahci_softc), ahci_pci_match, ahci_pci_attach
+};
+
struct cfdriver ahci_cd = {
NULL, "ahci", DV_DULL
};
diff --git a/sys/dev/pci/files.pci b/sys/dev/pci/files.pci
index ca4c67b7a04..21ccc611ddd 100644
--- a/sys/dev/pci/files.pci
+++ b/sys/dev/pci/files.pci
@@ -1,4 +1,4 @@
-# $OpenBSD: files.pci,v 1.238 2007/07/02 01:14:36 dlg Exp $
+# $OpenBSD: files.pci,v 1.239 2007/07/02 14:01:13 dlg Exp $
# $NetBSD: files.pci,v 1.20 1996/09/24 17:47:15 christos Exp $
#
# Config file and device description for machine-independent PCI code.
@@ -79,17 +79,16 @@ device arc: scsi
attach arc at pci
file dev/pci/arc.c arc
-# Advanced Host Controller Interface for Serial ATA
-device ahci: scsi, atascsi
-attach ahci at pci with ahci_pci
-file dev/pci/ahci.c ahci | ahci_pci
-
# JMicron JMB36x controllers
device jmb {}
attach jmb at pci
-attach ahci at jmb with ahci_jmb
-file dev/pci/jmb.c jmb | ahci_jmb
+file dev/pci/jmb.c jmb
+# Advanced Host Controller Interface for Serial ATA
+device ahci: scsi, atascsi
+attach ahci at pci with ahci_pci
+attach ahci at jmb with ahci_jmb
+file dev/pci/ahci.c ahci | ahci_pci | ahci_jmb
# AMI MegaRAID Express x00/Elite 1500/Express 1x00 RAID Controllers
attach ami at pci with ami_pci
@@ -264,8 +263,9 @@ file dev/pci/neo.c neo
# PCI IDE controllers
device pciide {[channel = -1]}: cy82c693, wdc_base, ata, atapi
-attach pciide at pci
-file dev/pci/pciide.c pciide
+attach pciide at pci with pciide_pci
+attach pciide at jmb with pciide_jmb
+file dev/pci/pciide.c pciide | pciide_pci | pciide_jmb
# PCI-PCI bridge chips
device ppb: pcibus
diff --git a/sys/dev/pci/jmb.c b/sys/dev/pci/jmb.c
index 12b78cc18b1..abad16379b7 100644
--- a/sys/dev/pci/jmb.c
+++ b/sys/dev/pci/jmb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: jmb.c,v 1.2 2007/07/02 07:17:34 dlg Exp $ */
+/* $OpenBSD: jmb.c,v 1.3 2007/07/02 14:01:14 dlg Exp $ */
/*
* Copyright (c) 2007 David Gwynne <dlg@openbsd.org>
@@ -31,10 +31,6 @@
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
-#include <dev/ata/atascsi.h>
-
-#include <dev/pci/ahcivar.h>
-
/* JMicron registers */
#define JM_PCI_CTL0 0x40 /* control register 0 */
#define JM_PCI_CTL0_ROM_EN (1<<31) /* External Option ROM */
@@ -85,22 +81,13 @@ struct cfdriver jmb_cd = {
NULL, "jmb", DV_DULL
};
-
-struct jmb_attach_args {
- enum {
- JMB_DEV_AHCI,
- JMB_DEV_IDE
- } ja_dev;
- struct pci_attach_args *ja_pa;
- pci_intr_handle_t ja_ih;
-};
-
static const struct pci_matchid jmb_devices[] = {
{ PCI_VENDOR_JMICRON, PCI_PRODUCT_JMICRON_JMB360 },
{ PCI_VENDOR_JMICRON, PCI_PRODUCT_JMICRON_JMB361 },
{ PCI_VENDOR_JMICRON, PCI_PRODUCT_JMICRON_JMB363 },
{ PCI_VENDOR_JMICRON, PCI_PRODUCT_JMICRON_JMB365 },
- { PCI_VENDOR_JMICRON, PCI_PRODUCT_JMICRON_JMB366 }
+ { PCI_VENDOR_JMICRON, PCI_PRODUCT_JMICRON_JMB366 },
+ { PCI_VENDOR_JMICRON, PCI_PRODUCT_JMICRON_JMB368 }
};
int
@@ -109,14 +96,13 @@ jmb_match(struct device *parent, void *match, void *aux)
struct pci_attach_args *pa = aux;
return (pci_matchbyid(pa, jmb_devices,
- sizeof(jmb_devices) / sizeof(jmb_devices[0])));
+ sizeof(jmb_devices) / sizeof(jmb_devices[0])) * 3);
}
void
jmb_attach(struct device *parent, struct device *self, void *aux)
{
- struct pci_attach_args *pa = aux;
- struct jmb_attach_args ja;
+ struct pci_attach_args *pa = aux, jpa;
u_int32_t ctl0, ctl5;
ctl0 = pci_conf_read(pa->pa_pc, pa->pa_tag, JM_PCI_CTL0);
@@ -135,7 +121,7 @@ jmb_attach(struct device *parent, struct device *self, void *aux)
/* set to single function AHCI mode */
ctl0 |= JM_PCI_CTL0_AHCI_EN | JM_PCI_CTL0_SATA0_AHCI |
JM_PCI_CTL0_SATA1_AHCI |
- JM_PCI_CTL0_F0_SUBCLASS(JM_PCI_CTL0_SUBCLASS_AHCI);
+ JM_PCI_CTL0_F0_SUBCLASS(JM_PCI_CTL0_SUBCLASS_IDE);
break;
case PCI_PRODUCT_JMICRON_JMB366:
@@ -148,69 +134,42 @@ jmb_attach(struct device *parent, struct device *self, void *aux)
/* enable AHCI */
ctl0 |= JM_PCI_CTL0_AHCI_EN |
JM_PCI_CTL0_SATA0_AHCI | JM_PCI_CTL0_SATA1_AHCI |
- JM_PCI_CTL0_PCIIDE_CS | JM_PCI_CTL0_IDEDMA_CFG;
+ JM_PCI_CTL0_PCIIDE_CS | JM_PCI_CTL0_IDEDMA_CFG |
+ JM_PCI_CTL0_F0_SUBCLASS(JM_PCI_CTL0_SUBCLASS_AHCI);
break;
}
pci_conf_write(pa->pa_pc, pa->pa_tag, JM_PCI_CTL0, ctl0);
pci_conf_write(pa->pa_pc, pa->pa_tag, JM_PCI_CTL5, ctl5);
- bzero(&ja, sizeof(ja));
- ja.ja_pa = pa;
+ printf("\n");
- if (pci_intr_map(pa, &ja.ja_ih) != 0) {
- printf(": unable to map interrupt\n");
- return;
- }
- printf(": %s\n", pci_intr_string(pa->pa_pc, ja.ja_ih));
+ jpa = *pa;
- ja.ja_dev = JMB_DEV_AHCI;
- config_found(self, &ja, jmb_print);
+ /* tweak the class to look like ahci, then try to attach it */
+ jpa.pa_class = (PCI_CLASS_MASS_STORAGE << PCI_CLASS_SHIFT) |
+ (PCI_SUBCLASS_MASS_STORAGE_SATA << PCI_SUBCLASS_SHIFT) |
+ (0x01 << PCI_INTERFACE_SHIFT); /* AHCI_PCI_INTERFACE */
+ config_found(self, &jpa, jmb_print);
- ja.ja_dev = JMB_DEV_IDE;
- config_found(self, &ja, jmb_print);
+ /* set things up for pciide */
+ jpa.pa_class = (PCI_CLASS_MASS_STORAGE << PCI_CLASS_SHIFT) |
+ (PCI_SUBCLASS_MASS_STORAGE_IDE << PCI_SUBCLASS_SHIFT) |
+ (0x85 << PCI_INTERFACE_SHIFT);
+ config_found(self, &jpa, jmb_print);
}
int
jmb_print(void *aux, const char *pnp)
{
- struct jmb_attach_args *ja = aux;
+ struct pci_attach_args *pa = aux;
+ char devinfo[256];
if (pnp != NULL) {
- printf("\"%s\" at %s",
- (ja->ja_dev == JMB_DEV_AHCI) ? "sata" : "pata", pnp);
+ pci_devinfo(pa->pa_id, pa->pa_class, 1, devinfo,
+ sizeof(devinfo));
+ printf("%s at %s", devinfo, pnp);
}
return (UNCONF);
}
-
-
-int ahci_jmb_match(struct device *, void *, void *);
-void ahci_jmb_attach(struct device *, struct device *,
- void *);
-
-struct cfattach ahci_jmb_ca = {
- sizeof(struct ahci_softc), ahci_jmb_match, ahci_jmb_attach
-};
-
-int
-ahci_jmb_match(struct device *parent, void *match, void *aux)
-{
- struct jmb_attach_args *ja = aux;
-
- if (ja->ja_dev == JMB_DEV_AHCI)
- return (1);
-
- return (0);
-}
-
-void
-ahci_jmb_attach(struct device *parent, struct device *self, void *aux)
-{
- struct ahci_softc *sc = (struct ahci_softc *)self;
- struct jmb_attach_args *ja = aux;
-
- printf(":");
-
- ahci_attach(sc, ja->ja_pa, ja->ja_ih);
-}
diff --git a/sys/dev/pci/pciide.c b/sys/dev/pci/pciide.c
index 1461c9a57bb..37bf4ce7834 100644
--- a/sys/dev/pci/pciide.c
+++ b/sys/dev/pci/pciide.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pciide.c,v 1.271 2007/06/26 17:48:18 kettenis Exp $ */
+/* $OpenBSD: pciide.c,v 1.272 2007/07/02 14:01:14 dlg Exp $ */
/* $NetBSD: pciide.c,v 1.127 2001/08/03 01:31:08 tsutsui Exp $ */
/*
@@ -1062,6 +1062,22 @@ const struct pciide_product_desc pciide_ati_products[] = {
};
const struct pciide_product_desc pciide_jmicron_products[] = {
+ { PCI_PRODUCT_JMICRON_JMB361,
+ 0,
+ jmicron_chip_map
+ },
+ { PCI_PRODUCT_JMICRON_JMB363,
+ 0,
+ jmicron_chip_map
+ },
+ { PCI_PRODUCT_JMICRON_JMB365,
+ 0,
+ jmicron_chip_map
+ },
+ { PCI_PRODUCT_JMICRON_JMB366,
+ 0,
+ jmicron_chip_map
+ },
{ PCI_PRODUCT_JMICRON_JMB368,
0,
jmicron_chip_map
@@ -1119,7 +1135,11 @@ const struct pciide_vendor_desc pciide_vendors[] = {
int pciide_match(struct device *, void *, void *);
void pciide_attach(struct device *, struct device *, void *);
-struct cfattach pciide_ca = {
+struct cfattach pciide_pci_ca = {
+ sizeof(struct pciide_softc), pciide_match, pciide_attach
+};
+
+struct cfattach pciide_jmb_ca = {
sizeof(struct pciide_softc), pciide_match, pciide_attach
};