Skip to contentSkip to conversation

O2 VICE support

PATCH [email protected] 4 participants 6 messages Dec 10, 2002 – Dec 23, 2002 MIPS

lore
Share & tools
lore
#0 lore raw

Attached is patch set to add support to kernel for O2 video compression engine (VICE). It should apply cleanly to latest CVS.

Ilya.

Index: arch/mips64/kernel/ioctl32.c
===================================================================
RCS file: /home/cvs/linux/arch/mips64/kernel/ioctl32.c,v retrieving revision 1.26

mips64/kernel/ioctl32.c +10 -0
diff -u -r1.26 ioctl32.c
@@ -55,6 +57,10 @@
 
 #include <linux/rtc.h>
 
+#ifdef CONFIG_O2_VICE
+#include <linux/vice.h>
+#endif
+
 long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg);
 
 static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
@@ -827,6 +968,12 @@
 COMPATIBLE_IOCTL(TIOCGSERIAL)
 COMPATIBLE_IOCTL(TIOCSSERIAL)
 COMPATIBLE_IOCTL(TIOCSERGETLSR)
+#ifdef CONFIG_O2_VICE
+COMPATIBLE_IOCTL(VICE_IOCTL_MAP_DMA)
+COMPATIBLE_IOCTL(VICE_IOCTL_MSP_RUN)
+COMPATIBLE_IOCTL(VICE_IOCTL_BSP_RUN)
+COMPATIBLE_IOCTL(VICE_IOCTL_DO_DMA)
+#endif
 
 COMPATIBLE_IOCTL(FIOCLEX)
 COMPATIBLE_IOCTL(FIONCLEX)

Index: drivers/char/Kconfig
===================================================================
RCS file: /home/cvs/linux/drivers/char/Kconfig,v
retrieving revision 1.1

char/Kconfig +2 -0
diff -u -r1.1 Kconfig
@@ -1281,6 +1281,8 @@
 
 source "drivers/char/pcmcia/Kconfig"
 
+source drivers/char/o2vice/Kconfig
+
 config MWAVE
 	tristate "ACP Modem (Mwave) support"
 	depends on X86

Index: drivers/char/Makefile
===================================================================
RCS file: /home/cvs/linux/drivers/char/Makefile,v
retrieving revision 1.100

char/Makefile +1 -0
diff -u -r1.100 Makefile
@@ -111,6 +111,7 @@
 obj-$(CONFIG_AGP) += agp/
 obj-$(CONFIG_DRM) += drm/
 obj-$(CONFIG_PCMCIA) += pcmcia/
+obj-$(CONFIG_O2_VICE) += o2vice/
 
 # Files generated that shall be removed upon make clean
 clean-files := consolemap_deftbl.c defkeymap.c qtronixmap.c
char/o2vice/Kconfig new file +32 -0
@@ -0,0 +1,32 @@
+#
+# O2 VICE Engine confiuration
+#
+
+config O2_VICE
+    tristate "O2 VICE Engine Support"
+    depends on SGI_IP32
+    ---help---
+      This option enables O2 VICE Engine support.
+      VICE stands for Video Image Compression Engine. This is very powerfull
+      piece of silicon, that can greatly speed up lots of graphics, vide, or
+      sound related tasks. To be able to use it, you will also need special
+      library, that can be found at <insert URL here>
+
+config O2_VICE_DBGG
+    bool "VICE Debugger Support. READ HELP!"
+    depends on O2_VICE
+    ---help---
+      This option enables features of VICE driver needed to debug VICE library.
+      This is probably serious security risk. You don't need it. If you think
+      you do, you are wrong. Say NO.
+
+config O2_VICE_DBG
+    bool "You seem to insist... did you read help? Yes? No? READ HELP!"
+    depends on O2_VICE_DBGG
+    ---help---
+      You are still here? Didn't I just tell you that it is not needed?
+      Or do you want to say you *legally* obtained information needed for
+      programming VICE? That you got all the tools needed? As a matter of
+      fact, these tools don't even exist yet!
+
+      Sigh... You've been warned...
char/o2vice/Makefile new file +21 -0
@@ -0,0 +1,21 @@
+#
+# drivers/char/o2vice/Makefile
+#
+# Makefile for the O2 VICE Engine driver.
+#
+
+SUB_DIRS     := 
+MOD_SUB_DIRS := $(SUB_DIRS)
+ALL_SUB_DIRS := $(SUB_DIRS)
+
+#O_TARGET := vice.o
+
+obj-y		:=
+obj-m		:=
+obj-n		:=
+obj-		:=
+
+obj-$(CONFIG_O2_VICE)	+= main.o msp.o bsp.o dma.o
+#obj-$(CONFIG_O2_VICE_DBG) += vicedebug.o
+
+include $(TOPDIR)/Rules.make
linux/vice.h new file +462 -0

