2 * Copyright (c) 2003 Hidetoshi Shimokawa
3 * Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the acknowledgement as bellow:
17 * This product includes software developed by K. Kobayashi and H. Shimokawa
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
34 * $FreeBSD: src/sys/dev/firewire/firewirereg.h,v 1.50 2007/07/20 03:42:57 simokawa Exp $
37 #ifndef _FIREWIREREG_H
38 #define _FIREWIREREG_H
43 typedef d_thread_t fw_proc
;
44 #include <sys/select.h>
45 #elif __FreeBSD_version >= 500000
46 typedef struct thread fw_proc
;
47 #include <sys/selinfo.h>
49 typedef struct proc fw_proc
;
50 #include <sys/select.h>
57 #include <sys/mutex.h>
58 #include <sys/taskqueue.h>
67 #define MAX_REQCOUNT 0xffff
69 STAILQ_HEAD(fw_xferlist
, fw_xfer
);
78 #define CSRROMOFF 0x400
79 #define CSRROMSIZE 0x400
80 int rommax
; /* offset from 0xffff f000 0000 */
81 uint32_t csrrom
[CSRROMSIZE
/4];
83 struct firewire_comm
*fc
;
86 #define FWDEVATTACHED 2
88 STAILQ_ENTRY(fw_device
) link
;
91 struct firewire_softc
{
92 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
95 struct firewire_comm
*fc
;
98 #define FW_MAX_DMACH 0x20
99 #define FW_MAX_DEVCH FW_MAX_DMACH
100 #define FW_XFERTIMEOUT 1
102 struct firewire_dev_comm
{
106 struct firewire_comm
*fc
;
107 void (*post_busreset
) (void *);
108 void (*post_explore
) (void *);
112 u_char hdr_len
; /* IEEE1394 header length */
114 #define FWTI_REQ (1 << 0)
115 #define FWTI_RES (1 << 1)
116 #define FWTI_TLABEL (1 << 2)
117 #define FWTI_BLOCK_STR (1 << 3)
118 #define FWTI_BLOCK_ASY (1 << 4)
123 struct crom_src_buf
{
125 struct crom_chunk root
;
126 struct crom_chunk vendor
;
127 struct crom_chunk hw
;
128 };//move from firewire.c to here
130 struct firewire_notify_hooks
{
131 status_t (*device_attach
)(struct firewire_softc
*sc
, void **cookie
);
132 status_t (*device_detach
)(struct firewire_softc
*sc
, void *cookie
);
135 struct firewire_child_info
{
136 const char *child_name
;
138 struct firewire_notify_hooks notify_hooks
;
139 struct firewire_child_info
*link
;
143 struct firewire_comm
{
157 #define FWPHYASYST (1 << 0)
159 #define FWBUSDETACH (-2)
160 #define FWBUSNOTREADY (-1)
163 #define FWBUSCYMELECT 2
164 #define FWBUSMGRELECT 3
165 #define FWBUSMGRDONE 4
166 #define FWBUSEXPLORE 5
167 #define FWBUSPHYCONF 6
168 #define FWBUSEXPDONE 7
169 #define FWBUSCOMPLETION 10
173 *arq
, *atq
, *ars
, *ats
, *it
[FW_MAX_DMACH
],*ir
[FW_MAX_DMACH
];
174 struct fw_xferlist tlabels
[0x40];
175 u_char last_tlabel
[0x40];
177 struct mtx tlabel_lock
;
181 STAILQ_HEAD(, fw_bind
) binds
;
182 STAILQ_HEAD(, fw_device
) devices
;
184 #define CSRSIZE 0x4000
185 uint32_t csr_arc
[CSRSIZE
/4];
186 #define CROMSIZE 0x400
187 uint32_t *config_rom
;
188 struct crom_src_buf
*crom_src_buf
;
189 struct crom_src
*crom_src
;
190 struct crom_chunk
*crom_root
;
191 struct fw_topology_map
*topology_map
;
192 struct fw_speed_map
*speed_map
;
194 struct callout busprobe_callout
;
195 struct callout bmr_callout
;
196 struct callout timeout_callout
;
197 struct task task_timeout
;
199 timer_id busprobe_callout
;
200 timer_id bmr_callout
;
201 timer_id timeout_callout
;
203 uint32_t (*cyctimer
) (struct firewire_comm
*);
204 void (*ibr
) (struct firewire_comm
*);
205 uint32_t (*set_bmr
) (struct firewire_comm
*, uint32_t);
207 int (*ioctl
) (struct cdev
*, u_long
, caddr_t
, int, fw_proc
*);
209 int (*ioctl
) (void *cookie
, uint32 cmd
, void *arg
, size_t len
);
211 int (*irx_enable
) (struct firewire_comm
*, int);
212 int (*irx_disable
) (struct firewire_comm
*, int);
213 int (*itx_enable
) (struct firewire_comm
*, int);
214 int (*itx_disable
) (struct firewire_comm
*, int);
215 void (*timeout
) (void *);
216 void (*poll
) (struct firewire_comm
*, int, int);
217 void (*set_intr
) (struct firewire_comm
*, int);
218 void (*irx_post
) (struct firewire_comm
*, uint32_t *);
219 void (*itx_post
) (struct firewire_comm
*, uint32_t *);
220 struct tcode_info
*tcode
;
224 struct mtx wait_lock
;
225 struct taskqueue
*taskqueue
;
226 struct proc
*probe_thread
;
231 thread_id probe_thread
;
233 area_id crom_sid_Area
;
234 struct firewire_child_info
*childList
;
237 #define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
239 #define FW_GMTX(fc) (&(fc)->mtx)
240 #define FW_GLOCK(fc) mtx_lock(FW_GMTX(fc))
241 #define FW_GUNLOCK(fc) mtx_unlock(FW_GMTX(fc))
243 #define FW_GLOCK_ASSERT(fc) mtx_assert(FW_GMTX(fc), MA_OWNED)
245 #define FW_GLOCK_ASSERT(fc)
250 #define FWXFERQ_CHTAGMASK 0xff
251 #define FWXFERQ_RUNNING (1 << 8)
252 #define FWXFERQ_STREAM (1 << 9)
254 #define FWXFERQ_BULK (1 << 11)
255 #define FWXFERQ_MODEMASK (7 << 10)
257 #define FWXFERQ_EXTBUF (1 << 13)
258 #define FWXFERQ_OPEN (1 << 14)
260 #define FWXFERQ_HANDLER (1 << 16)
261 #define FWXFERQ_WAKEUP (1 << 17)
262 void (*start
) (struct firewire_comm
*);
264 struct fw_xferlist q
;
268 struct fwdma_alloc_multi
*buf
;
271 struct fw_bulkxfer
*bulkxfer
;
272 STAILQ_HEAD(, fw_bulkxfer
) stvalid
;
273 STAILQ_HEAD(, fw_bulkxfer
) stfree
;
274 STAILQ_HEAD(, fw_bulkxfer
) stdma
;
275 struct fw_bulkxfer
*stproc
;
276 // struct selinfo rsel;
278 void (*hand
) (struct fw_xferq
*);
285 // struct mbuf *mbuf;
286 STAILQ_ENTRY(fw_bulkxfer
) link
;
295 struct fw_xferlist xferlist
;
296 STAILQ_ENTRY(fw_bind
) fclist
;
297 STAILQ_ENTRY(fw_bind
) chlist
;
303 struct firewire_comm
*fc
;
305 // struct timeval tv;
309 #define FWXF_INIT 0x00
310 #define FWXF_INQ 0x01
311 #define FWXF_START 0x02
312 #define FWXF_SENT 0x04
313 #define FWXF_SENTERR 0x08
314 #define FWXF_BUSY 0x10
315 #define FWXF_RCVD 0x20
317 #define FWXF_WAKE 0x80
320 void (*hand
) (struct fw_xfer
*);
329 // struct mbuf *mbuf;
330 STAILQ_ENTRY(fw_xfer
) link
;
331 STAILQ_ENTRY(fw_xfer
) tlabel
;
332 // struct malloc_type *malloc;
337 struct firewire_comm
*fc
;
338 struct fw_xfer
*xfer
;
344 void fw_sidrcv (struct firewire_comm
*, uint32_t *, u_int
);
345 void fw_rcv (struct fw_rcv_buf
*);
346 void fw_xfer_unload ( struct fw_xfer
*);
347 void fw_xfer_free_buf ( struct fw_xfer
*);
348 void fw_xfer_free ( struct fw_xfer
*);
349 struct fw_xfer
*fw_xfer_alloc (void);
350 struct fw_xfer
*fw_xfer_alloc_buf (int, int);
351 void fw_init (struct firewire_comm
*);
352 int fw_tbuf_update (struct firewire_comm
*, int, int);
353 int fw_rbuf_update (struct firewire_comm
*, int, int);
354 int fw_bindadd (struct firewire_comm
*, struct fw_bind
*);
355 int fw_bindremove (struct firewire_comm
*, struct fw_bind
*);
356 int fw_xferlist_add (struct fw_xferlist
*, int, int, int,
357 struct firewire_comm
*, void *, void (*)(struct fw_xfer
*));
358 void fw_xferlist_remove (struct fw_xferlist
*);
359 int fw_asyreq (struct firewire_comm
*, int, struct fw_xfer
*);
360 void fw_busreset (struct firewire_comm
*, uint32_t);
361 uint16_t fw_crc16 (uint32_t *, uint32_t);
362 void fw_xfer_timeout (void *);
363 void fw_xfer_done (struct fw_xfer
*);
364 void fw_xferwake (struct fw_xfer
*);
365 int fw_xferwait (struct fw_xfer
*);
366 void fw_asy_callback_free (struct fw_xfer
*);
367 struct fw_device
*fw_noderesolve_nodeid (struct firewire_comm
*, int);
368 struct fw_device
*fw_noderesolve_eui64 (struct firewire_comm
*, struct fw_eui64
*);
369 struct fw_bind
*fw_bindlookup (struct firewire_comm
*, uint16_t, uint32_t);
370 void fw_drain_txq (struct firewire_comm
*);
371 //int fwdev_makedev (struct firewire_softc *);
372 //int fwdev_destroydev (struct firewire_softc *);
373 //void fwdev_clone (void *, struct ucred *, char *, int, struct cdev **);
374 int fw_open_isodma(struct firewire_comm
*, int);
376 extern int firewire_debug
;
378 extern devclass_t firewire_devclass
;
380 extern int firewire_phydma_enable
;
386 #define FWPRI ((PZERO+8)|PCATCH)
389 #if defined(__DragonFly__) || __FreeBSD_version < 500000
390 #define CALLOUT_INIT(x) callout_init(x)
392 #define CALLOUT_INIT(x) callout_init(x, 1 /* mpsafe */)
395 #if defined(__DragonFly__) || __FreeBSD_version < 500000
396 /* compatibility shim for 4.X */
398 #define bio_bcount b_bcount
399 #define bio_cmd b_flags
400 #define bio_count b_count
401 #define bio_data b_data
402 #define bio_dev b_dev
403 #define bio_error b_error
404 #define bio_flags b_flags
405 #define bio_offset b_offset
406 #define bio_resid b_resid
407 #define BIO_ERROR B_ERROR
408 #define BIO_READ B_READ
409 #define BIO_WRITE B_WRITE
410 #define MIN(a,b) (((a)<(b))?(a):(b))
411 #define MAX(a,b) (((a)>(b))?(a):(b))
414 MALLOC_DECLARE(M_FW
);
415 MALLOC_DECLARE(M_FWXFER
);
418 int firewire_attach(struct firewire_comm
*fc
, struct firewire_softc
*sc
);
419 void firewire_detach(struct firewire_softc
*sc
);
421 status_t
fwohci_pci_attach(int index
);
422 status_t
fwohci_pci_detach(int index
);