[dahdi-commits] fjoe: freebsd/trunk r8863 - in /freebsd/trunk: drivers/dahdi/ freebsd/ freebs...
SVN commits to the DAHDI project
dahdi-commits at lists.digium.com
Thu Jul 8 07:47:46 CDT 2010
Author: fjoe
Date: Thu Jul 8 07:47:42 2010
New Revision: 8863
URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8863
Log:
- Initial dahdi_transcode driver port
- dahdi_fop_read(), dahdi_fop_write() and dahdi_copy_from_user() now return
negative values on error (as expected by Linux KPI)
Added:
freebsd/trunk/freebsd/dahdi_transcode/
freebsd/trunk/freebsd/dahdi_transcode/Makefile (with props)
Modified:
freebsd/trunk/drivers/dahdi/dahdi-base.c
freebsd/trunk/drivers/dahdi/dahdi_transcode.c
freebsd/trunk/freebsd/Makefile
freebsd/trunk/include/dahdi/compat/bsd.h
freebsd/trunk/include/dahdi/kernel.h
Modified: freebsd/trunk/drivers/dahdi/dahdi-base.c
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/drivers/dahdi/dahdi-base.c?view=diff&rev=8863&r1=8862&r2=8863
==============================================================================
--- freebsd/trunk/drivers/dahdi/dahdi-base.c (original)
+++ freebsd/trunk/drivers/dahdi/dahdi-base.c Thu Jul 8 07:47:42 2010
@@ -49,11 +49,6 @@
#include <net/ppp_defs.h>
#include "version.h"
-
-#define FOP_READ_ARGS_DECL struct file *file, struct uio *uio, size_t count
-#define FOP_READ_ARGS file, uio, count
-#define FOP_WRITE_ARGS_DECL struct file *file, struct uio *uio, size_t count
-#define FOP_WRITE_ARGS file, uio, count
#define MODULE_PARAM_PREFIX "dahdi"
#define MODULE_PARAM_PARENT _dahdi
@@ -183,23 +178,6 @@
static struct cdevsw dahdi_devsw;
-struct inode;
-
-struct file {
- struct cdev *dev;
- int f_flags;
-};
-
-struct vm_area_struct {
- vm_offset_t offset;
- vm_paddr_t *paddr;
- int nprot;
-};
-
-struct poll_table_struct {
- struct selinfo *selinfo;
-};
-
#define UNIT(file) dev2unit(file->dev)
struct dahdi_fp {
@@ -260,7 +238,7 @@
fp->fflags = fflags;
}
-static void *
+void *
dahdi_get_private_data(struct file *file)
{
int error;
@@ -273,7 +251,7 @@
return fp->private_data;
}
-static void
+void
dahdi_set_private_data(struct file *file, void *private_data)
{
int error;
@@ -299,7 +277,7 @@
TASK_INIT(&sel->task, 0, handle_selwakeup, &sel->selinfo);
}
-static void
+void
dahdi_poll_wait(struct file *file, struct pollinfo *sel, struct poll_table_struct *wait_table)
{
wait_table->selinfo = &sel->selinfo;
@@ -341,19 +319,19 @@
static int
dahdi_fop_read(FOP_READ_ARGS_DECL, int off, void *buf, int iocount)
{
- return uiomove(buf, iocount, uio);
+ return -uiomove(buf, iocount, uio);
}
static int
dahdi_fop_write(FOP_WRITE_ARGS_DECL, int off, void *buf, int iocount)
{
- return uiomove(buf, iocount, uio);
+ return -uiomove(buf, iocount, uio);
}
static int
dahdi_copy_from_user(void *to, const void *from, int n)
{
- return copyin(from, to, n);
+ return -copyin(from, to, n);
}
struct pseudo_free {
@@ -415,13 +393,13 @@
return file->f_flags;
}
-static void *
+void *
dahdi_get_private_data(struct file *file)
{
return file->private_data;
}
-static void
+void
dahdi_set_private_data(struct file *file, void *private_data)
{
file->private_data = private_data;
@@ -433,7 +411,7 @@
init_wait_queue_head(&sel->wait_queue);
}
-static void
+void
dahdi_poll_wait(struct file *file, struct pollinfo *sel, struct poll_table_struct *wait_table)
{
poll_wait(file, &sel->wait_queue, wait_table);
@@ -518,8 +496,6 @@
CLASS_DEV_DESTROY(dahdi_class, MKDEV(DAHDI_MAJOR, dev->minor));
return 0;
}
-
-struct file_operations *dahdi_transcode_fops = NULL;
EXPORT_SYMBOL(dahdi_transcode_fops);
EXPORT_SYMBOL(dahdi_init_tone_state);
@@ -602,6 +578,8 @@
#define class_destroy class_simple_destroy
#endif
#endif /* !__FreeBSD__ */
+
+struct file_operations *dahdi_transcode_fops = NULL;
static int deftaps = 64;
@@ -3204,7 +3182,6 @@
if (!unit)
return dahdi_ctl_open(file);
if (unit == 250) {
-#if !defined(__FreeBSD__)
if (!dahdi_transcode_fops) {
if (request_module("dahdi_transcode")) {
return -ENXIO;
@@ -3224,7 +3201,6 @@
* file_operations table. */
WARN_ON(1);
}
-#endif /* !__FreeBSD__ */
return -ENXIO;
}
if (unit == 253) {
@@ -3270,6 +3246,12 @@
return -EINVAL;
}
+ if (unit == 250) {
+ if (dahdi_transcode_fops && dahdi_transcode_fops->read)
+ return dahdi_transcode_fops->read(FOP_READ_ARGS);
+ return -ENOSYS;
+ }
+
if (unit == 253)
return -EINVAL;
@@ -3303,6 +3285,11 @@
return -EINVAL;
if (count < 0)
return -EINVAL;
+ if (unit == 250) {
+ if (dahdi_transcode_fops && dahdi_transcode_fops->write)
+ return dahdi_transcode_fops->write(FOP_WRITE_ARGS);
+ return -ENOSYS;
+ }
if (unit == 253)
return -EINVAL;
if (unit == 254) {
@@ -3781,11 +3768,16 @@
return dahdi_timer_release(file);
}
if (unit == 250) {
+#if defined(__FreeBSD__)
+ if (dahdi_transcode_fops && dahdi_transcode_fops->release)
+ return dahdi_transcode_fops->release(inode, file);
+#else
/* We should not be here because the dahdi_transcode.ko module
* should have updated the file_operations for this file
* handle when the file was opened. */
WARN_ON(1);
return -EFAULT;
+#endif
}
if (unit == 254) {
chan = dahdi_get_private_data(file);
@@ -6206,11 +6198,18 @@
}
if (unit == 250) {
+#if defined(__FreeBSD__)
+ if (dahdi_transcode_fops && dahdi_transcode_fops->ioctl) {
+ ret = dahdi_transcode_fops->ioctl(inode, file, cmd, data);
+ goto unlock_exit;
+ }
+#else
/* dahdi_transcode should have updated the file_operations on
* this file object on open, so we shouldn't be here. */
WARN_ON(1);
ret = -EFAULT;
goto unlock_exit;
+#endif
}
if (unit == 253) {
@@ -8408,11 +8407,11 @@
static int dahdi_mmap(struct file *file, struct vm_area_struct *vm)
{
-#if !defined(__FreeBSD__)
int unit = UNIT(file);
- if (unit == 250)
- return dahdi_transcode_fops->mmap(file, vm);
-#endif
+ if (unit == 250) {
+ if (dahdi_transcode_fops && dahdi_transcode_fops->mmap)
+ return dahdi_transcode_fops->mmap(file, vm);
+ }
return -ENOSYS;
}
@@ -8424,12 +8423,11 @@
if (!unit)
return -EINVAL;
- if (unit == 250)
-#if defined(__FreeBSD__)
- return -ENXIO;
-#else
- return dahdi_transcode_fops->poll(file, wait_table);
-#endif
+ if (unit == 250) {
+ if (dahdi_transcode_fops && dahdi_transcode_fops->poll)
+ return dahdi_transcode_fops->poll(file, wait_table);
+ return -ENOSYS;
+ }
if (unit == 253)
return dahdi_timer_poll(file, wait_table);
Modified: freebsd/trunk/drivers/dahdi/dahdi_transcode.c
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/drivers/dahdi/dahdi_transcode.c?view=diff&rev=8863&r1=8862&r2=8863
==============================================================================
--- freebsd/trunk/drivers/dahdi/dahdi_transcode.c (original)
+++ freebsd/trunk/drivers/dahdi/dahdi_transcode.c Thu Jul 8 07:47:42 2010
@@ -22,6 +22,15 @@
* this program for more details.
*/
+#if defined(__FreeBSD__)
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/conf.h>
+#include <sys/fcntl.h>
+#include <sys/ioccom.h>
+#include <sys/module.h>
+#include <sys/poll.h>
+#else /* !__FreeBSD__ */
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/module.h>
@@ -35,18 +44,23 @@
#include <linux/mm.h>
#include <linux/page-flags.h>
#include <asm/io.h>
+#endif /* !__FreeBSD__ */
#include <dahdi/kernel.h>
static int debug;
/* The registration list contains transcoders in the order in which they were
* registered. */
-static LIST_HEAD(registration_list);
+static _LIST_HEAD(registration_list);
/* The active list is sorted by the most recently used transcoder is last. This
* is used as a simplistic way to spread the load amongst the different hardware
* transcoders in the system. */
-static LIST_HEAD(active_list);
+static _LIST_HEAD(active_list);
+#ifdef DEFINE_SPINLOCK
+static DEFINE_SPINLOCK(translock);
+#else
static spinlock_t translock = SPIN_LOCK_UNLOCKED;
+#endif
EXPORT_SYMBOL(dahdi_transcoder_register);
EXPORT_SYMBOL(dahdi_transcoder_unregister);
@@ -150,6 +164,7 @@
static int dahdi_tc_open(struct inode *inode, struct file *file)
{
+#if !defined(__FreeBSD__)
const struct file_operations *original_fops;
BUG_ON(!dahdi_transcode_fops);
original_fops = file->f_op;
@@ -160,6 +175,7 @@
* responsible for taking a reference out on this module before
* calling this function. */
module_put(original_fops->owner);
+#endif
return 0;
}
@@ -174,7 +190,7 @@
static int dahdi_tc_release(struct inode *inode, struct file *file)
{
- struct dahdi_transcoder_channel *chan = file->private_data;
+ struct dahdi_transcoder_channel *chan = dahdi_get_private_data(file);
/* There will not be a transcoder channel associated with this file if
* the ALLOCATE ioctl never succeeded.
*/
@@ -223,8 +239,9 @@
* supported but all the channels are busy, or -ENODEV if there are not any
* transcoders that support the formats.
*/
-static struct dahdi_transcoder_channel *
-__find_free_channel(struct list_head *list, const struct dahdi_transcoder_formats *fmts)
+static int
+__find_free_channel(struct list_head *list, const struct dahdi_transcoder_formats *fmts,
+ struct dahdi_transcoder_channel **pchan)
{
struct dahdi_transcoder *tc;
struct dahdi_transcoder_channel *chan = NULL;
@@ -242,16 +259,18 @@
* transcoder in the system) we'll move tc
* to the end of the list. */
list_move_tail(&tc->active_list_node, list);
- return chan;
+ *pchan = chan;
+ return 0;
}
}
}
- return (void*)((long)((match) ? -EBUSY : -ENODEV));
+ return ((match) ? -EBUSY : -ENODEV);
}
static long dahdi_tc_allocate(struct file *file, unsigned long data)
{
- struct dahdi_transcoder_channel *chan = NULL;
+ int res;
+ struct dahdi_transcoder_channel *chan = NULL, *old_chan;
struct dahdi_transcoder_formats fmts;
if (copy_from_user(&fmts, (__user const void *) data, sizeof(fmts))) {
@@ -259,12 +278,10 @@
}
spin_lock(&translock);
- chan = __find_free_channel(&active_list, &fmts);
+ res = __find_free_channel(&active_list, &fmts, &chan);
spin_unlock(&translock);
-
- if (IS_ERR(chan)) {
- return PTR_ERR(chan);
- }
+ if (res)
+ return res;
/* Every transcoder channel must be associated with a parent
* transcoder. */
@@ -273,13 +290,14 @@
chan->srcfmt = fmts.srcfmt;
chan->dstfmt = fmts.dstfmt;
- if (file->private_data) {
+ if ((old_chan = dahdi_get_private_data(file)) != NULL) {
/* This open file is moving to a new channel. Cleanup and
* close the old channel here. */
- dtc_release(file->private_data);
- }
-
- file->private_data = chan;
+ dtc_release(old_chan);
+ }
+
+ dahdi_set_private_data(file, chan);
+#if !defined(__FreeBSD__)
if (chan->parent->fops.owner != file->f_op->owner) {
if (!try_module_get(chan->parent->fops.owner)) {
/* Failed to get a reference on the driver for the
@@ -290,6 +308,7 @@
module_put(file->f_op->owner);
file->f_op = &chan->parent->fops;
}
+#endif
if (file->f_flags & O_NONBLOCK) {
dahdi_tc_set_nonblock(chan);
@@ -336,9 +355,15 @@
return copy_to_user((__user void *) data, &info, sizeof(info)) ? -EFAULT : 0;
}
-static ssize_t dahdi_tc_write(struct file *file, __user const char *usrbuf, size_t count, loff_t *ppos)
-{
- if (file->private_data) {
+static ssize_t dahdi_tc_write(FOP_WRITE_ARGS_DECL)
+{
+ struct dahdi_transcoder_channel *chan = dahdi_get_private_data(file);
+
+ if (chan != NULL) {
+#if defined(__FreeBSD__)
+ if (chan->parent->fops.write)
+ return chan->parent->fops.write(FOP_WRITE_ARGS);
+#endif
/* file->private_data will not be NULL if DAHDI_TC_ALLOCATE was
* called, and therefore indicates that the transcoder driver
* did not export a read function. */
@@ -351,9 +376,15 @@
}
}
-static ssize_t dahdi_tc_read(struct file *file, __user char *usrbuf, size_t count, loff_t *ppos)
-{
- if (file->private_data) {
+static ssize_t dahdi_tc_read(FOP_READ_ARGS_DECL)
+{
+ struct dahdi_transcoder_channel *chan = dahdi_get_private_data(file);
+
+ if (chan != NULL) {
+#if defined(__FreeBSD__)
+ if (chan->parent->fops.read)
+ return chan->parent->fops.read(FOP_READ_ARGS);
+#endif
/* file->private_data will not be NULL if DAHDI_TC_ALLOCATE was
* called, and therefore indicates that the transcoder driver
* did not export a write function. */
@@ -410,7 +441,7 @@
static unsigned int dahdi_tc_poll(struct file *file, struct poll_table_struct *wait_table)
{
int ret;
- struct dahdi_transcoder_channel *chan = file->private_data;
+ struct dahdi_transcoder_channel *chan = dahdi_get_private_data(file);
if (!chan) {
/* This is because the DAHDI_TC_ALLOCATE ioctl was not called
@@ -418,7 +449,7 @@
return -EINVAL;
}
- poll_wait(file, &chan->ready, wait_table);
+ dahdi_poll_wait(file, &chan->ready, wait_table);
ret = dahdi_tc_is_busy(chan) ? 0 : POLLPRI;
ret |= dahdi_tc_is_built(chan) ? POLLOUT : 0;
@@ -435,7 +466,7 @@
.write = dahdi_tc_write,
.poll = dahdi_tc_poll,
.mmap = dahdi_tc_mmap,
-#if HAVE_UNLOCKED_IOCTL
+#ifdef HAVE_UNLOCKED_IOCTL
.unlocked_ioctl = dahdi_tc_unlocked_ioctl,
#endif
};
@@ -472,7 +503,36 @@
printk(KERN_DEBUG "%s: Unloaded.\n", THIS_MODULE->name);
}
+#if defined(__FreeBSD__)
+SYSCTL_NODE(_dahdi, OID_AUTO, transcode, CTLFLAG_RW, 0, "DAHDI Transcoder Support");
+#define MODULE_PARAM_PREFIX "dahdi.transcode"
+#define MODULE_PARAM_PARENT _dahdi_transcode
+#endif
+
module_param(debug, int, S_IRUGO | S_IWUSR);
+
+#if defined(__FreeBSD__)
+static int
+transcode_modevent(module_t mod __unused, int type, void *data __unused)
+{
+ int res;
+
+ switch (type) {
+ case MOD_LOAD:
+ res = dahdi_transcode_init();
+ return (-res);
+ case MOD_UNLOAD:
+ dahdi_transcode_cleanup();
+ return (0);
+ default:
+ return (EOPNOTSUPP);
+ }
+}
+
+DAHDI_DEV_MODULE(dahdi_transcode, transcode_modevent, NULL);
+MODULE_VERSION(dahdi_transcode, 1);
+MODULE_DEPEND(dahdi_transcode, dahdi, 1, 1, 1);
+#else /* !__FreeBSD__ */
MODULE_DESCRIPTION("DAHDI Transcoder Support");
MODULE_AUTHOR("Mark Spencer <markster at digium.com>");
#ifdef MODULE_LICENSE
@@ -481,3 +541,4 @@
module_init(dahdi_transcode_init);
module_exit(dahdi_transcode_cleanup);
+#endif
Modified: freebsd/trunk/freebsd/Makefile
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/freebsd/Makefile?view=diff&rev=8863&r1=8862&r2=8863
==============================================================================
--- freebsd/trunk/freebsd/Makefile (original)
+++ freebsd/trunk/freebsd/Makefile Thu Jul 8 07:47:42 2010
@@ -1,22 +1,29 @@
# $Id$
+# DAHDI
SUBDIR=\
dahdi\
dahdi_dynamic\
+ dahdi_transcode\
+ dahdi_voicebus
+
+# dynamic drivers
+SUBDIR+=\
dahdi_dynamic_loc\
dahdi_dynamic_eth\
dahdi_dynamic_ethmf\
+ ng_dahdi_netdev
+
+# SW echo cancellation drivers
+SUBDIR+=\
dahdi_echocan_jpah\
dahdi_echocan_kb1\
dahdi_echocan_mg2\
dahdi_echocan_sec\
- dahdi_echocan_sec2\
- dahdi-fw-hx8.bin\
- dahdi-fw-oct6114-064.bin\
- dahdi-fw-oct6114-128.bin\
- ${_dahdi_vpmadt032_loader}\
- dahdi_voicebus\
- ng_dahdi_netdev\
+ dahdi_echocan_sec2
+
+# HW drivers
+SUBDIR+=\
wcb4xxp\
wcfxo\
wct4xxp\
@@ -25,6 +32,13 @@
wcte11xp\
wcte12xp
+# firmware drivers
+SUBDIR+=\
+ dahdi-fw-hx8.bin\
+ dahdi-fw-oct6114-064.bin\
+ dahdi-fw-oct6114-128.bin\
+ ${_dahdi_vpmadt032_loader}
+
.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "amd64"
_dahdi_vpmadt032_loader= dahdi_vpmadt032_loader
.endif
Added: freebsd/trunk/freebsd/dahdi_transcode/Makefile
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/freebsd/dahdi_transcode/Makefile?view=auto&rev=8863
==============================================================================
--- freebsd/trunk/freebsd/dahdi_transcode/Makefile (added)
+++ freebsd/trunk/freebsd/dahdi_transcode/Makefile Thu Jul 8 07:47:42 2010
@@ -1,0 +1,8 @@
+# $Id$
+
+.PATH: ${.CURDIR}/../../drivers/dahdi
+
+KMOD= dahdi_transcode
+SRCS= dahdi_transcode.c
+
+.include <bsd.kmod.mk>
Propchange: freebsd/trunk/freebsd/dahdi_transcode/Makefile
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: freebsd/trunk/freebsd/dahdi_transcode/Makefile
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: freebsd/trunk/freebsd/dahdi_transcode/Makefile
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: freebsd/trunk/include/dahdi/compat/bsd.h
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/include/dahdi/compat/bsd.h?view=diff&rev=8863&r1=8862&r2=8863
==============================================================================
--- freebsd/trunk/include/dahdi/compat/bsd.h (original)
+++ freebsd/trunk/include/dahdi/compat/bsd.h Thu Jul 8 07:47:42 2010
@@ -479,4 +479,43 @@
void
dahdi_dma_free(bus_dma_tag_t *ptag, bus_dmamap_t *pmap, void **pvaddr, uint32_t *ppaddr);
+/*
+ * File operations
+ *
+ * Supposed to be used only for transcoders stuff
+ */
+
+struct inode;
+
+struct file {
+ struct cdev *dev;
+ int f_flags;
+};
+
+struct vm_area_struct {
+ vm_offset_t offset;
+ vm_paddr_t *paddr;
+ int nprot;
+};
+
+struct poll_table_struct {
+ struct selinfo *selinfo;
+};
+
+#define FOP_READ_ARGS_DECL struct file *file, struct uio *uio, size_t count
+#define FOP_READ_ARGS file, uio, count
+#define FOP_WRITE_ARGS_DECL struct file *file, struct uio *uio, size_t count
+#define FOP_WRITE_ARGS file, uio, count
+
+struct file_operations {
+ struct module *owner;
+ int (*open)(struct inode *inode, struct file *file);
+ int (*release)(struct inode *inode, struct file *file);
+ int (*ioctl)(struct inode *inode, struct file *file, unsigned int cmd, unsigned long data);
+ ssize_t (*read)(FOP_READ_ARGS_DECL);
+ ssize_t (*write)(FOP_WRITE_ARGS_DECL);
+ unsigned int (*poll)(struct file *file, struct poll_table_struct *wait_table);
+ int (*mmap)(struct file *file, struct vm_area_struct *vma);
+};
+
#endif /* _DAHDI_COMPAT_BSD_H_ */
Modified: freebsd/trunk/include/dahdi/kernel.h
URL: http://svnview.digium.com/svn/dahdi/freebsd/trunk/include/dahdi/kernel.h?view=diff&rev=8863&r1=8862&r2=8863
==============================================================================
--- freebsd/trunk/include/dahdi/kernel.h (original)
+++ freebsd/trunk/include/dahdi/kernel.h Thu Jul 8 07:47:42 2010
@@ -908,7 +908,7 @@
struct dahdi_transcoder_channel {
void *pvt;
struct dahdi_transcoder *parent;
- wait_queue_head_t ready;
+ struct pollinfo ready;
__u32 built_fmts;
#define DAHDI_TC_FLAG_BUSY 1
#define DAHDI_TC_FLAG_CHAN_BUILT 2
@@ -975,12 +975,7 @@
int numchannels;
unsigned int srcfmts;
unsigned int dstfmts;
-#if defined(__FreeBSD__)
- int (*write)(struct dahdi_transcoder_channel *channel, struct uio *uio, int ioflags);
- int (*read)(struct dahdi_transcoder_channel *channel, struct uio *uio, int ioflags);
-#else
struct file_operations fops;
-#endif
int (*allocate)(struct dahdi_transcoder_channel *channel);
int (*release)(struct dahdi_transcoder_channel *channel);
/* Transcoder channels */
@@ -1109,9 +1104,7 @@
void dahdi_ec_chunk(struct dahdi_chan *chan, unsigned char *rxchunk, const unsigned char *txchunk);
void dahdi_ec_span(struct dahdi_span *span);
-#if !defined(__FreeBSD__)
extern struct file_operations *dahdi_transcode_fops;
-#endif
/* Don't use these directly -- they're not guaranteed to
be there. */
@@ -1280,4 +1273,10 @@
#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
#endif
+void *dahdi_get_private_data(struct file *file);
+
+void dahdi_set_private_data(struct file *file, void *private_data);
+
+void dahdi_poll_wait(struct file *file, struct pollinfo *sel, struct poll_table_struct *wait_table);
+
#endif /* _DAHDI_KERNEL_H */
More information about the dahdi-commits
mailing list