462 lines not on this page · raw message

char/o2vice/bsp.c new file +161 -0

161 lines not on this page · raw message

char/o2vice/msp.c new file +157 -0

157 lines not on this page · raw message

char/o2vice/Kconfig new file +32 -0
@@ -0,0 +1,32 @@
+#
+# O2 VICE Engine confiuration
+#
+
+config O2_VICE
+    tristate "O2 VICE Engine Support"
+    depends on SGI_IP32
+    ---help---
+      This option enables O2 VICE Engine support.
+      VICE stands for Video Image Compression Engine. This is very powerfull
+      piece of silicon, that can greatly speed up lots of graphics, vide, or
+      sound related tasks. To be able to use it, you will also need special
+      library, that can be found at <insert URL here>
+
+config O2_VICE_DBGG
+    bool "VICE Debugger Support. READ HELP!"
+    depends on O2_VICE
+    ---help---
+      This option enables features of VICE driver needed to debug VICE library.
+      This is probably serious security risk. You don't need it. If you think
+      you do, you are wrong. Say NO.
+
+config O2_VICE_DBG
+    bool "You seem to insist... did you read help? Yes? No? READ HELP!"
+    depends on O2_VICE_DBGG
+    ---help---
+      You are still here? Didn't I just tell you that it is not needed?
+      Or do you want to say you *legally* obtained information needed for
+      programming VICE? That you got all the tools needed? As a matter of
+      fact, these tools don't even exist yet!
+
+      Sigh... You've been warned...
char/o2vice/Makefile new file +21 -0
@@ -0,0 +1,21 @@
+#
+# drivers/char/o2vice/Makefile
+#
+# Makefile for the O2 VICE Engine driver.
+#
+
+SUB_DIRS     := 
+MOD_SUB_DIRS := $(SUB_DIRS)
+ALL_SUB_DIRS := $(SUB_DIRS)
+
+#O_TARGET := vice.o
+
+obj-y		:=
+obj-m		:=
+obj-n		:=
+obj-		:=
+
+obj-$(CONFIG_O2_VICE)	+= main.o msp.o bsp.o dma.o
+#obj-$(CONFIG_O2_VICE_DBG) += vicedebug.o
+
+include $(TOPDIR)/Rules.make
char/o2vice/main.c new file +438 -0

438 lines not on this page · raw message

char/o2vice/dma.c new file +183 -0

183 lines not on this page · raw message

#1 lore raw

mips64/kernel/ioctl32.c line 62

Quoted 12 lines · On Tue, Dec 10, 2002 at 11:11:20AM -0800, [email protected] wrote:

RCS file: /home/cvs/linux/arch/mips64/kernel/ioctl32.c,v retrieving revision 1.26
diff -u -r1.26 ioctl32.c

mips64/kernel/ioctl32.c +3 -0
@@ -55,6 +57,10 @@
 
 #include <linux/rtc.h>
 
+#ifdef CONFIG_O2_VICE
+#include <linux/vice.h>
+#endif

Just include the header unconditionally.

mips64/kernel/ioctl32.c line 976

