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>
|
1999-12-02 18:07:38 -05:00
|
|
|
|
|
|
|
#include "raw1394.h"
|
|
|
|
#include "kernel-raw1394.h"
|
|
|
|
#include "raw1394_private.h"
|
|
|
|
|
|
|
|
|
|
|
|
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-06-02 13:03:00 -04:00
|
|
|
req->recvb = (__u64)buffer;
|
1999-12-02 18:07:38 -05:00
|
|
|
|
|
|
|
return (int)write(handle->fd, req, sizeof(*req));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-06-02 13:03:00 -04:00
|
|
|
req->sendb = (__u64)data;
|
1999-12-02 18:07:38 -05:00
|
|
|
|
|
|
|
return (int)write(handle->fd, req, sizeof(*req));
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
req->sendb = (__u64)sendbuf;
|
|
|
|
req->recvb = (__u64)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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 }; \
|
1999-12-02 18:07:38 -05:00
|
|
|
int err
|
|
|
|
|
1999-12-29 17:24:32 -05:00
|
|
|
#define SYNCFUNC_BODY \
|
|
|
|
while (!sd.done) { \
|
|
|
|
if (err < 0) return err; \
|
|
|
|
err = raw1394_loop_iterate(handle); \
|
|
|
|
} \
|
1999-12-02 18:07:38 -05:00
|
|
|
return sd.errcode
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1999-12-02 18:07:38 -05:00
|
|
|
#undef SYNCFUNC_VARS
|
|
|
|
#undef SYNCFUNC_BODY
|