Re: Bus DMA for USB - compilation problems.

2003-01-16 Thread Hiten Pandya
On Wed, Jan 15, 2003 at 10:58:04PM +0100, Thomas Moestl wrote the words in effect of:
 On Wed, 2003/01/15 at 20:20:33 +, Josef Karthauser wrote:
  On Wed, Jan 15, 2003 at 12:05:20PM -0800, Maxime Henrion wrote:
   Josef Karthauser wrote:
I've partially ported the NetBSD busdma code for USB to FreeBSD, but
it doesn't compile, probably for a trivial reason.

Anyone fancy helping me out?
   
   I didn't look at the patches yet, but could you give me the compilation
   error you are getting ?
   
  
  cc -c -O -pipe -march=pentium3 -Wall -Wredundant-decls -Wnested-externs
  -Wstrict-prototypes  -Wmissing-prototypes -Wpointer-arith -Winline
  -Wcast-qual  -fformat-extensions -ansi -g -nostdinc -I-  -I.
  -I/usr/src/sys -I/usr/src/sys/dev -I/usr/src/sys/contrib/dev/acpica
  -I/usr/src/sys/contrib/ipfilter -D_KERNEL -include opt_global.h
  -fno-common  -mno-align-long-strings -mpreferred-stack-boundary=2
  -ffreestanding -Werror  /usr/src/sys/dev/usb/uhci.c
  /usr/src/sys/dev/usb/uhci.c: In function `uhci_init':
  /usr/src/sys/dev/usb/uhci.c:425: dereferencing pointer to incomplete type
  /usr/src/sys/dev/usb/uhci.c: In function `uhci_power':
  /usr/src/sys/dev/usb/uhci.c:714: dereferencing pointer to incomplete type
  /usr/src/sys/dev/usb/uhci.c: In function `uhci_alloc_std':
  
  It's failing at lines like:
  
  UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(sc-sc_dma, 0)); /* set frame list */
  
  The problematic is DMAADDR, and it's because the sc-sc_dma, which is
  defined as usb_dma_t.  This is defined in usb_port.h, and it uses
  usb_dma_block which is defined in usb_mem.h.  I think that it's the
  usb_dma_block that is coming up as incomplete, but I'm not sure.
 
 DMAADDR is:
   
   #define DMAADDR(dma, o) ((dma)-block-map-dm_segs[0].ds_addr + (dma)-offs + (o))
 
 struct usb_dma_block starts like:
 
   typedef struct usb_dma_block {
 bus_dma_tag_t tag;
 bus_dmamap_t map;
 
 However, bus_dmamap_t (like bus_dma_tag_t) is supposed to be opaque to
 users of the busdma interface on FreeBSD. Our implementations enforce
 this by defining it as:
 
   typedef struct bus_dmamap *bus_dmamap_t;
 
 , and by not exporting struct bus_dmamap in public headers.
 
 The DMA addresses are obtained by writing an appropriate callback
 routine to process them and passing it to bus_dmamap_load().
 The usb_mem.c will need some other changes to work on FreeBSD, since
 our busdma code has diverged from NetBSD's quite a bit.

Hiya Joe!

The caller has to specify a routine to receive the DMA segment list, and
for processing any errors occured during this period.  If the operation
is delayed, than EINPROGRESS is returned.  If you specify
BUS_DMA_NOWAIT, then the bus dma interface allows you to fail the
request rather the delay (no sleep) it.  Neccessary prep. must be done
if you don't want bus_dmamap_load_*() to block, by setting the
BUS_DMA_ALLOCNOW flag at dma tag and map creation time.

You must also note, that the lifetime of the callback routine, should be
about the same as that of the bus_dma_segment_t array passed.

As defered from the NetBSD bus_dma interface, you can provide a filter
routine, at dma tag creation time (bus_dma_tag_create) to DMA to an
address range not accesilbe to the interface -- i.e. if such thing
happens, the routine is asked to take over the task.

The BusLogic driver is a very good driver to read for bus_dma related
things.  I personally found it good, as it covers many cases. JFYI.

HTH.

Cheers.

-- 
Hiten Pandya ([EMAIL PROTECTED], [EMAIL PROTECTED])
http://www.unixdaemons.com/~hiten/

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Bus DMA for USB - compilation problems.

2003-01-15 Thread Josef Karthauser
I've partially ported the NetBSD busdma code for USB to FreeBSD, but
it doesn't compile, probably for a trivial reason.

Anyone fancy helping me out?

Joe
p.s. patches attached
-- 
Josef Karthauser ([EMAIL PROTECTED])  http://www.josef-k.net/
FreeBSD (cvs meister, admin and hacker) http://www.uk.FreeBSD.org/
Physics Particle Theory (student)   http://www.pact.cpes.sussex.ac.uk/
 An eclectic mix of fact and theory. =

Index: conf/files
===
RCS file: /home/ncvs/src/sys/conf/files,v
retrieving revision 1.744
diff -u -r1.744 files
--- conf/files  8 Jan 2003 23:36:59 -   1.744
+++ conf/files  15 Jan 2003 19:35:10 -
@@ -758,7 +758,7 @@
 dev/usb/uvscom.c   optional uvscom ucom
 dev/usb/usb.c  optional usb
 dev/usb/usb_ethersubr.coptional usb
-#dev/usb/usb_mem.c optional usb
+dev/usb/usb_mem.c  optional usb
 dev/usb/usb_quirks.c   optional usb
 dev/usb/usb_subr.c optional usb
 dev/usb/usbdi.coptional usb
Index: dev/usb/usb_mem.h
===
RCS file: /home/ncvs/src/sys/dev/usb/usb_mem.h,v
retrieving revision 1.17
diff -u -r1.17 usb_mem.h
--- dev/usb/usb_mem.h   28 May 2002 20:51:43 -  1.17
+++ dev/usb/usb_mem.h   15 Jan 2003 19:12:39 -
@@ -38,7 +38,6 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
 typedef struct usb_dma_block {
bus_dma_tag_t tag;
bus_dmamap_t map;
@@ -57,35 +56,3 @@
 
 usbd_statususb_allocmem(usbd_bus_handle,size_t,size_t, usb_dma_t *);
 void   usb_freemem(usbd_bus_handle, usb_dma_t *);
-
-#elif defined(__FreeBSD__)
-
-/* 
- * FreeBSD does not have special functions for dma memory, so let's keep it
- * simple for now.
- */
-
-#include sys/param.h
-#include sys/systm.h
-#include sys/queue.h
-#include sys/proc.h
-#include sys/bio.h
-#include sys/buf.h
-#include sys/malloc.h
-#include sys/kernel.h
-#include vm/vm.h
-#include vm/pmap.h
-
-#include machine/pmap.h   /* for vtophys */
-
-#defineusb_allocmem(t,s,a,p)   (*(p) = malloc(s, M_USB, M_NOWAIT), 
(*(p) == NULL? USBD_NOMEM: USBD_NORMAL_COMPLETION))
-#defineusb_freemem(t,p)(free(*(p), M_USB))
-
-#ifdef __alpha__
-#define DMAADDR(dma, o)(alpha_XXX_dmamap((vm_offset_t) *(dma) + (o)))
-#else
-#define DMAADDR(dma, o)(vtophys(*(dma) + (o)))
-#endif
-#define KERNADDR(dma, o)   ((void *) ((char *)*(dma) + (o)))
-#endif /* __FreeBSD__ */
-
Index: dev/usb/usb_port.h
===
RCS file: /home/ncvs/src/sys/dev/usb/usb_port.h,v
retrieving revision 1.58
diff -u -r1.58 usb_port.h
--- dev/usb/usb_port.h  2 Oct 2002 07:44:20 -   1.58
+++ dev/usb/usb_port.h  15 Jan 2003 19:10:58 -
@@ -355,7 +355,12 @@
 #define USBDEVUNIT(bdev) device_get_unit(bdev)
 #define USBGETSOFTC(bdev) (device_get_softc(bdev))
 
-#define DECLARE_USB_DMA_T typedef char * usb_dma_t
+#define DECLARE_USB_DMA_T \
+   struct usb_dma_block; \
+   typedef struct { \
+   struct usb_dma_block *block; \
+   u_int offs; \
+   } usb_dma_t
 
 typedef struct thread *usb_proc_ptr;
 
Index: dev/usb/usbdivar.h
===
RCS file: /home/ncvs/src/sys/dev/usb/usbdivar.h,v
retrieving revision 1.37
diff -u -r1.37 usbdivar.h
--- dev/usb/usbdivar.h  7 Apr 2002 13:37:46 -   1.37
+++ dev/usb/usbdivar.h  15 Jan 2003 19:31:06 -
@@ -124,9 +124,7 @@
 #endif
 #endif
 
-#if defined(__NetBSD__) || defined(__OpenBSD__)
bus_dma_tag_t   dmatag; /* DMA tag */
-#endif
 };
 
 struct usbd_device {

/*  $NetBSD: usb_mem.c,v 1.25 2002/12/30 02:44:32 dsainty Exp $ */

/*
 * Copyright (c) 1998 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Lennart Augustsson ([EMAIL PROTECTED]) at
 * Carlstedt Research  Technology.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *notice, this list of conditions and the following disclaimer in the
 *documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *must display the following acknowledgement:
 *This product includes software developed by the NetBSD
 *Foundation, Inc. and its contributors.
 * 4. Neither the name of The NetBSD Foundation nor the names of its
 *contributors may be used to endorse or promote products 

Re: Bus DMA for USB - compilation problems.

2003-01-15 Thread Maxime Henrion
Josef Karthauser wrote:
 I've partially ported the NetBSD busdma code for USB to FreeBSD, but
 it doesn't compile, probably for a trivial reason.
 
 Anyone fancy helping me out?

I didn't look at the patches yet, but could you give me the compilation
error you are getting ?

Cheers,
Maxime

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Bus DMA for USB - compilation problems.

2003-01-15 Thread Josef Karthauser
On Wed, Jan 15, 2003 at 12:05:20PM -0800, Maxime Henrion wrote:
 Josef Karthauser wrote:
  I've partially ported the NetBSD busdma code for USB to FreeBSD, but
  it doesn't compile, probably for a trivial reason.
  
  Anyone fancy helping me out?
 
 I didn't look at the patches yet, but could you give me the compilation
 error you are getting ?
 

cc -c -O -pipe -march=pentium3 -Wall -Wredundant-decls -Wnested-externs
-Wstrict-prototypes  -Wmissing-prototypes -Wpointer-arith -Winline
-Wcast-qual  -fformat-extensions -ansi -g -nostdinc -I-  -I.
-I/usr/src/sys -I/usr/src/sys/dev -I/usr/src/sys/contrib/dev/acpica
-I/usr/src/sys/contrib/ipfilter -D_KERNEL -include opt_global.h
-fno-common  -mno-align-long-strings -mpreferred-stack-boundary=2
-ffreestanding -Werror  /usr/src/sys/dev/usb/uhci.c
/usr/src/sys/dev/usb/uhci.c: In function `uhci_init':
/usr/src/sys/dev/usb/uhci.c:425: dereferencing pointer to incomplete type
/usr/src/sys/dev/usb/uhci.c: In function `uhci_power':
/usr/src/sys/dev/usb/uhci.c:714: dereferencing pointer to incomplete type
/usr/src/sys/dev/usb/uhci.c: In function `uhci_alloc_std':