Quoted 11 lines
mips64/kernel/ioctl32.c +6 -0
 static int w_long(unsigned int fd, unsigned int cmd, unsigned long arg)
@@ -827,6 +968,12 @@
 COMPATIBLE_IOCTL(TIOCGSERIAL)
 COMPATIBLE_IOCTL(TIOCSSERIAL)
 COMPATIBLE_IOCTL(TIOCSERGETLSR)
+#ifdef CONFIG_O2_VICE
+COMPATIBLE_IOCTL(VICE_IOCTL_MAP_DMA)
+COMPATIBLE_IOCTL(VICE_IOCTL_MSP_RUN)
+COMPATIBLE_IOCTL(VICE_IOCTL_BSP_RUN)
+COMPATIBLE_IOCTL(VICE_IOCTL_DO_DMA)
+#endif

Dito. COMPATIBLE_IOCTL() isn't a big burgden, so it doesn't harm to get rid of the ifdefs.

mips64/kernel/ioctl32.c line 977

Quoted 1 line
mips64/kernel/ioctl32.c +1 -0
+source drivers/char/o2vice/Kconfig

I think it should be in drivers/media/vice (i.e. it's one of the media devices, and I don't think you need the o2, especially as you don't use it e.g. in the header name).

Quoted 9 lines
char/o2vice/Makefile new file +6 -0
@@ -0,0 +1,21 @@
+#
+# drivers/char/o2vice/Makefile
+#
+# Makefile for the O2 VICE Engine driver.
+#
+

char/o2vice/Makefile line 16

Quoted 10 lines
char/o2vice/Makefile new file +10 -0
+SUB_DIRS     := 
+MOD_SUB_DIRS := $(SUB_DIRS)
+ALL_SUB_DIRS := $(SUB_DIRS)
+
+#O_TARGET := vice.o
+
+obj-y		:=
+obj-m		:=
+obj-n		:=
+obj-		:=

This is 2.2 crap. Just get rid of it..

char/o2vice/Makefile line 21

Quoted 5 lines
char/o2vice/Makefile new file +5 -0
+
+obj-$(CONFIG_O2_VICE)	+= main.o msp.o bsp.o dma.o
+#obj-$(CONFIG_O2_VICE_DBG) += vicedebug.o
+
+include $(TOPDIR)/Rules.make

The include isn't needed anymore either in 2.5.

char/o2vice/Makefile

Quoted 11 lines
char/o2vice/Makefile new file +11 -0
+#include <linux/ioctl.h> /* needed for the _IOW etc stuff used later */
+#ifdef __KERNEL__
+#include <asm/pci.h>
+#endif
+#include <linux/types.h>	/* size_t */
+
+#ifndef __KERNEL__
+typedef __u64 u64;
+typedef __u32 u32;
+typedef __u16 u16;
+#endif /* __KERNEL */

Urgg. Usually kernel headers aren't supposed to be used in userspace. If you want to use a copy anyway it should be done with much less burden on the kernel code.

char/o2vice/Makefile

Quoted 7 lines
char/o2vice/Makefile new file +7 -0
+#ifdef VICE_DEBUG
+# define DPRINTK(fmt, args...) printk( KERN_DEBUG "vice: " fmt, ## args)
+#else
+# define DPRINTK(fmt, args...) /* not debugging: nothing */
+#endif
+
+#define PDEBUG DPRINTK

Just use pr_debug?

char/o2vice/Makefile

Quoted 4 lines
char/o2vice/Makefile new file +4 -0
+
+#ifndef VICE_MAJOR
+#define VICE_MAJOR 240   /* dynamic major by default */
+#endif

Comment doesn't match code.

char/o2vice/Makefile

Quoted 10 lines
char/o2vice/Makefile new file +10 -0
+/*
+ * Prototypes for shared functions
+ */
+ssize_t vice_read (struct file *filp, char *buf, size_t count,
+                    loff_t *f_pos);
+ssize_t vice_write (struct file *filp, const char *buf, size_t count,
+                     loff_t *f_pos);
+loff_t  vice_llseek (struct file *filp, loff_t off, int whence);
+int     vice_ioctl (struct inode *inode, struct file *filp,
+                     unsigned int cmd, unsigned long arg);

Exported file operations are usually a very bad sign. But it looks like you could just make them static anyway :)

