[Linux1394-cvslog] rev 564 - branches/rawiso
Brought to you by:
aeb,
bencollins
From: SVN U. <dm...@li...> - 2002-08-28 07:54:19
|
Author: dmaas Date: 2002-08-28 12:46:35 -0400 (Wed, 28 Aug 2002) New Revision: 564 Added: branches/rawiso/_libraw1394_patch Log: include the libraw1394 patch to expose the new ISO API Added: branches/rawiso/_libraw1394_patch ============================================================================== --- branches/rawiso/_libraw1394_patch (original) +++ branches/rawiso/_libraw1394_patch 2002-08-28 12:46:36.000000000 -0400 @@ -0,0 +1,413 @@ +diff -ru libraw1394/src/eventloop.c libraw1394-iso/src/eventloop.c +--- libraw1394/src/eventloop.c Sun May 13 21:02:10 2001 ++++ libraw1394-iso/src/eventloop.c Mon Aug 26 13:21:07 2002 +@@ -11,16 +11,58 @@ + #include <config.h> + #include <unistd.h> + #include <byteswap.h> ++#include <sys/poll.h> + + #include "raw1394.h" + #include "kernel-raw1394.h" + #include "raw1394_private.h" + ++/* ++ This is a bit complicated because the read/write interface and the ISO ++ interface are essentially two independent streams of input. ++ ++ poll() will return POLLIN or POLLOUT for pending read activity, and ++ POLLPRI for pending ISO activity. ++ ++ do_poll() returns 1 if there are pending events to read(), ++ 0 if there are no events, and -1 on error. ++*/ ++ ++static int do_poll(struct raw1394_handle *handle) ++{ ++ struct pollfd pfd[1]; ++ ++ pfd[0].fd = handle->fd; ++ pfd[0].events = POLLIN | POLLOUT | POLLPRI; ++ pfd[0].revents = 0; ++ ++ while(1) { ++ int ret = poll(pfd, 1, -1); ++ if(ret > 0) { ++ break; ++ } else if(ret < 0) { ++ return -1; ++ } ++ } ++ ++ if(pfd[0].revents & (POLLIN | POLLOUT)) { ++ return 1; ++ } ++ ++ return 0; ++} + + int raw1394_loop_iterate(struct raw1394_handle *handle) + { + struct raw1394_request *req = &handle->req; + int retval = 0, channel; ++ ++ int read_events = do_poll(handle); ++ if(read_events < 0) ++ return -1; ++ ++ if(read_events == 0) ++ return 0; + + if (read(handle->fd, req, sizeof(*req)) < 0) { + return -1; +diff -ru libraw1394/src/iso.c libraw1394-iso/src/iso.c +--- libraw1394/src/iso.c Sun Sep 10 18:18:49 2000 ++++ libraw1394-iso/src/iso.c Wed Aug 28 01:08:10 2002 +@@ -11,11 +11,15 @@ + #include <config.h> + #include <errno.h> + #include <unistd.h> ++#include <string.h> ++#include <sys/ioctl.h> ++#include <sys/mman.h> + + #include "raw1394.h" + #include "kernel-raw1394.h" + #include "raw1394_private.h" + ++/* old ISO API */ + + static int do_iso_listen(struct raw1394_handle *handle, int channel) + { +@@ -72,3 +76,104 @@ + + return do_iso_listen(handle, ~channel); + } ++ ++ ++ ++/* new ISO API */ ++ ++static int do_iso_start(raw1394handle_t handle, struct raw1394_iso_config *config, int xmit) ++{ ++ struct raw1394_kernel_iso_status kstat; ++ size_t pgsize; ++ ++ kstat.config.buf_packets = config->buf_packets; ++ kstat.config.max_packet_size = config->max_packet_size; ++ kstat.config.channel = config->channel; ++ kstat.config.speed = config->speed; ++ kstat.config.irq_interval = config->irq_interval; ++ ++ if(ioctl(handle->fd, xmit ? RAW1394_ISO_START_XMIT : RAW1394_ISO_START_RECV, &kstat.config)) ++ return -1; ++ ++ if(ioctl(handle->fd, RAW1394_ISO_GET_STATUS, &kstat)) ++ return -1; ++ ++ handle->iso_buffer_bytes = kstat.config.buf_packets * kstat.buf_stride; ++ ++ /* make sure buffer is a multiple of the page size */ ++ pgsize = getpagesize(); ++ if(handle->iso_buffer_bytes % pgsize) ++ handle->iso_buffer_bytes += pgsize - (handle->iso_buffer_bytes % pgsize); ++ ++ handle->iso_buffer = mmap(NULL, handle->iso_buffer_bytes, PROT_READ | PROT_WRITE, ++ MAP_SHARED, handle->fd, 0); ++ ++ if(handle->iso_buffer == (unsigned char*) MAP_FAILED) { ++ handle->iso_buffer = NULL; ++ raw1394_iso_stop(handle); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++void raw1394_iso_stop(raw1394handle_t handle) ++{ ++ if(handle->iso_buffer) { ++ munmap(handle->iso_buffer, handle->iso_buffer_bytes); ++ handle->iso_buffer = NULL; ++ } ++ ++ ioctl(handle->fd, RAW1394_ISO_STOP, 0); ++} ++ ++int raw1394_iso_xmit_start(raw1394handle_t handle, struct raw1394_iso_config *config) ++{ ++ return do_iso_start(handle, config, 1); ++} ++ ++int raw1394_iso_recv_start(raw1394handle_t handle, struct raw1394_iso_config *config) ++{ ++ return do_iso_start(handle, config, 0); ++} ++ ++int raw1394_iso_get_status(raw1394handle_t handle, struct raw1394_iso_status *stat) ++{ ++ struct raw1394_kernel_iso_status kstat; ++ int err; ++ ++ err = ioctl(handle->fd, RAW1394_ISO_GET_STATUS, &kstat); ++ if(err != 0) ++ return err; ++ ++ /* mediate between user and kernel versions of the structure */ ++ stat->config.buf_packets = kstat.config.buf_packets; ++ stat->config.max_packet_size = kstat.config.max_packet_size; ++ stat->config.channel = kstat.config.channel; ++ stat->config.speed = kstat.config.speed; ++ stat->config.irq_interval = kstat.config.irq_interval; ++ ++ stat->buf = handle->iso_buffer; ++ stat->buf_stride = kstat.buf_stride; ++ stat->packet_data_offset = kstat.packet_data_offset; ++ stat->packet_info_offset = kstat.packet_info_offset; ++ stat->first_packet = kstat.first_packet; ++ stat->n_packets = kstat.n_packets; ++ stat->overflows = kstat.overflows; ++ stat->first_packet_cycle = kstat.first_packet_cycle; ++ ++ return 0; ++} ++ ++int raw1394_iso_xmit_produce(raw1394handle_t handle, unsigned int n_packets) ++{ ++ if(!n_packets) return 0; ++ return ioctl(handle->fd, RAW1394_ISO_PRODUCE_CONSUME, n_packets); ++} ++ ++int raw1394_iso_recv_consume(raw1394handle_t handle, unsigned int n_packets) ++{ ++ if(!n_packets) return 0; ++ return ioctl(handle->fd, RAW1394_ISO_PRODUCE_CONSUME, n_packets); ++} ++ +diff -ru libraw1394/src/kernel-raw1394.h libraw1394-iso/src/kernel-raw1394.h +--- libraw1394/src/kernel-raw1394.h Mon Aug 7 20:29:08 2000 ++++ libraw1394-iso/src/kernel-raw1394.h Wed Aug 28 03:50:43 2002 +@@ -69,6 +69,57 @@ + __u8 name[32]; + }; + ++/* new ISO API */ ++ ++/* ioctls */ ++#define RAW1394_ISO_START_XMIT 1 ++#define RAW1394_ISO_START_RECV 2 ++#define RAW1394_ISO_GET_STATUS 3 ++#define RAW1394_ISO_STOP 4 ++#define RAW1394_ISO_PRODUCE_CONSUME 5 ++ ++/* argument to RAW1394_ISO_START_RECV, XMIT */ ++struct raw1394_kernel_iso_config { ++ unsigned int buf_packets; ++ unsigned int max_packet_size; ++ int channel; ++ int speed; /* xmit only */ ++ int irq_interval; ++}; ++ ++struct raw1394_kernel_iso_status { ++ /* current settings */ ++ struct raw1394_kernel_iso_config config; ++ ++ /* byte offset between successive packets in the buffer */ ++ int buf_stride; ++ ++ /* byte offset of data payload within each packet */ ++ int packet_data_offset; ++ ++ /* byte offset of struct iso_packet_info within each packet */ ++ int packet_info_offset; ++ ++ /* index of next packet to fill with data (ISO transmission) ++ or next packet containing data recieved (ISO reception) */ ++ unsigned int first_packet; ++ ++ /* number of packets waiting to be filled with data (ISO transmission) ++ or containing data received (ISO reception) */ ++ unsigned int n_packets; ++ ++ /* approximate number of packets dropped due to overflow or ++ underflow of the packet buffer (a value of zero guarantees ++ that no packets have been dropped) */ ++ unsigned int overflows; ++ ++ /* the value the ISO CYCLE_COUNT register will have when the first_packet ++ is sent (ISO transmission) or received (ISO reception). ++ set to -1 if you don't care about cycle matching. ++ */ ++ int first_packet_cycle; ++}; ++ + #ifdef __KERNEL__ + + struct iso_block_store { +@@ -77,6 +128,10 @@ + quadlet_t data[0]; + }; + ++enum raw1394_iso_state { RAW1394_ISO_INACTIVE = 0, ++ RAW1394_ISO_RECV = 1, ++ RAW1394_ISO_XMIT = 2 }; ++ + struct file_info { + struct list_head list; + +@@ -93,9 +148,14 @@ + + u8 *fcp_buffer; + ++ /* old ISO API */ + u64 listen_channels; + quadlet_t *iso_buffer; + size_t iso_buffer_length; ++ ++ /* new ISO API */ ++ enum raw1394_iso_state iso_state; ++ struct hpsb_iso *iso_handle; + }; + + struct pending_request { +diff -ru libraw1394/src/main.c libraw1394-iso/src/main.c +--- libraw1394/src/main.c Sun May 13 21:02:10 2001 ++++ libraw1394-iso/src/main.c Mon Aug 26 01:23:02 2002 +@@ -104,12 +104,18 @@ + handle->bus_reset_handler = bus_reset_default; + handle->tag_handler = tag_handler_default; + memset(handle->iso_handler, 0, sizeof(handle->iso_handler)); ++ handle->iso_buffer = NULL; ++ handle->iso_buffer_bytes = 0; ++ + return handle; + } + + void raw1394_destroy_handle(struct raw1394_handle *handle) + { + if (handle) { ++ if(handle->iso_buffer) { ++ raw1394_iso_stop(handle); ++ } + close(handle->fd); + free(handle); + } +diff -ru libraw1394/src/raw1394.h libraw1394-iso/src/raw1394.h +--- libraw1394/src/raw1394.h Sun May 13 21:02:10 2001 ++++ libraw1394-iso/src/raw1394.h Wed Aug 28 01:14:57 2002 +@@ -212,6 +212,101 @@ + */ + const char *raw1394_get_libversion(void); + ++ ++enum raw1394_iso_speed { ++ RAW1394_ISO_SPEED_100 = 0, ++ RAW1394_ISO_SPEED_200 = 1, ++ RAW1394_ISO_SPEED_400 = 2, ++}; ++ ++ ++struct raw1394_iso_config { ++ /* total number of packets in the buffer */ ++ unsigned int buf_packets; ++ ++ /* largest possible packet, in bytes */ ++ unsigned int max_packet_size; ++ ++ /* ISO channel */ ++ int channel; ++ ++ /* speed (transmission only) */ ++ enum raw1394_iso_speed speed; ++ ++ /* max latency of buffer, # of packets (-1 to get a default) */ ++ int irq_interval; ++}; ++ ++struct raw1394_iso_status { ++ /* current settings */ ++ struct raw1394_iso_config config; ++ ++ /* address of the packet buffer (first byte of first packet) */ ++ unsigned char *buf; ++ ++ /* byte offset between successive packets in the buffer */ ++ unsigned int buf_stride; ++ ++ /* byte offset of payload data within each packet */ ++ unsigned int packet_data_offset; ++ ++ /* byte offset of packet length within each packet */ ++ unsigned int packet_info_offset; ++ ++ /* index of next packet to fill with data (ISO transmission) ++ or next packet containing data recieved (ISO reception) */ ++ unsigned int first_packet; ++ ++ /* number of packets waiting to be filled with data (ISO transmission) ++ or containing data received (ISO reception) */ ++ unsigned int n_packets; ++ ++ /* approximate number of packets dropped due to overflow or ++ underflow of the packet buffer (a value of zero guarantees ++ that no packets have been dropped) */ ++ unsigned int overflows; ++ ++ /* the value the ISO CYCLE_COUNT register will have when the first_packet ++ is sent (ISO transmission) or received (ISO reception). ++ set to -1 if you don't care about cycle matching. ++ */ ++ int first_packet_cycle; ++}; ++ ++/* per-packet info embedded in the packet buffer */ ++struct raw1394_iso_packet_info { ++ unsigned short len; ++ unsigned char channel; /* receive only */ ++ unsigned char tag; ++ unsigned char tcode; /* receive only */ ++ unsigned char sy; ++}; ++ ++static inline struct raw1394_iso_packet_info* ++raw1394_iso_packet_info(struct raw1394_iso_status *stat, unsigned int index) ++{ ++ /* XXX make internal */ ++ return (struct raw1394_iso_packet_info*) (stat->buf + index * stat->buf_stride ++ + stat->packet_info_offset); ++} ++ ++static inline unsigned char* ++raw1394_iso_packet_data(struct raw1394_iso_status *stat, unsigned int index) ++{ ++ /* XXX make internal */ ++ return (stat->buf + index * stat->buf_stride + stat->packet_data_offset); ++} ++ ++int raw1394_iso_xmit_start(raw1394handle_t handle, struct raw1394_iso_config *config); ++int raw1394_iso_recv_start(raw1394handle_t handle, struct raw1394_iso_config *config); ++ ++int raw1394_iso_get_status(raw1394handle_t handle, struct raw1394_iso_status *status); ++ ++int raw1394_iso_xmit_produce(raw1394handle_t handle, unsigned int n_packets); ++int raw1394_iso_recv_consume(raw1394handle_t handle, unsigned int n_packets); ++ ++void raw1394_iso_stop(raw1394handle_t handle); ++ + #ifdef __cplusplus + } + #endif +diff -ru libraw1394/src/raw1394_private.h libraw1394-iso/src/raw1394_private.h +--- libraw1394/src/raw1394_private.h Thu Jan 18 20:08:19 2001 ++++ libraw1394-iso/src/raw1394_private.h Mon Aug 26 01:21:55 2002 +@@ -19,6 +19,9 @@ + fcp_handler_t fcp_handler; + iso_handler_t iso_handler[64]; + ++ unsigned char *iso_buffer; ++ unsigned long iso_buffer_bytes; ++ + struct raw1394_request req; + quadlet_t buffer[2048]; + }; |