diff --git a/tools/bus_space/C/lang.c b/tools/bus_space/C/lang.c index d9c3f52cde18..f9b404b1b26c 100644 --- a/tools/bus_space/C/lang.c +++ b/tools/bus_space/C/lang.c @@ -80,10 +80,10 @@ bus_write_4(int rid, long ofs, uint32_t val) } int -bus_map(const char *dev) +bus_map(const char *dev, const char *resource) { - return (bs_map(dev)); + return (bs_map(dev, resource)); } int diff --git a/tools/bus_space/C/libbus.h b/tools/bus_space/C/libbus.h index 50efd3808cc8..0fae9879d2ce 100644 --- a/tools/bus_space/C/libbus.h +++ b/tools/bus_space/C/libbus.h @@ -29,7 +29,7 @@ #ifndef _LIBBUS_SPACE_H_ #define _LIBBUS_SPACE_H_ -int bus_map(const char *dev); +int bus_map(const char *dev, const char *resource); int16_t bus_read_1(int rid, long ofs); int32_t bus_read_2(int rid, long ofs); int64_t bus_read_4(int rid, long ofs); diff --git a/tools/bus_space/Python/lang.c b/tools/bus_space/Python/lang.c index 0b96db3fcfd5..48a112ba0c30 100644 --- a/tools/bus_space/Python/lang.c +++ b/tools/bus_space/Python/lang.c @@ -131,12 +131,12 @@ bus_write_4(PyObject *self, PyObject *args) static PyObject * bus_map(PyObject *self, PyObject *args) { - char *dev; + char *dev, *resource; int rid; - if (!PyArg_ParseTuple(args, "s", &dev)) + if (!PyArg_ParseTuple(args, "ss", &dev, &resource)) return (NULL); - rid = bs_map(dev); + rid = bs_map(dev, resource); if (rid == -1) { PyErr_SetString(PyExc_IOError, strerror(errno)); return (NULL); diff --git a/tools/bus_space/bus.c b/tools/bus_space/bus.c index 01b7693c3bf8..1b0d2ca59c3d 100644 --- a/tools/bus_space/bus.c +++ b/tools/bus_space/bus.c @@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -92,19 +93,25 @@ rid_lookup(int rid) } int -bs_map(const char *dev) +bs_map(const char *dev, const char *res) { + char path[PATH_MAX]; struct proto_ioc_region region; struct resource *r; - int rid; + int len, rid; + len = snprintf(path, PATH_MAX, "/dev/proto/%s/%s", dev, res); + if (len >= PATH_MAX) { + errno = EINVAL; + return (-1); + } rid = rid_alloc(); if (rid == -1) return (-1); r = rid_lookup(rid); if (r == NULL) return (-1); - r->fd = open(dev, O_RDWR); + r->fd = open(path, O_RDWR); if (r->fd == -1) return (-1); r->rid = -1; diff --git a/tools/bus_space/bus.h b/tools/bus_space/bus.h index d34710641c66..a1835d74e2b5 100644 --- a/tools/bus_space/bus.h +++ b/tools/bus_space/bus.h @@ -29,7 +29,7 @@ #ifndef _TOOLS_BUS_SPACE_H_ #define _TOOLS_BUS_SPACE_H_ -int bs_map(const char *dev); +int bs_map(const char *dev, const char *res); int bs_read(int rid, off_t ofs, void *buf, ssize_t bufsz); int bs_subregion(int rid0, long ofs, long sz); int bs_unmap(int rid); diff --git a/tools/bus_space/busdma.c b/tools/bus_space/busdma.c index d50d5d23554c..3f948b72f983 100644 --- a/tools/bus_space/busdma.c +++ b/tools/bus_space/busdma.c @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -183,10 +184,16 @@ int bd_tag_create(const char *dev, u_long align, u_long bndry, u_long maxaddr, u_long maxsz, u_int nsegs, u_long maxsegsz, u_int datarate, u_int flags) { + char path[PATH_MAX]; struct obj *tag; - int fd; + int fd, len; - fd = open(dev, O_RDWR); + len = snprintf(path, PATH_MAX, "/dev/proto/%s/busdma", dev); + if (len >= PATH_MAX) { + errno = EINVAL; + return (-1); + } + fd = open(path, O_RDWR); if (fd == -1) return (-1);