work from JiSheng Zhang : firewire and ohci modules from FreeBSD current, update for fw_raw and fw_control. Thanks!

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22124 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2007-08-30 21:59:49 +00:00
parent 68f2081497
commit bb5ea4eb08
27 changed files with 7725 additions and 98 deletions
+39 -41
View File
@@ -5,63 +5,61 @@
*/
#ifndef _FW_MODULE_H
#define _FW_MODULE_H
#include <KernelExport.h>
#include <module.h>
#include <bus_manager.h>
#include "firewire.h"
#include "firewirereg.h"
#define FIREWIRE_MODULE_NAME "bus_managers/firewire/v1"
#define MAX_CARDS 4
struct fw_module_info{
bus_manager_info binfo;
struct fw_device * (*fw_noderesolve_nodeid)(struct firewire_comm *fc, int dst);
struct fw_device * (*fw_noderesolve_nodeid)(struct firewire_comm *fc, int dst);
struct fw_device * (*fw_noderesolve_eui64)(struct firewire_comm *fc, struct fw_eui64 *eui);
struct fw_device * (*fw_noderesolve_eui64)(struct firewire_comm *fc, struct fw_eui64 *eui);
int (*fw_asyreq)(struct firewire_comm *fc, int sub, struct fw_xfer *xfer);
int (*fw_asyreq)(struct firewire_comm *fc, int sub, struct fw_xfer *xfer);
void (*fw_xferwake)(struct fw_xfer *xfer);
int (*fw_xferwait)(struct fw_xfer *xfer);
void (*fw_xferwake)(struct fw_xfer *xfer);
int (*fw_xferwait)(struct fw_xfer *xfer);
struct fw_bind * (*fw_bindlookup)(struct firewire_comm *fc, uint16_t dest_hi, uint32_t dest_lo);
struct fw_bind * (*fw_bindlookup)(struct firewire_comm *fc, uint16_t dest_hi, uint32_t dest_lo);
int (*fw_bindadd)(struct firewire_comm *fc, struct fw_bind *fwb);
int (*fw_bindremove)(struct firewire_comm *fc, struct fw_bind *fwb);
int (*fw_xferlist_add)(struct fw_xferlist *q,
int slen, int rlen, int n,
struct firewire_comm *fc, void *sc, void (*hand)(struct fw_xfer *));
void (*fw_xferlist_remove)(struct fw_xferlist *q);
struct fw_xfer * (*fw_xfer_alloc)();
struct fw_xfer * (*fw_xfer_alloc_buf)(int send_len, int recv_len);
void (*fw_xfer_done)(struct fw_xfer *xfer);
void (*fw_xfer_unload)(struct fw_xfer* xfer);
void (*fw_xfer_free_buf)( struct fw_xfer* xfer);
void (*fw_xfer_free)( struct fw_xfer* xfer);
void (*fw_asy_callback_free)(struct fw_xfer *xfer);
int (*fw_open_isodma)(struct firewire_comm *fc, int tx);
int (*get_handle)(int socket, struct firewire_softc *handle);
struct fwdma_alloc_multi * (*fwdma_malloc_multiseg)(int alignment,
int esize, int n);
void (*fwdma_free_multiseg)(struct fwdma_alloc_multi *);
int (*fw_bindadd)(struct firewire_comm *fc, struct fw_bind *fwb);
int (*fw_bindremove)(struct firewire_comm *fc, struct fw_bind *fwb);
int (*fw_xferlist_add)(struct fw_xferlist *q,
int slen, int rlen, int n,
struct firewire_comm *fc, void *sc, void (*hand)(struct fw_xfer *));
void (*fw_xferlist_remove)(struct fw_xferlist *q);
struct fw_xfer * (*fw_xfer_alloc)();
struct fw_xfer * (*fw_xfer_alloc_buf)(int send_len, int recv_len);
void (*fw_xfer_done)(struct fw_xfer *xfer);
void (*fw_xfer_unload)(struct fw_xfer* xfer);
void (*fw_xfer_free_buf)( struct fw_xfer* xfer);
void (*fw_xfer_free)( struct fw_xfer* xfer);
void (*fw_asy_callback_free)(struct fw_xfer *xfer);
int (*fw_open_isodma)(struct firewire_comm *fc, int tx);
int (*get_handle)(int socket, struct firewire_softc **handle);
struct fwdma_alloc_multi * (*fwdma_malloc_multiseg)(int alignment,
int esize, int n);
void (*fwdma_free_multiseg)(struct fwdma_alloc_multi *);
};
#endif
+58 -36
View File
@@ -36,7 +36,9 @@
*/
#ifndef _FIREWIREREG_H
#define _FIREWIREREG_H
#ifndef __HAIKU__
#ifdef __HAIKU__
#include <OS.h>
#else
#ifdef __DragonFly__
typedef d_thread_t fw_proc;
#include <sys/select.h>
@@ -55,11 +57,15 @@ typedef struct proc fw_proc;
#include <sys/mutex.h>
#include <sys/taskqueue.h>
#define splfw splimp
#else
#define splfw disable_interrupts
#define splx restore_interrupts
#else
#include <lock.h>
#include <dpc.h>
#include "fwglue.h"
#include "timer.h"
#endif
#define MAX_REQCOUNT 0xffff
STAILQ_HEAD(fw_xferlist, fw_xfer);
struct fw_device{
@@ -119,8 +125,20 @@ struct crom_src_buf {
struct crom_chunk root;
struct crom_chunk vendor;
struct crom_chunk hw;
};//move from firewire.c to here
struct firewire_notify_hooks {
status_t (*device_attach)(struct firewire_softc *sc, void **cookie);
status_t (*device_detach)(struct firewire_softc *sc, void *cookie);
};
#endif //move from firewire.c to firewirereg.h
struct firewire_child_info {
const char *child_name;
void *cookie;
struct firewire_notify_hooks notify_hooks;
struct firewire_child_info *link;
};
#endif
struct firewire_comm{
#ifndef __HAIKU__
@@ -171,12 +189,12 @@ struct firewire_comm{
struct callout busprobe_callout;
struct callout bmr_callout;
struct callout timeout_callout;
struct task task_timeout;
#else
//timer_id busprobe_callout;
//timer_id bmr_callout;
//timer_id timeout_callout;
timer_id busprobe_callout;
timer_id bmr_callout;
timer_id timeout_callout;
#endif
//struct task task_timeout;
uint32_t (*cyctimer) (struct firewire_comm *);
void (*ibr) (struct firewire_comm *);
uint32_t (*set_bmr) (struct firewire_comm *, uint32_t);
@@ -199,29 +217,28 @@ struct firewire_comm{
bus_dma_tag_t dmat;
struct mtx mtx;
struct mtx wait_lock;
#else
sem_id mtx;
sem_id wait_lock;
#endif
// struct taskqueue *taskqueue;//to be completed
#ifndef __HAIKU__
struct taskqueue *taskqueue;
struct proc *probe_thread;
#else
benaphore mtx;
benaphore wait_lock;
void *taskqueue;
thread_id probe_thread;
sem_id Sem;
area_id crom_sid_Area;
struct firewire_child_info *childList;
#endif
};
#define CSRARC(sc, offset) ((sc)->csr_arc[(offset)/4])
#ifndef __HAIKU__
#define FW_GMTX(fc) (&(fc)->mtx)
#define FW_GLOCK(fc) mtx_lock(FW_GMTX(fc))
#define FW_GUNLOCK(fc) mtx_unlock(FW_GMTX(fc))
#ifndef __HAIKU__
#define FW_GLOCK_ASSERT(fc) mtx_assert(FW_GMTX(fc), MA_OWNED)
#endif
#define FW_GMTX(fc) ((fc)->mtx)
#define FW_GLOCK(fc) acquire_sem_etc(FW_GMTX(fc), 1, B_CAN_INTERRUPT | B_TIMEOUT, 0)
#define FW_GUNLOCK(fc) release_sem(FW_GMTX(fc))
#else
#define FW_GLOCK_ASSERT(fc)
#endif
struct fw_xferq {
int flag;
@@ -252,15 +269,15 @@ struct fw_xferq {
STAILQ_HEAD(, fw_bulkxfer) stdma;
struct fw_bulkxfer *stproc;
// struct selinfo rsel;
spinlock Spinlock;
sem_id Sem;
caddr_t sc;
void (*hand) (struct fw_xferq *);
spinlock Spinlock;
sem_id Sem;
};
struct fw_bulkxfer{
int poffset;
// struct mbuf *mbuf;//to be completed
// struct mbuf *mbuf;
STAILQ_ENTRY(fw_bulkxfer) link;
caddr_t start;
caddr_t end;
@@ -280,8 +297,10 @@ struct fw_xfer{
caddr_t sc;
struct firewire_comm *fc;
struct fw_xferq *q;
// struct timeval tv;//to be completed
int8_t resp;
// struct timeval tv;
bigtime_t tv;
int32_t resp;
#define FWXF_INIT 0x00
#define FWXF_INQ 0x01
#define FWXF_START 0x02
@@ -294,16 +313,19 @@ struct fw_xfer{
uint8_t flag;
int8_t tl;
void (*hand) (struct fw_xfer *);
struct {
struct send_recv{
struct fw_pkt hdr;
uint32_t *payload;
area_id payArea;
bus_addr_t bus_addr;
uint16_t pay_len;
uint8_t spd;
} send, recv;
// struct mbuf *mbuf;//to be completed
// struct mbuf *mbuf;
STAILQ_ENTRY(fw_xfer) link;
STAILQ_ENTRY(fw_xfer) tlabel;
struct malloc_type *malloc;
// struct malloc_type *malloc;
sem_id Sem;
};
struct fw_rcv_buf {
@@ -313,20 +335,20 @@ struct fw_rcv_buf {
u_int nvec;
uint8_t spd;
};
#ifndef __HAIKU__
//#ifndef __HAIKU__
void fw_sidrcv (struct firewire_comm *, uint32_t *, u_int);
void fw_rcv (struct fw_rcv_buf *);
void fw_xfer_unload ( struct fw_xfer*);
void fw_xfer_free_buf ( struct fw_xfer*);
void fw_xfer_free ( struct fw_xfer*);
struct fw_xfer *fw_xfer_alloc (struct malloc_type *);
struct fw_xfer *fw_xfer_alloc_buf (struct malloc_type *, int, int);
struct fw_xfer *fw_xfer_alloc ();
struct fw_xfer *fw_xfer_alloc_buf (int, int);
void fw_init (struct firewire_comm *);
int fw_tbuf_update (struct firewire_comm *, int, int);
int fw_rbuf_update (struct firewire_comm *, int, int);
int fw_bindadd (struct firewire_comm *, struct fw_bind *);
int fw_bindremove (struct firewire_comm *, struct fw_bind *);
int fw_xferlist_add (struct fw_xferlist *, struct malloc_type *, int, int, int,
int fw_xferlist_add (struct fw_xferlist *, int, int, int,
struct firewire_comm *, void *, void (*)(struct fw_xfer *));
void fw_xferlist_remove (struct fw_xferlist *);
int fw_asyreq (struct firewire_comm *, int, struct fw_xfer*);
@@ -341,11 +363,11 @@ struct fw_device *fw_noderesolve_nodeid (struct firewire_comm *, int);
struct fw_device *fw_noderesolve_eui64 (struct firewire_comm *, struct fw_eui64 *);
struct fw_bind *fw_bindlookup (struct firewire_comm *, uint16_t, uint32_t);
void fw_drain_txq (struct firewire_comm *);
int fwdev_makedev (struct firewire_softc *);
int fwdev_destroydev (struct firewire_softc *);
void fwdev_clone (void *, struct ucred *, char *, int, struct cdev **);
//int fwdev_makedev (struct firewire_softc *);
//int fwdev_destroydev (struct firewire_softc *);
//void fwdev_clone (void *, struct ucred *, char *, int, struct cdev **);
int fw_open_isodma(struct firewire_comm *, int);
#endif
//#endif
extern int firewire_debug;
#ifndef __HAIKU__
extern devclass_t firewire_devclass;
+9 -13
View File
@@ -36,21 +36,13 @@
#ifndef _FWDMA_H
#define _FWDMA_H
#ifndef howmany
#define howmany(x, y) (((x)+((y)-1))/(y)) // x/y的上界
#endif
#define rounddown(x, y) (((x)/(y))*(y)) // 比x小,y的最大的倍数
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ // 比x大,y的最小倍数
#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
#define powerof2(x) ((((x)-1)&(x))==0) // 是否是2的次方
#include "fwglue.h"
typedef uint32_t bus_addr_t;
typedef uint32_t bus_size_t;
struct fwdma_alloc {
// bus_dma_tag_t dma_tag;
// bus_dmamap_t dma_map;
area_id BufArea;
area_id Area;
void * v_addr;
bus_addr_t bus_addr;
};
@@ -67,7 +59,7 @@ struct fwdma_alloc_multi {
bus_size_t esize;
int nseg;
// bus_dma_tag_t dma_tag;
area_id BufArea;
area_id Area;
struct fwdma_seg seg[0];
};
@@ -119,12 +111,16 @@ fwdma_sync_multiseg_all(struct fwdma_alloc_multi *am, bus_dmasync_op_t op)
bus_dmamap_sync(am->dma_tag, seg->dma_map, op);
}
void *fwdma_malloc(int, bus_size_t, struct fwdma_alloc *, int);
void fwdma_free(struct fwdma_alloc *);
void *fwdma_malloc(struct firewire_comm *, int, bus_size_t, struct fwdma_alloc *, int);
void fwdma_free(struct firewire_comm *, struct fwdma_alloc *);
void *fwdma_malloc_size(bus_dma_tag_t, bus_dmamap_t *, bus_size_t, bus_addr_t *, int);
void fwdma_free_size(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t);
struct fwdma_alloc_multi *fwdma_malloc_multiseg(struct firewire_comm *,
int, int, int, int);
#else
struct fwdma_alloc_multi *fwdma_malloc_multiseg(int, int, int);
void fwdma_free_multiseg(struct fwdma_alloc_multi *);
#endif /*__HAIKU__*/
#endif /* _FWDMA_H*/
+56
View File
@@ -0,0 +1,56 @@
/*
* Copyright 2007, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* JiSheng Zhang
*/
#ifndef _FW_GLUE_H
#define _FW_GLUE_H
#include <stdint.h>
#include <dpc.h>
#define device_printf(dev, a...) dprintf("firewire:" a)
#define printf(a...) dprintf(a)
#define KASSERT(cond,msg) do { \
if (!cond) \
panic msg; \
} while(0)
#ifndef howmany
#define howmany(x, y) (((x)+((y)-1))/(y)) // x/y的上界
#endif
#define rounddown(x, y) (((x)/(y))*(y)) // 比x小,y的最大的倍数
#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) /* to any y */ // 比x大,y的最小倍数
#define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
#define powerof2(x) ((((x)-1)&(x))==0) // 是否是2的次方
typedef uint32_t bus_addr_t;
typedef uint32_t bus_size_t;
#define atomic_readandclear_int(a) atomic_set(a, 0)
#define atomic_set_int(addr, newvalue) atomic_set(addr, newvalue)
#define mtx_lock benaphore_lock
#define mtx_unlock benaphore_unlock
#define mtx_destroy benaphore_destroy
#define mtx_init(lockaddr, name, type, opts) benaphore_init(lockaddr, name)
#define splfw() 0
#define splx(s)
#define hz 1000000LL
#define DELAY(n) snooze(n)
#define OWRITE(sc, offset, value) (*(volatile uint32 *)((char *)(sc->regAddr) + (offset)) = value)
#define OREAD(sc, offset) (*(volatile uint32 *)((char *)(sc->regAddr) + (offset)))
#define MAX_CARDS 4
extern dpc_module_info *gDpc;
#define __offsetof(type, field) ((size_t)(&((type *)0)->field))
#endif /*_FW_GLUE_H*/
+44
View File
@@ -0,0 +1,44 @@
/* Realtek RTL8169 Family Driver
* Copyright (C) 2004 Marcus Overhagen <[email protected]>. All rights reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies, and that both the
* copyright notice and this permission notice appear in supporting documentation.
*
* Marcus Overhagen makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied warranty.
*
* MARCUS OVERHAGEN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL MARCUS
* OVERHAGEN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef __TIMER_H
#define __TIMER_H
#include <KernelExport.h>
// Since the BeOS kernel timers are executed in interrupt context,
// a new timer has been created. The timers are executed in thread
// context, and are passed a cookie.
typedef int32 timer_id;
typedef void (*timer_function)(void *cookie);
// create_timer() can be called from interrupt context.
// Only up to 8 concurrent timers are supported.
// Flags can be one of B_ONE_SHOT_ABSOLUTE_TIMER,
// B_ONE_SHOT_RELATIVE_TIMER or B_PERIODIC_TIMER.
timer_id create_timer(timer_function func, void *cookie, bigtime_t interval, uint32 flags);
status_t delete_timer(timer_id id);
status_t initialize_timer(void);
status_t terminate_timer(void);
#endif