2000-06-14 11:01:42 -04:00
|
|
|
/*
|
|
|
|
* libraw1394 - library for raw access to the 1394 bus with the Linux subsystem.
|
|
|
|
*
|
2002-10-13 18:54:49 -04:00
|
|
|
* Copyright (C) 1999,2000,2001,2002 Andreas Bombe
|
2002-10-23 17:18:49 -04:00
|
|
|
* 2002 Christian Toegel <christian.toegel@gmx.at>
|
|
|
|
* 2002 Manfred Weihs <weihs@ict.tuwien.ac.at>
|
2000-06-14 11:01:42 -04:00
|
|
|
*
|
|
|
|
* This library is licensed under the GNU Lesser General Public License (LGPL),
|
|
|
|
* version 2.1 or later. See the file COPYING.LIB in the distribution for
|
|
|
|
* details.
|
2002-10-23 17:18:49 -04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Contributions:
|
|
|
|
*
|
|
|
|
* Christian Toegel <christian.toegel@gmx.at>
|
|
|
|
* lock64 request
|
|
|
|
* transmit physical packet
|
|
|
|
* raw1394_echo_request, raw1394_wake_up (interrupt blocking wait)
|
|
|
|
*
|
|
|
|
* Manfred Weihs <weihs@ict.tuwien.ac.at>
|
|
|
|
* raw1394_start_async_send, raw1394_async_send
|
2000-06-14 11:01:42 -04:00
|
|
|
*/
|
1999-12-02 18:07:38 -05:00
|
|
|
|
2000-05-28 17:00:56 -04:00
|
|
|
#include <config.h>
|
1999-12-02 18:07:38 -05:00
|
|
|
#include <unistd.h>
|
2000-02-06 10:10:14 -05:00
|
|
|
#include <errno.h>
|
2002-10-23 17:18:49 -04:00
|
|
|
#include <string.h>
|
1999-12-02 18:07:38 -05:00
|
|
|
|
|
|
|
#include "raw1394.h"
|
|
|
|
#include "kernel-raw1394.h"
|
|
|
|
#include "raw1394_private.h"
|
|
|
|
|
|
|
|
|
2002-10-13 18:54:49 -04:00
|
|
|
/**
|
|
|
|
* raw1394_start_read - initiate a read transaction
|
|
|
|
* @node: target node
|
|
|
|
* @addr: address to read from
|
|
|
|
* @length: amount of data to read
|
|
|
|
* @buffer: pointer to buffer where data will be saved
|
|
|
|
* @tag: data to identify the request to completion handler
|
|
|
|
*
|
|
|
|
* This function starts the specified read request and returns %0 for success
|
|
|
|
* and a negative number for an error, in which case errno will be set. If
|
|
|
|
* @length is %4 a quadlet read is initiated and a block read otherwise.
|
|
|
|
*
|
|
|
|
* The transaction is only started, no success of the transaction is implied
|
|
|
|
* with a successful return of this function. When the transaction completes, a
|
|
|
|
* raw1394_loop_iterate() will call the tag handler and pass it the tag and
|
|
|
|
* error code of the transaction. @tag should therefore be set to something
|
|
|
|
* that uniquely identifies this transaction (e.g. a struct pointer casted to
|
|
|
|
* unsigned long).
|
|
|
|
**/
|
1999-12-02 18:07:38 -05:00
|
|
|
int raw1394_start_read(struct raw1394_handle *handle, nodeid_t node,
|
|
|
|
nodeaddr_t addr, size_t length, quadlet_t *buffer,
|
|
|
|
unsigned long tag)
|
|
|
|
{
|
|
|
|
struct raw1394_request *req = &handle->req;
|
|
|
|
|
|
|
|
CLEAR_REQ(req);
|
|
|
|
|
|
|
|
req->type = RAW1394_REQ_ASYNC_READ;
|
|
|
|
req->generation = handle->generation;
|
|
|
|
req->tag = tag;
|
|
|
|
|
2000-06-02 13:03:00 -04:00
|
|
|
req->address = ((__u64)node << 48) | addr;
|
1999-12-02 18:07:38 -05:00
|
|
|
req->length = length;
|
2000-09-10 18:18:49 -04:00
|
|
|
req->recvb = ptr2int(buffer);
|
1999-12-02 18:07:38 -05:00
|
|
|
|
|
|
|
return (int)write(handle->fd, req, sizeof(*req));
|
|
|
|
}
|
|
|
|
|
2002-10-13 18:54:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* raw1394_start_write - initiate a write transaction
|
|
|
|
* @node: target node
|
|
|
|
* @addr: address to write to
|
|
|
|
* @length: amount of data to write
|
|
|
|
* @data: pointer to data to be sent
|
|
|
|
* @tag: data to identify the request to completion handler
|
|
|
|
*
|
|
|
|
* This function starts the specified write request and returns %0 for success
|
|
|
|
* and a negative number for an error, in which case errno will be set. If
|
|
|
|
* @length is %4 a quadlet write is initiated and a block write otherwise.
|
|
|
|
*
|
|
|
|
* The transaction is only started, no success of the transaction is implied
|
|
|
|
* with a successful return of this function. When the transaction completes, a
|
|
|
|
* raw1394_loop_iterate() will call the tag handler and pass it the tag and
|
|
|
|
* error code of the transaction. @tag should therefore be set to something
|
|
|
|
* that uniquely identifies this transaction (e.g. a struct pointer casted to
|
|
|
|
* unsigned long).
|
|
|
|
**/
|
1999-12-02 18:07:38 -05:00
|
|
|
int raw1394_start_write(struct raw1394_handle *handle, nodeid_t node,
|
|
|
|
nodeaddr_t addr, size_t length, quadlet_t *data,
|
|
|
|
unsigned long tag)
|
|
|
|
{
|
|
|
|
struct raw1394_request *req = &handle->req;
|
|
|
|
|
|
|
|
CLEAR_REQ(req);
|
|
|
|
|
|
|
|
req->type = RAW1394_REQ_ASYNC_WRITE;
|
|
|
|
req->generation = handle->generation;
|
|
|
|
req->tag = tag;
|
|
|
|
|
2000-06-02 13:03:00 -04:00
|
|
|
req->address = ((__u64)node << 48) | addr;
|
1999-12-02 18:07:38 -05:00
|
|
|
req->length = length;
|
2000-09-10 18:18:49 -04:00
|
|
|
req->sendb = ptr2int(data);
|
1999-12-02 18:07:38 -05:00
|
|
|
|
|
|
|
return (int)write(handle->fd, req, sizeof(*req));
|
|
|
|
}
|
|
|
|
|
2002-10-13 18:54:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* raw1394_start_read - initiate a lock transaction
|
|
|
|
* @node: target node
|
|
|
|
* @addr: address to read from
|
|
|
|
* @extcode: extended transaction code determining the lock operation
|
|
|
|
* @data: data part of lock parameters
|
|
|
|
* @arg: arg part of lock parameters
|
|
|
|
* @result: address where return value will be written
|
|
|
|
* @tag: data to identify the request to completion handler
|
|
|
|
*
|
|
|
|
* This function starts the specified lock request and returns %0 for success
|
|
|
|
* and a negative number for an error, in which case errno will be set.
|
|
|
|
*
|
|
|
|
* The transaction is only started, no success of the transaction is implied
|
|
|
|
* with a successful return of this function. When the transaction completes, a
|
|
|
|
* raw1394_loop_iterate() will call the tag handler and pass it the tag and
|
|
|
|
* error code of the transaction. @tag should therefore be set to something
|
|
|
|
* that uniquely identifies this transaction (e.g. a struct pointer casted to
|
|
|
|
* unsigned long).
|
|
|
|
**/
|
2000-02-06 10:10:14 -05:00
|
|
|
int raw1394_start_lock(struct raw1394_handle *handle, nodeid_t node,
|
|
|
|
nodeaddr_t addr, unsigned int extcode, quadlet_t data,
|
2000-04-14 20:33:26 -04:00
|
|
|
quadlet_t arg, quadlet_t *result, unsigned long tag)
|
2000-02-06 10:10:14 -05:00
|
|
|
{
|
|
|
|
struct raw1394_request *req = &handle->req;
|
|
|
|
quadlet_t sendbuf[2];
|
|
|
|
|
|
|
|
if ((extcode > 7) || (extcode == 0)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CLEAR_REQ(req);
|
|
|
|
|
|
|
|
req->type = RAW1394_REQ_LOCK;
|
|
|
|
req->generation = handle->generation;
|
|
|
|
req->tag = tag;
|
|
|
|
|
2000-06-02 13:03:00 -04:00
|
|
|
req->address = ((__u64)node << 48) | addr;
|
2000-09-10 18:18:49 -04:00
|
|
|
req->sendb = ptr2int(sendbuf);
|
|
|
|
req->recvb = ptr2int(result);
|
2000-04-26 21:09:52 -04:00
|
|
|
req->misc = extcode;
|
2000-02-06 10:10:14 -05:00
|
|
|
|
|
|
|
switch (extcode) {
|
|
|
|
case 3: /* EXTCODE_FETCH_ADD */
|
|
|
|
case 4: /* EXTCODE_LITTLE_ADD */
|
|
|
|
sendbuf[0] = data;
|
|
|
|
req->length = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sendbuf[0] = arg;
|
|
|
|
sendbuf[1] = data;
|
|
|
|
req->length = 8;
|
|
|
|
break;
|
|
|
|
}
|
2002-10-23 17:18:49 -04:00
|
|
|
return (int)write(handle->fd, req, sizeof(*req));
|
|
|
|
}
|
|
|
|
|
|
|
|
int raw1394_start_lock64(struct raw1394_handle *handle, nodeid_t node,
|
|
|
|
nodeaddr_t addr, unsigned int extcode, octlet_t data,
|
|
|
|
octlet_t arg, octlet_t *result, unsigned long tag)
|
|
|
|
{
|
|
|
|
struct raw1394_request *req = &handle->req;
|
|
|
|
octlet_t sendbuf[2];
|
|
|
|
|
|
|
|
if ((extcode > 7) || (extcode == 0)) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CLEAR_REQ(req);
|
|
|
|
|
|
|
|
req->type = RAW1394_REQ_LOCK64;
|
|
|
|
req->generation = handle->generation;
|
|
|
|
req->tag = tag;
|
|
|
|
|
|
|
|
req->address = ((__u64)node << 48) | addr;
|
|
|
|
req->sendb = ptr2int(sendbuf);
|
|
|
|
req->recvb = ptr2int(result);
|
|
|
|
req->misc = extcode;
|
|
|
|
|
|
|
|
switch (extcode) {
|
|
|
|
case 3: /* EXTCODE_FETCH_ADD */
|
|
|
|
case 4: /* EXTCODE_LITTLE_ADD */
|
|
|
|
sendbuf[0] = data;
|
|
|
|
req->length = 8;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sendbuf[0] = arg;
|
|
|
|
sendbuf[1] = data;
|
|
|
|
req->length = 16;
|
|
|
|
break;
|
|
|
|
}
|
2000-02-06 10:10:14 -05:00
|
|
|
|
|
|
|
return (int)write(handle->fd, req, sizeof(*req));
|
|
|
|
}
|
1999-12-02 18:07:38 -05:00
|
|
|
|
2002-10-13 18:54:49 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* raw1394_start_iso_write - initiate an isochronous packet write
|
|
|
|
* @channel: channel number on which to send on
|
|
|
|
* @tag: data to be put into packet's tag field
|
|
|
|
* @sy: data to be put into packet's sy field
|
|
|
|
* @speed: speed at which to send
|
|
|
|
* @length: amount of data to send
|
|
|
|
* @data: pointer to data to send
|
|
|
|
* @rawtag: data to identify the request to completion handler
|
|
|
|
*
|
|
|
|
* This function starts the specified isochronous packet transmission and
|
|
|
|
* returns %0 for success and a negative number for an error, in which case
|
|
|
|
* errno will be set.
|
|
|
|
*
|
|
|
|
* When the send completes, a raw1394_loop_iterate() will call the tag handler
|
|
|
|
* and pass it the tag and error code of the transaction. @tag should therefore
|
|
|
|
* be set to something that uniquely identifies this transaction (e.g. a struct
|
|
|
|
* pointer casted to unsigned long).
|
|
|
|
*
|
|
|
|
* Isochronous packets are automatically
|
|
|
|
**/
|
2000-08-05 22:44:00 -04:00
|
|
|
int raw1394_start_iso_write(struct raw1394_handle *handle, unsigned int channel,
|
|
|
|
unsigned int tag, unsigned int sy,
|
|
|
|
unsigned int speed, size_t length, quadlet_t *data,
|
|
|
|
unsigned long rawtag)
|
|
|
|
{
|
|
|
|
struct raw1394_request *req = &handle->req;
|
|
|
|
|
|
|
|
CLEAR_REQ(req);
|
|
|
|
|
|
|
|
req->type = RAW1394_REQ_ISO_SEND;
|
|
|
|
req->generation = handle->generation;
|
2000-09-13 19:24:53 -04:00
|
|
|
req->tag = rawtag;
|
2000-08-05 22:44:00 -04:00
|
|
|
|
|
|
|
req->address = ((__u64)channel << 48) | speed;
|
|
|
|
req->misc = (tag << 16) | sy;
|
|
|
|
req->length = length;
|
2000-09-10 18:18:49 -04:00
|
|
|
req->sendb = ptr2int(data);
|
2000-08-05 22:44:00 -04:00
|
|
|
|
|
|
|
return (int)write(handle->fd, req, sizeof(*req));
|
|
|
|
}
|
|
|
|
|
2002-10-23 17:18:49 -04:00
|
|
|
int raw1394_start_async_send(struct raw1394_handle *handle,
|
|
|
|
size_t length, size_t header_length, unsigned int expect_response,
|
|
|
|
quadlet_t *data, unsigned long rawtag)
|
|
|
|
{
|
|
|
|
struct raw1394_request *req = &handle->req;
|
|
|
|
|
|
|
|
CLEAR_REQ(req);
|
|
|
|
|
|
|
|
req->type = RAW1394_REQ_ASYNC_SEND;
|
|
|
|
req->generation = handle->generation;
|
|
|
|
req->tag = rawtag;
|
|
|
|
|
|
|
|
req->length = length;
|
|
|
|
req->misc = (expect_response << 16) | (header_length & 0xffff);
|
|
|
|
req->sendb = ptr2int(data);
|
|
|
|
|
|
|
|
return (int)write(handle->fd, req, sizeof(*req));
|
|
|
|
}
|
|
|
|
|
1999-12-02 18:07:38 -05:00
|
|
|
|
1999-12-29 17:24:32 -05:00
|
|
|
#define SYNCFUNC_VARS \
|
|
|
|
struct sync_cb_data sd = { 0, 0 }; \
|
|
|
|
struct raw1394_reqhandle rh = { (req_callback_t)_raw1394_sync_cb, \
|
|
|
|
&sd }; \
|
2001-01-18 20:11:48 -05:00
|
|
|
int err = 0
|
|
|
|
|
|
|
|
#define SYNCFUNC_BODY \
|
|
|
|
while (!sd.done) { \
|
|
|
|
if (err < 0) return err; \
|
|
|
|
err = raw1394_loop_iterate(handle); \
|
|
|
|
} \
|
|
|
|
handle->err = sd.errcode; \
|
|
|
|
errno = raw1394_errcode_to_errno(sd.errcode); \
|
|
|
|
return (errno ? -1 : 0)
|
1999-12-02 18:07:38 -05:00
|
|
|
|
|
|
|
int raw1394_read(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr,
|
|
|
|
size_t length, quadlet_t *buffer)
|
|
|
|
{
|
|
|
|
SYNCFUNC_VARS;
|
|
|
|
|
|
|
|
err = raw1394_start_read(handle, node, addr, length, buffer,
|
|
|
|
(unsigned long)&rh);
|
|
|
|
|
|
|
|
SYNCFUNC_BODY;
|
|
|
|
}
|
|
|
|
|
|
|
|
int raw1394_write(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr,
|
|
|
|
size_t length, quadlet_t *data)
|
|
|
|
{
|
|
|
|
SYNCFUNC_VARS;
|
|
|
|
|
|
|
|
err = raw1394_start_write(handle, node, addr, length, data,
|
|
|
|
(unsigned long)&rh);
|
|
|
|
|
|
|
|
SYNCFUNC_BODY;
|
|
|
|
}
|
|
|
|
|
2000-02-06 10:10:14 -05:00
|
|
|
int raw1394_lock(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr,
|
2000-04-14 20:33:26 -04:00
|
|
|
unsigned int extcode, quadlet_t data, quadlet_t arg,
|
|
|
|
quadlet_t *result)
|
2000-02-06 10:10:14 -05:00
|
|
|
{
|
|
|
|
SYNCFUNC_VARS;
|
|
|
|
|
2000-04-14 20:33:26 -04:00
|
|
|
err = raw1394_start_lock(handle, node, addr, extcode, data, arg, result,
|
2000-02-06 10:10:14 -05:00
|
|
|
(unsigned long)&rh);
|
|
|
|
|
|
|
|
SYNCFUNC_BODY;
|
|
|
|
}
|
|
|
|
|
2002-10-23 17:18:49 -04:00
|
|
|
int raw1394_lock64(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr,
|
|
|
|
unsigned int extcode, octlet_t data, octlet_t arg,
|
|
|
|
octlet_t *result)
|
|
|
|
{
|
|
|
|
SYNCFUNC_VARS;
|
|
|
|
|
|
|
|
err = raw1394_start_lock64(handle, node, addr, extcode, data, arg, result,
|
|
|
|
(unsigned long)&rh);
|
|
|
|
|
|
|
|
SYNCFUNC_BODY;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-05 22:44:00 -04:00
|
|
|
int raw1394_iso_write(struct raw1394_handle *handle, unsigned int channel,
|
|
|
|
unsigned int tag, unsigned int sy, unsigned int speed,
|
|
|
|
size_t length, quadlet_t *data)
|
|
|
|
{
|
|
|
|
SYNCFUNC_VARS;
|
|
|
|
|
|
|
|
err = raw1394_start_iso_write(handle, channel, tag, sy, speed, length,
|
|
|
|
data, (unsigned long)&rh);
|
|
|
|
|
|
|
|
SYNCFUNC_BODY;
|
|
|
|
}
|
|
|
|
|
2002-10-23 17:18:49 -04:00
|
|
|
int raw1394_async_send(struct raw1394_handle *handle ,
|
|
|
|
size_t length, size_t header_length, unsigned int expect_response,
|
|
|
|
quadlet_t *data)
|
|
|
|
{
|
|
|
|
SYNCFUNC_VARS;
|
|
|
|
|
|
|
|
err = raw1394_start_async_send(handle, length, header_length, expect_response,
|
|
|
|
data, (unsigned long)&rh);
|
|
|
|
|
|
|
|
SYNCFUNC_BODY;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int raw1394_start_phy_packet_write(struct raw1394_handle *handle,
|
|
|
|
quadlet_t data, unsigned long tag)
|
|
|
|
{
|
|
|
|
struct raw1394_request *req = &handle->req;
|
|
|
|
|
|
|
|
CLEAR_REQ(req);
|
|
|
|
|
|
|
|
req->type = RAW1394_REQ_PHYPACKET;
|
|
|
|
req->generation = handle->generation;
|
|
|
|
req->tag = tag;
|
|
|
|
|
|
|
|
req->sendb = data;
|
|
|
|
|
|
|
|
return (int)write(handle->fd, req, sizeof(*req));
|
|
|
|
}
|
|
|
|
|
|
|
|
int raw1394_phy_packet_write (struct raw1394_handle *handle, quadlet_t data)
|
|
|
|
{
|
|
|
|
SYNCFUNC_VARS;
|
|
|
|
|
|
|
|
err = raw1394_start_phy_packet_write(handle, data, (unsigned long)&rh);
|
|
|
|
|
|
|
|
SYNCFUNC_BODY; /* return 0 on success */
|
|
|
|
}
|
|
|
|
|
|
|
|
int raw1394_echo_request(struct raw1394_handle *handle, quadlet_t data)
|
|
|
|
{
|
|
|
|
struct raw1394_request *req = &handle->req;
|
|
|
|
int retval=0;
|
|
|
|
|
|
|
|
CLEAR_REQ(req);
|
|
|
|
|
|
|
|
req->type = RAW1394_REQ_ECHO;
|
|
|
|
req->misc = data;
|
|
|
|
|
|
|
|
retval = (int)write(handle->fd, req, sizeof(*req));
|
|
|
|
if (retval == sizeof(*req)) {
|
|
|
|
return 0; /* succcess */
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int raw1394_wake_up(raw1394handle_t handle)
|
|
|
|
{
|
|
|
|
return raw1394_echo_request(handle, 0);
|
|
|
|
}
|
|
|
|
|
1999-12-02 18:07:38 -05:00
|
|
|
#undef SYNCFUNC_VARS
|
|
|
|
#undef SYNCFUNC_BODY
|