Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys add AGP v3 support to agp_generic_enable from FreeBSD



details:   https://anonhg.NetBSD.org/src/rev/71d3308ff0a5
branches:  trunk
changeset: 762076:71d3308ff0a5
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Tue Feb 15 08:57:01 2011 +0000

description:
add AGP v3 support to agp_generic_enable from FreeBSD

diffstat:

 sys/dev/pci/agp.c |  111 +++++++++++++++++++++++++++++++++++++++++++++++++----
 sys/sys/agpio.h   |   22 ++++++++-
 2 files changed, 119 insertions(+), 14 deletions(-)

diffs (208 lines):

diff -r 0a421d2472c4 -r 71d3308ff0a5 sys/dev/pci/agp.c
--- a/sys/dev/pci/agp.c Tue Feb 15 08:56:11 2011 +0000
+++ b/sys/dev/pci/agp.c Tue Feb 15 08:57:01 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: agp.c,v 1.76 2010/11/13 13:52:04 uebayasi Exp $        */
+/*     $NetBSD: agp.c,v 1.77 2011/02/15 08:57:01 jmcneill Exp $        */
 
 /*-
  * Copyright (c) 2000 Doug Rabson
@@ -65,7 +65,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: agp.c,v 1.76 2010/11/13 13:52:04 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: agp.c,v 1.77 2011/02/15 08:57:01 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -100,6 +100,10 @@
 static int agp_deallocate_user(struct agp_softc *, int);
 static int agp_bind_user(struct agp_softc *, agp_bind *);
 static int agp_unbind_user(struct agp_softc *, agp_unbind *);
+static int agp_generic_enable_v2(struct agp_softc *, struct pci_attach_args *,
+                                int, u_int32_t);
+static int agp_generic_enable_v3(struct agp_softc *, struct pci_attach_args *,
+                                int, u_int32_t);
 static int agpdev_match(struct pci_attach_args *);
 static bool agp_resume(device_t, const pmf_qual_t *);
 
@@ -456,8 +460,7 @@
 {
        struct pci_attach_args pa;
        pcireg_t tstatus, mstatus;
-       pcireg_t command;
-       int rq, sba, fw, rate, capoff;
+       int capoff;
 
        if (pci_find_device(&pa, agpdev_match) == 0 ||
            pci_get_capability(pa.pa_pc, pa.pa_tag, PCI_CAP_AGP,
@@ -471,6 +474,27 @@
        mstatus = pci_conf_read(pa.pa_pc, pa.pa_tag,
            capoff + AGP_STATUS);
 
+       if (AGP_MODE_GET_MODE_3(mode) &&
+           AGP_MODE_GET_MODE_3(tstatus) &&
+           AGP_MODE_GET_MODE_3(mstatus))
+               return agp_generic_enable_v3(sc, &pa, capoff, mode);
+       else
+               return agp_generic_enable_v2(sc, &pa, capoff, mode);
+}
+
+static int
+agp_generic_enable_v2(struct agp_softc *sc, struct pci_attach_args *pa,
+    int capoff, u_int32_t mode)
+{
+       pcireg_t tstatus, mstatus;
+       pcireg_t command;
+       int rq, sba, fw, rate;
+
+       tstatus = pci_conf_read(sc->as_pc, sc->as_tag,
+           sc->as_capoff + AGP_STATUS);
+       mstatus = pci_conf_read(pa->pa_pc, pa->pa_tag,
+           capoff + AGP_STATUS);
+
        /* Set RQ to the min of mode, tstatus and mstatus */
        rq = AGP_MODE_GET_RQ(mode);
        if (AGP_MODE_GET_RQ(tstatus) < rq)
@@ -492,12 +516,12 @@
        rate = (AGP_MODE_GET_RATE(tstatus)
                & AGP_MODE_GET_RATE(mstatus)
                & AGP_MODE_GET_RATE(mode));