Quoted 5 lines
char/o2vice/Makefile new file +5 -0
+/*
+ * VICE ioctl commands
+ */
+#ifdef __KERNEL__
+#define VICE_IOCTL_MAGIC	0x96

char/o2vice/Makefile

Quoted 10 lines
char/o2vice/Makefile new file +10 -0
+#define VICE_IOCTL_MAP_DMA	_IOR(VICE_IOCTL_MAGIC,1,unsigned long)
+#define VICE_IOCTL_MSP_RUN	_IOR(VICE_IOCTL_MAGIC,2,msp_run)
+#define VICE_IOCTL_BSP_RUN	_IOR(VICE_IOCTL_MAGIC,3,bsp_run)
+#define VICE_IOCTL_DO_DMA	_IOWR(VICE_IOCTL_MAGIC,4,dma_run)
+#else
+#define VICE_IOCTL_MAP_DMA	0x40089601
+#define VICE_IOCTL_MSP_RUN	0x400c9602
+#define VICE_IOCTL_BSP_RUN	0x400c9603
+#define VICE_IOCTL_DO_DMA	0xc00c9604
+#endif

Ummm..

char/o2vice/Makefile

Quoted 10 lines
char/o2vice/Makefile new file +10 -0
+static inline int vice_dma_mem_init(vice_dev *vice)
+{
+    int i;
+    for (i=0; i<64*2;i++){
+	if(!(vice->dma_kmem[i]=pci_alloc_consistent(0,VICE_PAGE_SIZE,&(vice->dma_mem[i])))) {
+	    DPRINTK("failed at page# %i\n",i);
+    	    return -ENOMEM;
+	}
+    }
+    return 0;

Please adopt to Documentation/CodingStyle

char/o2vice/Makefile

Quoted 3 lines
char/o2vice/Makefile new file +3 -0
+    DPRINTK("Falling asleep\n");
+    while(vice->msp_status==VICE_RES_STATUS_INPROGRESS) {
+        interruptible_sleep_on(&wq);

sleep_on is racy. You should at least use wait_even, but it doesn't look like vice->msp_status is atomically updated anyway.

char/o2vice/Makefile

Quoted 2 lines
char/o2vice/Makefile new file +0 -0

The diff seems to include the same hunk twice..

char/o2vice/Makefile

Quoted 7 lines
char/o2vice/Makefile new file +7 -0
+/* In vice_open, the fop_array is used according to TYPE(dev) */
+int vice_open(struct inode *inode, struct file *filp)
+{
+    vice_dev *vice=vice_device;		/* device information */
+    int res;
+
+    MOD_INC_USE_COUNT;		/* Before we maybe sleep */

Please set .owner in the file_operations instead.

char/o2vice/Makefile

Quoted 3 lines
char/o2vice/Makefile new file +3 -0
+
+    if(vice->is_open)
+	return -EBUSY;

This seems pretty racy.

char/o2vice/Makefile

Quoted 4 lines
char/o2vice/Makefile new file +4 -0
+
+    if (!filp->private_data) {
+	filp->private_data = vice_device;
+    }

filp->private_data can't be set.

Quoted 4 lines
char/o2vice/Makefile new file +4 -0
+ssize_t vice_read(struct file * filp, char *buf, size_t count, loff_t * f_pos)
+{
+    printk(KERN_WARNING
+	   "Processing bit streams through reading/writing is not supported yet\n");

char/o2vice/Makefile

Quoted 10 lines
char/o2vice/Makefile new file +10 -0
+    return -ENOSYS;
+}
+
+ssize_t vice_write(struct file * filp, const char *buf, size_t count,
+	   loff_t * f_pos)
+{
+    printk(KERN_WARNING
+	   "Processing bit streams through reading/writing is not supported (yet)\n");
+    return -ENOSYS;
+}

What about just not implementing the methods instead?

char/o2vice/Makefile

Quoted 5 lines
char/o2vice/Makefile new file +5 -0
+static void vice_vma_open(struct vm_area_struct *vma)
+{ MOD_INC_USE_COUNT; }
+
+static void vice_vma_close(struct vm_area_struct *vma)
+{ MOD_DEC_USE_COUNT; }

This is silly. You get a reference for vma->vm_file as long as you have any mmaps. That's enough for the refcounting.

char/o2vice/Makefile

Quoted 5 lines
char/o2vice/Makefile new file +5 -0
+static struct vm_operations_struct vice_vm_ops = {
+    open:  vice_vma_open,
+    close: vice_vma_close,
+    nopage: vice_vma_nopage,
+};

Please use C99-initializers (i.e. .foo = bar)

char/o2vice/Makefile

Quoted 6 lines
char/o2vice/Makefile new file +6 -0
+void vice_cleanup_module(void)
+{
+#ifndef CONFIG_DEVFS_FS
+    /* cleanup_module is never called if registering failed */
+    unregister_chrdev(vice_major, "vice");
+#endif

Umm, just because someone makes the mistake of enabling devfs he doesn't have to use it.. :)

char/o2vice/Makefile

Quoted 3 lines
char/o2vice/Makefile new file +3 -0
+#ifndef VICE_DEBUG
+    EXPORT_NO_SYMBOLS;		/* otherwise, leave global symbols visible */
+#endif

EXPORT_NO_SYMBOLS is a noop on 2.5

#2 lore raw
Quoted 3 lines

Urgg. Usually kernel headers aren't supposed to be used in userspace. If you want to use a copy anyway it should be done with much less burden on the kernel code.

Well, most of manipulation of this device will be done bu user-space code. Kernel's only job is synchronising access and managing memory. Thus we would like to keep all definitions in one place.

Quoted 5 lines

char/o2vice/main.c line 150

Quoted 3 lines
char/o2vice/main.c new file +3 -0
+    if (!filp->private_data) {
+	filp->private_data = vice_device;
+    }

filp->private_data can't be set.

???
I can live without using it of course, since it isn't currently possible to have more then one instance of VICE in same machine, but theoretical possibility does exist. Where should I pass information about which specific device current call is?

Quoted 17 lines
Quoted 5 lines
char/o2vice/main.c new file +4 -0
+ssize_t vice_read(struct file * filp, char *buf, size_t count, loff_t * f_pos)
+{
+    printk(KERN_WARNING
+	   "Processing bit streams through reading/writing is not supported yet\n");

char/o2vice/main.c line 213

Quoted 10 lines
char/o2vice/main.c new file +10 -0
+    return -ENOSYS;
+}
+
+ssize_t vice_write(struct file * filp, const char *buf, size_t count,
+	   loff_t * f_pos)
+{
+    printk(KERN_WARNING
+	   "Processing bit streams through reading/writing is not supported (yet)\n");
+    return -ENOSYS;
+}

What about just not implementing the methods instead?

This is more like reminder to myself that I should do that one day :)

Quoted 8 lines

char/o2vice/main.c line 247

Quoted 5 lines
char/o2vice/main.c new file +5 -0
+static void vice_vma_open(struct vm_area_struct *vma)
+{ MOD_INC_USE_COUNT; }
+
+static void vice_vma_close(struct vm_area_struct *vma)
+{ MOD_DEC_USE_COUNT; }

This is silly. You get a reference for vma->vm_file as long as you have any mmaps. That's enough for the refcounting.

I was wondering about that too, but this is the way i was in book :)

Quoted 9 lines

char/o2vice/main.c line 273

Quoted 6 lines
char/o2vice/main.c new file +5 -0
+static struct vm_operations_struct vice_vm_ops = {
+    open:  vice_vma_open,
+    close: vice_vma_close,
+    nopage: vice_vma_nopage,
+};

Please use C99-initializers (i.e. .foo = bar)

Quoted 9 lines

char/o2vice/main.c line 352

Quoted 6 lines
char/o2vice/main.c new file +6 -0
+void vice_cleanup_module(void)
+{
+#ifndef CONFIG_DEVFS_FS
+    /* cleanup_module is never called if registering failed */
+    unregister_chrdev(vice_major, "vice");
+#endif

Umm, just because someone makes the mistake of enabling devfs he doesn't have to use it.. :)

I'm not buying that one :)

Quoted 6 lines

char/o2vice/main.c line 425

Quoted 4 lines
char/o2vice/main.c new file +3 -0
+#ifndef VICE_DEBUG
+    EXPORT_NO_SYMBOLS;		/* otherwise, leave global symbols visible */
+#endif

EXPORT_NO_SYMBOLS is a noop on 2.5

Driver was written for 2.4 first.

Thanks a lot for constructive criticism.

Ilya.

#3 lore raw
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

"ilya" == ilya <[email protected]> writes:

Quoted 9 lines
Quoted 9 lines

char/o2vice/main.c line 352

Quoted 6 lines
char/o2vice/main.c new file +6 -0
+void vice_cleanup_module(void)
+{
+#ifndef CONFIG_DEVFS_FS
+    /* cleanup_module is never called if registering failed */
+    unregister_chrdev(vice_major, "vice");
+#endif

Umm, just because someone makes the mistake of enabling devfs he doesn't have to use it.. :)

ilya> I'm not buying that one :)

Read behind the joke:
- you have devfs compiled in
- you don't have devfs mounted

Conclusion:
there is a bug in your code :)

Later, Juan.

Signature · 2 lines
In theory, practice and theory are the same, but in practice they 
are different -- Larry McVoy
#4 lore raw
In reply to [email protected]
Quoted 10 lines · On Wed, Dec 11, 2002 at 02:16:29PM -0800, [email protected] wrote:
Quoted 5 lines

char/o2vice/main.c line 150

Quoted 3 lines
char/o2vice/main.c new file +3 -0
+    if (!filp->private_data) {
+	filp->private_data = vice_device;
+    }

filp->private_data can't be set.

???
I can live without using it of course, since it isn't currently possible to have more then one instance of VICE in same machine, but theoretical possibility does exist. Where should I pass information about which specific device current call is?

Sorry if that sentence was confusing. I meant it can't be already set in ->open so the if is superflous.

Quoted 10 lines
Quoted 9 lines

char/o2vice/main.c line 352

Quoted 6 lines
char/o2vice/main.c new file +6 -0
+void vice_cleanup_module(void)
+{
+#ifndef CONFIG_DEVFS_FS
+    /* cleanup_module is never called if registering failed */
+    unregister_chrdev(vice_major, "vice");
+#endif

Umm, just because someone makes the mistake of enabling devfs he doesn't have to use it.. :)

I'm not buying that one :)

You can have CONFIG_DEVFS_FS set but devfs not mounted and used. Thus #ifndef CONFIG_DEVFS_FS code is a very bad idea.

#5 lore raw
In reply to [email protected]

char/o2vice/Kconfig line 13

Quoted 12 lines · On Tue, 10 Dec 2002 [email protected] wrote:

Attached is patch set to add support to kernel for O2 video compression engine (VICE). It should apply cleanly to latest CVS.

char/o2vice/Kconfig new file +9 -0
+config O2_VICE
+    tristate "O2 VICE Engine Support"
+    depends on SGI_IP32
+    ---help---
+      This option enables O2 VICE Engine support.
+      VICE stands for Video Image Compression Engine. This is very powerfull
+      piece of silicon, that can greatly speed up lots of graphics, vide, or
+      sound related tasks. To be able to use it, you will also need special
+      library, that can be found at <insert URL here>
                                       ^^^^^^^^^^^^^^^^^

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds