fwmem.c (106804) | fwmem.c (106810) |
---|---|
1/* 2 * Copyright (C) 2002 3 * Hidetoshi Shimokawa. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * | 1/* 2 * Copyright (C) 2002 3 * Hidetoshi Shimokawa. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * |
34 * $FreeBSD: head/sys/dev/firewire/fwmem.c 106804 2002-11-12 11:08:50Z simokawa $ | 34 * $FreeBSD: head/sys/dev/firewire/fwmem.c 106810 2002-11-12 13:49:17Z simokawa $ |
35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/types.h> 40 41#include <sys/kernel.h> 42#include <sys/malloc.h> --- 6 unchanged lines hidden (view full) --- 49#include <sys/signal.h> 50#include <sys/mman.h> 51#include <sys/ioccom.h> 52 53#include <dev/firewire/firewire.h> 54#include <dev/firewire/firewirereg.h> 55#include <dev/firewire/fwmem.h> 56 | 35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/types.h> 40 41#include <sys/kernel.h> 42#include <sys/malloc.h> --- 6 unchanged lines hidden (view full) --- 49#include <sys/signal.h> 50#include <sys/mman.h> 51#include <sys/ioccom.h> 52 53#include <dev/firewire/firewire.h> 54#include <dev/firewire/firewirereg.h> 55#include <dev/firewire/fwmem.h> 56 |
57static int fwmem_node=0, fwmem_speed=2, fwmem_debug=0; | 57static int fwmem_speed=2, fwmem_debug=0; 58static struct fw_eui64 fwmem_eui64; |
58SYSCTL_DECL(_hw_firewire); 59SYSCTL_NODE(_hw_firewire, OID_AUTO, fwmem, CTLFLAG_RD, 0, 60 "Firewire Memory Access"); | 59SYSCTL_DECL(_hw_firewire); 60SYSCTL_NODE(_hw_firewire, OID_AUTO, fwmem, CTLFLAG_RD, 0, 61 "Firewire Memory Access"); |
61SYSCTL_INT(_hw_firewire_fwmem, OID_AUTO, node, CTLFLAG_RW, &fwmem_node, 0, 62 "Fwmem target node"); | 62SYSCTL_UINT(_hw_firewire_fwmem, OID_AUTO, eui64_hi, CTLFLAG_RW, 63 &fwmem_eui64.hi, 0, "Fwmem target EUI64 high"); 64SYSCTL_UINT(_hw_firewire_fwmem, OID_AUTO, eui64_low, CTLFLAG_RW, 65 &fwmem_eui64.lo, 0, "Fwmem target EUI64 low"); |
63SYSCTL_INT(_hw_firewire_fwmem, OID_AUTO, speed, CTLFLAG_RW, &fwmem_speed, 0, 64 "Fwmem link speed"); 65SYSCTL_INT(_debug, OID_AUTO, fwmem_debug, CTLFLAG_RW, &fwmem_debug, 0, 66 "Fwmem driver debug flag"); 67 68struct fw_xfer * 69fwmem_read_quad( | 66SYSCTL_INT(_hw_firewire_fwmem, OID_AUTO, speed, CTLFLAG_RW, &fwmem_speed, 0, 67 "Fwmem link speed"); 68SYSCTL_INT(_debug, OID_AUTO, fwmem_debug, CTLFLAG_RW, &fwmem_debug, 0, 69 "Fwmem driver debug flag"); 70 71struct fw_xfer * 72fwmem_read_quad( |
70 struct firewire_comm *fc, | 73 struct fw_device *fwdev, 74 caddr_t sc, |
71 u_int8_t spd, | 75 u_int8_t spd, |
72 int dst, | |
73 u_int16_t dst_hi, 74 u_int32_t dst_lo, 75 void (*hand)(struct fw_xfer *)) 76{ 77 struct fw_xfer *xfer; 78 struct fw_pkt *fp; 79 80 xfer = fw_xfer_alloc(); 81 if (xfer == NULL) 82 return NULL; 83 | 76 u_int16_t dst_hi, 77 u_int32_t dst_lo, 78 void (*hand)(struct fw_xfer *)) 79{ 80 struct fw_xfer *xfer; 81 struct fw_pkt *fp; 82 83 xfer = fw_xfer_alloc(); 84 if (xfer == NULL) 85 return NULL; 86 |
84 xfer->fc = fc; 85 xfer->dst = FWLOCALBUS | dst; | 87 xfer->fc = fwdev->fc; 88 xfer->dst = FWLOCALBUS | fwdev->dst; |
86 xfer->spd = spd; 87 xfer->send.len = 12; 88 xfer->send.buf = malloc(xfer->send.len, M_DEVBUF, M_NOWAIT | M_ZERO); 89 90 if (xfer->send.buf == NULL) 91 goto error; 92 93 xfer->send.off = 0; 94 xfer->act.hand = hand; 95 xfer->retry_req = fw_asybusy; 96 xfer->sc = NULL; 97 98 fp = (struct fw_pkt *)xfer->send.buf; 99 fp->mode.rreqq.tcode = FWTCODE_RREQQ; 100 fp->mode.rreqq.dst = htons(xfer->dst); 101 fp->mode.rreqq.dest_hi = htons(dst_hi); 102 fp->mode.rreqq.dest_lo = htonl(dst_lo); 103 104 if (fwmem_debug) | 89 xfer->spd = spd; 90 xfer->send.len = 12; 91 xfer->send.buf = malloc(xfer->send.len, M_DEVBUF, M_NOWAIT | M_ZERO); 92 93 if (xfer->send.buf == NULL) 94 goto error; 95 96 xfer->send.off = 0; 97 xfer->act.hand = hand; 98 xfer->retry_req = fw_asybusy; 99 xfer->sc = NULL; 100 101 fp = (struct fw_pkt *)xfer->send.buf; 102 fp->mode.rreqq.tcode = FWTCODE_RREQQ; 103 fp->mode.rreqq.dst = htons(xfer->dst); 104 fp->mode.rreqq.dest_hi = htons(dst_hi); 105 fp->mode.rreqq.dest_lo = htonl(dst_lo); 106 107 if (fwmem_debug) |
105 printf("fwmem: %d %04x:%08x\n", dst, dst_hi, dst_lo); | 108 printf("fwmem: %d %04x:%08x\n", fwdev->dst, dst_hi, dst_lo); |
106 | 109 |
107 if (fw_asyreq(fc, -1, xfer) == 0) | 110 if (fw_asyreq(xfer->fc, -1, xfer) == 0) |
108 return xfer; 109 110error: 111 fw_xfer_free(xfer); 112 return NULL; 113} 114 115struct fw_xfer * | 111 return xfer; 112 113error: 114 fw_xfer_free(xfer); 115 return NULL; 116} 117 118struct fw_xfer * |
119fwmem_write_quad( 120 struct fw_device *fwdev, 121 caddr_t sc, 122 u_int8_t spd, 123 u_int16_t dst_hi, 124 u_int32_t dst_lo, 125 u_int32_t data, 126 void (*hand)(struct fw_xfer *)) 127{ 128 struct fw_xfer *xfer; 129 struct fw_pkt *fp; 130 131 xfer = fw_xfer_alloc(); 132 if (xfer == NULL) 133 return NULL; 134 135 xfer->fc = fwdev->fc; 136 xfer->dst = FWLOCALBUS | fwdev->dst; 137 xfer->spd = spd; 138 xfer->send.len = 16; 139 xfer->send.buf = malloc(xfer->send.len, M_DEVBUF, M_NOWAIT | M_ZERO); 140 141 if (xfer->send.buf == NULL) 142 goto error; 143 144 xfer->send.off = 0; 145 xfer->act.hand = hand; 146 xfer->retry_req = fw_asybusy; 147 xfer->sc = sc; 148 149 fp = (struct fw_pkt *)xfer->send.buf; 150 fp->mode.wreqq.tcode = FWTCODE_RREQQ; 151 fp->mode.wreqq.dst = htons(xfer->dst); 152 fp->mode.wreqq.dest_hi = htons(dst_hi); 153 fp->mode.wreqq.dest_lo = htonl(dst_lo); 154 155 fp->mode.wreqq.data = htonl(data); 156 157 if (fwmem_debug) 158 printf("fwmem: %d %04x:%08x\n", fwdev->dst, dst_hi, dst_lo); 159 160 if (fw_asyreq(xfer->fc, -1, xfer) == 0) 161 return xfer; 162 163error: 164 fw_xfer_free(xfer); 165 return NULL; 166} 167 168struct fw_xfer * |
|
116fwmem_read_block( | 169fwmem_read_block( |
117 struct firewire_comm *fc, | 170 struct fw_device *fwdev, 171 caddr_t sc, |
118 u_int8_t spd, | 172 u_int8_t spd, |
119 int dst, | |
120 u_int16_t dst_hi, 121 u_int32_t dst_lo, 122 int len, 123 void (*hand)(struct fw_xfer *)) 124{ 125 struct fw_xfer *xfer; 126 struct fw_pkt *fp; 127 128 xfer = fw_xfer_alloc(); 129 if (xfer == NULL) 130 return NULL; 131 | 173 u_int16_t dst_hi, 174 u_int32_t dst_lo, 175 int len, 176 void (*hand)(struct fw_xfer *)) 177{ 178 struct fw_xfer *xfer; 179 struct fw_pkt *fp; 180 181 xfer = fw_xfer_alloc(); 182 if (xfer == NULL) 183 return NULL; 184 |
132 xfer->fc = fc; 133 xfer->dst = FWLOCALBUS | dst; | 185 xfer->fc = fwdev->fc; 186 xfer->dst = FWLOCALBUS | fwdev->dst; |
134 xfer->spd = spd; 135 xfer->send.len = 16; 136 xfer->send.buf = malloc(xfer->send.len, M_DEVBUF, M_NOWAIT | M_ZERO); 137 138 if (xfer->send.buf == NULL) 139 goto error; 140 141 xfer->send.off = 0; --- 4 unchanged lines hidden (view full) --- 146 fp = (struct fw_pkt *)xfer->send.buf; 147 fp->mode.rreqb.tcode = FWTCODE_RREQB; 148 fp->mode.rreqb.dst = htons(xfer->dst); 149 fp->mode.rreqb.dest_hi = htons(dst_hi); 150 fp->mode.rreqb.dest_lo = htonl(dst_lo); 151 fp->mode.rreqb.len = htons(len); 152 153 if (fwmem_debug) | 187 xfer->spd = spd; 188 xfer->send.len = 16; 189 xfer->send.buf = malloc(xfer->send.len, M_DEVBUF, M_NOWAIT | M_ZERO); 190 191 if (xfer->send.buf == NULL) 192 goto error; 193 194 xfer->send.off = 0; --- 4 unchanged lines hidden (view full) --- 199 fp = (struct fw_pkt *)xfer->send.buf; 200 fp->mode.rreqb.tcode = FWTCODE_RREQB; 201 fp->mode.rreqb.dst = htons(xfer->dst); 202 fp->mode.rreqb.dest_hi = htons(dst_hi); 203 fp->mode.rreqb.dest_lo = htonl(dst_lo); 204 fp->mode.rreqb.len = htons(len); 205 206 if (fwmem_debug) |
154 printf("fwmem: %d %04x:%08x %d\n", dst, dst_hi, dst_lo, len); 155 if (fw_asyreq(fc, -1, xfer) == 0) | 207 printf("fwmem: %d %04x:%08x %d\n", fwdev->dst, 208 dst_hi, dst_lo, len); 209 if (fw_asyreq(xfer->fc, -1, xfer) == 0) |
156 return xfer; 157 158error: 159 fw_xfer_free(xfer); 160 return NULL; 161} 162 163int --- 11 unchanged lines hidden (view full) --- 175} 176 177#define MAXLEN 2048 178#define USE_QUAD 0 179int 180fwmem_read (dev_t dev, struct uio *uio, int ioflag) 181{ 182 struct firewire_softc *sc; | 210 return xfer; 211 212error: 213 fw_xfer_free(xfer); 214 return NULL; 215} 216 217int --- 11 unchanged lines hidden (view full) --- 229} 230 231#define MAXLEN 2048 232#define USE_QUAD 0 233int 234fwmem_read (dev_t dev, struct uio *uio, int ioflag) 235{ 236 struct firewire_softc *sc; |
183 struct firewire_comm *fc; | 237 struct fw_device *fwdev; |
184 struct fw_xfer *xfer; 185 int err = 0, pad; 186 int unit = DEV2UNIT(dev); 187 u_int16_t dst_hi; 188 u_int32_t dst_lo; 189 off_t offset; 190 int len; 191 192 sc = devclass_get_softc(firewire_devclass, unit); | 238 struct fw_xfer *xfer; 239 int err = 0, pad; 240 int unit = DEV2UNIT(dev); 241 u_int16_t dst_hi; 242 u_int32_t dst_lo; 243 off_t offset; 244 int len; 245 246 sc = devclass_get_softc(firewire_devclass, unit); |
193 fc = sc->fc; | 247 fwdev = fw_noderesolve(sc->fc, fwmem_eui64); 248 if (fwdev == NULL) { 249 printf("fwmem: no such device ID:%08x%08x\n", 250 fwmem_eui64.hi, fwmem_eui64.lo); 251 return EINVAL; 252 } |
194 195 pad = uio->uio_offset % 4; 196 if (fwmem_debug && pad != 0) 197 printf("unaligned\n"); 198 while(uio->uio_resid > 0) { 199 offset = uio->uio_offset; 200 offset -= pad; 201 dst_hi = (offset >> 32) & 0xffff; 202 dst_lo = offset & 0xffffffff; 203#if USE_QUAD | 253 254 pad = uio->uio_offset % 4; 255 if (fwmem_debug && pad != 0) 256 printf("unaligned\n"); 257 while(uio->uio_resid > 0) { 258 offset = uio->uio_offset; 259 offset -= pad; 260 dst_hi = (offset >> 32) & 0xffff; 261 dst_lo = offset & 0xffffffff; 262#if USE_QUAD |
204 xfer = fwmem_read_quad(fc, fwmem_speed, fwmem_node, | 263 xfer = fwmem_read_quad(fwdev, NULL, fwmem_speed, |
205 dst_hi, dst_lo, fw_asy_callback); 206 if (xfer == NULL) 207 return EINVAL; 208 err = tsleep((caddr_t)xfer, FWPRI, "fwmem", hz); 209 if (err !=0 || xfer->resp != 0 || xfer->recv.buf == NULL) 210 return EINVAL; /* XXX */ 211 err = uiomove(xfer->recv.buf + xfer->recv.off + 4*3 + pad, 212 4 - pad, uio); 213#else 214 len = uio->uio_resid; 215 if (len > MAXLEN) 216 len = MAXLEN; | 264 dst_hi, dst_lo, fw_asy_callback); 265 if (xfer == NULL) 266 return EINVAL; 267 err = tsleep((caddr_t)xfer, FWPRI, "fwmem", hz); 268 if (err !=0 || xfer->resp != 0 || xfer->recv.buf == NULL) 269 return EINVAL; /* XXX */ 270 err = uiomove(xfer->recv.buf + xfer->recv.off + 4*3 + pad, 271 4 - pad, uio); 272#else 273 len = uio->uio_resid; 274 if (len > MAXLEN) 275 len = MAXLEN; |
217 xfer = fwmem_read_block(fc, fwmem_speed, fwmem_node, | 276 xfer = fwmem_read_block(fwdev, NULL, fwmem_speed, |
218 dst_hi, dst_lo, len, fw_asy_callback); 219 if (xfer == NULL) 220 return EINVAL; 221 err = tsleep((caddr_t)xfer, FWPRI, "fwmem", hz); 222 if (err != 0 || xfer->resp != 0 || xfer->recv.buf == NULL) 223 return EINVAL; /* XXX */ 224 err = uiomove(xfer->recv.buf + xfer->recv.off + 4*4 + pad, 225 len - pad, uio); --- 28 unchanged lines hidden --- | 277 dst_hi, dst_lo, len, fw_asy_callback); 278 if (xfer == NULL) 279 return EINVAL; 280 err = tsleep((caddr_t)xfer, FWPRI, "fwmem", hz); 281 if (err != 0 || xfer->resp != 0 || xfer->recv.buf == NULL) 282 return EINVAL; /* XXX */ 283 err = uiomove(xfer->recv.buf + xfer->recv.off + 4*4 + pad, 284 len - pad, uio); --- 28 unchanged lines hidden --- |