-       if (rate & AGP_MODE_RATE_4x)
-               rate = AGP_MODE_RATE_4x;
-       else if (rate & AGP_MODE_RATE_2x)
-               rate = AGP_MODE_RATE_2x;
+       if (rate & AGP_MODE_V2_RATE_4x)
+               rate = AGP_MODE_V2_RATE_4x;
+       else if (rate & AGP_MODE_V2_RATE_2x)
+               rate = AGP_MODE_V2_RATE_2x;
        else
-               rate = AGP_MODE_RATE_1x;
+               rate = AGP_MODE_V2_RATE_1x;
 
        /* Construct the new mode word and tell the hardware */
        command = AGP_MODE_SET_RQ(0, rq);
@@ -507,7 +531,74 @@
        command = AGP_MODE_SET_AGP(command, 1);
        pci_conf_write(sc->as_pc, sc->as_tag,
            sc->as_capoff + AGP_COMMAND, command);
-       pci_conf_write(pa.pa_pc, pa.pa_tag, capoff + AGP_COMMAND, command);
+       pci_conf_write(pa->pa_pc, pa->pa_tag, capoff + AGP_COMMAND, command);
+
+       return 0;
+}
+
+static int
+agp_generic_enable_v3(struct agp_softc *sc, struct pci_attach_args *pa,
+    int capoff, u_int32_t mode)
+{
+       pcireg_t tstatus, mstatus;
+       pcireg_t command;
+       int rq, sba, fw, rate, arqsz, cal;
+
+       tstatus = pci_conf_read(sc->as_pc, sc->as_tag,
+           sc->as_capoff + AGP_STATUS);
+       mstatus = pci_conf_read(pa->pa_pc, pa->pa_tag,
+           capoff + AGP_STATUS);
+
+       /* Set RQ to the min of mode, tstatus and mstatus */
+       rq = AGP_MODE_GET_RQ(mode);
+       if (AGP_MODE_GET_RQ(tstatus) < rq)
+               rq = AGP_MODE_GET_RQ(tstatus);
+       if (AGP_MODE_GET_RQ(mstatus) < rq)
+               rq = AGP_MODE_GET_RQ(mstatus);
+
+       /*
+        * ARQSZ - Set the value to the maximum one.
+        * Don't allow the mode register to override values.
+        */
+       arqsz = AGP_MODE_GET_ARQSZ(mode);
+       if (AGP_MODE_GET_ARQSZ(tstatus) > arqsz)
+               arqsz = AGP_MODE_GET_ARQSZ(tstatus);
+       if (AGP_MODE_GET_ARQSZ(mstatus) > arqsz)
+               arqsz = AGP_MODE_GET_ARQSZ(mstatus);
+
+       /* Calibration cycle - don't allow override by mode register */
+       cal = AGP_MODE_GET_CAL(tstatus);
+       if (AGP_MODE_GET_CAL(mstatus) < cal)
+               cal = AGP_MODE_GET_CAL(mstatus);
+
+       /* SBA must be supported for AGP v3. */
+       sba = 1;
+
+       /* Set FW if all three support it. */
+       fw = (AGP_MODE_GET_FW(tstatus)
+              & AGP_MODE_GET_FW(mstatus)
+              & AGP_MODE_GET_FW(mode));
+
+       /* Figure out the max rate */
+       rate = (AGP_MODE_GET_RATE(tstatus)
+               & AGP_MODE_GET_RATE(mstatus)
+               & AGP_MODE_GET_RATE(mode));
+       if (rate & AGP_MODE_V3_RATE_8x)
+               rate = AGP_MODE_V3_RATE_8x;
+       else
+               rate = AGP_MODE_V3_RATE_4x;
+
+       /* Construct the new mode word and tell the hardware */
+       command = AGP_MODE_SET_RQ(0, rq);
+       command = AGP_MODE_SET_ARQSZ(command, arqsz);
+       command = AGP_MODE_SET_CAL(command, cal);
+       command = AGP_MODE_SET_SBA(command, sba);
+       command = AGP_MODE_SET_FW(command, fw);
+       command = AGP_MODE_SET_RATE(command, rate);
+       command = AGP_MODE_SET_AGP(command, 1);
+       pci_conf_write(sc->as_pc, sc->as_tag,
+           sc->as_capoff + AGP_COMMAND, command);
+       pci_conf_write(pa->pa_pc, pa->pa_tag, capoff + AGP_COMMAND, command);
 
        return 0;
 }
diff -r 0a421d2472c4 -r 71d3308ff0a5 sys/sys/agpio.h
--- a/sys/sys/agpio.h   Tue Feb 15 08:56:11 2011 +0000
+++ b/sys/sys/agpio.h   Tue Feb 15 08:57:01 2011 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: agpio.h,v 1.9 2010/10/02 21:52:14 jym Exp $    */
+/*     $NetBSD: agpio.h,v 1.10 2011/02/15 08:57:01 jmcneill Exp $      */
 
 /*-
  * Copyright (c) 2000 Doug Rabson
@@ -41,20 +41,34 @@
  * Macros to manipulate AGP mode words.
  */
 #define AGP_MODE_GET_RQ(x)             (((x) & 0xff000000U) >> 24)
+#define AGP_MODE_GET_ARQSZ(x)          (((x) & 0x0000e000U) >> 13)
+#define AGP_MODE_GET_CAL(x)            (((x) & 0x00001c00U) >> 10)
 #define AGP_MODE_GET_SBA(x)            (((x) & 0x00000200U) >> 9)
 #define AGP_MODE_GET_AGP(x)            (((x) & 0x00000100U) >> 8)
 #define AGP_MODE_GET_4G(x)             (((x) & 0x00000020U) >> 5)
 #define AGP_MODE_GET_FW(x)             (((x) & 0x00000010U) >> 4)
+#define AGP_MODE_GET_MODE_3(x)         (((x) & 0x00000008U) >> 3)
 #define AGP_MODE_GET_RATE(x)           ((x) & 0x00000007U)
 #define AGP_MODE_SET_RQ(x,v)           (((x) & ~0xff000000U) | ((v) << 24))
+#define AGP_MODE_SET_ARQSZ(x,v)                (((x) & ~0x0000e000U) | ((v) << 13))
+#define AGP_MODE_SET_CAL(x,v)          (((x) & ~0x00001c00U) | ((v) << 10))
 #define AGP_MODE_SET_SBA(x,v)          (((x) & ~0x00000200U) | ((v) << 9))
 #define AGP_MODE_SET_AGP(x,v)          (((x) & ~0x00000100U) | ((v) << 8))
 #define AGP_MODE_SET_4G(x,v)           (((x) & ~0x00000020U) | ((v) << 5))
 #define AGP_MODE_SET_FW(x,v)           (((x) & ~0x00000010U) | ((v) << 4))
+#define AGP_MODE_SET_MODE_3(x,v)       (((x) & ~0x00000008U) | ((v) << 3))
 #define AGP_MODE_SET_RATE(x,v)         (((x) & ~0x00000007U) | (v))
-#define AGP_MODE_RATE_1x               0x00000001
-#define AGP_MODE_RATE_2x               0x00000002
-#define AGP_MODE_RATE_4x               0x00000004
+#define AGP_MODE_V2_RATE_1x            0x00000001
+#define AGP_MODE_V2_RATE_2x            0x00000002
+#define AGP_MODE_V2_RATE_4x            0x00000004
+#define AGP_MODE_V3_RATE_4x            0x00000001
+#define AGP_MODE_V3_RATE_8x            0x00000002
+#define AGP_MODE_V3_RATE_RSVD          0x00000004
+
+/* compat */
+#define AGP_MODE_RATE_1x               AGP_MODE_V2_RATE_1x
+#define AGP_MODE_RATE_2x               AGP_MODE_V2_RATE_2x
+#define AGP_MODE_RATE_4x               AGP_MODE_V2_RATE_4x
 
 #define AGPIOC_BASE       'A'
 #define AGPIOC_INFO       _IOR (AGPIOC_BASE, 0, agp_info)



Home | Main Index | Thread Index | Old Index