It's failing at lines like:

UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(sc-sc_dma, 0)); /* set frame list */

The problematic is DMAADDR, and it's because the sc-sc_dma, which is
defined as usb_dma_t.  This is defined in usb_port.h, and it uses
usb_dma_block which is defined in usb_mem.h.  I think that it's the
usb_dma_block that is coming up as incomplete, but I'm not sure.

Joe
-- 
Josef Karthauser ([EMAIL PROTECTED])  http://www.josef-k.net/
FreeBSD (cvs meister, admin and hacker) http://www.uk.FreeBSD.org/
Physics Particle Theory (student)   http://www.pact.cpes.sussex.ac.uk/
 An eclectic mix of fact and theory. =



msg50325/pgp0.pgp
Description: PGP signature


Re: Bus DMA for USB - compilation problems.

2003-01-15 Thread Thomas Moestl
On Wed, 2003/01/15 at 20:20:33 +, Josef Karthauser wrote:
 On Wed, Jan 15, 2003 at 12:05:20PM -0800, Maxime Henrion wrote:
  Josef Karthauser wrote:
   I've partially ported the NetBSD busdma code for USB to FreeBSD, but
   it doesn't compile, probably for a trivial reason.
   
   Anyone fancy helping me out?
  
  I didn't look at the patches yet, but could you give me the compilation
  error you are getting ?
  
 
 cc -c -O -pipe -march=pentium3 -Wall -Wredundant-decls -Wnested-externs
 -Wstrict-prototypes  -Wmissing-prototypes -Wpointer-arith -Winline
 -Wcast-qual  -fformat-extensions -ansi -g -nostdinc -I-  -I.
 -I/usr/src/sys -I/usr/src/sys/dev -I/usr/src/sys/contrib/dev/acpica
 -I/usr/src/sys/contrib/ipfilter -D_KERNEL -include opt_global.h
 -fno-common  -mno-align-long-strings -mpreferred-stack-boundary=2
 -ffreestanding -Werror  /usr/src/sys/dev/usb/uhci.c
 /usr/src/sys/dev/usb/uhci.c: In function `uhci_init':
 /usr/src/sys/dev/usb/uhci.c:425: dereferencing pointer to incomplete type
 /usr/src/sys/dev/usb/uhci.c: In function `uhci_power':
 /usr/src/sys/dev/usb/uhci.c:714: dereferencing pointer to incomplete type
 /usr/src/sys/dev/usb/uhci.c: In function `uhci_alloc_std':
 
 It's failing at lines like:
 
 UWRITE4(sc, UHCI_FLBASEADDR, DMAADDR(sc-sc_dma, 0)); /* set frame list */
 
 The problematic is DMAADDR, and it's because the sc-sc_dma, which is
 defined as usb_dma_t.  This is defined in usb_port.h, and it uses
 usb_dma_block which is defined in usb_mem.h.  I think that it's the
 usb_dma_block that is coming up as incomplete, but I'm not sure.

DMAADDR is:

  #define DMAADDR(dma, o) ((dma)-block-map-dm_segs[0].ds_addr + (dma)-offs + (o))

struct usb_dma_block starts like:

  typedef struct usb_dma_block {
  bus_dma_tag_t tag;
  bus_dmamap_t map;

However, bus_dmamap_t (like bus_dma_tag_t) is supposed to be opaque to
users of the busdma interface on FreeBSD. Our implementations enforce
this by defining it as:

  typedef struct bus_dmamap *bus_dmamap_t;

, and by not exporting struct bus_dmamap in public headers.

The DMA addresses are obtained by writing an appropriate callback
routine to process them and passing it to bus_dmamap_load().
The usb_mem.c will need some other changes to work on FreeBSD, since
our busdma code has diverged from NetBSD's quite a bit.

- Thomas

-- 
Thomas Moestl [EMAIL PROTECTED] http://www.tu-bs.de/~y0015675/
  [EMAIL PROTECTED] http://people.FreeBSD.org/~tmm/
PGP fingerprint: 1C97 A604 2BD0 E492 51D0  9C0F 1FE6 4F1D 419C 776C

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message



Re: Bus DMA for USB - compilation problems.

2003-01-15 Thread Josef Karthauser
On Wed, Jan 15, 2003 at 10:58:04PM +0100, Thomas Moestl wrote:
 
 DMAADDR is:
   
   #define DMAADDR(dma, o) ((dma)-block-map-dm_segs[0].ds_addr + (dma)-offs + (o))
 
 struct usb_dma_block starts like:
 
   typedef struct usb_dma_block {
 bus_dma_tag_t tag;
 bus_dmamap_t map;
 
 However, bus_dmamap_t (like bus_dma_tag_t) is supposed to be opaque to
 users of the busdma interface on FreeBSD. Our implementations enforce
 this by defining it as:
 
   typedef struct bus_dmamap *bus_dmamap_t;
 
 , and by not exporting struct bus_dmamap in public headers.
 
 The DMA addresses are obtained by writing an appropriate callback
 routine to process them and passing it to bus_dmamap_load().
 The usb_mem.c will need some other changes to work on FreeBSD, since
 our busdma code has diverged from NetBSD's quite a bit.
 

Is ours documented anywhere, or is converting usb_mem.c to our style
something that you could help me with?

Joe
-- 
Josef Karthauser ([EMAIL PROTECTED])  http://www.josef-k.net/
FreeBSD (cvs meister, admin and hacker) http://www.uk.FreeBSD.org/
Physics Particle Theory (student)   http://www.pact.cpes.sussex.ac.uk/
 An eclectic mix of fact and theory. =



msg50334/pgp0.pgp
Description: PGP signature


Re: Bus DMA for USB - compilation problems.

2003-01-15 Thread Maxime Henrion
Josef Karthauser wrote:
 On Wed, Jan 15, 2003 at 10:58:04PM +0100, Thomas Moestl wrote:
  
  DMAADDR is:
  
#define DMAADDR(dma, o) ((dma)-block-map-dm_segs[0].ds_addr + (dma)-offs + 
(o))
  
  struct usb_dma_block starts like:
  
typedef struct usb_dma_block {
bus_dma_tag_t tag;
bus_dmamap_t map;
  
  However, bus_dmamap_t (like bus_dma_tag_t) is supposed to be opaque to
  users of the busdma interface on FreeBSD. Our implementations enforce
  this by defining it as:
  
typedef struct bus_dmamap *bus_dmamap_t;
  
  , and by not exporting struct bus_dmamap in public headers.
  
  The DMA addresses are obtained by writing an appropriate callback
  routine to process them and passing it to bus_dmamap_load().
  The usb_mem.c will need some other changes to work on FreeBSD, since
  our busdma code has diverged from NetBSD's quite a bit.
 
 Is ours documented anywhere, or is converting usb_mem.c to our style
 something that you could help me with?

Sorry for the late reply.  As Thomas said, you have to get this
information in the callback routine.  Unfortunately, we don't have
manpages for the busdma API yet, but we should get them soon now as
someone is working on it.  You can get examples by looking at several
drivers which have been converted, like if_rl or if_sis.

Cheers,
Maxime



To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message