kern/128608: [patch] add support for powering down and up Cardbus
cards
Nick Hibma
nick at anywi.com
Wed Nov 5 04:30:09 PST 2008
>Number: 128608
>Category: kern
>Synopsis: [patch] add support for powering down and up Cardbus cards
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Wed Nov 05 12:30:05 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: Nick Hibma
>Release: FSBD-7-STABLE
>Organization:
AnyWi Technologies
>Environment:
FreeBSD hind.van-laarhoven.org 7.0-STABLE FreeBSD 7.0-STABLE #3: Thu Aug 14 21:10:55 CEST 2008 toor at hind.van-laarhoven.org:/usr/src/sys/i386/compile/HIND i386
>Description:
The supplied patch allows powering down and up cardbus slots through a sysctl.
Warner has been sent this patch for review as I do not know whether a sysctl is the right way.
With his permission I would be happy to commit this patch into current, followed by MFC to 7 and then 6.
Possible problems:
- need to check whether detachment is done properly (it does IMHO).
- usability: what about having switched off the power and then inserting a card, and ... surprise, surprise... the card does not work. Can this be detected and power automatically switched on? Haven't tried whether this is a problem at all.
>How-To-Repeat:
% sysctl dev.cbb.0.powered
dev.cbb.0.powered: 1
% sudo sysctl dev.cbb.0.powered=0
dev.cbb.0.powered: 1 -> 0
% sysctl dev.cbb.0.powered
dev.cbb.0.powered: 0
% sudo sysctl dev.cbb.0.powered=1
dev.cbb.0.powered: 0 -> 1
>Fix:
See attached diff.
Patch attached with submission follows:
Index: pccbb.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/pccbb/pccbb.c,v
retrieving revision 1.165
diff -u -r1.165 pccbb.c
--- pccbb.c 30 Sep 2007 11:05:15 -0000 1.165
+++ pccbb.c 11 Aug 2008 12:49:34 -0000
@@ -479,7 +479,7 @@
mtx_lock(&Giant);
status = cbb_get(sc, CBB_SOCKET_STATE);
DPRINTF(("Status is 0x%x\n", status));
- if (!CBB_CARD_PRESENT(status)) {
+ if (!CBB_CARD_PRESENT(status) || !sc->powered) {
not_a_card = 0; /* We know card type */
cbb_removal(sc);
} else if (status & CBB_STATE_NOT_A_CARD) {
@@ -1557,3 +1557,24 @@
sockstate = cbb_get(sc, CBB_SOCKET_STATE);
return (CBB_CARD_PRESENT(sockstate) && sc->cardok);
}
+
+int
+cbb_powered_sysctl(SYSCTL_HANDLER_ARGS)
+{
+ int error, powered;
+ struct cbb_softc *sc = (struct cbb_softc *)arg1;
+
+ powered = sc->powered;
+ error = sysctl_handle_int(oidp, &powered, 0, req);
+ if (error || !req->newptr)
+ return error;
+
+ if (powered != sc->powered) {
+ sc->powered = powered;
+ cv_signal(&sc->cv);
+ }
+
+ return error;
+}
+
+
Index: pccbb_pci.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/pccbb/pccbb_pci.c,v
retrieving revision 1.26
diff -u -r1.26 pccbb_pci.c
--- pccbb_pci.c 30 Sep 2007 11:05:15 -0000 1.26
+++ pccbb_pci.c 11 Aug 2008 12:50:33 -0000
@@ -365,6 +365,9 @@
SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "io2",
CTLFLAG_RD, &sc->subbus, 0, "io range 2 open");
#endif
+ SYSCTL_ADD_PROC(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "powered",
+ CTLTYPE_INT|CTLFLAG_RW, (void *)sc, 0, cbb_powered_sysctl, "I", "Slots powered");
+ sc->powered = 1;
/*
* This is a gross hack. We should be scanning the entire pci
Index: pccbbvar.h
===================================================================
RCS file: /home/ncvs/src/sys/dev/pccbb/pccbbvar.h,v
retrieving revision 1.32
diff -u -r1.32 pccbbvar.h
--- pccbbvar.h 30 Sep 2007 11:05:15 -0000 1.32
+++ pccbbvar.h 11 Aug 2008 12:50:07 -0000
@@ -90,6 +90,8 @@
struct proc *event_thread;
void (*chipinit)(struct cbb_softc *);
volatile int powerintr;
+
+ int powered;
};
/* result of detect_card */
@@ -145,6 +147,7 @@
void *cookie);
int cbb_write_ivar(device_t brdev, device_t child, int which,
uintptr_t value);
+int cbb_powered_sysctl(SYSCTL_HANDLER_ARGS);
/*
*/
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list