From d7530a1e767b562c7e071f559d542c132d85fff7 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 00:58:01 +0200 Subject: [PATCH] ieee1394: fix cosmetic problem in speed probe If ieee1394.h::IEEE1394_SPEED_MAX is bigger than the actual speed of an 1394b host adapter and the speed to another 1394b node was probed, a bigger speed than actually used was kept in host->speed[n]. The only resulting problem so far was sbp2 displaying bogus values in the syslog, e.g. S3200 for actual S800 connections if IEEE1394_SPEED_MAX was S3200. But other high-level drivers which access this field could get into more trouble. (Eth1394 is the only other in-tree driver which does so. It seems it is not affected.) Nodemgr now clips this value according to the host adapter's link speed. A pointer expression in nodemgr_check_speed is also changed for clarity. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/nodemgr.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index d541b508a15..dfed2ed2ed9 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -71,7 +71,7 @@ static int nodemgr_check_speed(struct nodemgr_csr_info *ci, u64 addr, u8 i, *speed, old_speed, good_speed; int ret; - speed = ci->host->speed + NODEID_TO_NODE(ci->nodeid); + speed = &(ci->host->speed[NODEID_TO_NODE(ci->nodeid)]); old_speed = *speed; good_speed = IEEE1394_SPEED_MAX + 1; @@ -1251,6 +1251,7 @@ static void nodemgr_node_scan_one(struct host_info *hi, octlet_t guid; struct csr1212_csr *csr; struct nodemgr_csr_info *ci; + u8 *speed; ci = kmalloc(sizeof(*ci), GFP_KERNEL); if (!ci) @@ -1259,8 +1260,12 @@ static void nodemgr_node_scan_one(struct host_info *hi, ci->host = host; ci->nodeid = nodeid; ci->generation = generation; - ci->speed_unverified = - host->speed[NODEID_TO_NODE(nodeid)] > IEEE1394_SPEED_100; + + /* Prepare for speed probe which occurs when reading the ROM */ + speed = &(host->speed[NODEID_TO_NODE(nodeid)]); + if (*speed > host->csr.lnk_spd) + *speed = host->csr.lnk_spd; + ci->speed_unverified = *speed > IEEE1394_SPEED_100; /* We need to detect when the ConfigROM's generation has changed, * so we only update the node's info when it needs to be. */ @@ -1300,8 +1305,6 @@ static void nodemgr_node_scan_one(struct host_info *hi, nodemgr_create_node(guid, csr, hi, nodeid, generation); else nodemgr_update_node(ne, csr, hi, nodeid, generation); - - return; } -- cgit v1.2.3 From 3ce6fb4358bce6aced489f798138795163ad3f7c Mon Sep 17 00:00:00 2001 From: Eric Hustvedt Date: Tue, 20 Jun 2006 14:36:41 -0400 Subject: intelfb: add vsync interrupt support [01/05] intelfb: Add 16-bit register access macros This patch adds macros to read and write two-byte MMIO registers. The interrupt-related registers are all word-sized, rather than long-sized. Signed-off-by: Eric Hustvedt --- drivers/video/intelfb/intelfbhw.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/video/intelfb/intelfbhw.h b/drivers/video/intelfb/intelfbhw.h index 10acda098b7..25823514991 100644 --- a/drivers/video/intelfb/intelfbhw.h +++ b/drivers/video/intelfb/intelfbhw.h @@ -468,9 +468,12 @@ /* I/O macros */ #define INREG8(addr) readb((u8 __iomem *)(dinfo->mmio_base + (addr))) +#define INREG16(addr) readw((u16 __iomem *)(dinfo->mmio_base + (addr))) #define INREG(addr) readl((u32 __iomem *)(dinfo->mmio_base + (addr))) #define OUTREG8(addr, val) writeb((val),(u8 __iomem *)(dinfo->mmio_base + \ (addr))) +#define OUTREG16(addr, val) writew((val),(u16 __iomem *)(dinfo->mmio_base + \ + (addr))) #define OUTREG(addr, val) writel((val),(u32 __iomem *)(dinfo->mmio_base + \ (addr))) -- cgit v1.2.3 From 9a5f019b1a9ea6a75ba36d7c312ff069006ed479 Mon Sep 17 00:00:00 2001 From: Eric Hustvedt Date: Tue, 20 Jun 2006 14:36:41 -0400 Subject: intelfb: add vsync interrupt support [02/05] intelfb: Add interrupt related register definitions Add constants for accessing HWSTAM, IER, IIR, and IMR registers. Add constants for interrupt types supported by the 8xx and 9xx chipsets. The registers are also stored in the hwstate struct and dumped in the debug routine. Signed-off-by: Eric Hustvedt --- drivers/video/intelfb/intelfb.h | 4 ++++ drivers/video/intelfb/intelfbhw.c | 9 +++++++++ drivers/video/intelfb/intelfbhw.h | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h index e290d7460e1..cb016fe4d48 100644 --- a/drivers/video/intelfb/intelfb.h +++ b/drivers/video/intelfb/intelfb.h @@ -195,6 +195,10 @@ struct intelfb_hwstate { u32 mem_mode; u32 fw_blc_0; u32 fw_blc_1; + u16 hwstam; + u16 ier; + u16 iir; + u16 imr; }; struct intelfb_heap_data { diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c index 7533b3dd08a..05aded669cd 100644 --- a/drivers/video/intelfb/intelfbhw.c +++ b/drivers/video/intelfb/intelfbhw.c @@ -587,6 +587,11 @@ intelfbhw_read_hw_state(struct intelfb_info *dinfo, struct intelfb_hwstate *hw, hw->fw_blc_0 = INREG(FW_BLC_0); hw->fw_blc_1 = INREG(FW_BLC_1); + hw->hwstam = INREG16(HWSTAM); + hw->ier = INREG16(IER); + hw->iir = INREG16(IIR); + hw->imr = INREG16(IMR); + return 0; } @@ -796,6 +801,10 @@ intelfbhw_print_hw_state(struct intelfb_info *dinfo, struct intelfb_hwstate *hw) printk(" FW_BLC_0 0x%08x\n", hw->fw_blc_0); printk(" FW_BLC_1 0x%08x\n", hw->fw_blc_1); + printk(" HWSTAM 0x%04x\n", hw->hwstam); + printk(" IER 0x%04x\n", hw->ier); + printk(" IIR 0x%04x\n", hw->iir); + printk(" IMR 0x%04x\n", hw->imr); printk("hw state dump end\n"); #endif } diff --git a/drivers/video/intelfb/intelfbhw.h b/drivers/video/intelfb/intelfbhw.h index 25823514991..8d2e36972fc 100644 --- a/drivers/video/intelfb/intelfbhw.h +++ b/drivers/video/intelfb/intelfbhw.h @@ -88,6 +88,19 @@ #define INSTDONE 0x2090 #define PRI_RING_EMPTY 1 +#define HWSTAM 0x2098 +#define IER 0x20A0 +#define IIR 0x20A4 +#define IMR 0x20A8 +#define VSYNC_PIPE_A_INTERRUPT (1 << 7) +#define PIPE_A_EVENT_INTERRUPT (1 << 4) +#define VSYNC_PIPE_B_INTERRUPT (1 << 5) +#define PIPE_B_EVENT_INTERRUPT (1 << 4) +#define HOST_PORT_EVENT_INTERRUPT (1 << 3) +#define CAPTURE_EVENT_INTERRUPT (1 << 2) +#define USER_DEFINED_INTERRUPT (1 << 1) +#define BREAKPOINT_INTERRUPT 1 + #define INSTPM 0x20c0 #define SYNC_FLUSH_ENABLE (1 << 5) -- cgit v1.2.3 From 7649757bd900bc900adcd95ab08903cdc28342fa Mon Sep 17 00:00:00 2001 From: Eric Hustvedt Date: Tue, 20 Jun 2006 14:36:41 -0400 Subject: intelfb: add vsync interrupt support [03/05] intelfb: Implement basic interrupt handling Functions have been added to enable and disable interrupts using the MMIO registers. Currently only pipe A vsync interrupts are enabled. A generalized vsync accounting struct is defined, with the intent that it can encapsulate per-pipe vsync related info in the future. Currently a single instance is hard-coded. The interrupt service routine currently only looks for vsync interrupts on pipe A, and increments a counter and wakes up anyone waiting on it. This implementation is heavily influenced by similar implementations in the atyfb and matroxfb drivers. Signed-off-by: Eric Hustvedt --- drivers/video/intelfb/intelfb.h | 11 ++++++ drivers/video/intelfb/intelfbdrv.c | 39 +++++++++++++++++++ drivers/video/intelfb/intelfbhw.c | 76 ++++++++++++++++++++++++++++++++++++++ drivers/video/intelfb/intelfbhw.h | 2 + 4 files changed, 128 insertions(+) diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h index cb016fe4d48..dab1f2d764d 100644 --- a/drivers/video/intelfb/intelfb.h +++ b/drivers/video/intelfb/intelfb.h @@ -208,6 +208,11 @@ struct intelfb_heap_data { u32 size; // in bytes }; +struct intelfb_vsync { + wait_queue_head_t wait; + unsigned int count; +}; + struct intelfb_info { struct fb_info *info; struct fb_ops *fbops; @@ -271,6 +276,12 @@ struct intelfb_info { int fixed_mode; int ring_active; int flag; + unsigned long irq_flags; + int open; + + /* vsync */ + struct intelfb_vsync vsync; + spinlock_t int_lock; /* hw cursor */ int cursor_on; diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c index 0a0a8b199ec..068c56d4e65 100644 --- a/drivers/video/intelfb/intelfbdrv.c +++ b/drivers/video/intelfb/intelfbdrv.c @@ -137,6 +137,8 @@ static void __devinit get_initial_mode(struct intelfb_info *dinfo); static void update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var); +static int intelfb_open(struct fb_info *info, int user); +static int intelfb_release(struct fb_info *info, int user); static int intelfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info); static int intelfb_set_par(struct fb_info *info); @@ -195,6 +197,8 @@ static int num_registered = 0; /* fb ops */ static struct fb_ops intel_fb_ops = { .owner = THIS_MODULE, + .fb_open = intelfb_open, + .fb_release = intelfb_release, .fb_check_var = intelfb_check_var, .fb_set_par = intelfb_set_par, .fb_setcolreg = intelfb_setcolreg, @@ -447,6 +451,8 @@ cleanup(struct intelfb_info *dinfo) if (!dinfo) return; + intelfbhw_disable_irq(dinfo); + fb_dealloc_cmap(&dinfo->info->cmap); kfree(dinfo->info->pixmap.addr); @@ -889,6 +895,11 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent) } dinfo->registered = 1; + dinfo->open = 0; + + init_waitqueue_head(&dinfo->vsync.wait); + spin_lock_init(&dinfo->int_lock); + dinfo->irq_flags = 0; return 0; @@ -1188,6 +1199,34 @@ update_dinfo(struct intelfb_info *dinfo, struct fb_var_screeninfo *var) * fbdev interface * ***************************************************************/ +static int +intelfb_open(struct fb_info *info, int user) +{ + struct intelfb_info *dinfo = GET_DINFO(info); + + if (user) { + dinfo->open++; + } + + return 0; +} + +static int +intelfb_release(struct fb_info *info, int user) +{ + struct intelfb_info *dinfo = GET_DINFO(info); + + if (user) { + dinfo->open--; + msleep(1); + if (!dinfo->open) { + intelfbhw_disable_irq(dinfo); + } + } + + return 0; +} + static int intelfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) { diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c index 05aded669cd..1a698a7230e 100644 --- a/drivers/video/intelfb/intelfbhw.c +++ b/drivers/video/intelfb/intelfbhw.c @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -1943,3 +1944,78 @@ intelfbhw_cursor_reset(struct intelfb_info *dinfo) { addr += 16; } } + +static irqreturn_t +intelfbhw_irq(int irq, void *dev_id, struct pt_regs *fp) { + int handled = 0; + u16 tmp; + struct intelfb_info *dinfo = (struct intelfb_info *)dev_id; + + spin_lock(&dinfo->int_lock); + + tmp = INREG16(IIR); + tmp &= VSYNC_PIPE_A_INTERRUPT; + + if (tmp == 0) { + spin_unlock(&dinfo->int_lock); + return IRQ_RETVAL(handled); + } + + OUTREG16(IIR, tmp); + + if (tmp & VSYNC_PIPE_A_INTERRUPT) { + dinfo->vsync.count++; + wake_up_interruptible(&dinfo->vsync.wait); + handled = 1; + } + + spin_unlock(&dinfo->int_lock); + + return IRQ_RETVAL(handled); +} + +int +intelfbhw_enable_irq(struct intelfb_info *dinfo, int reenable) { + + if (!test_and_set_bit(0, &dinfo->irq_flags)) { + if (request_irq(dinfo->pdev->irq, intelfbhw_irq, SA_SHIRQ, "intelfb", dinfo)) { + clear_bit(0, &dinfo->irq_flags); + return -EINVAL; + } + + spin_lock_irq(&dinfo->int_lock); + OUTREG16(HWSTAM, 0xfffe); + OUTREG16(IMR, 0x0); + OUTREG16(IER, VSYNC_PIPE_A_INTERRUPT); + spin_unlock_irq(&dinfo->int_lock); + } else if (reenable) { + u16 ier; + + spin_lock_irq(&dinfo->int_lock); + ier = INREG16(IER); + if ((ier & VSYNC_PIPE_A_INTERRUPT)) { + DBG_MSG("someone disabled the IRQ [%08X]\n", ier); + OUTREG(IER, VSYNC_PIPE_A_INTERRUPT); + } + spin_unlock_irq(&dinfo->int_lock); + } + return 0; +} + +void +intelfbhw_disable_irq(struct intelfb_info *dinfo) { + u16 tmp; + + if (test_and_clear_bit(0, &dinfo->irq_flags)) { + spin_lock_irq(&dinfo->int_lock); + OUTREG16(HWSTAM, 0xffff); + OUTREG16(IMR, 0xffff); + OUTREG16(IER, 0x0); + + tmp = INREG16(IIR); + OUTREG16(IIR, tmp); + spin_unlock_irq(&dinfo->int_lock); + + free_irq(dinfo->pdev->irq, dinfo); + } +} diff --git a/drivers/video/intelfb/intelfbhw.h b/drivers/video/intelfb/intelfbhw.h index 8d2e36972fc..aa0c139a230 100644 --- a/drivers/video/intelfb/intelfbhw.h +++ b/drivers/video/intelfb/intelfbhw.h @@ -561,5 +561,7 @@ extern void intelfbhw_cursor_setcolor(struct intelfb_info *dinfo, u32 bg, extern void intelfbhw_cursor_load(struct intelfb_info *dinfo, int width, int height, u8 *data); extern void intelfbhw_cursor_reset(struct intelfb_info *dinfo); +extern int intelfbhw_enable_irq(struct intelfb_info *dinfo, int reenable); +extern void intelfbhw_disable_irq(struct intelfb_info *dinfo); #endif /* _INTELFBHW_H */ -- cgit v1.2.3 From 37bced38b3d09c3de7c871790eddde81a3ce57cb Mon Sep 17 00:00:00 2001 From: Eric Hustvedt Date: Tue, 20 Jun 2006 14:36:42 -0400 Subject: intelfb: add vsync interrupt support [04/05] intelfb: implement FBIO_WAITFORVSYNC ioctl The (unofficial) FBIO_WAITFORVSYNC ioctl is implemented by sleeping on the appropriate waitqueue, as defined in my earlier patch. Currently, only display 0 (aka pipe A) is supported. Signed-off-by: Eric Hustvedt --- drivers/video/intelfb/intelfb.h | 4 ++++ drivers/video/intelfb/intelfbdrv.c | 13 +++++++++++++ drivers/video/intelfb/intelfbhw.c | 33 +++++++++++++++++++++++++++++++++ drivers/video/intelfb/intelfbhw.h | 1 + 4 files changed, 51 insertions(+) diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h index dab1f2d764d..65ac37071a0 100644 --- a/drivers/video/intelfb/intelfb.h +++ b/drivers/video/intelfb/intelfb.h @@ -304,6 +304,10 @@ struct intelfb_info { #define IS_I9XX(dinfo) (((dinfo)->chipset == INTEL_915G)||(dinfo->chipset == INTEL_915GM)||((dinfo)->chipset == INTEL_945G)||(dinfo->chipset==INTEL_945GM)) +#ifndef FBIO_WAITFORVSYNC +#define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) +#endif + /*** function prototypes ***/ extern int intelfb_var_to_depth(const struct fb_var_screeninfo *var); diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c index 068c56d4e65..08f8241bb92 100644 --- a/drivers/video/intelfb/intelfbdrv.c +++ b/drivers/video/intelfb/intelfbdrv.c @@ -1473,6 +1473,19 @@ static int intelfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) { int retval = 0; + struct intelfb_info *dinfo = GET_DINFO(info); + u32 pipe = 0; + + switch (cmd) { + case FBIO_WAITFORVSYNC: + if (get_user(pipe, (__u32 __user *)arg)) + return -EFAULT; + + retval = intelfbhw_wait_for_vsync(dinfo, pipe); + break; + default: + break; + } return retval; } diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c index 1a698a7230e..0f9631c2ad3 100644 --- a/drivers/video/intelfb/intelfbhw.c +++ b/drivers/video/intelfb/intelfbhw.c @@ -2019,3 +2019,36 @@ intelfbhw_disable_irq(struct intelfb_info *dinfo) { free_irq(dinfo->pdev->irq, dinfo); } } + +int +intelfbhw_wait_for_vsync(struct intelfb_info *dinfo, u32 pipe) { + struct intelfb_vsync *vsync; + unsigned int count; + int ret; + + switch (pipe) { + case 0: + vsync = &dinfo->vsync; + break; + default: + return -ENODEV; + } + + ret = intelfbhw_enable_irq(dinfo, 0); + if (ret) { + return ret; + } + + count = vsync->count; + ret = wait_event_interruptible_timeout(vsync->wait, count != vsync->count, HZ/10); + if (ret < 0) { + return ret; + } + if (ret == 0) { + intelfbhw_enable_irq(dinfo, 1); + DBG_MSG("wait_for_vsync timed out!\n"); + return -ETIMEDOUT; + } + + return 0; +} diff --git a/drivers/video/intelfb/intelfbhw.h b/drivers/video/intelfb/intelfbhw.h index aa0c139a230..36980c785e1 100644 --- a/drivers/video/intelfb/intelfbhw.h +++ b/drivers/video/intelfb/intelfbhw.h @@ -563,5 +563,6 @@ extern void intelfbhw_cursor_load(struct intelfb_info *dinfo, int width, extern void intelfbhw_cursor_reset(struct intelfb_info *dinfo); extern int intelfbhw_enable_irq(struct intelfb_info *dinfo, int reenable); extern void intelfbhw_disable_irq(struct intelfb_info *dinfo); +extern int intelfbhw_wait_for_vsync(struct intelfb_info *dinfo, u32 pipe); #endif /* _INTELFBHW_H */ -- cgit v1.2.3 From f80d0d23f2010b7682e06449345e8199a2b2619c Mon Sep 17 00:00:00 2001 From: Eric Hustvedt Date: Tue, 20 Jun 2006 14:36:42 -0400 Subject: intelfb: add vsync interrupt support [05/05] intelfb: Honor FB_ACTIVATE_VBL for display panning Extends the intelfb_vsync struct to store panning offset. The interrupt service routine uses the stored panning offset if a pan is requested for the vsync. intelfbhw_disable_irq also pans the display if there is a pending request. Signed-off-by: Eric Hustvedt --- drivers/video/intelfb/intelfb.h | 2 ++ drivers/video/intelfb/intelfbdrv.c | 2 ++ drivers/video/intelfb/intelfbhw.c | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h index 65ac37071a0..abd4c5632e3 100644 --- a/drivers/video/intelfb/intelfb.h +++ b/drivers/video/intelfb/intelfb.h @@ -211,6 +211,8 @@ struct intelfb_heap_data { struct intelfb_vsync { wait_queue_head_t wait; unsigned int count; + int pan_display; + u32 pan_offset; }; struct intelfb_info { diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c index 08f8241bb92..9e93f820a93 100644 --- a/drivers/video/intelfb/intelfbdrv.c +++ b/drivers/video/intelfb/intelfbdrv.c @@ -900,6 +900,8 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent) init_waitqueue_head(&dinfo->vsync.wait); spin_lock_init(&dinfo->int_lock); dinfo->irq_flags = 0; + dinfo->vsync.pan_display = 0; + dinfo->vsync.pan_offset = 0; return 0; diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c index 0f9631c2ad3..8038f558611 100644 --- a/drivers/video/intelfb/intelfbhw.c +++ b/drivers/video/intelfb/intelfbhw.c @@ -371,7 +371,13 @@ intelfbhw_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) offset += dinfo->fb.offset << 12; - OUTREG(DSPABASE, offset); + dinfo->vsync.pan_offset = offset; + if ((var->activate & FB_ACTIVATE_VBL) && !intelfbhw_enable_irq(dinfo, 0)) { + dinfo->vsync.pan_display = 1; + } else { + dinfo->vsync.pan_display = 0; + OUTREG(DSPABASE, offset); + } return 0; } @@ -1965,6 +1971,10 @@ intelfbhw_irq(int irq, void *dev_id, struct pt_regs *fp) { if (tmp & VSYNC_PIPE_A_INTERRUPT) { dinfo->vsync.count++; + if (dinfo->vsync.pan_display) { + dinfo->vsync.pan_display = 0; + OUTREG(DSPABASE, dinfo->vsync.pan_offset); + } wake_up_interruptible(&dinfo->vsync.wait); handled = 1; } @@ -2007,6 +2017,10 @@ intelfbhw_disable_irq(struct intelfb_info *dinfo) { u16 tmp; if (test_and_clear_bit(0, &dinfo->irq_flags)) { + if (dinfo->vsync.pan_display) { + dinfo->vsync.pan_display = 0; + OUTREG(DSPABASE, dinfo->vsync.pan_offset); + } spin_lock_irq(&dinfo->int_lock); OUTREG16(HWSTAM, 0xffff); OUTREG16(IMR, 0xffff); -- cgit v1.2.3 From c37bb26654bb8981ea237076e333eb37d4aa2dc6 Mon Sep 17 00:00:00 2001 From: Dennis Munsie Date: Tue, 20 Jun 2006 14:55:55 -0400 Subject: intelfb: add preliminary i2c support [01/07] i2c: add intelfb bit algorithm id Adds the intelfb bit algorithm id to i2c-id.h. Signed-off-by: Dennis Munsie --- include/linux/i2c-id.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h index c8b81f419fd..cce6074dd75 100644 --- a/include/linux/i2c-id.h +++ b/include/linux/i2c-id.h @@ -189,6 +189,7 @@ #define I2C_HW_B_RADEON 0x01001e /* radeon framebuffer driver */ #define I2C_HW_B_EM28XX 0x01001f /* em28xx video capture cards */ #define I2C_HW_B_CX2341X 0x010020 /* Conexant CX2341X MPEG encoder cards */ +#define I2C_HW_B_INTELFB 0x010021 /* intel framebuffer driver */ /* --- PCF 8584 based algorithms */ #define I2C_HW_P_LP 0x020000 /* Parallel port interface */ -- cgit v1.2.3 From 82c10f07c2d7baf6f280f206f9067a4715777962 Mon Sep 17 00:00:00 2001 From: Dennis Munsie Date: Tue, 20 Jun 2006 14:55:55 -0400 Subject: intelfb: add preliminary i2c support [02/07] intelfb: add GPIO registers. Signed-off-by: Dennis Munsie --- drivers/video/intelfb/intelfbhw.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/video/intelfb/intelfbhw.h b/drivers/video/intelfb/intelfbhw.h index 36980c785e1..8c54ba8fbdd 100644 --- a/drivers/video/intelfb/intelfbhw.h +++ b/drivers/video/intelfb/intelfbhw.h @@ -126,6 +126,12 @@ #define FW_DISPC_BL_SHIFT 8 #define FW_DISPC_BL_MASK 0x7 +#define GPIOA 0x5010 +#define GPIOB 0x5014 +#define GPIOC 0x5018 // this may be external DDC on i830 +#define GPIOD 0x501C // this is DVO DDC +#define GPIOE 0x5020 // this is DVO i2C +#define GPIOF 0x5024 /* PLL registers */ #define VGA0_DIVISOR 0x06000 -- cgit v1.2.3 From 183b1214402a205bf6eea2030686249c7d365fd1 Mon Sep 17 00:00:00 2001 From: Dennis Munsie Date: Tue, 20 Jun 2006 14:55:55 -0400 Subject: intelfb: add preliminary i2c support [03/07] intelfb: add intelfb_i2c_chan struct. Signed-off-by: Dennis Munsie --- drivers/video/intelfb/intelfb.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h index abd4c5632e3..5a216b81aa2 100644 --- a/drivers/video/intelfb/intelfb.h +++ b/drivers/video/intelfb/intelfb.h @@ -6,6 +6,10 @@ #include #include +#ifdef CONFIG_FB_INTEL_I2C +#include +#include +#endif /*** Version/name ***/ #define INTELFB_VERSION "0.9.4" @@ -208,6 +212,15 @@ struct intelfb_heap_data { u32 size; // in bytes }; +#ifdef CONFIG_FB_INTEL_I2C +struct intelfb_i2c_chan { + struct intelfb_info *dinfo; + u32 reg; + struct i2c_adapter adapter; + struct i2c_algo_bit_data algo; +}; +#endif + struct intelfb_vsync { wait_queue_head_t wait; unsigned int count; -- cgit v1.2.3 From 399fb4316ab4fe4c46d1e4ed8b12d56c94b4c251 Mon Sep 17 00:00:00 2001 From: Dennis Munsie Date: Tue, 20 Jun 2006 14:55:55 -0400 Subject: intelfb: add preliminary i2c support [04/07] intelfb: add intelfb_output_rec struct and the constants for it's fields. Signed-off-by: Dennis Munsie --- drivers/video/intelfb/intelfb.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h index 5a216b81aa2..179db05f195 100644 --- a/drivers/video/intelfb/intelfb.h +++ b/drivers/video/intelfb/intelfb.h @@ -119,6 +119,24 @@ /* Intel agpgart driver */ #define AGP_PHYSICAL_MEMORY 2 +/* these are outputs from the chip - integrated only + external chips are via DVO or SDVO output */ +#define INTELFB_OUTPUT_UNUSED 0 +#define INTELFB_OUTPUT_ANALOG 1 +#define INTELFB_OUTPUT_DVO 2 +#define INTELFB_OUTPUT_SDVO 3 +#define INTELFB_OUTPUT_LVDS 4 +#define INTELFB_OUTPUT_TVOUT 5 + +#define INTELFB_DVO_CHIP_NONE 0 +#define INTELFB_DVO_CHIP_LVDS 1 +#define INTELFB_DVO_CHIP_TMDS 2 +#define INTELFB_DVO_CHIP_TVOUT 4 + +#define INTELFB_OUTPUT_PIPE_NC 0 +#define INTELFB_OUTPUT_PIPE_A 1 +#define INTELFB_OUTPUT_PIPE_B 2 + /*** Data Types ***/ /* supported chipsets */ @@ -221,6 +239,17 @@ struct intelfb_i2c_chan { }; #endif +struct intelfb_output_rec { + int type; + int pipe; + int flags; + +#ifdef CONFIG_FB_INTEL_I2C + struct intelfb_i2c_chan i2c_bus; + struct intelfb_i2c_chan ddc_bus; +#endif +}; + struct intelfb_vsync { wait_queue_head_t wait; unsigned int count; -- cgit v1.2.3 From dd696ec852dc34c40e2a18cc426c8f462c0715a5 Mon Sep 17 00:00:00 2001 From: Dennis Munsie Date: Tue, 20 Jun 2006 14:55:55 -0400 Subject: intelfb: add preliminary i2c support [05/07] intelfb: add output fields to dinfo. Signed-off-by: Dennis Munsie --- drivers/video/intelfb/intelfb.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h index 179db05f195..9092bda9d4b 100644 --- a/drivers/video/intelfb/intelfb.h +++ b/drivers/video/intelfb/intelfb.h @@ -119,6 +119,11 @@ /* Intel agpgart driver */ #define AGP_PHYSICAL_MEMORY 2 +/* store information about an Ixxx DVO */ +/* The i830->i865 use multiple DVOs with multiple i2cs */ +/* the i915, i945 have a single sDVO i2c bus - which is different */ +#define MAX_OUTPUTS 6 + /* these are outputs from the chip - integrated only external chips are via DVO or SDVO output */ #define INTELFB_OUTPUT_UNUSED 0 @@ -344,6 +349,10 @@ struct intelfb_info { /* index into plls */ int pll_index; + + /* outputs */ + int num_outputs; + struct intelfb_output_rec output[MAX_OUTPUTS]; }; #define IS_I9XX(dinfo) (((dinfo)->chipset == INTEL_915G)||(dinfo->chipset == INTEL_915GM)||((dinfo)->chipset == INTEL_945G)||(dinfo->chipset==INTEL_945GM)) -- cgit v1.2.3 From 41c9480a1d22e8f28b8675a2d7ec7fd4c50bc900 Mon Sep 17 00:00:00 2001 From: Dennis Munsie Date: Tue, 20 Jun 2006 14:55:55 -0400 Subject: intelfb: add preliminary i2c support [06/07] intelfb: adds intelfb_i2c.c which contains the infrastructure needed to enumerate the i2c busses on the intelfb. Signed-off-by: Dennis Munsie --- drivers/video/intelfb/intelfb.h | 4 + drivers/video/intelfb/intelfb_i2c.c | 184 ++++++++++++++++++++++++++++++++++++ drivers/video/intelfb/intelfbdrv.c | 5 + 3 files changed, 193 insertions(+) create mode 100644 drivers/video/intelfb/intelfb_i2c.c diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h index 9092bda9d4b..6ef38c90c4d 100644 --- a/drivers/video/intelfb/intelfb.h +++ b/drivers/video/intelfb/intelfb.h @@ -365,4 +365,8 @@ struct intelfb_info { extern int intelfb_var_to_depth(const struct fb_var_screeninfo *var); +#ifdef CONFIG_FB_INTEL_I2C +extern void intelfb_create_i2c_busses(struct intelfb_info *dinfo); +#endif + #endif /* _INTELFB_H */ diff --git a/drivers/video/intelfb/intelfb_i2c.c b/drivers/video/intelfb/intelfb_i2c.c new file mode 100644 index 00000000000..d73572355c5 --- /dev/null +++ b/drivers/video/intelfb/intelfb_i2c.c @@ -0,0 +1,184 @@ +/************************************************************************** + + Copyright 2006 Dave Airlie + +All Rights Reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +on the rights to use, copy, modify, merge, publish, distribute, sub +license, and/or sell copies of the Software, and to permit persons to whom +the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL +THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. + +**************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include "intelfb.h" +#include "intelfbhw.h" + +/* bit locations in the registers */ +#define SCL_DIR_MASK 0x0001 +#define SCL_DIR 0x0002 +#define SCL_VAL_MASK 0x0004 +#define SCL_VAL_OUT 0x0008 +#define SCL_VAL_IN 0x0010 +#define SDA_DIR_MASK 0x0100 +#define SDA_DIR 0x0200 +#define SDA_VAL_MASK 0x0400 +#define SDA_VAL_OUT 0x0800 +#define SDA_VAL_IN 0x1000 + +static void intelfb_gpio_setscl(void *data, int state) +{ + struct intelfb_i2c_chan *chan = data; + struct intelfb_info *dinfo = chan->dinfo; + u32 val; + + OUTREG(chan->reg, (state ? SCL_VAL_OUT : 0) | SCL_DIR | SCL_DIR_MASK | SCL_VAL_MASK); + val = INREG(chan->reg); +} + +static void intelfb_gpio_setsda(void *data, int state) +{ + struct intelfb_i2c_chan *chan = data; + struct intelfb_info *dinfo = chan->dinfo; + u32 val; + + OUTREG(chan->reg, (state ? SDA_VAL_OUT : 0) | SDA_DIR | SDA_DIR_MASK | SDA_VAL_MASK); + val = INREG(chan->reg); +} + +static int intelfb_gpio_getscl(void *data) +{ + struct intelfb_i2c_chan *chan = data; + struct intelfb_info *dinfo = chan->dinfo; + u32 val; + + OUTREG(chan->reg, SCL_DIR_MASK); + OUTREG(chan->reg, 0); + val = INREG(chan->reg); + return ((val & SCL_VAL_IN) != 0); +} + +static int intelfb_gpio_getsda(void *data) +{ + struct intelfb_i2c_chan *chan = data; + struct intelfb_info *dinfo = chan->dinfo; + u32 val; + + OUTREG(chan->reg, SDA_DIR_MASK); + OUTREG(chan->reg, 0); + val = INREG(chan->reg); + return ((val & SDA_VAL_IN) != 0); +} + +static int intelfb_setup_i2c_bus(struct intelfb_info *dinfo, + struct intelfb_i2c_chan *chan, + const u32 reg, const char *name) +{ + int rc; + + chan->dinfo = dinfo; + chan->reg = reg; + snprintf(chan->adapter.name, I2C_NAME_SIZE, "intelfb %s", name); + chan->adapter.owner = THIS_MODULE; + chan->adapter.id = I2C_HW_B_INTELFB; + chan->adapter.algo_data = &chan->algo; + chan->adapter.dev.parent = &chan->dinfo->pdev->dev; + chan->algo.setsda = intelfb_gpio_setsda; + chan->algo.setscl = intelfb_gpio_setscl; + chan->algo.getsda = intelfb_gpio_getsda; + chan->algo.getscl = intelfb_gpio_getscl; + chan->algo.udelay = 40; + chan->algo.timeout = 20; + chan->algo.data = chan; + + i2c_set_adapdata(&chan->adapter, chan); + + /* Raise SCL and SDA */ + intelfb_gpio_setsda(chan, 1); + intelfb_gpio_setscl(chan, 1); + udelay(20); + + rc = i2c_bit_add_bus(&chan->adapter); + if (rc == 0) + DBG_MSG("I2C bus %s registered.\n", name); + else + WRN_MSG("Failed to register I2C bus %s.\n", name); + return rc; +} + +void intelfb_create_i2c_busses(struct intelfb_info *dinfo) +{ + int i = 0; + + /* everyone has at least a single analog output */ + dinfo->num_outputs = 1; + dinfo->output[i].type = INTELFB_OUTPUT_ANALOG; + + /* setup the DDC bus for analog output */ + intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].ddc_bus, GPIOA, "CRTDDC_A"); + i++; + + /* need to add the output busses for each device + - this function is very incomplete + - i915GM has LVDS and TVOUT for example + */ + switch(dinfo->chipset) { + case INTEL_830M: + case INTEL_845G: + case INTEL_855GM: + case INTEL_865G: + dinfo->output[i].type = INTELFB_OUTPUT_DVO; + intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].ddc_bus, GPIOD, "DVODDC_D"); + intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].i2c_bus, GPIOE, "DVOI2C_E"); + i++; + break; + case INTEL_915G: + case INTEL_915GM: + /* has some LVDS + tv-out */ + case INTEL_945G: + case INTEL_945GM: + /* SDVO ports have a single control bus - 2 devices */ + dinfo->output[i].type = INTELFB_OUTPUT_SDVO; + intelfb_setup_i2c_bus(dinfo, &dinfo->output[i].i2c_bus, GPIOE, "SDVOCTRL_E"); + /* TODO: initialize the SDVO */ +// I830SDVOInit(pScrn, i, DVOB); + i++; + + /* set up SDVOC */ + dinfo->output[i].type = INTELFB_OUTPUT_SDVO; + dinfo->output[i].i2c_bus = dinfo->output[i - 1].i2c_bus; + /* TODO: initialize the SDVO */ +// I830SDVOInit(pScrn, i, DVOC); + i++; + break; + } + dinfo->num_outputs = i; +} diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c index 9e93f820a93..f412b5ab8f9 100644 --- a/drivers/video/intelfb/intelfbdrv.c +++ b/drivers/video/intelfb/intelfbdrv.c @@ -851,6 +851,11 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent) if (bailearly == 5) bailout(dinfo); +#ifdef CONFIG_FB_INTEL_I2C + /* register I2C bus */ + intelfb_create_i2c_busses(dinfo); +#endif + if (bailearly == 6) bailout(dinfo); -- cgit v1.2.3 From 1f6e8449e11fd79ee30456ce7ec973317b8dd6ae Mon Sep 17 00:00:00 2001 From: Dennis Munsie Date: Tue, 20 Jun 2006 14:55:55 -0400 Subject: intelfb: add preliminary i2c support [07/07] intelfb: adds an option to enable I2C support in the intelfb driver. Also adds the intel_i2c.c file to the Makefile. Signed-off-by: Dennis Munsie --- drivers/video/Kconfig | 20 ++++++++++++++++++-- drivers/video/intelfb/Makefile | 4 +++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 5a2840aeb54..743c853ad15 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -809,6 +809,8 @@ config FB_INTEL depends on FB && EXPERIMENTAL && PCI && X86 select AGP select AGP_INTEL + select I2C_ALGOBIT if FB_INTEL_I2C + select I2C if FB_INTEL_I2C select FB_MODE_HELPERS select FB_CFB_FILLRECT select FB_CFB_COPYAREA @@ -818,17 +820,31 @@ config FB_INTEL 830M/845G/852GM/855GM/865G chipsets. Say Y if you have and plan to use such a board. - To compile this driver as a module, choose M here: the + If you say Y here and want DDC/I2C support you must first say Y to + "I2C support" and "I2C bit-banging support" in the character devices + section. + + If you say M here then "I2C support" and "I2C bit-banging support" + can be build either as modules or built-in. + + To compile this driver as a module, choose M here: the module will be called intelfb. config FB_INTEL_DEBUG - bool "Intel driver Debug Messages" + bool "Intel driver Debug Messages" depends on FB_INTEL ---help--- Say Y here if you want the Intel driver to output all sorts of debugging informations to provide to the maintainer when something goes wrong. +config FB_INTEL_I2C + bool "DDC/I2C for Intel framebuffer support" + depends on FB_INTEL + default y + help + Say Y here if you want DDC/I2C support for your on-board Intel graphics. + config FB_MATROX tristate "Matrox acceleration" depends on FB && PCI diff --git a/drivers/video/intelfb/Makefile b/drivers/video/intelfb/Makefile index 722d21d6e5c..6c782d3ae1b 100644 --- a/drivers/video/intelfb/Makefile +++ b/drivers/video/intelfb/Makefile @@ -1,6 +1,8 @@ obj-$(CONFIG_FB_INTEL) += intelfb.o -intelfb-objs := intelfbdrv.o intelfbhw.o +intelfb-y := intelfbdrv.o intelfbhw.o +intelfb-$(CONFIG_FB_INTEL_I2C) += intelfb_i2c.o +intelfb-objs := $(intelfb-y) ifdef CONFIG_FB_INTEL_DEBUG #EXTRA_CFLAGS += -DDEBUG -DVERBOSE -DREGDUMP -- cgit v1.2.3 From 7627899b11ece118b46fbf652e944f9a239f6cd1 Mon Sep 17 00:00:00 2001 From: Dennis Munsie Date: Tue, 20 Jun 2006 14:55:55 -0400 Subject: intelfb: add preliminary i2c support Adds code to unregister the I2C buses in the cleanup function. Signed-off-by: Dennis Munsie --- drivers/video/intelfb/intelfb.h | 1 + drivers/video/intelfb/intelfb_i2c.c | 16 ++++++++++++++++ drivers/video/intelfb/intelfbdrv.c | 5 +++++ 3 files changed, 22 insertions(+) diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h index 6ef38c90c4d..abdadc2a1b4 100644 --- a/drivers/video/intelfb/intelfb.h +++ b/drivers/video/intelfb/intelfb.h @@ -367,6 +367,7 @@ extern int intelfb_var_to_depth(const struct fb_var_screeninfo *var); #ifdef CONFIG_FB_INTEL_I2C extern void intelfb_create_i2c_busses(struct intelfb_info *dinfo); +extern void intelfb_delete_i2c_busses(struct intelfb_info *dinfo); #endif #endif /* _INTELFB_H */ diff --git a/drivers/video/intelfb/intelfb_i2c.c b/drivers/video/intelfb/intelfb_i2c.c index d73572355c5..c1113d6e941 100644 --- a/drivers/video/intelfb/intelfb_i2c.c +++ b/drivers/video/intelfb/intelfb_i2c.c @@ -182,3 +182,19 @@ void intelfb_create_i2c_busses(struct intelfb_info *dinfo) } dinfo->num_outputs = i; } + +void intelfb_delete_i2c_busses(struct intelfb_info *dinfo) +{ + int i; + + for (i = 0; i < MAX_OUTPUTS; i++) { + if (dinfo->output[i].i2c_bus.dinfo) { + i2c_bit_del_bus(&dinfo->output[i].i2c_bus.adapter); + dinfo->output[i].i2c_bus.dinfo = NULL; + } + if (dinfo->output[i].ddc_bus.dinfo) { + i2c_bit_del_bus(&dinfo->output[i].ddc_bus.adapter); + dinfo->output[i].ddc_bus.dinfo = NULL; + } + } +} diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c index f412b5ab8f9..f6e30b3d108 100644 --- a/drivers/video/intelfb/intelfbdrv.c +++ b/drivers/video/intelfb/intelfbdrv.c @@ -474,6 +474,11 @@ cleanup(struct intelfb_info *dinfo) agp_free_memory(dinfo->gtt_ring_mem); } +#ifdef CONFIG_FB_INTEL_I2C + /* un-register I2C bus */ + intelfb_delete_i2c_busses(dinfo); +#endif + if (dinfo->mmio_base) iounmap((void __iomem *)dinfo->mmio_base); if (dinfo->aperture.virtual) -- cgit v1.2.3 From 31a379e1067834868b8f1ce3e409392c42dc0f2b Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:01:58 -0400 Subject: [PATCH] ieee1394: sbp2: enable auto spin-up for Maxtor disks At least Maxtor OneTouch III require a "start stop unit" command after auto spin-down before the next access can proceed. This patch activates the responsible code in scsi_mod for all Maxtor SBP-2 disks. https://bugzilla.novell.com/show_bug.cgi?id=183011 Maybe that should be done for all SBP-2 disks, but better be cautious. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/sbp2.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index aaa74f293aa..b08755e2e68 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -2515,6 +2515,9 @@ static int sbp2scsi_slave_configure(struct scsi_device *sdev) sdev->skip_ms_page_8 = 1; if (scsi_id->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) sdev->fix_capacity = 1; + if (scsi_id->ne->guid_vendor_id == 0x0010b9 && /* Maxtor's OUI */ + (sdev->type == TYPE_DISK || sdev->type == TYPE_RBC)) + sdev->allow_restart = 1; return 0; } -- cgit v1.2.3 From f0cbefe63c4347044fffebca24c03f3c6829f322 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:01:59 -0400 Subject: [PATCH] ieee1394: fix calculation of csr->expire This variant of calculate_expire() is more correct and easier to read. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/csr.c | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/drivers/ieee1394/csr.c b/drivers/ieee1394/csr.c index 149573db91c..ab0c80f61b9 100644 --- a/drivers/ieee1394/csr.c +++ b/drivers/ieee1394/csr.c @@ -17,11 +17,13 @@ * */ -#include +#include +#include #include #include #include #include +#include #include "csr1212.h" #include "ieee1394_types.h" @@ -149,31 +151,18 @@ static void host_reset(struct hpsb_host *host) /* * HI == seconds (bits 0:2) - * LO == fraction units of 1/8000 of a second, as per 1394 (bits 19:31) - * - * Convert to units and then to HZ, for comparison to jiffies. - * - * By default this will end up being 800 units, or 100ms (125usec per - * unit). + * LO == fractions of a second in units of 125usec (bits 19:31) * - * NOTE: The spec says 1/8000, but also says we can compute based on 1/8192 - * like CSR specifies. Should make our math less complex. + * Convert SPLIT_TIMEOUT to jiffies. + * The default and minimum as per 1394a-2000 clause 8.3.2.2.6 is 100ms. */ static inline void calculate_expire(struct csr_control *csr) { - unsigned long units; - - /* Take the seconds, and convert to units */ - units = (unsigned long)(csr->split_timeout_hi & 0x07) << 13; - - /* Add in the fractional units */ - units += (unsigned long)(csr->split_timeout_lo >> 19); - - /* Convert to jiffies */ - csr->expire = (unsigned long)(units * HZ) >> 13UL; + unsigned long usecs = + (csr->split_timeout_hi & 0x07) * USEC_PER_SEC + + (csr->split_timeout_lo >> 19) * 125L; - /* Just to keep from rounding low */ - csr->expire++; + csr->expire = usecs_to_jiffies(usecs > 100000L ? usecs : 100000L); HPSB_VERBOSE("CSR: setting expire to %lu, HZ=%u", csr->expire, HZ); } -- cgit v1.2.3 From 433a87d528f685028b6f61fc3d7fae07ed915aa8 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:27 -0400 Subject: [PATCH] ieee1394: skip dummy loop in build_speed_map The last loop in ieee1394 core's speed calculation is not required unless ieee1394.h::IEEE1394_SPEED_MAX is changed from its current value of 3. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/ieee1394.h | 2 ++ drivers/ieee1394/ieee1394_core.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/ieee1394/ieee1394.h b/drivers/ieee1394/ieee1394.h index 936d776de00..d911abe3a35 100644 --- a/drivers/ieee1394/ieee1394.h +++ b/drivers/ieee1394/ieee1394.h @@ -77,6 +77,8 @@ extern const char *hpsb_speedto_str[]; #define SELFID_PORT_NCONN 0x1 #define SELFID_PORT_NONE 0x0 +#define SELFID_SPEED_UNKNOWN 0x3 /* 1394b PHY */ + #define PHYPACKET_LINKON 0x40000000 #define PHYPACKET_PHYCONFIG_R 0x00800000 #define PHYPACKET_PHYCONFIG_T 0x00400000 diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c index f43739c5cab..559c477092f 100644 --- a/drivers/ieee1394/ieee1394_core.c +++ b/drivers/ieee1394/ieee1394_core.c @@ -355,10 +355,12 @@ static void build_speed_map(struct hpsb_host *host, int nodecount) } } +#if SELFID_SPEED_UNKNOWN != IEEE1394_SPEED_MAX /* assume maximum speed for 1394b PHYs, nodemgr will correct it */ for (n = 0; n < nodecount; n++) - if (speedcap[n] == 3) + if (speedcap[n] == SELFID_SPEED_UNKNOWN) speedcap[n] = IEEE1394_SPEED_MAX; +#endif } -- cgit v1.2.3 From 2b01b80b944b3abf623c8acc2b5537a85b5ebd3c Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:28 -0400 Subject: [PATCH] ieee1394: replace __inline__ by inline Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/ieee1394_types.h | 2 +- drivers/ieee1394/ohci1394.c | 5 +++-- drivers/ieee1394/sbp2.c | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/ieee1394/ieee1394_types.h b/drivers/ieee1394/ieee1394_types.h index 3165609ec1e..440d977031e 100644 --- a/drivers/ieee1394/ieee1394_types.h +++ b/drivers/ieee1394/ieee1394_types.h @@ -75,7 +75,7 @@ typedef u16 arm_length_t; #ifdef __BIG_ENDIAN -static __inline__ void *memcpy_le32(u32 *dest, const u32 *__src, size_t count) +static inline void *memcpy_le32(u32 *dest, const u32 *__src, size_t count) { void *tmp = dest; u32 *src = (u32 *)__src; diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index d4bad6704bb..2283005e303 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c @@ -2598,8 +2598,9 @@ static const int TCODE_SIZE[16] = {20, 0, 16, -1, 16, 20, 20, 0, * Determine the length of a packet in the buffer * Optimization suggested by Pascal Drolet */ -static __inline__ int packet_length(struct dma_rcv_ctx *d, int idx, quadlet_t *buf_ptr, - int offset, unsigned char tcode, int noswap) +static inline int packet_length(struct dma_rcv_ctx *d, int idx, + quadlet_t *buf_ptr, int offset, + unsigned char tcode, int noswap) { int length = -1; diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index b08755e2e68..baa063c9e6e 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -356,7 +356,7 @@ static const struct { /* * Converts a buffer from be32 to cpu byte ordering. Length is in bytes. */ -static __inline__ void sbp2util_be32_to_cpu_buffer(void *buffer, int length) +static inline void sbp2util_be32_to_cpu_buffer(void *buffer, int length) { u32 *temp = buffer; @@ -369,7 +369,7 @@ static __inline__ void sbp2util_be32_to_cpu_buffer(void *buffer, int length) /* * Converts a buffer from cpu to be32 byte ordering. Length is in bytes. */ -static __inline__ void sbp2util_cpu_to_be32_buffer(void *buffer, int length) +static inline void sbp2util_cpu_to_be32_buffer(void *buffer, int length) { u32 *temp = buffer; -- cgit v1.2.3 From e1d118f16dca0f54faba3e8dd5b6adbbf7ac68c8 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:28 -0400 Subject: [PATCH] ieee1394: coding style and comment fixes in midlayer header files Adjust tabulators, line wraps, empty lines, and comment style. Update comments in ieee1394_transactions.h and highlevel.h. Fix typo in comment in csr.h. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/csr.h | 98 +++++----- drivers/ieee1394/dma.h | 81 +++++--- drivers/ieee1394/highlevel.h | 197 ++++++++++--------- drivers/ieee1394/hosts.h | 15 +- drivers/ieee1394/ieee1394-ioctl.h | 9 +- drivers/ieee1394/ieee1394.h | 314 +++++++++++++++---------------- drivers/ieee1394/ieee1394_core.h | 17 +- drivers/ieee1394/ieee1394_transactions.h | 32 ++-- drivers/ieee1394/ieee1394_types.h | 31 ++- drivers/ieee1394/iso.h | 80 ++++---- drivers/ieee1394/nodemgr.h | 16 +- 11 files changed, 449 insertions(+), 441 deletions(-) diff --git a/drivers/ieee1394/csr.h b/drivers/ieee1394/csr.h index ea9aa4f53ab..0655596f25d 100644 --- a/drivers/ieee1394/csr.h +++ b/drivers/ieee1394/csr.h @@ -8,68 +8,68 @@ #include "csr1212.h" -#define CSR_REGISTER_BASE 0xfffff0000000ULL +#define CSR_REGISTER_BASE 0xfffff0000000ULL /* register offsets relative to CSR_REGISTER_BASE */ -#define CSR_STATE_CLEAR 0x0 -#define CSR_STATE_SET 0x4 -#define CSR_NODE_IDS 0x8 -#define CSR_RESET_START 0xc -#define CSR_SPLIT_TIMEOUT_HI 0x18 -#define CSR_SPLIT_TIMEOUT_LO 0x1c -#define CSR_CYCLE_TIME 0x200 -#define CSR_BUS_TIME 0x204 -#define CSR_BUSY_TIMEOUT 0x210 -#define CSR_BUS_MANAGER_ID 0x21c -#define CSR_BANDWIDTH_AVAILABLE 0x220 -#define CSR_CHANNELS_AVAILABLE 0x224 -#define CSR_CHANNELS_AVAILABLE_HI 0x224 -#define CSR_CHANNELS_AVAILABLE_LO 0x228 -#define CSR_BROADCAST_CHANNEL 0x234 -#define CSR_CONFIG_ROM 0x400 -#define CSR_CONFIG_ROM_END 0x800 -#define CSR_FCP_COMMAND 0xB00 -#define CSR_FCP_RESPONSE 0xD00 -#define CSR_FCP_END 0xF00 -#define CSR_TOPOLOGY_MAP 0x1000 -#define CSR_TOPOLOGY_MAP_END 0x1400 -#define CSR_SPEED_MAP 0x2000 -#define CSR_SPEED_MAP_END 0x3000 +#define CSR_STATE_CLEAR 0x0 +#define CSR_STATE_SET 0x4 +#define CSR_NODE_IDS 0x8 +#define CSR_RESET_START 0xc +#define CSR_SPLIT_TIMEOUT_HI 0x18 +#define CSR_SPLIT_TIMEOUT_LO 0x1c +#define CSR_CYCLE_TIME 0x200 +#define CSR_BUS_TIME 0x204 +#define CSR_BUSY_TIMEOUT 0x210 +#define CSR_BUS_MANAGER_ID 0x21c +#define CSR_BANDWIDTH_AVAILABLE 0x220 +#define CSR_CHANNELS_AVAILABLE 0x224 +#define CSR_CHANNELS_AVAILABLE_HI 0x224 +#define CSR_CHANNELS_AVAILABLE_LO 0x228 +#define CSR_BROADCAST_CHANNEL 0x234 +#define CSR_CONFIG_ROM 0x400 +#define CSR_CONFIG_ROM_END 0x800 +#define CSR_FCP_COMMAND 0xB00 +#define CSR_FCP_RESPONSE 0xD00 +#define CSR_FCP_END 0xF00 +#define CSR_TOPOLOGY_MAP 0x1000 +#define CSR_TOPOLOGY_MAP_END 0x1400 +#define CSR_SPEED_MAP 0x2000 +#define CSR_SPEED_MAP_END 0x3000 /* IEEE 1394 bus specific Configuration ROM Key IDs */ #define IEEE1394_KV_ID_POWER_REQUIREMENTS (0x30) -/* IEEE 1394 Bus Inforamation Block specifics */ +/* IEEE 1394 Bus Information Block specifics */ #define CSR_BUS_INFO_SIZE (5 * sizeof(quadlet_t)) -#define CSR_IRMC_SHIFT 31 -#define CSR_CMC_SHIFT 30 -#define CSR_ISC_SHIFT 29 -#define CSR_BMC_SHIFT 28 -#define CSR_PMC_SHIFT 27 -#define CSR_CYC_CLK_ACC_SHIFT 16 -#define CSR_MAX_REC_SHIFT 12 -#define CSR_MAX_ROM_SHIFT 8 -#define CSR_GENERATION_SHIFT 4 +#define CSR_IRMC_SHIFT 31 +#define CSR_CMC_SHIFT 30 +#define CSR_ISC_SHIFT 29 +#define CSR_BMC_SHIFT 28 +#define CSR_PMC_SHIFT 27 +#define CSR_CYC_CLK_ACC_SHIFT 16 +#define CSR_MAX_REC_SHIFT 12 +#define CSR_MAX_ROM_SHIFT 8 +#define CSR_GENERATION_SHIFT 4 #define CSR_SET_BUS_INFO_GENERATION(csr, gen) \ ((csr)->bus_info_data[2] = \ cpu_to_be32((be32_to_cpu((csr)->bus_info_data[2]) & \ - ~(0xf << CSR_GENERATION_SHIFT)) | \ + ~(0xf << CSR_GENERATION_SHIFT)) | \ (gen) << CSR_GENERATION_SHIFT)) struct csr_control { - spinlock_t lock; - - quadlet_t state; - quadlet_t node_ids; - quadlet_t split_timeout_hi, split_timeout_lo; - unsigned long expire; // Calculated from split_timeout - quadlet_t cycle_time; - quadlet_t bus_time; - quadlet_t bus_manager_id; - quadlet_t bandwidth_available; - quadlet_t channels_available_hi, channels_available_lo; + spinlock_t lock; + + quadlet_t state; + quadlet_t node_ids; + quadlet_t split_timeout_hi, split_timeout_lo; + unsigned long expire; /* Calculated from split_timeout */ + quadlet_t cycle_time; + quadlet_t bus_time; + quadlet_t bus_manager_id; + quadlet_t bandwidth_available; + quadlet_t channels_available_hi, channels_available_lo; quadlet_t broadcast_channel; /* Bus Info */ @@ -84,8 +84,8 @@ struct csr_control { struct csr1212_csr *rom; - quadlet_t topology_map[256]; - quadlet_t speed_map[1024]; + quadlet_t topology_map[256]; + quadlet_t speed_map[1024]; }; extern struct csr1212_bus_ops csr_bus_ops; diff --git a/drivers/ieee1394/dma.h b/drivers/ieee1394/dma.h index 061550a6fb9..b0f0885c455 100644 --- a/drivers/ieee1394/dma.h +++ b/drivers/ieee1394/dma.h @@ -13,66 +13,85 @@ #include #include -/* struct dma_prog_region - - a small, physically-contiguous DMA buffer with random-access, - synchronous usage characteristics -*/ - +/** + * struct dma_prog_region - small contiguous DMA buffer + * @kvirt: kernel virtual address + * @dev: PCI device + * @n_pages: number of kernel pages + * @bus_addr: base bus address + * + * a small, physically contiguous DMA buffer with random-access, synchronous + * usage characteristics + */ struct dma_prog_region { - unsigned char *kvirt; /* kernel virtual address */ - struct pci_dev *dev; /* PCI device */ - unsigned int n_pages; /* # of kernel pages */ - dma_addr_t bus_addr; /* base bus address */ + unsigned char *kvirt; + struct pci_dev *dev; + unsigned int n_pages; + dma_addr_t bus_addr; }; /* clear out all fields but do not allocate any memory */ void dma_prog_region_init(struct dma_prog_region *prog); -int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes, struct pci_dev *dev); +int dma_prog_region_alloc(struct dma_prog_region *prog, unsigned long n_bytes, + struct pci_dev *dev); void dma_prog_region_free(struct dma_prog_region *prog); -static inline dma_addr_t dma_prog_region_offset_to_bus(struct dma_prog_region *prog, unsigned long offset) +static inline dma_addr_t dma_prog_region_offset_to_bus( + struct dma_prog_region *prog, unsigned long offset) { return prog->bus_addr + offset; } -/* struct dma_region - - a large, non-physically-contiguous DMA buffer with streaming, - asynchronous usage characteristics -*/ - +/** + * struct dma_region - large non-contiguous DMA buffer + * @virt: kernel virtual address + * @dev: PCI device + * @n_pages: number of kernel pages + * @n_dma_pages: number of IOMMU pages + * @sglist: IOMMU mapping + * @direction: PCI_DMA_TODEVICE, etc. + * + * a large, non-physically-contiguous DMA buffer with streaming, asynchronous + * usage characteristics + */ struct dma_region { - unsigned char *kvirt; /* kernel virtual address */ - struct pci_dev *dev; /* PCI device */ - unsigned int n_pages; /* # of kernel pages */ - unsigned int n_dma_pages; /* # of IOMMU pages */ - struct scatterlist *sglist; /* IOMMU mapping */ - int direction; /* PCI_DMA_TODEVICE, etc */ + unsigned char *kvirt; + struct pci_dev *dev; + unsigned int n_pages; + unsigned int n_dma_pages; + struct scatterlist *sglist; + int direction; }; /* clear out all fields but do not allocate anything */ void dma_region_init(struct dma_region *dma); /* allocate the buffer and map it to the IOMMU */ -int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes, struct pci_dev *dev, int direction); +int dma_region_alloc(struct dma_region *dma, unsigned long n_bytes, + struct pci_dev *dev, int direction); /* unmap and free the buffer */ void dma_region_free(struct dma_region *dma); /* sync the CPU's view of the buffer */ -void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset, unsigned long len); +void dma_region_sync_for_cpu(struct dma_region *dma, unsigned long offset, + unsigned long len); + /* sync the IO bus' view of the buffer */ -void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset, unsigned long len); +void dma_region_sync_for_device(struct dma_region *dma, unsigned long offset, + unsigned long len); /* map the buffer into a user space process */ -int dma_region_mmap(struct dma_region *dma, struct file *file, struct vm_area_struct *vma); +int dma_region_mmap(struct dma_region *dma, struct file *file, + struct vm_area_struct *vma); /* macro to index into a DMA region (or dma_prog_region) */ -#define dma_region_i(_dma, _type, _index) ( ((_type*) ((_dma)->kvirt)) + (_index) ) +#define dma_region_i(_dma, _type, _index) \ + ( ((_type*) ((_dma)->kvirt)) + (_index) ) /* return the DMA bus address of the byte with the given offset - relative to the beginning of the dma_region */ -dma_addr_t dma_region_offset_to_bus(struct dma_region *dma, unsigned long offset); + * relative to the beginning of the dma_region */ +dma_addr_t dma_region_offset_to_bus(struct dma_region *dma, + unsigned long offset); #endif /* IEEE1394_DMA_H */ diff --git a/drivers/ieee1394/highlevel.h b/drivers/ieee1394/highlevel.h index e119fb87e5b..134bb6c3ead 100644 --- a/drivers/ieee1394/highlevel.h +++ b/drivers/ieee1394/highlevel.h @@ -1,60 +1,51 @@ - #ifndef IEEE1394_HIGHLEVEL_H #define IEEE1394_HIGHLEVEL_H - +/* internal to ieee1394 core */ struct hpsb_address_serve { - struct list_head host_list; /* per host list */ - - struct list_head hl_list; /* hpsb_highlevel list */ - - struct hpsb_address_ops *op; - + struct list_head host_list; /* per host list */ + struct list_head hl_list; /* hpsb_highlevel list */ + struct hpsb_address_ops *op; struct hpsb_host *host; - - /* first address handled and first address behind, quadlet aligned */ - u64 start, end; + u64 start; /* first address handled, quadlet aligned */ + u64 end; /* first address behind, quadlet aligned */ }; - -/* - * The above structs are internal to highlevel driver handling. Only the - * following structures are of interest to actual highlevel drivers. - */ +/* Only the following structures are of interest to actual highlevel drivers. */ struct hpsb_highlevel { struct module *owner; const char *name; - /* Any of the following pointers can legally be NULL, except for - * iso_receive which can only be NULL when you don't request - * channels. */ + /* Any of the following pointers can legally be NULL, except for + * iso_receive which can only be NULL when you don't request + * channels. */ - /* New host initialized. Will also be called during - * hpsb_register_highlevel for all hosts already installed. */ - void (*add_host) (struct hpsb_host *host); + /* New host initialized. Will also be called during + * hpsb_register_highlevel for all hosts already installed. */ + void (*add_host)(struct hpsb_host *host); - /* Host about to be removed. Will also be called during - * hpsb_unregister_highlevel once for each host. */ - void (*remove_host) (struct hpsb_host *host); + /* Host about to be removed. Will also be called during + * hpsb_unregister_highlevel once for each host. */ + void (*remove_host)(struct hpsb_host *host); - /* Host experienced bus reset with possible configuration changes. + /* Host experienced bus reset with possible configuration changes. * Note that this one may occur during interrupt/bottom half handling. * You can not expect to be able to do stock hpsb_reads. */ - void (*host_reset) (struct hpsb_host *host); + void (*host_reset)(struct hpsb_host *host); - /* An isochronous packet was received. Channel contains the channel - * number for your convenience, it is also contained in the included - * packet header (first quadlet, CRCs are missing). You may get called - * for channel/host combinations you did not request. */ - void (*iso_receive) (struct hpsb_host *host, int channel, - quadlet_t *data, size_t length); + /* An isochronous packet was received. Channel contains the channel + * number for your convenience, it is also contained in the included + * packet header (first quadlet, CRCs are missing). You may get called + * for channel/host combinations you did not request. */ + void (*iso_receive)(struct hpsb_host *host, int channel, + quadlet_t *data, size_t length); - /* A write request was received on either the FCP_COMMAND (direction = - * 0) or the FCP_RESPONSE (direction = 1) register. The cts arg - * contains the cts field (first byte of data). */ - void (*fcp_request) (struct hpsb_host *host, int nodeid, int direction, - int cts, u8 *data, size_t length); + /* A write request was received on either the FCP_COMMAND (direction = + * 0) or the FCP_RESPONSE (direction = 1) register. The cts arg + * contains the cts field (first byte of data). */ + void (*fcp_request)(struct hpsb_host *host, int nodeid, int direction, + int cts, u8 *data, size_t length); /* These are initialized by the subsystem when the * hpsb_higlevel is registered. */ @@ -67,61 +58,62 @@ struct hpsb_highlevel { }; struct hpsb_address_ops { - /* - * Null function pointers will make the respective operation complete - * with RCODE_TYPE_ERROR. Makes for easy to implement read-only - * registers (just leave everything but read NULL). - * - * All functions shall return appropriate IEEE 1394 rcodes. - */ - - /* These functions have to implement block reads for themselves. */ - /* These functions either return a response code - or a negative number. In the first case a response will be generated; in the - later case, no response will be sent and the driver, that handled the request - will send the response itself - */ - int (*read) (struct hpsb_host *host, int nodeid, quadlet_t *buffer, - u64 addr, size_t length, u16 flags); - int (*write) (struct hpsb_host *host, int nodeid, int destid, - quadlet_t *data, u64 addr, size_t length, u16 flags); - - /* Lock transactions: write results of ext_tcode operation into - * *store. */ - int (*lock) (struct hpsb_host *host, int nodeid, quadlet_t *store, - u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, u16 flags); - int (*lock64) (struct hpsb_host *host, int nodeid, octlet_t *store, - u64 addr, octlet_t data, octlet_t arg, int ext_tcode, u16 flags); + /* + * Null function pointers will make the respective operation complete + * with RCODE_TYPE_ERROR. Makes for easy to implement read-only + * registers (just leave everything but read NULL). + * + * All functions shall return appropriate IEEE 1394 rcodes. + */ + + /* These functions have to implement block reads for themselves. + * + * These functions either return a response code or a negative number. + * In the first case a response will be generated. In the latter case, + * no response will be sent and the driver which handled the request + * will send the response itself. */ + int (*read)(struct hpsb_host *host, int nodeid, quadlet_t *buffer, + u64 addr, size_t length, u16 flags); + int (*write)(struct hpsb_host *host, int nodeid, int destid, + quadlet_t *data, u64 addr, size_t length, u16 flags); + + /* Lock transactions: write results of ext_tcode operation into + * *store. */ + int (*lock)(struct hpsb_host *host, int nodeid, quadlet_t *store, + u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, + u16 flags); + int (*lock64)(struct hpsb_host *host, int nodeid, octlet_t *store, + u64 addr, octlet_t data, octlet_t arg, int ext_tcode, + u16 flags); }; - void highlevel_add_host(struct hpsb_host *host); void highlevel_remove_host(struct hpsb_host *host); void highlevel_host_reset(struct hpsb_host *host); - -/* these functions are called to handle transactions. They are called, when - a packet arrives. The flags argument contains the second word of the first header - quadlet of the incoming packet (containing transaction label, retry code, - transaction code and priority). These functions either return a response code - or a negative number. In the first case a response will be generated; in the - later case, no response will be sent and the driver, that handled the request - will send the response itself. -*/ -int highlevel_read(struct hpsb_host *host, int nodeid, void *data, - u64 addr, unsigned int length, u16 flags); -int highlevel_write(struct hpsb_host *host, int nodeid, int destid, - void *data, u64 addr, unsigned int length, u16 flags); +/* + * These functions are called to handle transactions. They are called when a + * packet arrives. The flags argument contains the second word of the first + * header quadlet of the incoming packet (containing transaction label, retry + * code, transaction code and priority). These functions either return a + * response code or a negative number. In the first case a response will be + * generated. In the latter case, no response will be sent and the driver which + * handled the request will send the response itself. + */ +int highlevel_read(struct hpsb_host *host, int nodeid, void *data, u64 addr, + unsigned int length, u16 flags); +int highlevel_write(struct hpsb_host *host, int nodeid, int destid, void *data, + u64 addr, unsigned int length, u16 flags); int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store, - u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, u16 flags); + u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode, + u16 flags); int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store, - u64 addr, octlet_t data, octlet_t arg, int ext_tcode, u16 flags); + u64 addr, octlet_t data, octlet_t arg, int ext_tcode, + u16 flags); -void highlevel_iso_receive(struct hpsb_host *host, void *data, - size_t length); +void highlevel_iso_receive(struct hpsb_host *host, void *data, size_t length); void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction, - void *data, size_t length); - + void *data, size_t length); /* * Register highlevel driver. The name pointer has to stay valid at all times @@ -132,13 +124,15 @@ void hpsb_unregister_highlevel(struct hpsb_highlevel *hl); /* * Register handlers for host address spaces. Start and end are 48 bit pointers - * and have to be quadlet aligned (end points to the first address behind the - * handled addresses. This function can be called multiple times for a single - * hpsb_highlevel to implement sparse register sets. The requested region must - * not overlap any previously allocated region, otherwise registering will fail. + * and have to be quadlet aligned. Argument "end" points to the first address + * behind the handled addresses. This function can be called multiple times for + * a single hpsb_highlevel to implement sparse register sets. The requested + * region must not overlap any previously allocated region, otherwise + * registering will fail. * - * It returns true for successful allocation. There is no unregister function, - * all address spaces are deallocated together with the hpsb_highlevel. + * It returns true for successful allocation. Address spaces can be + * unregistered with hpsb_unregister_addrspace. All remaining address spaces + * are automatically deallocated together with the hpsb_highlevel. */ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, @@ -146,20 +140,18 @@ u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl, u64 size, u64 alignment, u64 start, u64 end); int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, - struct hpsb_address_ops *ops, u64 start, u64 end); - + struct hpsb_address_ops *ops, u64 start, u64 end); int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host, - u64 start); + u64 start); /* * Enable or disable receving a certain isochronous channel through the * iso_receive op. */ int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, - unsigned int channel); + unsigned int channel); void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host, - unsigned int channel); - + unsigned int channel); /* Retrieve a hostinfo pointer bound to this driver/host */ void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host); @@ -172,19 +164,24 @@ void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host); /* Set an alternate lookup key for the hostinfo bound to this driver/host */ -void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host, unsigned long key); +void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host, + unsigned long key); -/* Retrieve the alternate lookup key for the hostinfo bound to this driver/host */ -unsigned long hpsb_get_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host); +/* Retrieve the alternate lookup key for the hostinfo bound to this + * driver/host */ +unsigned long hpsb_get_hostinfo_key(struct hpsb_highlevel *hl, + struct hpsb_host *host); /* Retrieve a hostinfo pointer bound to this driver using its alternate key */ void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key); /* Set the hostinfo pointer to something useful. Usually follows a call to * hpsb_create_hostinfo, where the size is 0. */ -int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, void *data); +int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host, + void *data); /* Retrieve hpsb_host using a highlevel handle and a key */ -struct hpsb_host *hpsb_get_host_bykey(struct hpsb_highlevel *hl, unsigned long key); +struct hpsb_host *hpsb_get_host_bykey(struct hpsb_highlevel *hl, + unsigned long key); #endif /* IEEE1394_HIGHLEVEL_H */ diff --git a/drivers/ieee1394/hosts.h b/drivers/ieee1394/hosts.h index 9ad4b246307..857d7d80bc8 100644 --- a/drivers/ieee1394/hosts.h +++ b/drivers/ieee1394/hosts.h @@ -112,7 +112,7 @@ enum devctl_cmd { enum isoctl_cmd { /* rawiso API - see iso.h for the meanings of these commands - (they correspond exactly to the hpsb_iso_* API functions) + * (they correspond exactly to the hpsb_iso_* API functions) * INIT = allocate resources * START = begin transmission/reception * STOP = halt transmission/reception @@ -160,7 +160,8 @@ struct hpsb_host_driver { /* The hardware driver may optionally support a function that is used * to set the hardware ConfigROM if the hardware supports handling * reads to the ConfigROM on its own. */ - void (*set_hw_config_rom) (struct hpsb_host *host, quadlet_t *config_rom); + void (*set_hw_config_rom)(struct hpsb_host *host, + quadlet_t *config_rom); /* This function shall implement packet transmission based on * packet->type. It shall CRC both parts of the packet (unless @@ -170,20 +171,21 @@ struct hpsb_host_driver { * called. Return 0 on success, negative errno on failure. * NOTE: The function must be callable in interrupt context. */ - int (*transmit_packet) (struct hpsb_host *host, - struct hpsb_packet *packet); + int (*transmit_packet)(struct hpsb_host *host, + struct hpsb_packet *packet); /* This function requests miscellanous services from the driver, see * above for command codes and expected actions. Return -1 for unknown * command, though that should never happen. */ - int (*devctl) (struct hpsb_host *host, enum devctl_cmd command, int arg); + int (*devctl)(struct hpsb_host *host, enum devctl_cmd command, int arg); /* ISO transmission/reception functions. Return 0 on success, -1 * (or -EXXX errno code) on failure. If the low-level driver does not * support the new ISO API, set isoctl to NULL. */ - int (*isoctl) (struct hpsb_iso *iso, enum isoctl_cmd command, unsigned long arg); + int (*isoctl)(struct hpsb_iso *iso, enum isoctl_cmd command, + unsigned long arg); /* This function is mainly to redirect local CSR reads/locks to the iso * management registers (bus manager id, bandwidth available, channels @@ -196,7 +198,6 @@ struct hpsb_host_driver { quadlet_t data, quadlet_t compare); }; - struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra, struct device *dev); int hpsb_add_host(struct hpsb_host *host); diff --git a/drivers/ieee1394/ieee1394-ioctl.h b/drivers/ieee1394/ieee1394-ioctl.h index 15670398634..8f207508ed1 100644 --- a/drivers/ieee1394/ieee1394-ioctl.h +++ b/drivers/ieee1394/ieee1394-ioctl.h @@ -1,5 +1,7 @@ -/* Base file for all ieee1394 ioctl's. Linux-1394 has allocated base '#' - * with a range of 0x00-0x3f. */ +/* + * Base file for all ieee1394 ioctl's. + * Linux-1394 has allocated base '#' with a range of 0x00-0x3f. + */ #ifndef __IEEE1394_IOCTL_H #define __IEEE1394_IOCTL_H @@ -96,8 +98,7 @@ _IOW ('#', 0x27, struct raw1394_iso_packets) #define RAW1394_IOC_ISO_XMIT_SYNC \ _IO ('#', 0x28) -#define RAW1394_IOC_ISO_RECV_FLUSH \ +#define RAW1394_IOC_ISO_RECV_FLUSH \ _IO ('#', 0x29) - #endif /* __IEEE1394_IOCTL_H */ diff --git a/drivers/ieee1394/ieee1394.h b/drivers/ieee1394/ieee1394.h index d911abe3a35..40492074c01 100644 --- a/drivers/ieee1394/ieee1394.h +++ b/drivers/ieee1394/ieee1394.h @@ -5,77 +5,76 @@ #ifndef _IEEE1394_IEEE1394_H #define _IEEE1394_IEEE1394_H -#define TCODE_WRITEQ 0x0 -#define TCODE_WRITEB 0x1 -#define TCODE_WRITE_RESPONSE 0x2 -#define TCODE_READQ 0x4 -#define TCODE_READB 0x5 -#define TCODE_READQ_RESPONSE 0x6 -#define TCODE_READB_RESPONSE 0x7 -#define TCODE_CYCLE_START 0x8 -#define TCODE_LOCK_REQUEST 0x9 -#define TCODE_ISO_DATA 0xa -#define TCODE_STREAM_DATA 0xa -#define TCODE_LOCK_RESPONSE 0xb - -#define RCODE_COMPLETE 0x0 -#define RCODE_CONFLICT_ERROR 0x4 -#define RCODE_DATA_ERROR 0x5 -#define RCODE_TYPE_ERROR 0x6 -#define RCODE_ADDRESS_ERROR 0x7 - -#define EXTCODE_MASK_SWAP 0x1 -#define EXTCODE_COMPARE_SWAP 0x2 -#define EXTCODE_FETCH_ADD 0x3 -#define EXTCODE_LITTLE_ADD 0x4 -#define EXTCODE_BOUNDED_ADD 0x5 -#define EXTCODE_WRAP_ADD 0x6 - -#define ACK_COMPLETE 0x1 -#define ACK_PENDING 0x2 -#define ACK_BUSY_X 0x4 -#define ACK_BUSY_A 0x5 -#define ACK_BUSY_B 0x6 -#define ACK_TARDY 0xb -#define ACK_CONFLICT_ERROR 0xc -#define ACK_DATA_ERROR 0xd -#define ACK_TYPE_ERROR 0xe -#define ACK_ADDRESS_ERROR 0xf +#define TCODE_WRITEQ 0x0 +#define TCODE_WRITEB 0x1 +#define TCODE_WRITE_RESPONSE 0x2 +#define TCODE_READQ 0x4 +#define TCODE_READB 0x5 +#define TCODE_READQ_RESPONSE 0x6 +#define TCODE_READB_RESPONSE 0x7 +#define TCODE_CYCLE_START 0x8 +#define TCODE_LOCK_REQUEST 0x9 +#define TCODE_ISO_DATA 0xa +#define TCODE_STREAM_DATA 0xa +#define TCODE_LOCK_RESPONSE 0xb + +#define RCODE_COMPLETE 0x0 +#define RCODE_CONFLICT_ERROR 0x4 +#define RCODE_DATA_ERROR 0x5 +#define RCODE_TYPE_ERROR 0x6 +#define RCODE_ADDRESS_ERROR 0x7 + +#define EXTCODE_MASK_SWAP 0x1 +#define EXTCODE_COMPARE_SWAP 0x2 +#define EXTCODE_FETCH_ADD 0x3 +#define EXTCODE_LITTLE_ADD 0x4 +#define EXTCODE_BOUNDED_ADD 0x5 +#define EXTCODE_WRAP_ADD 0x6 + +#define ACK_COMPLETE 0x1 +#define ACK_PENDING 0x2 +#define ACK_BUSY_X 0x4 +#define ACK_BUSY_A 0x5 +#define ACK_BUSY_B 0x6 +#define ACK_TARDY 0xb +#define ACK_CONFLICT_ERROR 0xc +#define ACK_DATA_ERROR 0xd +#define ACK_TYPE_ERROR 0xe +#define ACK_ADDRESS_ERROR 0xf /* Non-standard "ACK codes" for internal use */ -#define ACKX_NONE (-1) -#define ACKX_SEND_ERROR (-2) -#define ACKX_ABORTED (-3) -#define ACKX_TIMEOUT (-4) - - -#define IEEE1394_SPEED_100 0x00 -#define IEEE1394_SPEED_200 0x01 -#define IEEE1394_SPEED_400 0x02 -#define IEEE1394_SPEED_800 0x03 -#define IEEE1394_SPEED_1600 0x04 -#define IEEE1394_SPEED_3200 0x05 +#define ACKX_NONE (-1) +#define ACKX_SEND_ERROR (-2) +#define ACKX_ABORTED (-3) +#define ACKX_TIMEOUT (-4) + +#define IEEE1394_SPEED_100 0x00 +#define IEEE1394_SPEED_200 0x01 +#define IEEE1394_SPEED_400 0x02 +#define IEEE1394_SPEED_800 0x03 +#define IEEE1394_SPEED_1600 0x04 +#define IEEE1394_SPEED_3200 0x05 + /* The current highest tested speed supported by the subsystem */ -#define IEEE1394_SPEED_MAX IEEE1394_SPEED_800 +#define IEEE1394_SPEED_MAX IEEE1394_SPEED_800 /* Maps speed values above to a string representation */ extern const char *hpsb_speedto_str[]; - /* 1394a cable PHY packets */ -#define SELFID_PWRCL_NO_POWER 0x0 -#define SELFID_PWRCL_PROVIDE_15W 0x1 -#define SELFID_PWRCL_PROVIDE_30W 0x2 -#define SELFID_PWRCL_PROVIDE_45W 0x3 -#define SELFID_PWRCL_USE_1W 0x4 -#define SELFID_PWRCL_USE_3W 0x5 -#define SELFID_PWRCL_USE_6W 0x6 -#define SELFID_PWRCL_USE_10W 0x7 - -#define SELFID_PORT_CHILD 0x3 -#define SELFID_PORT_PARENT 0x2 -#define SELFID_PORT_NCONN 0x1 -#define SELFID_PORT_NONE 0x0 +#define SELFID_PWRCL_NO_POWER 0x0 +#define SELFID_PWRCL_PROVIDE_15W 0x1 +#define SELFID_PWRCL_PROVIDE_30W 0x2 +#define SELFID_PWRCL_PROVIDE_45W 0x3 +#define SELFID_PWRCL_USE_1W 0x4 +#define SELFID_PWRCL_USE_3W 0x5 +#define SELFID_PWRCL_USE_6W 0x6 +#define SELFID_PWRCL_USE_10W 0x7 + +#define SELFID_PORT_CHILD 0x3 +#define SELFID_PORT_PARENT 0x2 +#define SELFID_PORT_NCONN 0x1 +#define SELFID_PORT_NONE 0x0 #define SELFID_SPEED_UNKNOWN 0x3 /* 1394b PHY */ @@ -93,76 +92,76 @@ extern const char *hpsb_speedto_str[]; #define EXTPHYPACKET_TYPEMASK 0xC0FC0000 -#define PHYPACKET_PORT_SHIFT 24 -#define PHYPACKET_GAPCOUNT_SHIFT 16 +#define PHYPACKET_PORT_SHIFT 24 +#define PHYPACKET_GAPCOUNT_SHIFT 16 /* 1394a PHY register map bitmasks */ -#define PHY_00_PHYSICAL_ID 0xFC -#define PHY_00_R 0x02 /* Root */ -#define PHY_00_PS 0x01 /* Power Status*/ -#define PHY_01_RHB 0x80 /* Root Hold-Off */ -#define PHY_01_IBR 0x80 /* Initiate Bus Reset */ -#define PHY_01_GAP_COUNT 0x3F -#define PHY_02_EXTENDED 0xE0 /* 0x7 for 1394a-compliant PHY */ -#define PHY_02_TOTAL_PORTS 0x1F -#define PHY_03_MAX_SPEED 0xE0 -#define PHY_03_DELAY 0x0F -#define PHY_04_LCTRL 0x80 /* Link Active Report Control */ -#define PHY_04_CONTENDER 0x40 -#define PHY_04_JITTER 0x38 -#define PHY_04_PWR_CLASS 0x07 /* Power Class */ -#define PHY_05_WATCHDOG 0x80 -#define PHY_05_ISBR 0x40 /* Initiate Short Bus Reset */ -#define PHY_05_LOOP 0x20 /* Loop Detect */ -#define PHY_05_PWR_FAIL 0x10 /* Cable Power Failure Detect */ -#define PHY_05_TIMEOUT 0x08 /* Arbitration State Machine Timeout */ -#define PHY_05_PORT_EVENT 0x04 /* Port Event Detect */ -#define PHY_05_ENAB_ACCEL 0x02 /* Enable Arbitration Acceleration */ -#define PHY_05_ENAB_MULTI 0x01 /* Ena. Multispeed Packet Concatenation */ +#define PHY_00_PHYSICAL_ID 0xFC +#define PHY_00_R 0x02 /* Root */ +#define PHY_00_PS 0x01 /* Power Status*/ +#define PHY_01_RHB 0x80 /* Root Hold-Off */ +#define PHY_01_IBR 0x80 /* Initiate Bus Reset */ +#define PHY_01_GAP_COUNT 0x3F +#define PHY_02_EXTENDED 0xE0 /* 0x7 for 1394a-compliant PHY */ +#define PHY_02_TOTAL_PORTS 0x1F +#define PHY_03_MAX_SPEED 0xE0 +#define PHY_03_DELAY 0x0F +#define PHY_04_LCTRL 0x80 /* Link Active Report Control */ +#define PHY_04_CONTENDER 0x40 +#define PHY_04_JITTER 0x38 +#define PHY_04_PWR_CLASS 0x07 /* Power Class */ +#define PHY_05_WATCHDOG 0x80 +#define PHY_05_ISBR 0x40 /* Initiate Short Bus Reset */ +#define PHY_05_LOOP 0x20 /* Loop Detect */ +#define PHY_05_PWR_FAIL 0x10 /* Cable Power Failure Detect */ +#define PHY_05_TIMEOUT 0x08 /* Arbitration State Machine Timeout */ +#define PHY_05_PORT_EVENT 0x04 /* Port Event Detect */ +#define PHY_05_ENAB_ACCEL 0x02 /* Enable Arbitration Acceleration */ +#define PHY_05_ENAB_MULTI 0x01 /* Ena. Multispeed Packet Concatenation */ #include #ifdef __BIG_ENDIAN_BITFIELD struct selfid { - u32 packet_identifier:2; /* always binary 10 */ - u32 phy_id:6; - /* byte */ - u32 extended:1; /* if true is struct ext_selfid */ - u32 link_active:1; - u32 gap_count:6; - /* byte */ - u32 speed:2; - u32 phy_delay:2; - u32 contender:1; - u32 power_class:3; - /* byte */ - u32 port0:2; - u32 port1:2; - u32 port2:2; - u32 initiated_reset:1; - u32 more_packets:1; + u32 packet_identifier:2; /* always binary 10 */ + u32 phy_id:6; + /* byte */ + u32 extended:1; /* if true is struct ext_selfid */ + u32 link_active:1; + u32 gap_count:6; + /* byte */ + u32 speed:2; + u32 phy_delay:2; + u32 contender:1; + u32 power_class:3; + /* byte */ + u32 port0:2; + u32 port1:2; + u32 port2:2; + u32 initiated_reset:1; + u32 more_packets:1; } __attribute__((packed)); struct ext_selfid { - u32 packet_identifier:2; /* always binary 10 */ - u32 phy_id:6; - /* byte */ - u32 extended:1; /* if false is struct selfid */ - u32 seq_nr:3; - u32 reserved:2; - u32 porta:2; - /* byte */ - u32 portb:2; - u32 portc:2; - u32 portd:2; - u32 porte:2; - /* byte */ - u32 portf:2; - u32 portg:2; - u32 porth:2; - u32 reserved2:1; - u32 more_packets:1; + u32 packet_identifier:2; /* always binary 10 */ + u32 phy_id:6; + /* byte */ + u32 extended:1; /* if false is struct selfid */ + u32 seq_nr:3; + u32 reserved:2; + u32 porta:2; + /* byte */ + u32 portb:2; + u32 portc:2; + u32 portd:2; + u32 porte:2; + /* byte */ + u32 portf:2; + u32 portg:2; + u32 porth:2; + u32 reserved2:1; + u32 more_packets:1; } __attribute__((packed)); #elif defined __LITTLE_ENDIAN_BITFIELD /* __BIG_ENDIAN_BITFIELD */ @@ -173,49 +172,48 @@ struct ext_selfid { */ struct selfid { - u32 phy_id:6; - u32 packet_identifier:2; /* always binary 10 */ - /* byte */ - u32 gap_count:6; - u32 link_active:1; - u32 extended:1; /* if true is struct ext_selfid */ - /* byte */ - u32 power_class:3; - u32 contender:1; - u32 phy_delay:2; - u32 speed:2; - /* byte */ - u32 more_packets:1; - u32 initiated_reset:1; - u32 port2:2; - u32 port1:2; - u32 port0:2; + u32 phy_id:6; + u32 packet_identifier:2; /* always binary 10 */ + /* byte */ + u32 gap_count:6; + u32 link_active:1; + u32 extended:1; /* if true is struct ext_selfid */ + /* byte */ + u32 power_class:3; + u32 contender:1; + u32 phy_delay:2; + u32 speed:2; + /* byte */ + u32 more_packets:1; + u32 initiated_reset:1; + u32 port2:2; + u32 port1:2; + u32 port0:2; } __attribute__((packed)); struct ext_selfid { - u32 phy_id:6; - u32 packet_identifier:2; /* always binary 10 */ - /* byte */ - u32 porta:2; - u32 reserved:2; - u32 seq_nr:3; - u32 extended:1; /* if false is struct selfid */ - /* byte */ - u32 porte:2; - u32 portd:2; - u32 portc:2; - u32 portb:2; - /* byte */ - u32 more_packets:1; - u32 reserved2:1; - u32 porth:2; - u32 portg:2; - u32 portf:2; + u32 phy_id:6; + u32 packet_identifier:2; /* always binary 10 */ + /* byte */ + u32 porta:2; + u32 reserved:2; + u32 seq_nr:3; + u32 extended:1; /* if false is struct selfid */ + /* byte */ + u32 porte:2; + u32 portd:2; + u32 portc:2; + u32 portb:2; + /* byte */ + u32 more_packets:1; + u32 reserved2:1; + u32 porth:2; + u32 portg:2; + u32 portf:2; } __attribute__((packed)); #else #error What? PDP endian? #endif /* __BIG_ENDIAN_BITFIELD */ - #endif /* _IEEE1394_IEEE1394_H */ diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h index 0ecbf335c64..31d9efccdc0 100644 --- a/drivers/ieee1394/ieee1394_core.h +++ b/drivers/ieee1394/ieee1394_core.h @@ -58,7 +58,6 @@ struct hpsb_packet { size_t header_size; size_t data_size; - struct hpsb_host *host; unsigned int generation; @@ -80,7 +79,7 @@ struct hpsb_packet { /* Set a task for when a packet completes */ void hpsb_set_packet_complete_task(struct hpsb_packet *packet, - void (*routine)(void *), void *data); + void (*routine)(void *), void *data); static inline struct hpsb_packet *driver_packet(struct list_head *l) { @@ -92,7 +91,6 @@ void abort_timedouts(unsigned long __opaque); struct hpsb_packet *hpsb_alloc_packet(size_t data_size); void hpsb_free_packet(struct hpsb_packet *packet); - /* * Generation counter for the complete 1394 subsystem. Generation gets * incremented on every change in the subsystem (e.g. bus reset). @@ -204,10 +202,14 @@ void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size, #define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15 #define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0) -#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16) -#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_VIDEO1394 * 16) -#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16) -#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16) +#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \ + IEEE1394_MINOR_BLOCK_RAW1394 * 16) +#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \ + IEEE1394_MINOR_BLOCK_VIDEO1394 * 16) +#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \ + IEEE1394_MINOR_BLOCK_DV1394 * 16) +#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \ + IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16) /* return the index (within a minor number block) of a file */ static inline unsigned char ieee1394_file_to_instance(struct file *file) @@ -223,4 +225,3 @@ extern struct class hpsb_host_class; extern struct class *hpsb_protocol_class; #endif /* _IEEE1394_CORE_H */ - diff --git a/drivers/ieee1394/ieee1394_transactions.h b/drivers/ieee1394/ieee1394_transactions.h index 45ba784fe6d..5f809f50845 100644 --- a/drivers/ieee1394/ieee1394_transactions.h +++ b/drivers/ieee1394/ieee1394_transactions.h @@ -3,30 +3,25 @@ #include "ieee1394_core.h" - -/* - * Get and free transaction labels. - */ int hpsb_get_tlabel(struct hpsb_packet *packet); void hpsb_free_tlabel(struct hpsb_packet *packet); - struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node, u64 addr, size_t length); struct hpsb_packet *hpsb_make_lockpacket(struct hpsb_host *host, nodeid_t node, - u64 addr, int extcode, quadlet_t *data, + u64 addr, int extcode, quadlet_t *data, quadlet_t arg); -struct hpsb_packet *hpsb_make_lock64packet(struct hpsb_host *host, nodeid_t node, - u64 addr, int extcode, octlet_t *data, - octlet_t arg); -struct hpsb_packet *hpsb_make_phypacket(struct hpsb_host *host, - quadlet_t data) ; -struct hpsb_packet *hpsb_make_isopacket(struct hpsb_host *host, - int length, int channel, - int tag, int sync); -struct hpsb_packet *hpsb_make_writepacket (struct hpsb_host *host, nodeid_t node, - u64 addr, quadlet_t *buffer, size_t length); +struct hpsb_packet *hpsb_make_lock64packet(struct hpsb_host *host, + nodeid_t node, u64 addr, int extcode, + octlet_t *data, octlet_t arg); +struct hpsb_packet *hpsb_make_phypacket(struct hpsb_host *host, quadlet_t data); +struct hpsb_packet *hpsb_make_isopacket(struct hpsb_host *host, int length, + int channel, int tag, int sync); +struct hpsb_packet *hpsb_make_writepacket(struct hpsb_host *host, + nodeid_t node, u64 addr, + quadlet_t *buffer, size_t length); struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 *buffer, - int length, int channel, int tag, int sync); + int length, int channel, int tag, + int sync); /* * hpsb_packet_success - Make sense of the ack and reply codes and @@ -40,9 +35,8 @@ struct hpsb_packet *hpsb_make_streampacket(struct hpsb_host *host, u8 *buffer, */ int hpsb_packet_success(struct hpsb_packet *packet); - /* - * The generic read, write and lock functions. All recognize the local node ID + * The generic read and write functions. All recognize the local node ID * and act accordingly. Read and write automatically use quadlet commands if * length == 4 and and block commands otherwise (however, they do not yet * support lengths that are not a multiple of 4). You must explicitly specifiy diff --git a/drivers/ieee1394/ieee1394_types.h b/drivers/ieee1394/ieee1394_types.h index 440d977031e..ed6fdd811a0 100644 --- a/drivers/ieee1394/ieee1394_types.h +++ b/drivers/ieee1394/ieee1394_types.h @@ -31,7 +31,6 @@ do { \ sema_init(&(_tp)->count, 63); \ } while (0) - typedef u32 quadlet_t; typedef u64 octlet_t; typedef u16 nodeid_t; @@ -54,16 +53,17 @@ typedef u16 arm_length_t; #define NODE_BUS_ARGS(__host, __nodeid) \ __host->id, NODEID_TO_NODE(__nodeid), NODEID_TO_BUS(__nodeid) -#define HPSB_PRINT(level, fmt, args...) printk(level "ieee1394: " fmt "\n" , ## args) +#define HPSB_PRINT(level, fmt, args...) \ + printk(level "ieee1394: " fmt "\n" , ## args) -#define HPSB_DEBUG(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args) -#define HPSB_INFO(fmt, args...) HPSB_PRINT(KERN_INFO, fmt , ## args) -#define HPSB_NOTICE(fmt, args...) HPSB_PRINT(KERN_NOTICE, fmt , ## args) -#define HPSB_WARN(fmt, args...) HPSB_PRINT(KERN_WARNING, fmt , ## args) -#define HPSB_ERR(fmt, args...) HPSB_PRINT(KERN_ERR, fmt , ## args) +#define HPSB_DEBUG(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args) +#define HPSB_INFO(fmt, args...) HPSB_PRINT(KERN_INFO, fmt , ## args) +#define HPSB_NOTICE(fmt, args...) HPSB_PRINT(KERN_NOTICE, fmt , ## args) +#define HPSB_WARN(fmt, args...) HPSB_PRINT(KERN_WARNING, fmt , ## args) +#define HPSB_ERR(fmt, args...) HPSB_PRINT(KERN_ERR, fmt , ## args) #ifdef CONFIG_IEEE1394_VERBOSEDEBUG -#define HPSB_VERBOSE(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args) +#define HPSB_VERBOSE(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args) #else #define HPSB_VERBOSE(fmt, args...) #endif @@ -77,23 +77,20 @@ typedef u16 arm_length_t; static inline void *memcpy_le32(u32 *dest, const u32 *__src, size_t count) { - void *tmp = dest; + void *tmp = dest; u32 *src = (u32 *)__src; - count /= 4; - - while (count--) { - *dest++ = swab32p(src++); - } - - return tmp; + count /= 4; + while (count--) + *dest++ = swab32p(src++); + return tmp; } #else static __inline__ void *memcpy_le32(u32 *dest, const u32 *src, size_t count) { - return memcpy(dest, src, count); + return memcpy(dest, src, count); } #endif /* __BIG_ENDIAN */ diff --git a/drivers/ieee1394/iso.h b/drivers/ieee1394/iso.h index 3efc60b33a8..ed639c4c510 100644 --- a/drivers/ieee1394/iso.h +++ b/drivers/ieee1394/iso.h @@ -17,28 +17,30 @@ /* high-level ISO interface */ -/* This API sends and receives isochronous packets on a large, - virtually-contiguous kernel memory buffer. The buffer may be mapped - into a user-space process for zero-copy transmission and reception. - - There are no explicit boundaries between packets in the buffer. A - packet may be transmitted or received at any location. However, - low-level drivers may impose certain restrictions on alignment or - size of packets. (e.g. in OHCI no packet may cross a page boundary, - and packets should be quadlet-aligned) -*/ +/* + * This API sends and receives isochronous packets on a large, + * virtually-contiguous kernel memory buffer. The buffer may be mapped + * into a user-space process for zero-copy transmission and reception. + * + * There are no explicit boundaries between packets in the buffer. A + * packet may be transmitted or received at any location. However, + * low-level drivers may impose certain restrictions on alignment or + * size of packets. (e.g. in OHCI no packet may cross a page boundary, + * and packets should be quadlet-aligned) + */ /* Packet descriptor - the API maintains a ring buffer of these packet - descriptors in kernel memory (hpsb_iso.infos[]). */ - + * descriptors in kernel memory (hpsb_iso.infos[]). */ struct hpsb_iso_packet_info { /* offset of data payload relative to the first byte of the buffer */ __u32 offset; - /* length of the data payload, in bytes (not including the isochronous header) */ + /* length of the data payload, in bytes (not including the isochronous + * header) */ __u16 len; - /* (recv only) the cycle number (mod 8000) on which the packet was received */ + /* (recv only) the cycle number (mod 8000) on which the packet was + * received */ __u16 cycle; /* (recv only) channel on which the packet was received */ @@ -48,12 +50,10 @@ struct hpsb_iso_packet_info { __u8 tag; __u8 sy; - /* - * length in bytes of the packet including header/trailer. - * MUST be at structure end, since the first part of this structure is also - * defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is copied to - * userspace and is accessed there through libraw1394. - */ + /* length in bytes of the packet including header/trailer. + * MUST be at structure end, since the first part of this structure is + * also defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is + * copied to userspace and is accessed there through libraw1394. */ __u16 total_len; }; @@ -75,8 +75,8 @@ struct hpsb_iso { void *hostdata; /* a function to be called (from interrupt context) after - outgoing packets have been sent, or incoming packets have - arrived */ + * outgoing packets have been sent, or incoming packets have + * arrived */ void (*callback)(struct hpsb_iso*); /* wait for buffer space */ @@ -88,7 +88,7 @@ struct hpsb_iso { /* greatest # of packets between interrupts - controls - the maximum latency of the buffer */ + * the maximum latency of the buffer */ int irq_interval; /* the buffer for packet data payloads */ @@ -112,8 +112,8 @@ struct hpsb_iso { int pkt_dma; /* how many packets, starting at first_packet: - (transmit) are ready to be filled with data - (receive) contain received data */ + * (transmit) are ready to be filled with data + * (receive) contain received data */ int n_ready_packets; /* how many times the buffer has overflowed or underflowed */ @@ -134,7 +134,7 @@ struct hpsb_iso { int start_cycle; /* cycle at which next packet will be transmitted, - -1 if not known */ + * -1 if not known */ int xmit_cycle; /* ringbuffer of packet descriptors in regular kernel memory @@ -170,25 +170,30 @@ int hpsb_iso_recv_unlisten_channel(struct hpsb_iso *iso, unsigned char channel); int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask); /* start/stop DMA */ -int hpsb_iso_xmit_start(struct hpsb_iso *iso, int start_on_cycle, int prebuffer); -int hpsb_iso_recv_start(struct hpsb_iso *iso, int start_on_cycle, int tag_mask, int sync); +int hpsb_iso_xmit_start(struct hpsb_iso *iso, int start_on_cycle, + int prebuffer); +int hpsb_iso_recv_start(struct hpsb_iso *iso, int start_on_cycle, + int tag_mask, int sync); void hpsb_iso_stop(struct hpsb_iso *iso); /* deallocate buffer and DMA context */ void hpsb_iso_shutdown(struct hpsb_iso *iso); -/* queue a packet for transmission. 'offset' is relative to the beginning of the - DMA buffer, where the packet's data payload should already have been placed */ -int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len, u8 tag, u8 sy); +/* queue a packet for transmission. + * 'offset' is relative to the beginning of the DMA buffer, where the packet's + * data payload should already have been placed. */ +int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len, + u8 tag, u8 sy); /* wait until all queued packets have been transmitted to the bus */ int hpsb_iso_xmit_sync(struct hpsb_iso *iso); /* N packets have been read out of the buffer, re-use the buffer space */ -int hpsb_iso_recv_release_packets(struct hpsb_iso *recv, unsigned int n_packets); +int hpsb_iso_recv_release_packets(struct hpsb_iso *recv, + unsigned int n_packets); /* check for arrival of new packets immediately (even if irq_interval - has not yet been reached) */ + * has not yet been reached) */ int hpsb_iso_recv_flush(struct hpsb_iso *iso); /* returns # of packets ready to send or receive */ @@ -197,14 +202,15 @@ int hpsb_iso_n_ready(struct hpsb_iso *iso); /* the following are callbacks available to low-level drivers */ /* call after a packet has been transmitted to the bus (interrupt context is OK) - 'cycle' is the _exact_ cycle the packet was sent on - 'error' should be non-zero if some sort of error occurred when sending the packet -*/ + * 'cycle' is the _exact_ cycle the packet was sent on + * 'error' should be non-zero if some sort of error occurred when sending the + * packet */ void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error); /* call after a packet has been received (interrupt context OK) */ void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len, - u16 total_len, u16 cycle, u8 channel, u8 tag, u8 sy); + u16 total_len, u16 cycle, u8 channel, u8 tag, + u8 sy); /* call to wake waiting processes after buffer space has opened up. */ void hpsb_iso_wake(struct hpsb_iso *iso); diff --git a/drivers/ieee1394/nodemgr.h b/drivers/ieee1394/nodemgr.h index 0b26616e16c..b35c1b5c8d8 100644 --- a/drivers/ieee1394/nodemgr.h +++ b/drivers/ieee1394/nodemgr.h @@ -44,7 +44,6 @@ struct bus_options { u16 max_rec; /* Maximum packet size node can receive */ }; - #define UNIT_DIRECTORY_VENDOR_ID 0x01 #define UNIT_DIRECTORY_MODEL_ID 0x02 #define UNIT_DIRECTORY_SPECIFIER_ID 0x04 @@ -59,8 +58,8 @@ struct bus_options { * unit directory for each of these protocols. */ struct unit_directory { - struct node_entry *ne; /* The node which this directory belongs to */ - octlet_t address; /* Address of the unit directory on the node */ + struct node_entry *ne; /* The node which this directory belongs to */ + octlet_t address; /* Address of the unit directory on the node */ u8 flags; /* Indicates which entries were read */ quadlet_t vendor_id; @@ -79,11 +78,10 @@ struct unit_directory { int length; /* Number of quadlets */ struct device device; - struct class_device class_dev; struct csr1212_keyval *ud_kv; - u32 lun; /* logical unit number immediate value */ + u32 lun; /* logical unit number immediate value */ }; struct node_entry { @@ -106,7 +104,6 @@ struct node_entry { struct hpsb_tlabel_pool *tpool; struct device device; - struct class_device class_dev; /* Means this node is not attached anymore */ @@ -153,8 +150,8 @@ static inline int hpsb_node_entry_valid(struct node_entry *ne) /* * This will fill in the given, pre-initialised hpsb_packet with the current * information from the node entry (host, node ID, generation number). It will - * return false if the node owning the GUID is not accessible (and not modify the - * hpsb_packet) and return true otherwise. + * return false if the node owning the GUID is not accessible (and not modify + * the hpsb_packet) and return true otherwise. * * Note that packet sending may still fail in hpsb_send_packet if a bus reset * happens while you are trying to set up the packet (due to obsolete generation @@ -170,16 +167,13 @@ int hpsb_node_write(struct node_entry *ne, u64 addr, int hpsb_node_lock(struct node_entry *ne, u64 addr, int extcode, quadlet_t *data, quadlet_t arg); - /* Iterate the hosts, calling a given function with supplied data for each * host. */ int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *)); - int init_ieee1394_nodemgr(void); void cleanup_ieee1394_nodemgr(void); - /* The template for a host device */ extern struct device nodemgr_dev_template_host; -- cgit v1.2.3 From de4394f13cc843fae2a3ba2df752ee20e6e779a8 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:29 -0400 Subject: [PATCH] ieee1394: update #include directives in midlayer header files Remove unnecessary includes, add missing includes. Use forward type declarations for some structs. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/csr.h | 6 ++---- drivers/ieee1394/dma.c | 7 +++++-- drivers/ieee1394/dma.h | 7 +++++-- drivers/ieee1394/dv1394.c | 12 ++++++------ drivers/ieee1394/eth1394.c | 11 ++++++----- drivers/ieee1394/highlevel.h | 10 ++++++++++ drivers/ieee1394/hosts.h | 10 ++++++---- drivers/ieee1394/ieee1394_core.h | 10 +++++++--- drivers/ieee1394/ieee1394_hotplug.h | 3 +-- drivers/ieee1394/ieee1394_transactions.h | 7 ++++++- drivers/ieee1394/ieee1394_types.h | 7 ++----- drivers/ieee1394/iso.c | 5 ++++- drivers/ieee1394/iso.h | 7 ++++++- drivers/ieee1394/nodemgr.c | 9 +++++---- drivers/ieee1394/nodemgr.h | 10 ++++++++-- drivers/ieee1394/raw1394.c | 11 ++++++----- drivers/ieee1394/video1394.c | 12 ++++++------ 17 files changed, 91 insertions(+), 53 deletions(-) diff --git a/drivers/ieee1394/csr.h b/drivers/ieee1394/csr.h index 0655596f25d..2bc080f7651 100644 --- a/drivers/ieee1394/csr.h +++ b/drivers/ieee1394/csr.h @@ -1,12 +1,10 @@ - #ifndef _IEEE1394_CSR_H #define _IEEE1394_CSR_H -#ifdef CONFIG_PREEMPT -#include -#endif +#include #include "csr1212.h" +#include "ieee1394_types.h" #define CSR_REGISTER_BASE 0xfffff0000000ULL diff --git a/drivers/ieee1394/dma.c b/drivers/ieee1394/dma.c index ca5167de707..c68f328e1a2 100644 --- a/drivers/ieee1394/dma.c +++ b/drivers/ieee1394/dma.c @@ -7,10 +7,13 @@ * directory of the kernel sources for details. */ +#include #include -#include +#include #include -#include +#include +#include + #include "dma.h" /* dma_prog_region */ diff --git a/drivers/ieee1394/dma.h b/drivers/ieee1394/dma.h index b0f0885c455..a1682aba71c 100644 --- a/drivers/ieee1394/dma.h +++ b/drivers/ieee1394/dma.h @@ -10,8 +10,11 @@ #ifndef IEEE1394_DMA_H #define IEEE1394_DMA_H -#include -#include +#include + +struct pci_dev; +struct scatterlist; +struct vm_area_struct; /** * struct dma_prog_region - small contiguous DMA buffer diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c index 87532dd4337..bdc50f25fb4 100644 --- a/drivers/ieee1394/dv1394.c +++ b/drivers/ieee1394/dv1394.c @@ -110,15 +110,15 @@ #include #include +#include "dv1394.h" +#include "dv1394-private.h" +#include "highlevel.h" +#include "hosts.h" #include "ieee1394.h" +#include "ieee1394_core.h" +#include "ieee1394_hotplug.h" #include "ieee1394_types.h" #include "nodemgr.h" -#include "hosts.h" -#include "ieee1394_core.h" -#include "highlevel.h" -#include "dv1394.h" -#include "dv1394-private.h" - #include "ohci1394.h" /* DEBUG LEVELS: diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c index 2d5b57be98c..09826be86aa 100644 --- a/drivers/ieee1394/eth1394.c +++ b/drivers/ieee1394/eth1394.c @@ -67,16 +67,17 @@ #include #include +#include "config_roms.h" #include "csr1212.h" -#include "ieee1394_types.h" +#include "eth1394.h" +#include "highlevel.h" +#include "ieee1394.h" #include "ieee1394_core.h" +#include "ieee1394_hotplug.h" #include "ieee1394_transactions.h" -#include "ieee1394.h" -#include "highlevel.h" +#include "ieee1394_types.h" #include "iso.h" #include "nodemgr.h" -#include "eth1394.h" -#include "config_roms.h" #define ETH1394_PRINT_G(level, fmt, args...) \ printk(level "%s: " fmt, driver_name, ## args) diff --git a/drivers/ieee1394/highlevel.h b/drivers/ieee1394/highlevel.h index 134bb6c3ead..50f2dd2c7e2 100644 --- a/drivers/ieee1394/highlevel.h +++ b/drivers/ieee1394/highlevel.h @@ -1,6 +1,16 @@ #ifndef IEEE1394_HIGHLEVEL_H #define IEEE1394_HIGHLEVEL_H +#include +#include +#include + +struct module; + +#include "ieee1394_types.h" + +struct hpsb_host; + /* internal to ieee1394 core */ struct hpsb_address_serve { struct list_head host_list; /* per host list */ diff --git a/drivers/ieee1394/hosts.h b/drivers/ieee1394/hosts.h index 857d7d80bc8..b911e2af99a 100644 --- a/drivers/ieee1394/hosts.h +++ b/drivers/ieee1394/hosts.h @@ -2,17 +2,19 @@ #define _IEEE1394_HOSTS_H #include -#include #include -#include #include +#include +#include +#include +#include -#include +struct pci_dev; +struct module; #include "ieee1394_types.h" #include "csr.h" - struct hpsb_packet; struct hpsb_iso; diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h index 31d9efccdc0..1ce172b2856 100644 --- a/drivers/ieee1394/ieee1394_core.h +++ b/drivers/ieee1394/ieee1394_core.h @@ -1,12 +1,16 @@ - #ifndef _IEEE1394_CORE_H #define _IEEE1394_CORE_H -#include +#include +#include +#include +#include +#include #include #include -#include "hosts.h" +#include "hosts.h" +#include "ieee1394_types.h" struct hpsb_packet { /* This struct is basically read-only for hosts with the exception of diff --git a/drivers/ieee1394/ieee1394_hotplug.h b/drivers/ieee1394/ieee1394_hotplug.h index 5be70d31b00..183d93188d4 100644 --- a/drivers/ieee1394/ieee1394_hotplug.h +++ b/drivers/ieee1394/ieee1394_hotplug.h @@ -1,9 +1,8 @@ #ifndef _IEEE1394_HOTPLUG_H #define _IEEE1394_HOTPLUG_H -#include -#include #include +#include /* Unit spec id and sw version entry for some protocols */ #define AVC_UNIT_SPEC_ID_ENTRY 0x0000A02D diff --git a/drivers/ieee1394/ieee1394_transactions.h b/drivers/ieee1394/ieee1394_transactions.h index 5f809f50845..290d37060b0 100644 --- a/drivers/ieee1394/ieee1394_transactions.h +++ b/drivers/ieee1394/ieee1394_transactions.h @@ -1,7 +1,12 @@ #ifndef _IEEE1394_TRANSACTIONS_H #define _IEEE1394_TRANSACTIONS_H -#include "ieee1394_core.h" +#include + +#include "ieee1394_types.h" + +struct hpsb_packet; +struct hpsb_host; int hpsb_get_tlabel(struct hpsb_packet *packet); void hpsb_free_tlabel(struct hpsb_packet *packet); diff --git a/drivers/ieee1394/ieee1394_types.h b/drivers/ieee1394/ieee1394_types.h index ed6fdd811a0..6c246913b16 100644 --- a/drivers/ieee1394/ieee1394_types.h +++ b/drivers/ieee1394/ieee1394_types.h @@ -1,17 +1,14 @@ - #ifndef _IEEE1394_TYPES_H #define _IEEE1394_TYPES_H #include -#include #include -#include #include #include +#include -#include #include - +#include /* Transaction Label handling */ struct hpsb_tlabel_pool { diff --git a/drivers/ieee1394/iso.c b/drivers/ieee1394/iso.c index f26680ebef7..08bd15d2a7b 100644 --- a/drivers/ieee1394/iso.c +++ b/drivers/ieee1394/iso.c @@ -9,8 +9,11 @@ * directory of the kernel sources for details. */ -#include +#include #include +#include + +#include "hosts.h" #include "iso.h" void hpsb_iso_stop(struct hpsb_iso *iso) diff --git a/drivers/ieee1394/iso.h b/drivers/ieee1394/iso.h index ed639c4c510..1210a97e868 100644 --- a/drivers/ieee1394/iso.h +++ b/drivers/ieee1394/iso.h @@ -12,9 +12,14 @@ #ifndef IEEE1394_ISO_H #define IEEE1394_ISO_H -#include "hosts.h" +#include +#include +#include + #include "dma.h" +struct hpsb_host; + /* high-level ISO interface */ /* diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index dfed2ed2ed9..b873e5d5795 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -21,13 +21,14 @@ #include #include -#include "ieee1394_types.h" +#include "csr.h" +#include "highlevel.h" +#include "hosts.h" #include "ieee1394.h" #include "ieee1394_core.h" -#include "hosts.h" +#include "ieee1394_hotplug.h" +#include "ieee1394_types.h" #include "ieee1394_transactions.h" -#include "highlevel.h" -#include "csr.h" #include "nodemgr.h" static int ignore_drivers; diff --git a/drivers/ieee1394/nodemgr.h b/drivers/ieee1394/nodemgr.h index b35c1b5c8d8..f649c9d321b 100644 --- a/drivers/ieee1394/nodemgr.h +++ b/drivers/ieee1394/nodemgr.h @@ -21,9 +21,15 @@ #define _IEEE1394_NODEMGR_H #include -#include "csr1212.h" +#include + #include "ieee1394_core.h" -#include "ieee1394_hotplug.h" +#include "ieee1394_types.h" + +struct csr1212_csr; +struct csr1212_keyval; +struct hpsb_host; +struct ieee1394_device_id; /* '1' '3' '9' '4' in ASCII */ #define IEEE1394_BUSID_MAGIC __constant_cpu_to_be32(0x31333934) diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c index 571ea68c0cf..46c88e8a24f 100644 --- a/drivers/ieee1394/raw1394.c +++ b/drivers/ieee1394/raw1394.c @@ -44,14 +44,15 @@ #include #include "csr1212.h" +#include "highlevel.h" +#include "hosts.h" #include "ieee1394.h" -#include "ieee1394_types.h" #include "ieee1394_core.h" -#include "nodemgr.h" -#include "hosts.h" -#include "highlevel.h" -#include "iso.h" +#include "ieee1394_hotplug.h" #include "ieee1394_transactions.h" +#include "ieee1394_types.h" +#include "iso.h" +#include "nodemgr.h" #include "raw1394.h" #include "raw1394-private.h" diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c index c6e3f02bc6d..6b5353d81ae 100644 --- a/drivers/ieee1394/video1394.c +++ b/drivers/ieee1394/video1394.c @@ -49,16 +49,16 @@ #include #include -#include "ieee1394.h" -#include "ieee1394_types.h" +#include "dma.h" +#include "highlevel.h" #include "hosts.h" +#include "ieee1394.h" #include "ieee1394_core.h" -#include "highlevel.h" -#include "video1394.h" +#include "ieee1394_hotplug.h" +#include "ieee1394_types.h" #include "nodemgr.h" -#include "dma.h" - #include "ohci1394.h" +#include "video1394.h" #define ISO_CHANNELS 64 -- cgit v1.2.3 From 66faadfac3b8488d27374acaa407e3bd7380131a Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:30 -0400 Subject: [PATCH] ieee1394: remove redundant code from ieee1394_hotplug.h Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/ieee1394_hotplug.h | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/drivers/ieee1394/ieee1394_hotplug.h b/drivers/ieee1394/ieee1394_hotplug.h index 183d93188d4..dd5500ed832 100644 --- a/drivers/ieee1394/ieee1394_hotplug.h +++ b/drivers/ieee1394/ieee1394_hotplug.h @@ -1,32 +1,19 @@ #ifndef _IEEE1394_HOTPLUG_H #define _IEEE1394_HOTPLUG_H -#include -#include - /* Unit spec id and sw version entry for some protocols */ #define AVC_UNIT_SPEC_ID_ENTRY 0x0000A02D #define AVC_SW_VERSION_ENTRY 0x00010001 #define CAMERA_UNIT_SPEC_ID_ENTRY 0x0000A02D #define CAMERA_SW_VERSION_ENTRY 0x00000100 -/* Check to make sure this all isn't already defined */ -#ifndef IEEE1394_MATCH_VENDOR_ID - -#define IEEE1394_MATCH_VENDOR_ID 0x0001 -#define IEEE1394_MATCH_MODEL_ID 0x0002 -#define IEEE1394_MATCH_SPECIFIER_ID 0x0004 -#define IEEE1394_MATCH_VERSION 0x0008 - -struct ieee1394_device_id { - u32 match_flags; - u32 vendor_id; - u32 model_id; - u32 specifier_id; - u32 version; - void *driver_data; -}; - -#endif +/* /include/linux/mod_devicetable.h defines: + * IEEE1394_MATCH_VENDOR_ID + * IEEE1394_MATCH_MODEL_ID + * IEEE1394_MATCH_SPECIFIER_ID + * IEEE1394_MATCH_VERSION + * struct ieee1394_device_id + */ +#include #endif /* _IEEE1394_HOTPLUG_H */ -- cgit v1.2.3 From d83e7d8e7e9f41a9d0e68aaf24ec4e785dd071bb Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:31 -0400 Subject: [PATCH] ieee1394: remove unused macros HPSB_PANIC and HPSB_TRACE Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/ieee1394_transactions.c | 6 +++--- drivers/ieee1394/ieee1394_types.h | 5 ----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/ieee1394/ieee1394_transactions.c b/drivers/ieee1394/ieee1394_transactions.c index a114b91d606..751960037e2 100644 --- a/drivers/ieee1394/ieee1394_transactions.c +++ b/drivers/ieee1394/ieee1394_transactions.c @@ -14,6 +14,7 @@ #include #include +#include #include #include "ieee1394.h" @@ -214,7 +215,7 @@ int hpsb_packet_success(struct hpsb_packet *packet) packet->node_id); return -EAGAIN; } - HPSB_PANIC("reached unreachable code 1 in %s", __FUNCTION__); + BUG(); case ACK_BUSY_X: case ACK_BUSY_A: @@ -261,8 +262,7 @@ int hpsb_packet_success(struct hpsb_packet *packet) packet->ack_code, packet->node_id, packet->tcode); return -EAGAIN; } - - HPSB_PANIC("reached unreachable code 2 in %s", __FUNCTION__); + BUG(); } struct hpsb_packet *hpsb_make_readpacket(struct hpsb_host *host, nodeid_t node, diff --git a/drivers/ieee1394/ieee1394_types.h b/drivers/ieee1394/ieee1394_types.h index 6c246913b16..16fd2d0b5ed 100644 --- a/drivers/ieee1394/ieee1394_types.h +++ b/drivers/ieee1394/ieee1394_types.h @@ -65,11 +65,6 @@ typedef u16 arm_length_t; #define HPSB_VERBOSE(fmt, args...) #endif -#define HPSB_PANIC(fmt, args...) panic("ieee1394: " fmt "\n" , ## args) - -#define HPSB_TRACE() HPSB_PRINT(KERN_INFO, "TRACE - %s, %s(), line %d", __FILE__, __FUNCTION__, __LINE__) - - #ifdef __BIG_ENDIAN static inline void *memcpy_le32(u32 *dest, const u32 *__src, size_t count) -- cgit v1.2.3 From d8831d5554c2f295a6746e9d3b4cbd8bb13a540f Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:31 -0400 Subject: [PATCH] ieee1394: clean up declarations of hpsb_*_config_rom hpsb_update_config_rom() is defined in csr.c, not hosts.c. hpsb_get_config_rom() does not exist. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/csr.h | 5 +++++ drivers/ieee1394/hosts.h | 7 ------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/ieee1394/csr.h b/drivers/ieee1394/csr.h index 2bc080f7651..f11546550d8 100644 --- a/drivers/ieee1394/csr.h +++ b/drivers/ieee1394/csr.h @@ -91,4 +91,9 @@ extern struct csr1212_bus_ops csr_bus_ops; int init_csr(void); void cleanup_csr(void); +/* hpsb_update_config_rom() is deprecated */ +struct hpsb_host; +int hpsb_update_config_rom(struct hpsb_host *host, const quadlet_t *new_rom, + size_t size, unsigned char rom_version); + #endif /* _IEEE1394_CSR_H */ diff --git a/drivers/ieee1394/hosts.h b/drivers/ieee1394/hosts.h index b911e2af99a..69a7c9ff5ed 100644 --- a/drivers/ieee1394/hosts.h +++ b/drivers/ieee1394/hosts.h @@ -205,13 +205,6 @@ struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra, int hpsb_add_host(struct hpsb_host *host); void hpsb_remove_host(struct hpsb_host *h); -/* The following 2 functions are deprecated and will be removed when the - * raw1394/libraw1394 update is complete. */ -int hpsb_update_config_rom(struct hpsb_host *host, - const quadlet_t *new_rom, size_t size, unsigned char rom_version); -int hpsb_get_config_rom(struct hpsb_host *host, quadlet_t *buffer, - size_t buffersize, size_t *rom_size, unsigned char *rom_version); - /* Updates the configuration rom image of a host. rom_version must be the * current version, otherwise it will fail with return value -1. If this * host does not support config-rom-update, it will return -EINVAL. -- cgit v1.2.3 From 438bd525e5240a48233cd3290f7fe66ff0167e20 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:32 -0400 Subject: [PATCH] ieee1394: dv1394: sem2mutex conversion Signed-off-by: Stefan Richter (not runtime-tested) Signed-off-by: Ben Collins --- drivers/ieee1394/dv1394-private.h | 6 +++--- drivers/ieee1394/dv1394.c | 31 ++++++++++++++++--------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/ieee1394/dv1394-private.h b/drivers/ieee1394/dv1394-private.h index 80b5ac7fe38..7d1d2845b42 100644 --- a/drivers/ieee1394/dv1394-private.h +++ b/drivers/ieee1394/dv1394-private.h @@ -460,7 +460,7 @@ struct video_card { int dma_running; /* - 3) the sleeping semaphore 'sem' - this is used from process context only, + 3) the sleeping mutex 'mtx' - this is used from process context only, to serialize various operations on the video_card. Even though only one open() is allowed, we still need to prevent multiple threads of execution from entering calls like read, write, ioctl, etc. @@ -468,9 +468,9 @@ struct video_card { I honestly can't think of a good reason to use dv1394 from several threads at once, but we need to serialize anyway to prevent oopses =). - NOTE: if you need both spinlock and sem, take sem first to avoid deadlock! + NOTE: if you need both spinlock and mtx, take mtx first to avoid deadlock! */ - struct semaphore sem; + struct mutex mtx; /* people waiting for buffer space, please form a line here... */ wait_queue_head_t waitq; diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c index bdc50f25fb4..6e71d68b109 100644 --- a/drivers/ieee1394/dv1394.c +++ b/drivers/ieee1394/dv1394.c @@ -95,6 +95,7 @@ #include #include #include +#include #include #include #include @@ -247,7 +248,7 @@ static void frame_delete(struct frame *f) Frame_prepare() must be called OUTSIDE the video->spinlock. However, frame_prepare() must still be serialized, so - it should be called WITH the video->sem taken. + it should be called WITH the video->mtx taken. */ static void frame_prepare(struct video_card *video, unsigned int this_frame) @@ -1271,7 +1272,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma) int retval = -EINVAL; /* serialize mmap */ - down(&video->sem); + mutex_lock(&video->mtx); if ( ! video_card_initialized(video) ) { retval = do_dv1394_init_default(video); @@ -1281,7 +1282,7 @@ static int dv1394_mmap(struct file *file, struct vm_area_struct *vma) retval = dma_region_mmap(&video->dv_buf, file, vma); out: - up(&video->sem); + mutex_unlock(&video->mtx); return retval; } @@ -1337,17 +1338,17 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t /* serialize this to prevent multi-threaded mayhem */ if (file->f_flags & O_NONBLOCK) { - if (down_trylock(&video->sem)) + if (!mutex_trylock(&video->mtx)) return -EAGAIN; } else { - if (down_interruptible(&video->sem)) + if (mutex_lock_interruptible(&video->mtx)) return -ERESTARTSYS; } if ( !video_card_initialized(video) ) { ret = do_dv1394_init_default(video); if (ret) { - up(&video->sem); + mutex_unlock(&video->mtx); return ret; } } @@ -1418,7 +1419,7 @@ static ssize_t dv1394_write(struct file *file, const char __user *buffer, size_t remove_wait_queue(&video->waitq, &wait); set_current_state(TASK_RUNNING); - up(&video->sem); + mutex_unlock(&video->mtx); return ret; } @@ -1434,17 +1435,17 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count /* serialize this to prevent multi-threaded mayhem */ if (file->f_flags & O_NONBLOCK) { - if (down_trylock(&video->sem)) + if (!mutex_trylock(&video->mtx)) return -EAGAIN; } else { - if (down_interruptible(&video->sem)) + if (mutex_lock_interruptible(&video->mtx)) return -ERESTARTSYS; } if ( !video_card_initialized(video) ) { ret = do_dv1394_init_default(video); if (ret) { - up(&video->sem); + mutex_unlock(&video->mtx); return ret; } video->continuity_counter = -1; @@ -1526,7 +1527,7 @@ static ssize_t dv1394_read(struct file *file, char __user *buffer, size_t count remove_wait_queue(&video->waitq, &wait); set_current_state(TASK_RUNNING); - up(&video->sem); + mutex_unlock(&video->mtx); return ret; } @@ -1547,12 +1548,12 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg) /* serialize this to prevent multi-threaded mayhem */ if (file->f_flags & O_NONBLOCK) { - if (down_trylock(&video->sem)) { + if (!mutex_trylock(&video->mtx)) { unlock_kernel(); return -EAGAIN; } } else { - if (down_interruptible(&video->sem)) { + if (mutex_lock_interruptible(&video->mtx)) { unlock_kernel(); return -ERESTARTSYS; } @@ -1778,7 +1779,7 @@ static long dv1394_ioctl(struct file *file, unsigned int cmd, unsigned long arg) } out: - up(&video->sem); + mutex_unlock(&video->mtx); unlock_kernel(); return ret; } @@ -2253,7 +2254,7 @@ static int dv1394_init(struct ti_ohci *ohci, enum pal_or_ntsc format, enum modes clear_bit(0, &video->open); spin_lock_init(&video->spinlock); video->dma_running = 0; - init_MUTEX(&video->sem); + mutex_init(&video->mtx); init_waitqueue_head(&video->waitq); video->fasync = NULL; -- cgit v1.2.3 From 45289bf6ac70b106f5000d10b040e4485dd3e9d5 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:33 -0400 Subject: [PATCH] ieee1394: raw1394: remove redundant counting semaphore An already existing wait queue replaces raw1394's complete_sem which was maintained in parallel to the wait queue. The role of the semaphore's counter is taken over by a direct check of what was really counted: The presence of items in the list of completed requests. Notes: - raw1394_release() sleeps uninterruptibly until all requests were completed. This is the same behaviour as before the patch. - The macros wait_event and wait_event_interruptible are called with a condition argument which has a side effect, i.e. manipulation of the requests list. This side effect happens only if the condition is true. The patch relies on the fact that wait_event[_interruptible] does not evaluate the condition again after it became true. - The diffstat looks unfavorable with respect to added lines of code. However 19 of them are comments, and some are due to separation of existing code blocks into two small helper functions. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/raw1394-private.h | 3 +- drivers/ieee1394/raw1394.c | 91 ++++++++++++++++++++++++-------------- 2 files changed, 58 insertions(+), 36 deletions(-) diff --git a/drivers/ieee1394/raw1394-private.h b/drivers/ieee1394/raw1394-private.h index c93587be9ca..c7731d1bcd8 100644 --- a/drivers/ieee1394/raw1394-private.h +++ b/drivers/ieee1394/raw1394-private.h @@ -29,9 +29,8 @@ struct file_info { struct list_head req_pending; struct list_head req_complete; - struct semaphore complete_sem; spinlock_t reqlists_lock; - wait_queue_head_t poll_wait_complete; + wait_queue_head_t wait_complete; struct list_head addr_list; diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c index 46c88e8a24f..840b705fd5d 100644 --- a/drivers/ieee1394/raw1394.c +++ b/drivers/ieee1394/raw1394.c @@ -133,10 +133,9 @@ static void free_pending_request(struct pending_request *req) static void __queue_complete_req(struct pending_request *req) { struct file_info *fi = req->file_info; - list_move_tail(&req->list, &fi->req_complete); - up(&fi->complete_sem); - wake_up_interruptible(&fi->poll_wait_complete); + list_move_tail(&req->list, &fi->req_complete); + wake_up(&fi->wait_complete); } static void queue_complete_req(struct pending_request *req) @@ -464,13 +463,36 @@ raw1394_compat_read(const char __user *buf, struct raw1394_request *r) #endif +/* get next completed request (caller must hold fi->reqlists_lock) */ +static inline struct pending_request *__next_complete_req(struct file_info *fi) +{ + struct list_head *lh; + struct pending_request *req = NULL; + + if (!list_empty(&fi->req_complete)) { + lh = fi->req_complete.next; + list_del(lh); + req = list_entry(lh, struct pending_request, list); + } + return req; +} + +/* atomically get next completed request */ +static struct pending_request *next_complete_req(struct file_info *fi) +{ + unsigned long flags; + struct pending_request *req; + + spin_lock_irqsave(&fi->reqlists_lock, flags); + req = __next_complete_req(fi); + spin_unlock_irqrestore(&fi->reqlists_lock, flags); + return req; +} static ssize_t raw1394_read(struct file *file, char __user * buffer, size_t count, loff_t * offset_is_ignored) { - unsigned long flags; struct file_info *fi = (struct file_info *)file->private_data; - struct list_head *lh; struct pending_request *req; ssize_t ret; @@ -488,22 +510,21 @@ static ssize_t raw1394_read(struct file *file, char __user * buffer, } if (file->f_flags & O_NONBLOCK) { - if (down_trylock(&fi->complete_sem)) { + if (!(req = next_complete_req(fi))) return -EAGAIN; - } } else { - if (down_interruptible(&fi->complete_sem)) { + /* + * NB: We call the macro wait_event_interruptible() with a + * condition argument with side effect. This is only possible + * because the side effect does not occur until the condition + * became true, and wait_event_interruptible() won't evaluate + * the condition again after that. + */ + if (wait_event_interruptible(fi->wait_complete, + (req = next_complete_req(fi)))) return -ERESTARTSYS; - } } - spin_lock_irqsave(&fi->reqlists_lock, flags); - lh = fi->req_complete.next; - list_del(lh); - spin_unlock_irqrestore(&fi->reqlists_lock, flags); - - req = list_entry(lh, struct pending_request, list); - if (req->req.length) { if (copy_to_user(int2ptr(req->req.recvb), req->data, req->req.length)) { @@ -2745,7 +2766,7 @@ static unsigned int raw1394_poll(struct file *file, poll_table * pt) unsigned int mask = POLLOUT | POLLWRNORM; unsigned long flags; - poll_wait(file, &fi->poll_wait_complete, pt); + poll_wait(file, &fi->wait_complete, pt); spin_lock_irqsave(&fi->reqlists_lock, flags); if (!list_empty(&fi->req_complete)) { @@ -2770,9 +2791,8 @@ static int raw1394_open(struct inode *inode, struct file *file) fi->state = opened; INIT_LIST_HEAD(&fi->req_pending); INIT_LIST_HEAD(&fi->req_complete); - sema_init(&fi->complete_sem, 0); spin_lock_init(&fi->reqlists_lock); - init_waitqueue_head(&fi->poll_wait_complete); + init_waitqueue_head(&fi->wait_complete); INIT_LIST_HEAD(&fi->addr_list); file->private_data = fi; @@ -2785,7 +2805,7 @@ static int raw1394_release(struct inode *inode, struct file *file) struct file_info *fi = file->private_data; struct list_head *lh; struct pending_request *req; - int done = 0, i, fail = 0; + int i, fail; int retval = 0; struct list_head *entry; struct arm_addr *addr = NULL; @@ -2865,25 +2885,28 @@ static int raw1394_release(struct inode *inode, struct file *file) "error(s) occurred \n"); } - while (!done) { + for (;;) { + /* This locked section guarantees that neither + * complete nor pending requests exist once i!=0 */ spin_lock_irqsave(&fi->reqlists_lock, flags); - - while (!list_empty(&fi->req_complete)) { - lh = fi->req_complete.next; - list_del(lh); - - req = list_entry(lh, struct pending_request, list); - + while ((req = __next_complete_req(fi))) free_pending_request(req); - } - - if (list_empty(&fi->req_pending)) - done = 1; + i = list_empty(&fi->req_pending); spin_unlock_irqrestore(&fi->reqlists_lock, flags); - if (!done) - down_interruptible(&fi->complete_sem); + if (i) + break; + /* + * Sleep until more requests can be freed. + * + * NB: We call the macro wait_event() with a condition argument + * with side effect. This is only possible because the side + * effect does not occur until the condition became true, and + * wait_event() won't evaluate the condition again after that. + */ + wait_event(fi->wait_complete, (req = next_complete_req(fi))); + free_pending_request(req); } /* Remove any sub-trees left by user space programs */ -- cgit v1.2.3 From 1ee0dc51fb68d2d25888250c554492c4926c5ec1 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:33 -0400 Subject: [PATCH] ieee1394: nodemgr: remove unnecessary includes Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/nodemgr.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index b873e5d5795..bfab7933d68 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -12,12 +12,8 @@ #include #include #include -#include -#include -#include #include #include -#include #include #include -- cgit v1.2.3 From 40fd89cc54a8a67c81b5aa40b22c4f40b39e47b9 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:34 -0400 Subject: [PATCH] ieee1394: nodemgr: do not spawn kernel_thread for sysfs rescan nodemgr.c::fw_set_rescan() is used to re-run the driver core over nodemgr's representation of unit directories in order to initiate protocol driver probes. It is initiated via write access to one of nodemgr's sysfs attributes. The purpose is to attach drivers to units after switching a unit's ignore_driver attribute from 1 to 0. It is not really necessary to fork a kernel_thread for this job. The call to kernel_thread() can be eliminated to avoid the deprecated API and to simplify the code a bit. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/nodemgr.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index bfab7933d68..1ce3d8a14ae 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -405,26 +405,11 @@ static ssize_t fw_get_destroy_node(struct bus_type *bus, char *buf) } static BUS_ATTR(destroy_node, S_IWUSR | S_IRUGO, fw_get_destroy_node, fw_set_destroy_node); -static int nodemgr_rescan_bus_thread(void *__unused) -{ - /* No userlevel access needed */ - daemonize("kfwrescan"); - - bus_rescan_devices(&ieee1394_bus_type); - - return 0; -} static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, size_t count) { - int state = simple_strtoul(buf, NULL, 10); - - /* Don't wait for this, or care about errors. Root could do - * something stupid and spawn this a lot of times, but that's - * root's fault. */ - if (state == 1) - kernel_thread(nodemgr_rescan_bus_thread, NULL, CLONE_KERNEL); - + if (simple_strtoul(buf, NULL, 10) == 1) + bus_rescan_devices(&ieee1394_bus_type); return count; } static ssize_t fw_get_rescan(struct bus_type *bus, char *buf) -- cgit v1.2.3 From 3a632fe2321f6440ea8184b99549c74b912f5cef Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:35 -0400 Subject: [PATCH] ieee1394: nodemgr: make module parameter ignore_drivers writable Nodemgr's ignore_drivers variable is exposed as a module load parameter (therefore also as a sysfs attribute below /sys/module) and additionally as an attribute below /sys/bus/ieee1394. Since the latter is writable, make the former writable too. Note, the bus's attribute ignore_drivers is only relevant to newly added units, not to present or suspended or resuming units. Those have their own attribute ignore_driver. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/nodemgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index 1ce3d8a14ae..04b62eca647 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -28,7 +28,7 @@ #include "nodemgr.h" static int ignore_drivers; -module_param(ignore_drivers, int, 0444); +module_param(ignore_drivers, int, S_IRUGO | S_IWUSR); MODULE_PARM_DESC(ignore_drivers, "Disable automatic probing for drivers."); struct nodemgr_csr_info { -- cgit v1.2.3 From d2f119fe319528da8c76a1107459d6f478cbf28c Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:35 -0400 Subject: [PATCH] ieee1394: nodemgr: switch to kthread api, replace reset semaphore Convert nodemgr's host thread from kernel_thread to kthread and its sleep/restart mechanism from a counting semaphore to a schedule()/ wake_up_process() scheme. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/nodemgr.c | 120 ++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 79 deletions(-) diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index 04b62eca647..2e6dc5990ce 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -12,8 +12,8 @@ #include #include #include -#include #include +#include #include #include @@ -163,11 +163,7 @@ static DECLARE_MUTEX(nodemgr_serialize); struct host_info { struct hpsb_host *host; struct list_head list; - struct completion exited; - struct semaphore reset_sem; - int pid; - char daemon_name[15]; - int kill_me; + struct task_struct *thread; }; static int nodemgr_bus_match(struct device * dev, struct device_driver * drv); @@ -1477,9 +1473,8 @@ static void nodemgr_node_probe(struct host_info *hi, int generation) /* If we had a bus reset while we were scanning the bus, it is * possible that we did not probe all nodes. In that case, we * skip the clean up for now, since we could remove nodes that - * were still on the bus. The bus reset increased hi->reset_sem, - * so there's a bus scan pending which will do the clean up - * eventually. + * were still on the bus. Another bus scan is pending which will + * do the clean up eventually. * * Now let's tell the bus to rescan our devices. This may seem * like overhead, but the driver-model core will only scan a @@ -1607,41 +1602,37 @@ static int nodemgr_host_thread(void *__hi) { struct host_info *hi = (struct host_info *)__hi; struct hpsb_host *host = hi->host; - int reset_cycles = 0; - - /* No userlevel access needed */ - daemonize(hi->daemon_name); + unsigned int g, generation = get_hpsb_generation(host) - 1; + int i, reset_cycles = 0; /* Setup our device-model entries */ nodemgr_create_host_dev_files(host); - /* Sit and wait for a signal to probe the nodes on the bus. This - * happens when we get a bus reset. */ - while (1) { - unsigned int generation = 0; - int i; + for (;;) { + /* Sleep until next bus reset */ + set_current_state(TASK_INTERRUPTIBLE); + if (get_hpsb_generation(host) == generation) + schedule(); + __set_current_state(TASK_RUNNING); + + /* Thread may have been woken up to freeze or to exit */ + if (try_to_freeze()) + continue; + if (kthread_should_stop()) + goto exit; - if (down_interruptible(&hi->reset_sem) || - down_interruptible(&nodemgr_serialize)) { + if (down_interruptible(&nodemgr_serialize)) { if (try_to_freeze()) continue; - printk("NodeMgr: received unexpected signal?!\n" ); - break; - } - - if (hi->kill_me) { - up(&nodemgr_serialize); - break; + goto exit; } /* Pause for 1/4 second in 1/16 second intervals, * to make sure things settle down. */ + g = get_hpsb_generation(host); for (i = 0; i < 4 ; i++) { - set_current_state(TASK_INTERRUPTIBLE); - if (msleep_interruptible(63)) { - up(&nodemgr_serialize); - goto caught_signal; - } + if (msleep_interruptible(63) || kthread_should_stop()) + goto unlock_exit; /* Now get the generation in which the node ID's we collect * are valid. During the bus scan we will use this generation @@ -1652,14 +1643,8 @@ static int nodemgr_host_thread(void *__hi) /* If we get a reset before we are done waiting, then * start the the waiting over again */ - while (!down_trylock(&hi->reset_sem)) - i = 0; - - /* Check the kill_me again */ - if (hi->kill_me) { - up(&nodemgr_serialize); - goto caught_signal; - } + if (generation != g) + g = generation, i = 0; } if (!nodemgr_check_irm_capability(host, reset_cycles) || @@ -1685,11 +1670,11 @@ static int nodemgr_host_thread(void *__hi) up(&nodemgr_serialize); } - -caught_signal: +unlock_exit: + up(&nodemgr_serialize); +exit: HPSB_VERBOSE("NodeMgr: Exiting thread"); - - complete_and_exit(&hi->exited, 0); + return 0; } int nodemgr_for_each_host(void *__data, int (*cb)(struct hpsb_host *, void *)) @@ -1749,41 +1734,27 @@ static void nodemgr_add_host(struct hpsb_host *host) struct host_info *hi; hi = hpsb_create_hostinfo(&nodemgr_highlevel, host, sizeof(*hi)); - if (!hi) { - HPSB_ERR ("NodeMgr: out of memory in add host"); + HPSB_ERR("NodeMgr: out of memory in add host"); return; } - hi->host = host; - init_completion(&hi->exited); - sema_init(&hi->reset_sem, 0); - - sprintf(hi->daemon_name, "knodemgrd_%d", host->id); - - hi->pid = kernel_thread(nodemgr_host_thread, hi, CLONE_KERNEL); - - if (hi->pid < 0) { - HPSB_ERR ("NodeMgr: failed to start %s thread for %s", - hi->daemon_name, host->driver->name); + hi->thread = kthread_run(nodemgr_host_thread, hi, "knodemgrd_%d", + host->id); + if (IS_ERR(hi->thread)) { + HPSB_ERR("NodeMgr: cannot start thread for host %d", host->id); hpsb_destroy_hostinfo(&nodemgr_highlevel, host); - return; } - - return; } static void nodemgr_host_reset(struct hpsb_host *host) { struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host); - if (hi != NULL) { - HPSB_VERBOSE("NodeMgr: Processing host reset for %s", hi->daemon_name); - up(&hi->reset_sem); - } else - HPSB_ERR ("NodeMgr: could not process reset of unused host"); - - return; + if (hi) { + HPSB_VERBOSE("NodeMgr: Processing reset for host %d", host->id); + wake_up_process(hi->thread); + } } static void nodemgr_remove_host(struct hpsb_host *host) @@ -1791,18 +1762,9 @@ static void nodemgr_remove_host(struct hpsb_host *host) struct host_info *hi = hpsb_get_hostinfo(&nodemgr_highlevel, host); if (hi) { - if (hi->pid >= 0) { - hi->kill_me = 1; - mb(); - up(&hi->reset_sem); - wait_for_completion(&hi->exited); - nodemgr_remove_host_dev(&host->device); - } - } else - HPSB_ERR("NodeMgr: host %s does not exist, cannot remove", - host->driver->name); - - return; + kthread_stop(hi->thread); + nodemgr_remove_host_dev(&host->device); + } } static struct hpsb_highlevel nodemgr_highlevel = { -- cgit v1.2.3 From cab8d154e2ed43fe1495aa0e18103e747552891b Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:36 -0400 Subject: [PATCH] ieee1394: nodemgr: convert nodemgr_serialize semaphore to mutex Another trivial sem2mutex conversion. Side note: nodemgr_serialize's purpose, when introduced in linux1394's revision 529 in July 2002, was to protect several data structures which are now largely handled by or together with Linux' driver core and are now protected by the LDM's own mechanisms. It may very well be possible to remove this mutex now. But fully parallelized node scanning is on our long-term TODO list anyway; the mutex will certainly go away then. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/nodemgr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index 2e6dc5990ce..f8f6079cc48 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -158,7 +158,7 @@ static struct csr1212_bus_ops nodemgr_csr_ops = { * but now we are much simpler because of the LDM. */ -static DECLARE_MUTEX(nodemgr_serialize); +static DEFINE_MUTEX(nodemgr_serialize); struct host_info { struct hpsb_host *host; @@ -1621,7 +1621,7 @@ static int nodemgr_host_thread(void *__hi) if (kthread_should_stop()) goto exit; - if (down_interruptible(&nodemgr_serialize)) { + if (mutex_lock_interruptible(&nodemgr_serialize)) { if (try_to_freeze()) continue; goto exit; @@ -1650,7 +1650,7 @@ static int nodemgr_host_thread(void *__hi) if (!nodemgr_check_irm_capability(host, reset_cycles) || !nodemgr_do_irm_duties(host, reset_cycles)) { reset_cycles++; - up(&nodemgr_serialize); + mutex_unlock(&nodemgr_serialize); continue; } reset_cycles = 0; @@ -1668,10 +1668,10 @@ static int nodemgr_host_thread(void *__hi) /* Update some of our sysfs symlinks */ nodemgr_update_host_dev_links(host); - up(&nodemgr_serialize); + mutex_unlock(&nodemgr_serialize); } unlock_exit: - up(&nodemgr_serialize); + mutex_unlock(&nodemgr_serialize); exit: HPSB_VERBOSE("NodeMgr: Exiting thread"); return 0; -- cgit v1.2.3 From 3c6c65f5ed5a6d307bd607aecd06d658c0934d88 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 3 Jul 2006 12:02:37 -0400 Subject: [PATCH] ieee1394: fix kerneldoc of hpsb_alloc_host There was stuff between the comment and the function. Signed-off-by: Stefan Richter Signed-off-by: Ben Collins --- drivers/ieee1394/hosts.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c index 2c669287f5b..3ed56be8706 100644 --- a/drivers/ieee1394/hosts.c +++ b/drivers/ieee1394/hosts.c @@ -90,6 +90,8 @@ static int alloc_hostnum_cb(struct hpsb_host *host, void *__data) return 0; } +static DEFINE_MUTEX(host_num_alloc); + /** * hpsb_alloc_host - allocate a new host controller. * @drv: the driver that will manage the host controller @@ -105,8 +107,6 @@ static int alloc_hostnum_cb(struct hpsb_host *host, void *__data) * Return Value: a pointer to the &hpsb_host if successful, %NULL if * no memory was available. */ -static DEFINE_MUTEX(host_num_alloc); - struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra, struct device *dev) { -- cgit v1.2.3 From d463d34e7b336ae3645ac331adccb578ae5a4285 Mon Sep 17 00:00:00 2001 From: Christian Merkle Date: Tue, 22 Aug 2006 10:07:01 +1000 Subject: intelfb: update doc and Kconfig (supported devices) According to drivers/video/intelfb/intelfb.h, the intelfb driver supportes the following devices: 830M/845G/852GM/855GM/865G/915G/915GM/945G/945GM. So the description in drivers/video/Kconfig and the documentation in Documentation/fb/intelfb.txt is outdated. airlied: cleaned up some other obvious mistakes in intelfb.txt. Signed-off-by: Christian Merkle Signed-off-by: Dave Airlie --- Documentation/fb/intelfb.txt | 11 +++++++---- drivers/video/Kconfig | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Documentation/fb/intelfb.txt b/Documentation/fb/intelfb.txt index c12d39a23c3..aa0d322db17 100644 --- a/Documentation/fb/intelfb.txt +++ b/Documentation/fb/intelfb.txt @@ -1,16 +1,19 @@ -Intel 830M/845G/852GM/855GM/865G/915G Framebuffer driver +Intel 830M/845G/852GM/855GM/865G/915G/945G Framebuffer driver ================================================================ A. Introduction - This is a framebuffer driver for various Intel 810/815 compatible + This is a framebuffer driver for various Intel 8xx/9xx compatible graphics devices. These would include: Intel 830M - Intel 810E845G + Intel 845G Intel 852GM Intel 855GM Intel 865G Intel 915G + Intel 915GM + Intel 945G + Intel 945GM B. List of available options @@ -78,7 +81,7 @@ C. Kernel booting Separate each option/option-pair by commas (,) and the option from its value with an equals sign (=) as in the following: -video=i810fb:option1,option2=value2 +video=intelfb:option1,option2=value2 Sample Usage ------------ diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index 743c853ad15..60c6773eaac 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -805,7 +805,7 @@ config FB_I810_I2C help config FB_INTEL - tristate "Intel 830M/845G/852GM/855GM/865G support (EXPERIMENTAL)" + tristate "Intel 830M/845G/852GM/855GM/865G/915G/945G support (EXPERIMENTAL)" depends on FB && EXPERIMENTAL && PCI && X86 select AGP select AGP_INTEL @@ -817,7 +817,7 @@ config FB_INTEL select FB_CFB_IMAGEBLIT help This driver supports the on-board graphics built in to the Intel - 830M/845G/852GM/855GM/865G chipsets. + 830M/845G/852GM/855GM/865G/915G/915GM/945G/945GM chipsets. Say Y if you have and plan to use such a board. If you say Y here and want DDC/I2C support you must first say Y to @@ -830,6 +830,8 @@ config FB_INTEL To compile this driver as a module, choose M here: the module will be called intelfb. + For more information, please read + config FB_INTEL_DEBUG bool "Intel driver Debug Messages" depends on FB_INTEL -- cgit v1.2.3 From d5afabcea215a828eb00df992b429486aae14c2f Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Tue, 22 Aug 2006 10:10:56 +1000 Subject: intelfb: fix mtrr_reg signedness This is my fix for gcc 4.1 sign issue reported by Eric Sesterhenn . Signed-off-by: Dave Airlie --- drivers/video/intelfb/intelfb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h index abdadc2a1b4..80b94c19a9f 100644 --- a/drivers/video/intelfb/intelfb.h +++ b/drivers/video/intelfb/intelfb.h @@ -278,7 +278,7 @@ struct intelfb_info { u8 fbmem_gart; /* mtrr support */ - u32 mtrr_reg; + int mtrr_reg; u32 has_mtrr; /* heap data */ -- cgit v1.2.3 From 4dc3595f5c569021b1bd0109502acfca82036902 Mon Sep 17 00:00:00 2001 From: Parag Warudkar Date: Tue, 22 Aug 2006 10:12:58 +1000 Subject: intelfbhw.c: intelfbhw_get_p1p2 defined but not used intelfbhw_get_p1p2 is used only if REGDUMP is defined - compile it in only if REGDUMP is defined - one less compiler warning. Signed-off-by: Dave Airlie --- drivers/video/intelfb/intelfbhw.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c index 8038f558611..bbd82fffc3f 100644 --- a/drivers/video/intelfb/intelfbhw.c +++ b/drivers/video/intelfb/intelfbhw.c @@ -627,6 +627,7 @@ static int calc_vclock(int index, int m1, int m2, int n, int p1, int p2, int lvd return vco / p; } +#if REGDUMP static void intelfbhw_get_p1p2(struct intelfb_info *dinfo, int dpll, int *o_p1, int *o_p2) { @@ -652,6 +653,7 @@ intelfbhw_get_p1p2(struct intelfb_info *dinfo, int dpll, int *o_p1, int *o_p2) *o_p1 = p1; *o_p2 = p2; } +#endif void -- cgit v1.2.3 From 3bc87f243f64c953717bea058f4b458a57fc1a29 Mon Sep 17 00:00:00 2001 From: Russell King Date: Sun, 27 Aug 2006 13:51:28 +0100 Subject: [MMC] Convert mmci to use data->blksz rather than data->blksz_bits Signed-off-by: Russell King --- drivers/mmc/mmci.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/mmci.c b/drivers/mmc/mmci.c index 1886562abdd..8419489e774 100644 --- a/drivers/mmc/mmci.c +++ b/drivers/mmc/mmci.c @@ -69,12 +69,13 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) unsigned int datactrl, timeout, irqmask; unsigned long long clks; void __iomem *base; + int blksz_bits; DBG(host, "blksz %04x blks %04x flags %08x\n", - 1 << data->blksz_bits, data->blocks, data->flags); + data->blksz, data->blocks, data->flags); host->data = data; - host->size = data->blocks << data->blksz_bits; + host->size = data->blksz; host->data_xfered = 0; mmci_init_sg(host, data); @@ -88,7 +89,10 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) writel(timeout, base + MMCIDATATIMER); writel(host->size, base + MMCIDATALENGTH); - datactrl = MCI_DPSM_ENABLE | data->blksz_bits << 4; + blksz_bits = ffs(data->blksz) - 1; + BUG_ON(1 << blksz_bits != data->blksz); + + datactrl = MCI_DPSM_ENABLE | blksz_bits << 4; if (data->flags & MMC_DATA_READ) { datactrl |= MCI_DPSM_DIRECTION; irqmask = MCI_RXFIFOHALFFULLMASK; @@ -145,7 +149,7 @@ mmci_data_irq(struct mmci_host *host, struct mmc_data *data, unsigned int status) { if (status & MCI_DATABLOCKEND) { - host->data_xfered += 1 << data->blksz_bits; + host->data_xfered += data->blksz; } if (status & (MCI_DATACRCFAIL|MCI_DATATIMEOUT|MCI_TXUNDERRUN|MCI_RXOVERRUN)) { if (status & MCI_DATACRCFAIL) -- cgit v1.2.3 From 132919ba80ad207755fe271277bfefff865a54fe Mon Sep 17 00:00:00 2001 From: Russell King Date: Sun, 27 Aug 2006 13:56:52 +0100 Subject: [MMC] Remove data->blksz_bits member data->blksz_bits is unused now - remove it. Signed-off-by: Russell King --- drivers/mmc/mmc.c | 1 - drivers/mmc/mmc_block.c | 1 - include/linux/mmc/mmc.h | 1 - 3 files changed, 3 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 74eaaee66de..5b9caa7978d 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -996,7 +996,6 @@ static void mmc_read_scrs(struct mmc_host *host) mmc_set_data_timeout(&data, card, 0); - data.blksz_bits = 3; data.blksz = 1 << 3; data.blocks = 1; data.flags = MMC_DATA_READ; diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c index a0e0dad1b41..f3a99dd8df8 100644 --- a/drivers/mmc/mmc_block.c +++ b/drivers/mmc/mmc_block.c @@ -172,7 +172,6 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) brq.cmd.arg = req->sector << 9; brq.cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; - brq.data.blksz_bits = md->block_bits; brq.data.blksz = 1 << md->block_bits; brq.data.blocks = req->nr_sectors >> (md->block_bits - 9); brq.stop.opcode = MMC_STOP_TRANSMISSION; diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h index 627e2c08ce4..a3594dfd696 100644 --- a/include/linux/mmc/mmc.h +++ b/include/linux/mmc/mmc.h @@ -68,7 +68,6 @@ struct mmc_command { struct mmc_data { unsigned int timeout_ns; /* data timeout (in ns, max 80ms) */ unsigned int timeout_clks; /* data timeout (in clocks) */ - unsigned int blksz_bits; /* data block size */ unsigned int blksz; /* data block size */ unsigned int blocks; /* number of blocks */ unsigned int error; /* data error */ -- cgit v1.2.3 From db53f28b3a6d9338cca1b7e917dc063ac99e1871 Mon Sep 17 00:00:00 2001 From: Russell King Date: Wed, 30 Aug 2006 15:14:56 +0100 Subject: [MMC] Add multi block-write capability Add a capability flag for drivers to set when they can perform multi- block transfers to cards _and_ correctly report the number of bytes transferred should an error occur. The last point is very important - if a driver reports more bytes than were actually accepted by the card and an error occurs, there is the possibility for data loss. Pierre Ossman provided the patch for wbsd and sdhci. Signed-off-by: Pierre Ossman Signed-off-by: Russell King --- drivers/mmc/mmc_block.c | 27 ++++++++++++++++++++------- drivers/mmc/mmci.c | 1 + drivers/mmc/sdhci.c | 2 +- drivers/mmc/wbsd.c | 2 +- include/linux/mmc/host.h | 1 + 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/mmc_block.c b/drivers/mmc/mmc_block.c index f3a99dd8df8..8d18b87bfd3 100644 --- a/drivers/mmc/mmc_block.c +++ b/drivers/mmc/mmc_block.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -165,6 +166,7 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) do { struct mmc_blk_request brq; struct mmc_command cmd; + u32 readcmd, writecmd; memset(&brq, 0, sizeof(struct mmc_blk_request)); brq.mrq.cmd = &brq.cmd; @@ -180,20 +182,31 @@ static int mmc_blk_issue_rq(struct mmc_queue *mq, struct request *req) mmc_set_data_timeout(&brq.data, card, rq_data_dir(req) != READ); - if (rq_data_dir(req) == READ) { - brq.cmd.opcode = brq.data.blocks > 1 ? MMC_READ_MULTIPLE_BLOCK : MMC_READ_SINGLE_BLOCK; - brq.data.flags |= MMC_DATA_READ; - } else { - brq.cmd.opcode = MMC_WRITE_BLOCK; - brq.data.flags |= MMC_DATA_WRITE; + /* + * If the host doesn't support multiple block writes, force + * block writes to single block. + */ + if (rq_data_dir(req) != READ && + !(card->host->caps & MMC_CAP_MULTIWRITE)) brq.data.blocks = 1; - } if (brq.data.blocks > 1) { brq.data.flags |= MMC_DATA_MULTI; brq.mrq.stop = &brq.stop; + readcmd = MMC_READ_MULTIPLE_BLOCK; + writecmd = MMC_WRITE_MULTIPLE_BLOCK; } else { brq.mrq.stop = NULL; + readcmd = MMC_READ_SINGLE_BLOCK; + writecmd = MMC_WRITE_BLOCK; + } + + if (rq_data_dir(req) == READ) { + brq.cmd.opcode = readcmd; + brq.data.flags |= MMC_DATA_READ; + } else { + brq.cmd.opcode = writecmd; + brq.data.flags |= MMC_DATA_WRITE; } brq.data.sg = mq->sg; diff --git a/drivers/mmc/mmci.c b/drivers/mmc/mmci.c index 8419489e774..2b5a0cc9ea5 100644 --- a/drivers/mmc/mmci.c +++ b/drivers/mmc/mmci.c @@ -509,6 +509,7 @@ static int mmci_probe(struct amba_device *dev, void *id) mmc->f_min = (host->mclk + 511) / 512; mmc->f_max = min(host->mclk, fmax); mmc->ocr_avail = plat->ocr_mask; + mmc->caps = MMC_CAP_MULTIWRITE; /* * We can do SGIO diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c index 4e21b3b9d33..dea4edd1c43 100644 --- a/drivers/mmc/sdhci.c +++ b/drivers/mmc/sdhci.c @@ -1262,7 +1262,7 @@ static int __devinit sdhci_probe_slot(struct pci_dev *pdev, int slot) mmc->ops = &sdhci_ops; mmc->f_min = host->max_clk / 256; mmc->f_max = host->max_clk; - mmc->caps = MMC_CAP_4_BIT_DATA; + mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE; mmc->ocr_avail = 0; if (caps & SDHCI_CAN_VDD_330) diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c index c351c6d1a18..4a6617d9a49 100644 --- a/drivers/mmc/wbsd.c +++ b/drivers/mmc/wbsd.c @@ -1323,7 +1323,7 @@ static int __devinit wbsd_alloc_mmc(struct device *dev) mmc->f_min = 375000; mmc->f_max = 24000000; mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34; - mmc->caps = MMC_CAP_4_BIT_DATA; + mmc->caps = MMC_CAP_4_BIT_DATA | MMC_CAP_MULTIWRITE; spin_lock_init(&host->lock); diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index ba095aebedf..b282ec9bba0 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -85,6 +85,7 @@ struct mmc_host { unsigned long caps; /* Host capabilities */ #define MMC_CAP_4_BIT_DATA (1 << 0) /* Can the host do 4 bit transfers */ +#define MMC_CAP_MULTIWRITE (1 << 1) /* Can accurately report bytes sent to card on error */ /* host specific block data */ unsigned int max_seg_size; /* see blk_queue_max_segment_size */ -- cgit v1.2.3 From 9951903e616662e9a5dad5fbd296690e2ebbbc65 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 2 Jul 2006 14:17:00 +0200 Subject: ieee1394: shrink tlabel pools, remove tpool semaphores This patch reduces the size of struct hpsb_host and also removes semaphores from ieee1394_transactions.c. On i386, struct hpsb_host shrinks from 10656 bytes to 6688 bytes. This is accomplished by - using a single wait_queue for hpsb_get_tlabel instead of many instances of semaphores, - using a single lock to serialize access to all tlabel pools (the protected code regions are small, i.e. lock contention very low), - omitting the sysfs attribute tlabels_allocations. Drawback: In the rare case that a process needs to sleep because all transaction labels for the node are temporarily exhausted, it is also woken up if a tlabel for a different node became free, checks for an available tlabel, and is put to sleep again. The check is not costly and the situation occurs extremely rarely. (Tlabels are typically only exhausted if there was no context switch to the khpsbpkt thread which recycles tlables.) Therefore the benefit of reduced tpool size outweighs this drawback. The sysfs attributes tlabels_free and tlabels_mask are not compiled anymore unless CONFIG_IEEE1394_VERBOSEDEBUG is set. The by far biggest member of struct hpsb_host, the struct csr_control csr (5272 bytes on i386), is now placed at the end of struct hpsb_host. Note, hpsb_get_tlabel calls the macro wait_event_interruptible with a condition argument which has a side effect (allocation of a tlabel and manipulation of the packet). This side effect happens only if the condition is true. The patch relies on wait_event_interruptible not evaluating the condition again after it became true. Signed-off-by: Stefan Richter --- drivers/ieee1394/hosts.c | 3 - drivers/ieee1394/hosts.h | 19 +++--- drivers/ieee1394/ieee1394_transactions.c | 108 ++++++++++++++++++------------- drivers/ieee1394/ieee1394_transactions.h | 4 ++ drivers/ieee1394/ieee1394_types.h | 23 +------ drivers/ieee1394/nodemgr.c | 43 +++++++----- drivers/ieee1394/nodemgr.h | 1 - 7 files changed, 102 insertions(+), 99 deletions(-) diff --git a/drivers/ieee1394/hosts.c b/drivers/ieee1394/hosts.c index 59e6f49545b..d90a3a1898c 100644 --- a/drivers/ieee1394/hosts.c +++ b/drivers/ieee1394/hosts.c @@ -143,9 +143,6 @@ struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra, for (i = 2; i < 16; i++) h->csr.gen_timestamp[i] = jiffies - 60 * HZ; - for (i = 0; i < ARRAY_SIZE(h->tpool); i++) - HPSB_TPOOL_INIT(&h->tpool[i]); - atomic_set(&h->generation, 0); INIT_WORK(&h->delayed_reset, delayed_reset_bus, h); diff --git a/drivers/ieee1394/hosts.h b/drivers/ieee1394/hosts.h index 69a7c9ff5ed..bc6dbfadb89 100644 --- a/drivers/ieee1394/hosts.h +++ b/drivers/ieee1394/hosts.h @@ -35,7 +35,6 @@ struct hpsb_host { int node_count; /* number of identified nodes on this bus */ int selfid_count; /* total number of SelfIDs received */ int nodes_active; /* number of nodes with active link layer */ - u8 speed[ALL_NODES]; /* speed between each node and local node */ nodeid_t node_id; /* node ID of this host */ nodeid_t irm_id; /* ID of this bus' isochronous resource manager */ @@ -55,31 +54,29 @@ struct hpsb_host { int reset_retries; quadlet_t *topology_map; u8 *speed_map; - struct csr_control csr; - - /* Per node tlabel pool allocation */ - struct hpsb_tlabel_pool tpool[ALL_NODES]; + int id; struct hpsb_host_driver *driver; - struct pci_dev *pdev; - - int id; - struct device device; struct class_device class_dev; int update_config_rom; struct work_struct delayed_reset; - unsigned int config_roms; struct list_head addr_space; u64 low_addr_space; /* upper bound of physical DMA area */ u64 middle_addr_space; /* upper bound of posted write area */ -}; + u8 speed[ALL_NODES]; /* speed between each node and local node */ + /* per node tlabel allocation */ + u8 next_tl[ALL_NODES]; + struct { DECLARE_BITMAP(map, 64); } tl_pool[ALL_NODES]; + + struct csr_control csr; +}; enum devctl_cmd { /* Host is requested to reset its bus and cancel all outstanding async diff --git a/drivers/ieee1394/ieee1394_transactions.c b/drivers/ieee1394/ieee1394_transactions.c index 751960037e2..0833fc9f50c 100644 --- a/drivers/ieee1394/ieee1394_transactions.c +++ b/drivers/ieee1394/ieee1394_transactions.c @@ -9,10 +9,9 @@ * directory of the kernel sources for details. */ -#include #include -#include -#include +#include +#include #include #include @@ -21,8 +20,6 @@ #include "ieee1394_types.h" #include "hosts.h" #include "ieee1394_core.h" -#include "highlevel.h" -#include "nodemgr.h" #include "ieee1394_transactions.h" #define PREP_ASYNC_HEAD_ADDRESS(tc) \ @@ -32,6 +29,13 @@ packet->header[1] = (packet->host->node_id << 16) | (addr >> 32); \ packet->header[2] = addr & 0xffffffff +#ifndef HPSB_DEBUG_TLABELS +static +#endif +spinlock_t hpsb_tlabel_lock = SPIN_LOCK_UNLOCKED; + +static DECLARE_WAIT_QUEUE_HEAD(tlabel_wq); + static void fill_async_readquad(struct hpsb_packet *packet, u64 addr) { PREP_ASYNC_HEAD_ADDRESS(TCODE_READQ); @@ -115,9 +119,41 @@ static void fill_async_stream_packet(struct hpsb_packet *packet, int length, packet->tcode = TCODE_ISO_DATA; } +/* same as hpsb_get_tlabel, except that it returns immediately */ +static int hpsb_get_tlabel_atomic(struct hpsb_packet *packet) +{ + unsigned long flags, *tp; + u8 *next; + int tlabel, n = NODEID_TO_NODE(packet->node_id); + + /* Broadcast transactions are complete once the request has been sent. + * Use the same transaction label for all broadcast transactions. */ + if (unlikely(n == ALL_NODES)) { + packet->tlabel = 0; + return 0; + } + tp = packet->host->tl_pool[n].map; + next = &packet->host->next_tl[n]; + + spin_lock_irqsave(&hpsb_tlabel_lock, flags); + tlabel = find_next_zero_bit(tp, 64, *next); + if (tlabel > 63) + tlabel = find_first_zero_bit(tp, 64); + if (tlabel > 63) { + spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); + return -EAGAIN; + } + __set_bit(tlabel, tp); + *next = (tlabel + 1) & 63; + spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); + + packet->tlabel = tlabel; + return 0; +} + /** * hpsb_get_tlabel - allocate a transaction label - * @packet: the packet who's tlabel/tpool we set + * @packet: the packet whose tlabel and tl_pool we set * * Every asynchronous transaction on the 1394 bus needs a transaction * label to match the response to the request. This label has to be @@ -131,42 +167,25 @@ static void fill_async_stream_packet(struct hpsb_packet *packet, int length, * Return value: Zero on success, otherwise non-zero. A non-zero return * generally means there are no available tlabels. If this is called out * of interrupt or atomic context, then it will sleep until can return a - * tlabel. + * tlabel or a signal is received. */ int hpsb_get_tlabel(struct hpsb_packet *packet) { - unsigned long flags; - struct hpsb_tlabel_pool *tp; - int n = NODEID_TO_NODE(packet->node_id); - - if (unlikely(n == ALL_NODES)) - return 0; - tp = &packet->host->tpool[n]; - - if (irqs_disabled() || in_atomic()) { - if (down_trylock(&tp->count)) - return 1; - } else { - down(&tp->count); - } - - spin_lock_irqsave(&tp->lock, flags); - - packet->tlabel = find_next_zero_bit(tp->pool, 64, tp->next); - if (packet->tlabel > 63) - packet->tlabel = find_first_zero_bit(tp->pool, 64); - tp->next = (packet->tlabel + 1) % 64; - /* Should _never_ happen */ - BUG_ON(test_and_set_bit(packet->tlabel, tp->pool)); - tp->allocations++; - spin_unlock_irqrestore(&tp->lock, flags); - - return 0; + if (irqs_disabled() || in_atomic()) + return hpsb_get_tlabel_atomic(packet); + + /* NB: The macro wait_event_interruptible() is called with a condition + * argument with side effect. This is only possible because the side + * effect does not occur until the condition became true, and + * wait_event_interruptible() won't evaluate the condition again after + * that. */ + return wait_event_interruptible(tlabel_wq, + !hpsb_get_tlabel_atomic(packet)); } /** * hpsb_free_tlabel - free an allocated transaction label - * @packet: packet whos tlabel/tpool needs to be cleared + * @packet: packet whose tlabel and tl_pool needs to be cleared * * Frees the transaction label allocated with hpsb_get_tlabel(). The * tlabel has to be freed after the transaction is complete (i.e. response @@ -177,21 +196,20 @@ int hpsb_get_tlabel(struct hpsb_packet *packet) */ void hpsb_free_tlabel(struct hpsb_packet *packet) { - unsigned long flags; - struct hpsb_tlabel_pool *tp; - int n = NODEID_TO_NODE(packet->node_id); + unsigned long flags, *tp; + int tlabel, n = NODEID_TO_NODE(packet->node_id); if (unlikely(n == ALL_NODES)) return; - tp = &packet->host->tpool[n]; - - BUG_ON(packet->tlabel > 63 || packet->tlabel < 0); + tp = packet->host->tl_pool[n].map; + tlabel = packet->tlabel; + BUG_ON(tlabel > 63 || tlabel < 0); - spin_lock_irqsave(&tp->lock, flags); - BUG_ON(!test_and_clear_bit(packet->tlabel, tp->pool)); - spin_unlock_irqrestore(&tp->lock, flags); + spin_lock_irqsave(&hpsb_tlabel_lock, flags); + BUG_ON(!__test_and_clear_bit(tlabel, tp)); + spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); - up(&tp->count); + wake_up_interruptible(&tlabel_wq); } int hpsb_packet_success(struct hpsb_packet *packet) diff --git a/drivers/ieee1394/ieee1394_transactions.h b/drivers/ieee1394/ieee1394_transactions.h index 290d37060b0..c1369c41469 100644 --- a/drivers/ieee1394/ieee1394_transactions.h +++ b/drivers/ieee1394/ieee1394_transactions.h @@ -53,4 +53,8 @@ int hpsb_read(struct hpsb_host *host, nodeid_t node, unsigned int generation, int hpsb_write(struct hpsb_host *host, nodeid_t node, unsigned int generation, u64 addr, quadlet_t *buffer, size_t length); +#ifdef HPSB_DEBUG_TLABELS +extern spinlock_t hpsb_tlabel_lock; +#endif + #endif /* _IEEE1394_TRANSACTIONS_H */ diff --git a/drivers/ieee1394/ieee1394_types.h b/drivers/ieee1394/ieee1394_types.h index 16fd2d0b5ed..a8de375e79b 100644 --- a/drivers/ieee1394/ieee1394_types.h +++ b/drivers/ieee1394/ieee1394_types.h @@ -2,31 +2,9 @@ #define _IEEE1394_TYPES_H #include -#include -#include #include #include - #include -#include - -/* Transaction Label handling */ -struct hpsb_tlabel_pool { - DECLARE_BITMAP(pool, 64); - spinlock_t lock; - u8 next; - u32 allocations; - struct semaphore count; -}; - -#define HPSB_TPOOL_INIT(_tp) \ -do { \ - bitmap_zero((_tp)->pool, 64); \ - spin_lock_init(&(_tp)->lock); \ - (_tp)->next = 0; \ - (_tp)->allocations = 0; \ - sema_init(&(_tp)->count, 63); \ -} while (0) typedef u32 quadlet_t; typedef u64 octlet_t; @@ -61,6 +39,7 @@ typedef u16 arm_length_t; #ifdef CONFIG_IEEE1394_VERBOSEDEBUG #define HPSB_VERBOSE(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args) +#define HPSB_DEBUG_TLABELS #else #define HPSB_VERBOSE(fmt, args...) #endif diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index f8f6079cc48..eabc51b23c0 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -327,34 +327,44 @@ static ssize_t fw_show_ne_bus_options(struct device *dev, struct device_attribut static DEVICE_ATTR(bus_options,S_IRUGO,fw_show_ne_bus_options,NULL); -/* tlabels_free, tlabels_allocations, tlabels_mask are read non-atomically - * here, therefore displayed values may be occasionally wrong. */ -static ssize_t fw_show_ne_tlabels_free(struct device *dev, struct device_attribute *attr, char *buf) +#ifdef HPSB_DEBUG_TLABELS +static ssize_t fw_show_ne_tlabels_free(struct device *dev, + struct device_attribute *attr, char *buf) { struct node_entry *ne = container_of(dev, struct node_entry, device); - return sprintf(buf, "%d\n", 64 - bitmap_weight(ne->tpool->pool, 64)); -} -static DEVICE_ATTR(tlabels_free,S_IRUGO,fw_show_ne_tlabels_free,NULL); + unsigned long flags; + unsigned long *tp = ne->host->tl_pool[NODEID_TO_NODE(ne->nodeid)].map; + int tf; + spin_lock_irqsave(&hpsb_tlabel_lock, flags); + tf = 64 - bitmap_weight(tp, 64); + spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); -static ssize_t fw_show_ne_tlabels_allocations(struct device *dev, struct device_attribute *attr, char *buf) -{ - struct node_entry *ne = container_of(dev, struct node_entry, device); - return sprintf(buf, "%u\n", ne->tpool->allocations); + return sprintf(buf, "%d\n", tf); } -static DEVICE_ATTR(tlabels_allocations,S_IRUGO,fw_show_ne_tlabels_allocations,NULL); +static DEVICE_ATTR(tlabels_free,S_IRUGO,fw_show_ne_tlabels_free,NULL); -static ssize_t fw_show_ne_tlabels_mask(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t fw_show_ne_tlabels_mask(struct device *dev, + struct device_attribute *attr, char *buf) { struct node_entry *ne = container_of(dev, struct node_entry, device); + unsigned long flags; + unsigned long *tp = ne->host->tl_pool[NODEID_TO_NODE(ne->nodeid)].map; + u64 tm; + + spin_lock_irqsave(&hpsb_tlabel_lock, flags); #if (BITS_PER_LONG <= 32) - return sprintf(buf, "0x%08lx%08lx\n", ne->tpool->pool[0], ne->tpool->pool[1]); + tm = ((u64)tp[0] << 32) + tp[1]; #else - return sprintf(buf, "0x%016lx\n", ne->tpool->pool[0]); + tm = tp[0]; #endif + spin_unlock_irqrestore(&hpsb_tlabel_lock, flags); + + return sprintf(buf, "0x%016llx\n", tm); } static DEVICE_ATTR(tlabels_mask, S_IRUGO, fw_show_ne_tlabels_mask, NULL); +#endif /* HPSB_DEBUG_TLABELS */ static ssize_t fw_set_ignore_driver(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -461,9 +471,10 @@ static struct device_attribute *const fw_ne_attrs[] = { &dev_attr_ne_vendor_id, &dev_attr_ne_nodeid, &dev_attr_bus_options, +#ifdef HPSB_DEBUG_TLABELS &dev_attr_tlabels_free, - &dev_attr_tlabels_allocations, &dev_attr_tlabels_mask, +#endif }; @@ -782,8 +793,6 @@ static struct node_entry *nodemgr_create_node(octlet_t guid, struct csr1212_csr if (!ne) return NULL; - ne->tpool = &host->tpool[nodeid & NODE_MASK]; - ne->host = host; ne->nodeid = nodeid; ne->generation = generation; diff --git a/drivers/ieee1394/nodemgr.h b/drivers/ieee1394/nodemgr.h index f649c9d321b..0e1e7d93078 100644 --- a/drivers/ieee1394/nodemgr.h +++ b/drivers/ieee1394/nodemgr.h @@ -107,7 +107,6 @@ struct node_entry { const char *vendor_oui; u32 capabilities; - struct hpsb_tlabel_pool *tpool; struct device device; struct class_device class_dev; -- cgit v1.2.3 From 9154df538fa044ac2b729ae5c6c47cae09e6977f Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 23 Jul 2006 22:01:00 +0200 Subject: ieee1394: remove #include These includes in ieee1394_core and eth1394 are obsolete. Signed-off-by: Stefan Richter --- drivers/ieee1394/eth1394.c | 1 - drivers/ieee1394/ieee1394_core.c | 1 - drivers/ieee1394/ieee1394_core.h | 1 - 3 files changed, 3 deletions(-) diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c index 09826be86aa..8a7b8fab623 100644 --- a/drivers/ieee1394/eth1394.c +++ b/drivers/ieee1394/eth1394.c @@ -64,7 +64,6 @@ #include #include #include -#include #include #include "config_roms.h" diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c index 559c477092f..e4dd5bc3fb7 100644 --- a/drivers/ieee1394/ieee1394_core.c +++ b/drivers/ieee1394/ieee1394_core.c @@ -35,7 +35,6 @@ #include #include -#include #include "ieee1394_types.h" #include "ieee1394.h" diff --git a/drivers/ieee1394/ieee1394_core.h b/drivers/ieee1394/ieee1394_core.h index 1ce172b2856..af4a78a8ef3 100644 --- a/drivers/ieee1394/ieee1394_core.h +++ b/drivers/ieee1394/ieee1394_core.h @@ -7,7 +7,6 @@ #include #include #include -#include #include "hosts.h" #include "ieee1394_types.h" -- cgit v1.2.3 From cc078189125db84a85a3bbb82df788b84fc68aa1 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 23 Jul 2006 22:12:00 +0200 Subject: ieee1394: sbp2: safer last_orb and next_ORB handling The sbp2 initiator has two ways to tell a target's fetch agent about new command ORBs: - Write the ORB's address to the ORB_POINTER register. This must not be done while the fetch agent is active. - Put the ORB's address into the previously submitted ORB's next_ORB field and write to the DOORBELL register. This may be done while the fetch agent is active or suspended. It must not be done while the fetch agent is in reset state. Sbp2 has a last_orb pointer which indicates in what way a new command should be announced. That pointer is concurrently accessed at various occasions. Furthermore, initiator and target are accessing the next_ORB field of ORBs concurrently and asynchronously. This patch does: - Protect all initiator accesses to last_orb by sbp2_command_orb_lock. - Add pci_dma_sync_single_for_device before a previously submitted ORB's next_ORB field is overwritten. - Insert a memory barrier between when next_ORB_lo and next_ORB_hi are overwritten. Next_ORB_hi must not be updated before next_ORB_lo. - Remove the rather unspecific and now superfluous qualifier "volatile" from the next_ORB fields. - Add comments on how last_orb is connected with what is known about the target's fetch agent's state. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 101 +++++++++++++++++++++++------------------------- drivers/ieee1394/sbp2.h | 4 +- 2 files changed, 50 insertions(+), 55 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index baa063c9e6e..e312d5e2a64 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -1705,6 +1705,7 @@ static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait) quadlet_t data; u64 addr; int retval; + unsigned long flags; SBP2_DEBUG_ENTER(); @@ -1724,7 +1725,9 @@ static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait) /* * Need to make sure orb pointer is written on next command */ + spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); scsi_id->last_orb = NULL; + spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); return 0; } @@ -1966,8 +1969,12 @@ static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, { struct sbp2scsi_host_info *hi = scsi_id->hi; struct sbp2_command_orb *command_orb = &command->command_orb; - struct node_entry *ne = scsi_id->ne; - u64 addr; + struct sbp2_command_orb *last_orb; + dma_addr_t last_orb_dma; + u64 addr = scsi_id->sbp2_command_block_agent_addr; + quadlet_t data[2]; + size_t length; + unsigned long flags; outstanding_orb_incr; SBP2_ORB_DEBUG("sending command orb %p, total orbs = %x", @@ -1982,64 +1989,50 @@ static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, /* * Check to see if there are any previous orbs to use */ - if (scsi_id->last_orb == NULL) { - quadlet_t data[2]; - + spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); + last_orb = scsi_id->last_orb; + last_orb_dma = scsi_id->last_orb_dma; + if (!last_orb) { /* - * Ok, let's write to the target's management agent register + * last_orb == NULL means: We know that the target's fetch agent + * is not active right now. */ - addr = scsi_id->sbp2_command_block_agent_addr + SBP2_ORB_POINTER_OFFSET; + addr += SBP2_ORB_POINTER_OFFSET; data[0] = ORB_SET_NODE_ID(hi->host->node_id); data[1] = command->command_orb_dma; sbp2util_cpu_to_be32_buffer(data, 8); - - SBP2_ORB_DEBUG("write command agent, command orb %p", command_orb); - - if (sbp2util_node_write_no_wait(ne, addr, data, 8) < 0) { - SBP2_ERR("sbp2util_node_write_no_wait failed.\n"); - return -EIO; - } - - SBP2_ORB_DEBUG("write command agent complete"); - - scsi_id->last_orb = command_orb; - scsi_id->last_orb_dma = command->command_orb_dma; - + length = 8; } else { - quadlet_t data; - /* - * We have an orb already sent (maybe or maybe not - * processed) that we can append this orb to. So do so, - * and ring the doorbell. Have to be very careful - * modifying these next orb pointers, as they are accessed - * both by the sbp2 device and us. + * last_orb != NULL means: We know that the target's fetch agent + * is (very probably) not dead or in reset state right now. + * We have an ORB already sent that we can append a new one to. + * The target's fetch agent may or may not have read this + * previous ORB yet. */ - scsi_id->last_orb->next_ORB_lo = - cpu_to_be32(command->command_orb_dma); + pci_dma_sync_single_for_cpu(hi->host->pdev, last_orb_dma, + sizeof(struct sbp2_command_orb), + PCI_DMA_BIDIRECTIONAL); + last_orb->next_ORB_lo = cpu_to_be32(command->command_orb_dma); + wmb(); /* Tells hardware that this pointer is valid */ - scsi_id->last_orb->next_ORB_hi = 0x0; - pci_dma_sync_single_for_device(hi->host->pdev, - scsi_id->last_orb_dma, + last_orb->next_ORB_hi = 0; + pci_dma_sync_single_for_device(hi->host->pdev, last_orb_dma, sizeof(struct sbp2_command_orb), PCI_DMA_BIDIRECTIONAL); + addr += SBP2_DOORBELL_OFFSET; + data[0] = 0; + length = 4; + } + scsi_id->last_orb = command_orb; + scsi_id->last_orb_dma = command->command_orb_dma; + spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); - /* - * Ring the doorbell - */ - data = cpu_to_be32(command->command_orb_dma); - addr = scsi_id->sbp2_command_block_agent_addr + SBP2_DOORBELL_OFFSET; - - SBP2_ORB_DEBUG("ring doorbell, command orb %p", command_orb); - - if (sbp2util_node_write_no_wait(ne, addr, &data, 4) < 0) { - SBP2_ERR("sbp2util_node_write_no_wait failed"); - return -EIO; - } - - scsi_id->last_orb = command_orb; - scsi_id->last_orb_dma = command->command_orb_dma; - + SBP2_ORB_DEBUG("write to %s register, command orb %p", + last_orb ? "DOORBELL" : "ORB_POINTER", command_orb); + if (sbp2util_node_write_no_wait(scsi_id->ne, addr, data, length) < 0) { + SBP2_ERR("sbp2util_node_write_no_wait failed.\n"); + return -EIO; } return 0; } @@ -2231,14 +2224,16 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest } /* - * Check here to see if there are no commands in-use. If there are none, we can - * null out last orb so that next time around we write directly to the orb pointer... - * Quick start saves one 1394 bus transaction. + * Check here to see if there are no commands in-use. If there + * are none, we know that the fetch agent left the active state + * _and_ that we did not reactivate it yet. Therefore clear + * last_orb so that next time we write directly to the + * ORB_POINTER register. That way the fetch agent does not need + * to refetch the next_ORB. */ spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); - if (list_empty(&scsi_id->sbp2_command_orb_inuse)) { + if (list_empty(&scsi_id->sbp2_command_orb_inuse)) scsi_id->last_orb = NULL; - } spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); } else { diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h index b22ce1aa8fe..dd80906e8a9 100644 --- a/drivers/ieee1394/sbp2.h +++ b/drivers/ieee1394/sbp2.h @@ -46,8 +46,8 @@ #define ORB_SET_DIRECTION(value) ((value & 0x1) << 27) struct sbp2_command_orb { - volatile u32 next_ORB_hi; - volatile u32 next_ORB_lo; + u32 next_ORB_hi; + u32 next_ORB_lo; u32 data_descriptor_hi; u32 data_descriptor_lo; u32 misc; -- cgit v1.2.3 From 28212767e58402ea362edcb80b753d49bfd44d98 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 23 Jul 2006 22:10:00 +0200 Subject: ieee1394: sbp2: discard return value of sbp2_link_orb_command Since sbp2 is at the moment unable to do anything with the return value of sbp2_link_orb_command, just discard it. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 8 +++----- drivers/ieee1394/sbp2.h | 5 ----- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index e312d5e2a64..670a13981fd 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -1964,7 +1964,7 @@ static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id, /* * This function is called in order to begin a regular SBP-2 command. */ -static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, +static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, struct sbp2_command_info *command) { struct sbp2scsi_host_info *hi = scsi_id->hi; @@ -2030,11 +2030,9 @@ static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, SBP2_ORB_DEBUG("write to %s register, command orb %p", last_orb ? "DOORBELL" : "ORB_POINTER", command_orb); - if (sbp2util_node_write_no_wait(scsi_id->ne, addr, data, length) < 0) { + if (sbp2util_node_write_no_wait(scsi_id->ne, addr, data, length)) SBP2_ERR("sbp2util_node_write_no_wait failed.\n"); - return -EIO; - } - return 0; + /* We rely on SCSI EH to deal with _node_write_ failures. */ } /* diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h index dd80906e8a9..b17016b7cfc 100644 --- a/drivers/ieee1394/sbp2.h +++ b/drivers/ieee1394/sbp2.h @@ -390,11 +390,6 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id); static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int destid, quadlet_t *data, u64 addr, size_t length, u16 flags); static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait); -static int sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, - struct sbp2_command_info *command); -static int sbp2_send_command(struct scsi_id_instance_data *scsi_id, - struct scsi_cmnd *SCpnt, - void (*done)(struct scsi_cmnd *)); static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense_data); static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, -- cgit v1.2.3 From d4018d7fa63d25f3e1ecf6949fca6b81a182231a Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 23 Jul 2006 22:57:00 +0200 Subject: ieee1394: sbp2: optimize DMA direction of command ORBs Only the driver writes ORBs, the device just reads them. Therefore PCI_DMA_BIDIRECTIONAL can be replaced by PCI_DMA_TODEVICE which may be cheaper on some architectures. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 670a13981fd..11595df8b75 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -492,7 +492,7 @@ static int sbp2util_create_command_orb_pool(struct scsi_id_instance_data *scsi_i command->command_orb_dma = pci_map_single(hi->host->pdev, &command->command_orb, sizeof(struct sbp2_command_orb), - PCI_DMA_BIDIRECTIONAL); + PCI_DMA_TODEVICE); SBP2_DMA_ALLOC("single command orb DMA"); command->sge_dma = pci_map_single(hi->host->pdev, @@ -525,7 +525,7 @@ static void sbp2util_remove_command_orb_pool(struct scsi_id_instance_data *scsi_ /* Release our generic DMA's */ pci_unmap_single(host->pdev, command->command_orb_dma, sizeof(struct sbp2_command_orb), - PCI_DMA_BIDIRECTIONAL); + PCI_DMA_TODEVICE); SBP2_DMA_FREE("single command orb DMA"); pci_unmap_single(host->pdev, command->sge_dma, sizeof(command->scatter_gather_element), @@ -1982,7 +1982,7 @@ static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, pci_dma_sync_single_for_device(hi->host->pdev, command->command_orb_dma, sizeof(struct sbp2_command_orb), - PCI_DMA_BIDIRECTIONAL); + PCI_DMA_TODEVICE); pci_dma_sync_single_for_device(hi->host->pdev, command->sge_dma, sizeof(command->scatter_gather_element), PCI_DMA_BIDIRECTIONAL); @@ -2012,14 +2012,14 @@ static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, */ pci_dma_sync_single_for_cpu(hi->host->pdev, last_orb_dma, sizeof(struct sbp2_command_orb), - PCI_DMA_BIDIRECTIONAL); + PCI_DMA_TODEVICE); last_orb->next_ORB_lo = cpu_to_be32(command->command_orb_dma); wmb(); /* Tells hardware that this pointer is valid */ last_orb->next_ORB_hi = 0; pci_dma_sync_single_for_device(hi->host->pdev, last_orb_dma, sizeof(struct sbp2_command_orb), - PCI_DMA_BIDIRECTIONAL); + PCI_DMA_TODEVICE); addr += SBP2_DOORBELL_OFFSET; data[0] = 0; length = 4; @@ -2176,7 +2176,7 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest SBP2_DEBUG("Found status for command ORB"); pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma, sizeof(struct sbp2_command_orb), - PCI_DMA_BIDIRECTIONAL); + PCI_DMA_TODEVICE); pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma, sizeof(command->scatter_gather_element), PCI_DMA_BIDIRECTIONAL); @@ -2365,7 +2365,7 @@ static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id command = list_entry(lh, struct sbp2_command_info, list); pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma, sizeof(struct sbp2_command_orb), - PCI_DMA_BIDIRECTIONAL); + PCI_DMA_TODEVICE); pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma, sizeof(command->scatter_gather_element), PCI_DMA_BIDIRECTIONAL); @@ -2548,7 +2548,7 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt) pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma, sizeof(struct sbp2_command_orb), - PCI_DMA_BIDIRECTIONAL); + PCI_DMA_TODEVICE); pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma, sizeof(command->scatter_gather_element), -- cgit v1.2.3 From 3e98eab46d1a482532c653bdb0c006413654d171 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 23 Jul 2006 22:16:00 +0200 Subject: ieee1394: sbp2: safer initialization of status fifo Sbp2's copy of the status fifo was cleared when management ORBs or new command ORBs were prepared. The latter had potential for a race condition if the block layer's soft IRQ and the 1394 LLD's interrupt handler ran on different CPUs. It would also yield wrong status if a command was completed with non-zero completion status before other commands that had zero completion status, and no new command was enqueued in the meantime. Now, the status buffer is cleared right before it is written. Thus it ends up in the following simpler and safer access pattern: - sbp2_alloc_device: allocates and implicitly clears once, - sbp2_handle_status_write: clears, writes, and reads, - sbp2_query_logins, sbp2_login_device, sbp2_reconnect_device: read. The latter three do not race with sbp2_handle_status_write because of how the protocol works. As a tiny optimization, the first two quadlets of the status never need to be cleared. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 80 +++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 50 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 11595df8b75..c6776909747 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -1182,7 +1182,6 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) "sbp2 query logins orb", scsi_id->query_logins_orb_dma); memset(scsi_id->query_logins_response, 0, sizeof(struct sbp2_query_logins_response)); - memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block)); data[0] = ORB_SET_NODE_ID(hi->host->node_id); data[1] = scsi_id->query_logins_orb_dma; @@ -1278,7 +1277,6 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) "sbp2 login orb", scsi_id->login_orb_dma); memset(scsi_id->login_response, 0, sizeof(struct sbp2_login_response)); - memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block)); data[0] = ORB_SET_NODE_ID(hi->host->node_id); data[1] = scsi_id->login_orb_dma; @@ -1445,14 +1443,6 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) sbp2util_packet_dump(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb), "sbp2 reconnect orb", scsi_id->reconnect_orb_dma); - /* - * Initialize status fifo - */ - memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block)); - - /* - * Ok, let's write to the target's management agent register - */ data[0] = ORB_SET_NODE_ID(hi->host->node_id); data[1] = scsi_id->reconnect_orb_dma; sbp2util_cpu_to_be32_buffer(data, 8); @@ -2068,11 +2058,6 @@ static int sbp2_send_command(struct scsi_id_instance_data *scsi_id, sbp2util_packet_dump(&command->command_orb, sizeof(struct sbp2_command_orb), "sbp2 command orb", command->command_orb_dma); - /* - * Initialize status fifo - */ - memset(&scsi_id->status_block, 0, sizeof(struct sbp2_status_block)); - /* * Link up the orb, and ring the doorbell if needed */ @@ -2114,12 +2099,14 @@ static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense /* * This function deals with status writes from the SBP-2 device */ -static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int destid, - quadlet_t *data, u64 addr, size_t length, u16 fl) +static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, + int destid, quadlet_t *data, u64 addr, + size_t length, u16 fl) { struct sbp2scsi_host_info *hi; struct scsi_id_instance_data *scsi_id = NULL, *scsi_id_tmp; struct scsi_cmnd *SCpnt = NULL; + struct sbp2_status_block *sb; u32 scsi_status = SBP2_SCSI_STATUS_GOOD; struct sbp2_command_info *command; unsigned long flags; @@ -2158,19 +2145,21 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest } /* - * Put response into scsi_id status fifo... + * Put response into scsi_id status fifo buffer. The first two bytes + * come in big endian bit order. Often the target writes only a + * truncated status block, minimally the first two quadlets. The rest + * is implied to be zeros. */ - memcpy(&scsi_id->status_block, data, length); + sb = &scsi_id->status_block; + memset(sb->command_set_dependent, 0, sizeof(sb->command_set_dependent)); + memcpy(sb, data, length); + sbp2util_be32_to_cpu_buffer(sb, 8); /* - * Byte swap first two quadlets (8 bytes) of status for processing + * Handle command ORB status here if necessary. First, need to match + * status with command. */ - sbp2util_be32_to_cpu_buffer(&scsi_id->status_block, 8); - - /* - * Handle command ORB status here if necessary. First, need to match status with command. - */ - command = sbp2util_find_command_for_orb(scsi_id, scsi_id->status_block.ORB_offset_lo); + command = sbp2util_find_command_for_orb(scsi_id, sb->ORB_offset_lo); if (command) { SBP2_DEBUG("Found status for command ORB"); @@ -2185,7 +2174,8 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest outstanding_orb_decr; /* - * Matched status with command, now grab scsi command pointers and check status + * Matched status with command, now grab scsi command pointers + * and check status. */ SCpnt = command->Current_SCpnt; spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); @@ -2193,28 +2183,22 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); if (SCpnt) { - /* - * See if the target stored any scsi status information + * See if the target stored any scsi status information. */ - if (STATUS_GET_LENGTH(scsi_id->status_block.ORB_offset_hi_misc) > 1) { - /* - * Translate SBP-2 status to SCSI sense data - */ + if (STATUS_GET_LENGTH(sb->ORB_offset_hi_misc) > 1) { SBP2_DEBUG("CHECK CONDITION"); - scsi_status = sbp2_status_to_sense_data((unchar *)&scsi_id->status_block, SCpnt->sense_buffer); + scsi_status = sbp2_status_to_sense_data( + (unchar *)sb, SCpnt->sense_buffer); } /* - * Check to see if the dead bit is set. If so, we'll have to initiate - * a fetch agent reset. + * Check to see if the dead bit is set. If so, we'll + * have to initiate a fetch agent reset. */ - if (STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc)) { - - /* - * Initiate a fetch agent reset. - */ - SBP2_DEBUG("Dead bit set - initiating fetch agent reset"); + if (STATUS_GET_DEAD_BIT(sb->ORB_offset_hi_misc)) { + SBP2_DEBUG("Dead bit set - " + "initiating fetch agent reset"); sbp2_agent_reset(scsi_id, 0); } @@ -2235,21 +2219,17 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, int dest spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); } else { - /* * It's probably a login/logout/reconnect status. */ - if ((scsi_id->login_orb_dma == scsi_id->status_block.ORB_offset_lo) || - (scsi_id->query_logins_orb_dma == scsi_id->status_block.ORB_offset_lo) || - (scsi_id->reconnect_orb_dma == scsi_id->status_block.ORB_offset_lo) || - (scsi_id->logout_orb_dma == scsi_id->status_block.ORB_offset_lo)) { + if ((sb->ORB_offset_lo == scsi_id->reconnect_orb_dma) || + (sb->ORB_offset_lo == scsi_id->login_orb_dma) || + (sb->ORB_offset_lo == scsi_id->query_logins_orb_dma) || + (sb->ORB_offset_lo == scsi_id->logout_orb_dma)) atomic_set(&scsi_id->sbp2_login_complete, 1); - } } if (SCpnt) { - - /* Complete the SCSI command. */ SBP2_DEBUG("Completing SCSI command"); sbp2scsi_complete_command(scsi_id, scsi_status, SCpnt, command->Current_done); -- cgit v1.2.3 From 6065772d54a3b994b9b5d3df6413ec6a1c8c2ec1 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 23 Jul 2006 22:18:00 +0200 Subject: ieee1394: sbp2: more checks of status block - Add checks for the (very unlikely) cases that the target writes too little or too much status data or writes unsolicited status. - Indicate that these and similar conditions are unlikely(). - Check the 'resp' and 'sbp_status' fields for possible failure status. - Slightly optimize access macros for the status block bitfields. - Unify a few related log messages. TODO: Check if 'src'==1, then withhold the respective ORB from reuse until status for any subsequent ORB was received. This is an old bug whose fix requires more complex command queue handling. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 70 +++++++++++++++++++++---------------------------- drivers/ieee1394/sbp2.h | 14 +++++----- 2 files changed, 38 insertions(+), 46 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index c6776909747..07030be0ef2 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -1201,11 +1201,8 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) return -EIO; } - if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) || - STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) || - STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) { - - SBP2_INFO("Error querying logins to SBP-2 device - timed out"); + if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) { + SBP2_INFO("Error querying logins to SBP-2 device - failed"); return -EIO; } @@ -1298,18 +1295,12 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) * Sanity. Make sure status returned matches login orb. */ if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) { - SBP2_ERR("Error logging into SBP-2 device - login timed-out"); + SBP2_ERR("Error logging into SBP-2 device - timed out"); return -EIO; } - /* - * Check status - */ - if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) || - STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) || - STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) { - - SBP2_ERR("Error logging into SBP-2 device - login failed"); + if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) { + SBP2_ERR("Error logging into SBP-2 device - failed"); return -EIO; } @@ -1333,9 +1324,7 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) scsi_id->sbp2_command_block_agent_addr &= 0x0000ffffffffffffULL; SBP2_INFO("Logged into SBP-2 device"); - return 0; - } /* @@ -1466,25 +1455,17 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) * Sanity. Make sure status returned matches reconnect orb. */ if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) { - SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out"); + SBP2_ERR("Error reconnecting to SBP-2 device - timed out"); return -EIO; } - /* - * Check status - */ - if (STATUS_GET_RESP(scsi_id->status_block.ORB_offset_hi_misc) || - STATUS_GET_DEAD_BIT(scsi_id->status_block.ORB_offset_hi_misc) || - STATUS_GET_SBP_STATUS(scsi_id->status_block.ORB_offset_hi_misc)) { - - SBP2_ERR("Error reconnecting to SBP-2 device - reconnect failed"); + if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) { + SBP2_ERR("Error reconnecting to SBP-2 device - failed"); return -EIO; } HPSB_DEBUG("Reconnected to SBP-2 device"); - return 0; - } /* @@ -2115,18 +2096,19 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, sbp2util_packet_dump(data, length, "sbp2 status write by device", (u32)addr); - if (!host) { + if (unlikely(length < 8 || length > sizeof(struct sbp2_status_block))) { + SBP2_ERR("Wrong size of status block"); + return RCODE_ADDRESS_ERROR; + } + if (unlikely(!host)) { SBP2_ERR("host is NULL - this is bad!"); return RCODE_ADDRESS_ERROR; } - hi = hpsb_get_hostinfo(&sbp2_highlevel, host); - - if (!hi) { + if (unlikely(!hi)) { SBP2_ERR("host info is NULL - this is bad!"); return RCODE_ADDRESS_ERROR; } - /* * Find our scsi_id structure by looking at the status fifo address * written to by the sbp2 device. @@ -2138,8 +2120,7 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, break; } } - - if (!scsi_id) { + if (unlikely(!scsi_id)) { SBP2_ERR("scsi_id is NULL - device is gone?"); return RCODE_ADDRESS_ERROR; } @@ -2156,12 +2137,14 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, sbp2util_be32_to_cpu_buffer(sb, 8); /* - * Handle command ORB status here if necessary. First, need to match - * status with command. + * Ignore unsolicited status. Handle command ORB status. */ - command = sbp2util_find_command_for_orb(scsi_id, sb->ORB_offset_lo); + if (unlikely(STATUS_GET_SRC(sb->ORB_offset_hi_misc) == 2)) + command = NULL; + else + command = sbp2util_find_command_for_orb(scsi_id, + sb->ORB_offset_lo); if (command) { - SBP2_DEBUG("Found status for command ORB"); pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma, sizeof(struct sbp2_command_orb), @@ -2177,16 +2160,23 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, * Matched status with command, now grab scsi command pointers * and check status. */ + /* + * FIXME: If the src field in the status is 1, the ORB DMA must + * not be reused until status for a subsequent ORB is received. + */ SCpnt = command->Current_SCpnt; spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); sbp2util_mark_command_completed(scsi_id, command); spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); if (SCpnt) { + if (STATUS_TEST_RS(sb->ORB_offset_hi_misc)) + scsi_status = + SBP2_SCSI_STATUS_COMMAND_TERMINATED; /* * See if the target stored any scsi status information. */ - if (STATUS_GET_LENGTH(sb->ORB_offset_hi_misc) > 1) { + if (STATUS_GET_LEN(sb->ORB_offset_hi_misc) > 1) { SBP2_DEBUG("CHECK CONDITION"); scsi_status = sbp2_status_to_sense_data( (unchar *)sb, SCpnt->sense_buffer); @@ -2196,7 +2186,7 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, * Check to see if the dead bit is set. If so, we'll * have to initiate a fetch agent reset. */ - if (STATUS_GET_DEAD_BIT(sb->ORB_offset_hi_misc)) { + if (STATUS_TEST_D(sb->ORB_offset_hi_misc)) { SBP2_DEBUG("Dead bit set - " "initiating fetch agent reset"); sbp2_agent_reset(scsi_id, 0); diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h index b17016b7cfc..34e3d37fc79 100644 --- a/drivers/ieee1394/sbp2.h +++ b/drivers/ieee1394/sbp2.h @@ -180,12 +180,14 @@ struct sbp2_unrestricted_page_table { #define SBP2_SCSI_STATUS_SELECTION_TIMEOUT 0xff -#define STATUS_GET_ORB_OFFSET_HI(value) (value & 0xffff) -#define STATUS_GET_SBP_STATUS(value) ((value >> 16) & 0xff) -#define STATUS_GET_LENGTH(value) ((value >> 24) & 0x7) -#define STATUS_GET_DEAD_BIT(value) ((value >> 27) & 0x1) -#define STATUS_GET_RESP(value) ((value >> 28) & 0x3) -#define STATUS_GET_SRC(value) ((value >> 30) & 0x3) +#define STATUS_GET_SRC(value) (((value) >> 30) & 0x3) +#define STATUS_GET_LEN(value) (((value) >> 24) & 0x7) +#define STATUS_GET_ORB_OFFSET_HI(value) ((value) & 0x0000ffff) +#define STATUS_TEST_D(value) ((value) & 0x08000000) +/* test 'resp' | 'sbp2_status' */ +#define STATUS_TEST_RS(value) ((value) & 0x30ff0000) +/* test 'resp' | 'dead' | 'sbp2_status' */ +#define STATUS_TEST_RDS(value) ((value) & 0x38ff0000) struct sbp2_status_block { u32 ORB_offset_hi_misc; -- cgit v1.2.3 From e8398bb737ceadff8825aa98cb9f4a5e96857546 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 23 Jul 2006 22:19:00 +0200 Subject: ieee1394: sbp2: convert sbp2util_down_timeout to waitqueue The waitqueue API is used to replace a custom wait mechanism. Only one global waitqueue (instead of per-device waitqueues or completions) is added because there is usually just one waiter. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 51 +++++++++++++++++++++---------------------------- drivers/ieee1394/sbp2.h | 4 ++-- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 07030be0ef2..6adbe1c796c 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -55,12 +55,12 @@ #include #include #include +#include #include #include #include #include -#include #include #include @@ -420,21 +420,23 @@ static void sbp2util_packet_dump(void *buffer, int length, char *dump_name, #define sbp2util_packet_dump(w,x,y,z) #endif +static DECLARE_WAIT_QUEUE_HEAD(access_wq); + /* - * Goofy routine that basically does a down_timeout function. + * Waits for completion of an SBP-2 access request. + * Returns nonzero if timed out or prematurely interrupted. */ -static int sbp2util_down_timeout(atomic_t *done, int timeout) +static int sbp2util_access_timeout(struct scsi_id_instance_data *scsi_id, + int timeout) { - int i; + long leftover = wait_event_interruptible_timeout( + access_wq, scsi_id->access_complete, timeout); - for (i = timeout; (i > 0 && atomic_read(done) == 0); i-= HZ/10) { - if (msleep_interruptible(100)) /* 100ms */ - return 1; - } - return (i > 0) ? 0 : 1; + scsi_id->access_complete = 0; + return leftover <= 0; } -/* Free's an allocated packet */ +/* Frees an allocated packet */ static void sbp2_free_packet(struct hpsb_packet *packet) { hpsb_free_tlabel(packet); @@ -794,7 +796,6 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud scsi_id->speed_code = IEEE1394_SPEED_100; scsi_id->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100]; scsi_id->status_fifo_addr = CSR1212_INVALID_ADDR_SPACE; - atomic_set(&scsi_id->sbp2_login_complete, 0); INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_inuse); INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed); INIT_LIST_HEAD(&scsi_id->scsi_list); @@ -1187,11 +1188,9 @@ static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) data[1] = scsi_id->query_logins_orb_dma; sbp2util_cpu_to_be32_buffer(data, 8); - atomic_set(&scsi_id->sbp2_login_complete, 0); - hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); - if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 2*HZ)) { + if (sbp2util_access_timeout(scsi_id, 2*HZ)) { SBP2_INFO("Error querying logins to SBP-2 device - timed out"); return -EIO; } @@ -1279,15 +1278,13 @@ static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) data[1] = scsi_id->login_orb_dma; sbp2util_cpu_to_be32_buffer(data, 8); - atomic_set(&scsi_id->sbp2_login_complete, 0); - hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); /* * Wait for login status (up to 20 seconds)... */ - if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, 20*HZ)) { - SBP2_ERR("Error logging into SBP-2 device - login timed-out"); + if (sbp2util_access_timeout(scsi_id, 20*HZ)) { + SBP2_ERR("Error logging into SBP-2 device - timed out"); return -EIO; } @@ -1374,21 +1371,17 @@ static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id) data[1] = scsi_id->logout_orb_dma; sbp2util_cpu_to_be32_buffer(data, 8); - atomic_set(&scsi_id->sbp2_login_complete, 0); - error = hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); if (error) return error; /* Wait for device to logout...1 second. */ - if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, HZ)) + if (sbp2util_access_timeout(scsi_id, HZ)) return -EIO; SBP2_INFO("Logged out of SBP-2 device"); - return 0; - } /* @@ -1436,8 +1429,6 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) data[1] = scsi_id->reconnect_orb_dma; sbp2util_cpu_to_be32_buffer(data, 8); - atomic_set(&scsi_id->sbp2_login_complete, 0); - error = hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); if (error) @@ -1446,8 +1437,8 @@ static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) /* * Wait for reconnect status (up to 1 second)... */ - if (sbp2util_down_timeout(&scsi_id->sbp2_login_complete, HZ)) { - SBP2_ERR("Error reconnecting to SBP-2 device - reconnect timed-out"); + if (sbp2util_access_timeout(scsi_id, HZ)) { + SBP2_ERR("Error reconnecting to SBP-2 device - timed out"); return -EIO; } @@ -2215,8 +2206,10 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, if ((sb->ORB_offset_lo == scsi_id->reconnect_orb_dma) || (sb->ORB_offset_lo == scsi_id->login_orb_dma) || (sb->ORB_offset_lo == scsi_id->query_logins_orb_dma) || - (sb->ORB_offset_lo == scsi_id->logout_orb_dma)) - atomic_set(&scsi_id->sbp2_login_complete, 1); + (sb->ORB_offset_lo == scsi_id->logout_orb_dma)) { + scsi_id->access_complete = 1; + wake_up_interruptible(&access_wq); + } } if (SCpnt) { diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h index 34e3d37fc79..89098fe565e 100644 --- a/drivers/ieee1394/sbp2.h +++ b/drivers/ieee1394/sbp2.h @@ -320,9 +320,9 @@ struct scsi_id_instance_data { u64 status_fifo_addr; /* - * Variable used for logins, reconnects, logouts, query logins + * Waitqueue flag for logins, reconnects, logouts, query logins */ - atomic_t sbp2_login_complete; + int access_complete:1; /* * Pool of command orbs, so we can have more than overlapped command per id -- cgit v1.2.3 From 8df4083c5291b3647e0381d3c69ab2196f5dd3b7 Mon Sep 17 00:00:00 2001 From: Andi Kleen Date: Thu, 27 Jul 2006 21:54:00 +0200 Subject: Initialize ieee1394 early when built in This makes debugging with firescope easier. Signed-off-by: Andi Kleen (original patch) Update: - no need for #ifdef MODULE - add comment in ieee1394_core, more verbose comment in ohci1394 Signed-off-by: Stefan Richter (update) --- drivers/ieee1394/ieee1394_core.c | 2 +- drivers/ieee1394/ohci1394.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c index e4dd5bc3fb7..991c378496f 100644 --- a/drivers/ieee1394/ieee1394_core.c +++ b/drivers/ieee1394/ieee1394_core.c @@ -1170,7 +1170,7 @@ static void __exit ieee1394_cleanup(void) unregister_chrdev_region(IEEE1394_CORE_DEV, 256); } -module_init(ieee1394_init); +fs_initcall(ieee1394_init); /* same as ohci1394 */ module_exit(ieee1394_cleanup); /* Exported symbols */ diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index baa090d08d2..330dcf7c699 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c @@ -3719,5 +3719,7 @@ static int __init ohci1394_init(void) return pci_register_driver(&ohci1394_pci_driver); } -module_init(ohci1394_init); +/* Register before most other device drivers. + * Useful for remote debugging via physical DMA, e.g. using firescope. */ +fs_initcall(ohci1394_init); module_exit(ohci1394_cleanup); -- cgit v1.2.3 From a1b3206b362335f7986d1fab294c16148a8c50ab Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Sat, 29 Jul 2006 19:48:28 +0200 Subject: the scheduled removal of drivers/ieee1394/sbp2.c:force_inquiry_hack This patch contains the scheduled removal of the force_inquiry_hack module parameter. Signed-off-by: Adrian Bunk Signed-off-by: Stefan Richter --- Documentation/feature-removal-schedule.txt | 9 --------- drivers/ieee1394/sbp2.c | 10 ---------- 2 files changed, 19 deletions(-) diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt index d1cd5f93e02..d0e7917b30f 100644 --- a/Documentation/feature-removal-schedule.txt +++ b/Documentation/feature-removal-schedule.txt @@ -31,15 +31,6 @@ Who: Jody McIntyre --------------------------- -What: sbp2: module parameter "force_inquiry_hack" -When: July 2006 -Why: Superceded by parameter "workarounds". Both parameters are meant to be - used ad-hoc and for single devices only, i.e. not in modprobe.conf, - therefore the impact of this feature replacement should be low. -Who: Stefan Richter - ---------------------------- - What: Video4Linux API 1 ioctls and video_decoder.h from Video devices. When: July 2006 Why: V4L1 AP1 was replaced by V4L2 API. during migration from 2.4 to 2.6 diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 6adbe1c796c..1c8ce7acba8 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -173,11 +173,6 @@ MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0" ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE) ", or a combination)"); -/* legacy parameter */ -static int force_inquiry_hack; -module_param(force_inquiry_hack, int, 0644); -MODULE_PARM_DESC(force_inquiry_hack, "Deprecated, use 'workarounds'"); - /* * Export information about protocols/devices supported by this driver. */ @@ -1554,11 +1549,6 @@ static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, } workarounds = sbp2_default_workarounds; - if (force_inquiry_hack) { - SBP2_WARN("force_inquiry_hack is deprecated. " - "Use parameter 'workarounds' instead."); - workarounds |= SBP2_WORKAROUND_INQUIRY_36; - } if (!(workarounds & SBP2_WORKAROUND_OVERRIDE)) for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) { -- cgit v1.2.3 From 4b60912e52bc6ccdf587f2b92f3435ee2678d730 Mon Sep 17 00:00:00 2001 From: David Moore Date: Wed, 2 Aug 2006 01:00:00 +0200 Subject: video1394: add poll file operation support This patch adds support for the poll file operation to the video1394 driver. Signed-off-by: David Moore Signed-off-by: Stefan Richter --- drivers/ieee1394/video1394.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c index 6b5353d81ae..af78b840dc2 100644 --- a/drivers/ieee1394/video1394.c +++ b/drivers/ieee1394/video1394.c @@ -1181,7 +1181,8 @@ static int video1394_mmap(struct file *file, struct vm_area_struct *vma) lock_kernel(); if (ctx->current_ctx == NULL) { - PRINT(KERN_ERR, ctx->ohci->host->id, "Current iso context not set"); + PRINT(KERN_ERR, ctx->ohci->host->id, + "Current iso context not set"); } else res = dma_region_mmap(&ctx->current_ctx->dma, file, vma); unlock_kernel(); @@ -1189,6 +1190,40 @@ static int video1394_mmap(struct file *file, struct vm_area_struct *vma) return res; } +static unsigned int video1394_poll(struct file *file, poll_table *pt) +{ + struct file_ctx *ctx; + unsigned int mask = 0; + unsigned long flags; + struct dma_iso_ctx *d; + int i; + + lock_kernel(); + ctx = file->private_data; + d = ctx->current_ctx; + if (d == NULL) { + PRINT(KERN_ERR, ctx->ohci->host->id, + "Current iso context not set"); + mask = POLLERR; + goto done; + } + + poll_wait(file, &d->waitq, pt); + + spin_lock_irqsave(&d->lock, flags); + for (i = 0; i < d->num_desc; i++) { + if (d->buffer_status[i] == VIDEO1394_BUFFER_READY) { + mask |= POLLIN | POLLRDNORM; + break; + } + } + spin_unlock_irqrestore(&d->lock, flags); +done: + unlock_kernel(); + + return mask; +} + static int video1394_open(struct inode *inode, struct file *file) { int i = ieee1394_file_to_instance(file); @@ -1257,6 +1292,7 @@ static struct file_operations video1394_fops= #ifdef CONFIG_COMPAT .compat_ioctl = video1394_compat_ioctl, #endif + .poll = video1394_poll, .mmap = video1394_mmap, .open = video1394_open, .release = video1394_release -- cgit v1.2.3 From 611aa19fd60fe57059d9972fa6ae29f7472a13cf Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Wed, 2 Aug 2006 18:44:00 +0200 Subject: ieee1394: safer definition of empty macros A deactivated macro, defined as "#define foo(bar)", will result in silent corruption if somebody forgets a semicolon after a call to foo. Replace it by "#define foo(bar) do {} while (0)" which will reveal any respective syntax errors. Signed-off-by: Stefan Richter --- drivers/ieee1394/dv1394.c | 4 ++-- drivers/ieee1394/ieee1394_core.c | 2 +- drivers/ieee1394/ieee1394_types.h | 2 +- drivers/ieee1394/ohci1394.c | 8 ++++---- drivers/ieee1394/raw1394.c | 2 +- drivers/ieee1394/sbp2.c | 18 +++++++++--------- drivers/ieee1394/video1394.c | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c index 6e71d68b109..6c72f04b2b5 100644 --- a/drivers/ieee1394/dv1394.c +++ b/drivers/ieee1394/dv1394.c @@ -137,13 +137,13 @@ #if DV1394_DEBUG_LEVEL >= 2 #define irq_printk( args... ) printk( args ) #else -#define irq_printk( args... ) +#define irq_printk( args... ) do {} while (0) #endif #if DV1394_DEBUG_LEVEL >= 1 #define debug_printk( args... ) printk( args) #else -#define debug_printk( args... ) +#define debug_printk( args... ) do {} while (0) #endif /* issue a dummy PCI read to force the preceding write diff --git a/drivers/ieee1394/ieee1394_core.c b/drivers/ieee1394/ieee1394_core.c index 991c378496f..5fccf9f7a1d 100644 --- a/drivers/ieee1394/ieee1394_core.c +++ b/drivers/ieee1394/ieee1394_core.c @@ -85,7 +85,7 @@ static void dump_packet(const char *text, quadlet_t *data, int size, int speed) printk("\n"); } #else -#define dump_packet(a,b,c,d) +#define dump_packet(a,b,c,d) do {} while (0) #endif static void abort_requests(struct hpsb_host *host); diff --git a/drivers/ieee1394/ieee1394_types.h b/drivers/ieee1394/ieee1394_types.h index a8de375e79b..9803aaa15be 100644 --- a/drivers/ieee1394/ieee1394_types.h +++ b/drivers/ieee1394/ieee1394_types.h @@ -41,7 +41,7 @@ typedef u16 arm_length_t; #define HPSB_VERBOSE(fmt, args...) HPSB_PRINT(KERN_DEBUG, fmt , ## args) #define HPSB_DEBUG_TLABELS #else -#define HPSB_VERBOSE(fmt, args...) +#define HPSB_VERBOSE(fmt, args...) do {} while (0) #endif #ifdef __BIG_ENDIAN diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index 330dcf7c699..ea14c831ff4 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c @@ -136,7 +136,7 @@ #define DBGMSG(fmt, args...) \ printk(KERN_INFO "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args) #else -#define DBGMSG(fmt, args...) +#define DBGMSG(fmt, args...) do {} while (0) #endif #ifdef CONFIG_IEEE1394_OHCI_DMA_DEBUG @@ -148,8 +148,8 @@ printk(KERN_INFO "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host-> --global_outstanding_dmas, ## args) static int global_outstanding_dmas = 0; #else -#define OHCI_DMA_ALLOC(fmt, args...) -#define OHCI_DMA_FREE(fmt, args...) +#define OHCI_DMA_ALLOC(fmt, args...) do {} while (0) +#define OHCI_DMA_FREE(fmt, args...) do {} while (0) #endif /* print general (card independent) information */ @@ -210,7 +210,7 @@ static inline void packet_swab(quadlet_t *data, int tcode) } #else /* Don't waste cycles on same sex byte swaps */ -#define packet_swab(w,x) +#define packet_swab(w,x) do {} while (0) #endif /* !LITTLE_ENDIAN */ /*********************************** diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c index 840b705fd5d..47e66759324 100644 --- a/drivers/ieee1394/raw1394.c +++ b/drivers/ieee1394/raw1394.c @@ -67,7 +67,7 @@ #define DBGMSG(fmt, args...) \ printk(KERN_INFO "raw1394:" fmt "\n" , ## args) #else -#define DBGMSG(fmt, args...) +#define DBGMSG(fmt, args...) do {} while (0) #endif static LIST_HEAD(host_info_list); diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 1c8ce7acba8..668b4512def 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -203,9 +203,9 @@ static u32 global_outstanding_command_orbs = 0; #define outstanding_orb_incr global_outstanding_command_orbs++ #define outstanding_orb_decr global_outstanding_command_orbs-- #else -#define SBP2_ORB_DEBUG(fmt, args...) -#define outstanding_orb_incr -#define outstanding_orb_decr +#define SBP2_ORB_DEBUG(fmt, args...) do {} while (0) +#define outstanding_orb_incr do {} while (0) +#define outstanding_orb_decr do {} while (0) #endif #ifdef CONFIG_IEEE1394_SBP2_DEBUG_DMA @@ -217,8 +217,8 @@ static u32 global_outstanding_command_orbs = 0; --global_outstanding_dmas, ## args) static u32 global_outstanding_dmas = 0; #else -#define SBP2_DMA_ALLOC(fmt, args...) -#define SBP2_DMA_FREE(fmt, args...) +#define SBP2_DMA_ALLOC(fmt, args...) do {} while (0) +#define SBP2_DMA_FREE(fmt, args...) do {} while (0) #endif #if CONFIG_IEEE1394_SBP2_DEBUG >= 2 @@ -232,7 +232,7 @@ static u32 global_outstanding_dmas = 0; #define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args) #define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args) #else -#define SBP2_DEBUG(fmt, args...) +#define SBP2_DEBUG(fmt, args...) do {} while (0) #define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args) #define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args) #define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args) @@ -375,8 +375,8 @@ static inline void sbp2util_cpu_to_be32_buffer(void *buffer, int length) } #else /* BIG_ENDIAN */ /* Why waste the cpu cycles? */ -#define sbp2util_be32_to_cpu_buffer(x,y) -#define sbp2util_cpu_to_be32_buffer(x,y) +#define sbp2util_be32_to_cpu_buffer(x,y) do {} while (0) +#define sbp2util_cpu_to_be32_buffer(x,y) do {} while (0) #endif #ifdef CONFIG_IEEE1394_SBP2_PACKET_DUMP @@ -412,7 +412,7 @@ static void sbp2util_packet_dump(void *buffer, int length, char *dump_name, return; } #else -#define sbp2util_packet_dump(w,x,y,z) +#define sbp2util_packet_dump(w,x,y,z) do {} while (0) #endif static DECLARE_WAIT_QUEUE_HEAD(access_wq); diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c index af78b840dc2..9bc65059cc6 100644 --- a/drivers/ieee1394/video1394.c +++ b/drivers/ieee1394/video1394.c @@ -129,7 +129,7 @@ struct file_ctx { #define DBGMSG(card, fmt, args...) \ printk(KERN_INFO "video1394_%d: " fmt "\n" , card , ## args) #else -#define DBGMSG(card, fmt, args...) +#define DBGMSG(card, fmt, args...) do {} while (0) #endif /* print general (card independent) information */ -- cgit v1.2.3 From 2a874182842c6a70f245b7f1ad859f9152517951 Mon Sep 17 00:00:00 2001 From: Alexey Dobriyan Date: Fri, 11 Aug 2006 16:46:14 -0700 Subject: CONFIG_PM=n slim: drivers/ieee1394/ohci1394.c Remove some code which is unneeded if CONFIG_PM=n. Signed-off-by: Alexey Dobriyan Signed-off-by: Andrew Morton Signed-off-by: Stefan Richter --- drivers/ieee1394/ohci1394.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index ea14c831ff4..9890ab73bb5 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c @@ -3530,7 +3530,7 @@ static void ohci1394_pci_remove(struct pci_dev *pdev) put_device(dev); } - +#ifdef CONFIG_PM static int ohci1394_pci_resume (struct pci_dev *pdev) { #ifdef CONFIG_PPC_PMAC @@ -3568,7 +3568,7 @@ static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) return 0; } - +#endif #define PCI_CLASS_FIREWIRE_OHCI ((PCI_CLASS_SERIAL_FIREWIRE << 8) | 0x10) @@ -3591,8 +3591,10 @@ static struct pci_driver ohci1394_pci_driver = { .id_table = ohci1394_pci_tbl, .probe = ohci1394_pci_probe, .remove = ohci1394_pci_remove, +#ifdef CONFIG_PM .resume = ohci1394_pci_resume, .suspend = ohci1394_pci_suspend, +#endif }; /*********************************** -- cgit v1.2.3 From 09ee67abe997ee95cd3f6cc552fa9532bc722d83 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 14 Aug 2006 18:43:00 +0200 Subject: ieee1394: sbp2: handle "sbp2util_node_write_no_wait failed" Fix for http://bugzilla.kernel.org/show_bug.cgi?id=6948 Because sbp2 writes to the target's fetch agent's registers from within atomic context, it cannot sleep to guaranteedly get a free transaction label. This may repeatedly lead to "sbp2util_node_write_no_wait failed" and consequently to SCSI command abortion after timeout. A likely cause is that many queue_command softirqs may occur before khpsbpkt (the ieee1394 driver's thread which cleans up after finished transactions) is woken up to recycle tlabels. Sbp2 now schedules a workqueue job whenever sbp2_link_orb_command fails in sbp2util_node_write_no_wait. The job will reliably get a transaction label because it can sleep. We use the kernel-wide shared workqueue because it is unlikely that the job itself actually needs to sleep. In the improbable case that it has to sleep, it doesn't need to sleep long since the standard transaction timeout is 100ms. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 71 +++++++++++++++++++++++++++++++++++++++++++++---- drivers/ieee1394/sbp2.h | 3 +++ 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 668b4512def..c4d30a7b8b1 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -465,6 +465,44 @@ static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr, return 0; } +static void sbp2util_notify_fetch_agent(struct scsi_id_instance_data *scsi_id, + u64 offset, quadlet_t *data, size_t len) +{ + /* + * There is a small window after a bus reset within which the node + * entry's generation is current but the reconnect wasn't completed. + */ + if (atomic_read(&scsi_id->unfinished_reset)) + return; + + if (hpsb_node_write(scsi_id->ne, + scsi_id->sbp2_command_block_agent_addr + offset, + data, len)) + SBP2_ERR("sbp2util_notify_fetch_agent failed."); + /* + * Now accept new SCSI commands, unless a bus reset happended during + * hpsb_node_write. + */ + if (!atomic_read(&scsi_id->unfinished_reset)) + scsi_unblock_requests(scsi_id->scsi_host); +} + +static void sbp2util_write_orb_pointer(void *p) +{ + quadlet_t data[2]; + + data[0] = ORB_SET_NODE_ID( + ((struct scsi_id_instance_data *)p)->hi->host->node_id); + data[1] = ((struct scsi_id_instance_data *)p)->last_orb_dma; + sbp2util_cpu_to_be32_buffer(data, 8); + sbp2util_notify_fetch_agent(p, SBP2_ORB_POINTER_OFFSET, data, 8); +} + +static void sbp2util_write_doorbell(void *p) +{ + sbp2util_notify_fetch_agent(p, SBP2_DOORBELL_OFFSET, NULL, 4); +} + /* * This function is called to create a pool of command orbs used for * command processing. It is called when a new sbp2 device is detected. @@ -712,6 +750,7 @@ static int sbp2_remove(struct device *dev) sbp2scsi_complete_all_commands(scsi_id, DID_NO_CONNECT); /* scsi_remove_device() will trigger shutdown functions of SCSI * highlevel drivers which would deadlock if blocked. */ + atomic_set(&scsi_id->unfinished_reset, 0); scsi_unblock_requests(scsi_id->scsi_host); } sdev = scsi_id->sdev; @@ -765,6 +804,7 @@ static int sbp2_update(struct unit_directory *ud) /* Make sure we unblock requests (since this is likely after a bus * reset). */ + atomic_set(&scsi_id->unfinished_reset, 0); scsi_unblock_requests(scsi_id->scsi_host); return 0; @@ -795,6 +835,8 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed); INIT_LIST_HEAD(&scsi_id->scsi_list); spin_lock_init(&scsi_id->sbp2_command_orb_lock); + atomic_set(&scsi_id->unfinished_reset, 0); + INIT_WORK(&scsi_id->protocol_work, NULL, NULL); ud->device.driver_data = scsi_id; @@ -879,8 +921,10 @@ static void sbp2_host_reset(struct hpsb_host *host) hi = hpsb_get_hostinfo(&sbp2_highlevel, host); if (hi) { - list_for_each_entry(scsi_id, &hi->scsi_ids, scsi_list) + list_for_each_entry(scsi_id, &hi->scsi_ids, scsi_list) { + atomic_set(&scsi_id->unfinished_reset, 1); scsi_block_requests(scsi_id->scsi_host); + } } } @@ -1032,7 +1076,7 @@ static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id) scsi_remove_host(scsi_id->scsi_host); scsi_host_put(scsi_id->scsi_host); } - + flush_scheduled_work(); sbp2util_remove_command_orb_pool(scsi_id); list_del(&scsi_id->scsi_list); @@ -1661,6 +1705,10 @@ static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait) SBP2_DEBUG_ENTER(); + cancel_delayed_work(&scsi_id->protocol_work); + if (wait) + flush_scheduled_work(); + data = ntohl(SBP2_AGENT_RESET_DATA); addr = scsi_id->sbp2_command_block_agent_addr + SBP2_AGENT_RESET_OFFSET; @@ -1982,9 +2030,22 @@ static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, SBP2_ORB_DEBUG("write to %s register, command orb %p", last_orb ? "DOORBELL" : "ORB_POINTER", command_orb); - if (sbp2util_node_write_no_wait(scsi_id->ne, addr, data, length)) - SBP2_ERR("sbp2util_node_write_no_wait failed.\n"); - /* We rely on SCSI EH to deal with _node_write_ failures. */ + if (sbp2util_node_write_no_wait(scsi_id->ne, addr, data, length)) { + /* + * sbp2util_node_write_no_wait failed. We certainly ran out + * of transaction labels, perhaps just because there were no + * context switches which gave khpsbpkt a chance to collect + * free tlabels. Try again in non-atomic context. If necessary, + * the workqueue job will sleep to guaranteedly get a tlabel. + * We do not accept new commands until the job is over. + */ + scsi_block_requests(scsi_id->scsi_host); + PREPARE_WORK(&scsi_id->protocol_work, + last_orb ? sbp2util_write_doorbell: + sbp2util_write_orb_pointer, + scsi_id); + schedule_work(&scsi_id->protocol_work); + } } /* diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h index 89098fe565e..1c9fe422cf4 100644 --- a/drivers/ieee1394/sbp2.h +++ b/drivers/ieee1394/sbp2.h @@ -346,6 +346,9 @@ struct scsi_id_instance_data { /* Device specific workarounds/brokeness */ unsigned workarounds; + + atomic_t unfinished_reset; + struct work_struct protocol_work; }; /* Sbp2 host data structure (one per IEEE1394 host) */ -- cgit v1.2.3 From 1f427e8055b1ab408395d6da421d93783120484c Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 14 Aug 2006 18:44:00 +0200 Subject: ieee1394: sbp2: safer agent reset in error handlers The scsi_host_template's eh_abort_handler and eh_device_reset_handler are allowed to sleep. Use this to run sbp2_agent_reset in the more reliable mode which returns _after_ its write transaction was finished. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index c4d30a7b8b1..b5bcca36d43 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -2578,7 +2578,7 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt) /* * Initiate a fetch agent reset. */ - sbp2_agent_reset(scsi_id, 0); + sbp2_agent_reset(scsi_id, 1); sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); } @@ -2597,7 +2597,7 @@ static int sbp2scsi_reset(struct scsi_cmnd *SCpnt) if (sbp2util_node_is_available(scsi_id)) { SBP2_ERR("Generating sbp2 fetch agent reset"); - sbp2_agent_reset(scsi_id, 0); + sbp2_agent_reset(scsi_id, 1); } return SUCCESS; -- cgit v1.2.3 From 4fc383c09d14783ca7d7e97e2134abbe7dc43230 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 14 Aug 2006 18:46:00 +0200 Subject: ieee1394: sbp2: recheck node generation in sbp2_update While sbp2_update() is doing its duties after a bus reset, another reset could happen. Don't accept new requests until the next undisturbed sbp2_update() or until sbp2_remove(). Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index b5bcca36d43..5440cd05026 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -802,11 +802,12 @@ static int sbp2_update(struct unit_directory *ud) */ sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); - /* Make sure we unblock requests (since this is likely after a bus - * reset). */ - atomic_set(&scsi_id->unfinished_reset, 0); - scsi_unblock_requests(scsi_id->scsi_host); - + /* Accept new commands unless there was another bus reset in the + * meantime. */ + if (hpsb_node_entry_valid(scsi_id->ne)) { + atomic_set(&scsi_id->unfinished_reset, 0); + scsi_unblock_requests(scsi_id->scsi_host); + } return 0; } -- cgit v1.2.3 From abbca103a02ff0e87569c38be518f9cb2d6baabc Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 14 Aug 2006 18:51:00 +0200 Subject: ieee1394: sbp2: better handling of transport errors If the target signals a transport failure via status block, complete the request with DID_BUSY to indicate to the SCSI subsystem that the command may succeed when retried. Also log diagnostic information if the status block shows a transport related problem. It may point to hardware faults. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 16 +++++++++++----- drivers/ieee1394/sbp2.h | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 5440cd05026..6b3350f71a8 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -2213,28 +2213,34 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); if (SCpnt) { - if (STATUS_TEST_RS(sb->ORB_offset_hi_misc)) + u32 h = sb->ORB_offset_hi_misc; + u32 r = STATUS_GET_RESP(h); + + if (r != RESP_STATUS_REQUEST_COMPLETE) { + SBP2_WARN("resp 0x%x, sbp_status 0x%x", + r, STATUS_GET_SBP_STATUS(h)); scsi_status = + r == RESP_STATUS_TRANSPORT_FAILURE ? + SBP2_SCSI_STATUS_BUSY : SBP2_SCSI_STATUS_COMMAND_TERMINATED; + } /* * See if the target stored any scsi status information. */ - if (STATUS_GET_LEN(sb->ORB_offset_hi_misc) > 1) { + if (STATUS_GET_LEN(h) > 1) { SBP2_DEBUG("CHECK CONDITION"); scsi_status = sbp2_status_to_sense_data( (unchar *)sb, SCpnt->sense_buffer); } - /* * Check to see if the dead bit is set. If so, we'll * have to initiate a fetch agent reset. */ - if (STATUS_TEST_D(sb->ORB_offset_hi_misc)) { + if (STATUS_TEST_DEAD(h)) { SBP2_DEBUG("Dead bit set - " "initiating fetch agent reset"); sbp2_agent_reset(scsi_id, 0); } - SBP2_ORB_DEBUG("completing command orb %p", &command->command_orb); } diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h index 1c9fe422cf4..34c52bf4fa3 100644 --- a/drivers/ieee1394/sbp2.h +++ b/drivers/ieee1394/sbp2.h @@ -181,11 +181,11 @@ struct sbp2_unrestricted_page_table { #define SBP2_SCSI_STATUS_SELECTION_TIMEOUT 0xff #define STATUS_GET_SRC(value) (((value) >> 30) & 0x3) +#define STATUS_GET_RESP(value) (((value) >> 28) & 0x3) #define STATUS_GET_LEN(value) (((value) >> 24) & 0x7) +#define STATUS_GET_SBP_STATUS(value) (((value) >> 16) & 0xff) #define STATUS_GET_ORB_OFFSET_HI(value) ((value) & 0x0000ffff) -#define STATUS_TEST_D(value) ((value) & 0x08000000) -/* test 'resp' | 'sbp2_status' */ -#define STATUS_TEST_RS(value) ((value) & 0x30ff0000) +#define STATUS_TEST_DEAD(value) ((value) & 0x08000000) /* test 'resp' | 'dead' | 'sbp2_status' */ #define STATUS_TEST_RDS(value) ((value) & 0x38ff0000) -- cgit v1.2.3 From 902abed1587805fe8513e10aef6643f58a6de0a6 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 14 Aug 2006 18:56:00 +0200 Subject: ieee1394: sbp2: update includes Remove unused includes. Add missing includes, i.e. explicitly include all used headers. Sort includes alphabetically. Replace one call to signal_pending(current) to avoid to include headers just for this line. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 6b3350f71a8..3cb6b479b2e 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -38,31 +38,36 @@ * but the code needs additional debugging. */ +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include +#include +#include #include -#include -#include -#include #include -#include +#include +#include #include +#include +#include + +#ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA +#include /* for bus_to_virt */ +#endif #include #include @@ -71,13 +76,14 @@ #include #include "csr1212.h" +#include "highlevel.h" +#include "hosts.h" #include "ieee1394.h" -#include "ieee1394_types.h" #include "ieee1394_core.h" -#include "nodemgr.h" -#include "hosts.h" -#include "highlevel.h" +#include "ieee1394_hotplug.h" #include "ieee1394_transactions.h" +#include "ieee1394_types.h" +#include "nodemgr.h" #include "sbp2.h" /* @@ -1011,8 +1017,7 @@ static int sbp2_start_device(struct scsi_id_instance_data *scsi_id) * connected to the sbp2 device being removed. That host would * have a certain amount of time to relogin before the sbp2 device * allows someone else to login instead. One second makes sense. */ - msleep_interruptible(1000); - if (signal_pending(current)) { + if (msleep_interruptible(1000)) { sbp2_remove_device(scsi_id); return -EINTR; } -- cgit v1.2.3 From 2cccbb555c77e641de9008660e08bdf17fc4206a Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 14 Aug 2006 18:59:00 +0200 Subject: ieee1394: sbp2: prevent rare deadlock in shutdown Scsi_remove_device() may go into uninterruptible sleep if blocked. Therefore sbp2_remove() unblocks the Scsi_Host before the device is requested to be removed. But there could be another 1394 bus reset after that which would block the host again. The 1394 subsystem won't call sbp2_update() concurrently to sbp2_remove(), which is why there is no chance for sbp2_remove() to be unblocked by sbp2_update(). The fix is to tell sbp2's bus reset handler when a device is to be shut down so that it skips scsi_block_requests() on that host. As before, any new commands after a reset without reconnect will be failed quickly by sbp2scsi_queuecommand(). In the long term, means to go without scsi_block_requests() should be found. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 21 +++++++++++---------- drivers/ieee1394/sbp2.h | 9 ++++++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 3cb6b479b2e..017259cc34f 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -478,7 +478,7 @@ static void sbp2util_notify_fetch_agent(struct scsi_id_instance_data *scsi_id, * There is a small window after a bus reset within which the node * entry's generation is current but the reconnect wasn't completed. */ - if (atomic_read(&scsi_id->unfinished_reset)) + if (unlikely(atomic_read(&scsi_id->state) == SBP2LU_STATE_IN_RESET)) return; if (hpsb_node_write(scsi_id->ne, @@ -489,7 +489,7 @@ static void sbp2util_notify_fetch_agent(struct scsi_id_instance_data *scsi_id, * Now accept new SCSI commands, unless a bus reset happended during * hpsb_node_write. */ - if (!atomic_read(&scsi_id->unfinished_reset)) + if (likely(atomic_read(&scsi_id->state) != SBP2LU_STATE_IN_RESET)) scsi_unblock_requests(scsi_id->scsi_host); } @@ -756,7 +756,7 @@ static int sbp2_remove(struct device *dev) sbp2scsi_complete_all_commands(scsi_id, DID_NO_CONNECT); /* scsi_remove_device() will trigger shutdown functions of SCSI * highlevel drivers which would deadlock if blocked. */ - atomic_set(&scsi_id->unfinished_reset, 0); + atomic_set(&scsi_id->state, SBP2LU_STATE_IN_SHUTDOWN); scsi_unblock_requests(scsi_id->scsi_host); } sdev = scsi_id->sdev; @@ -811,7 +811,7 @@ static int sbp2_update(struct unit_directory *ud) /* Accept new commands unless there was another bus reset in the * meantime. */ if (hpsb_node_entry_valid(scsi_id->ne)) { - atomic_set(&scsi_id->unfinished_reset, 0); + atomic_set(&scsi_id->state, SBP2LU_STATE_RUNNING); scsi_unblock_requests(scsi_id->scsi_host); } return 0; @@ -842,7 +842,7 @@ static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed); INIT_LIST_HEAD(&scsi_id->scsi_list); spin_lock_init(&scsi_id->sbp2_command_orb_lock); - atomic_set(&scsi_id->unfinished_reset, 0); + atomic_set(&scsi_id->state, SBP2LU_STATE_RUNNING); INIT_WORK(&scsi_id->protocol_work, NULL, NULL); ud->device.driver_data = scsi_id; @@ -926,13 +926,14 @@ static void sbp2_host_reset(struct hpsb_host *host) struct scsi_id_instance_data *scsi_id; hi = hpsb_get_hostinfo(&sbp2_highlevel, host); - - if (hi) { - list_for_each_entry(scsi_id, &hi->scsi_ids, scsi_list) { - atomic_set(&scsi_id->unfinished_reset, 1); + if (!hi) + return; + list_for_each_entry(scsi_id, &hi->scsi_ids, scsi_list) + if (likely(atomic_read(&scsi_id->state) != + SBP2LU_STATE_IN_SHUTDOWN)) { + atomic_set(&scsi_id->state, SBP2LU_STATE_IN_RESET); scsi_block_requests(scsi_id->scsi_host); } - } } /* diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h index 34c52bf4fa3..abbe48e646c 100644 --- a/drivers/ieee1394/sbp2.h +++ b/drivers/ieee1394/sbp2.h @@ -347,10 +347,17 @@ struct scsi_id_instance_data { /* Device specific workarounds/brokeness */ unsigned workarounds; - atomic_t unfinished_reset; + atomic_t state; struct work_struct protocol_work; }; +/* For use in scsi_id_instance_data.state */ +enum sbp2lu_state_types { + SBP2LU_STATE_RUNNING, /* all normal */ + SBP2LU_STATE_IN_RESET, /* between bus reset and reconnect */ + SBP2LU_STATE_IN_SHUTDOWN /* when sbp2_remove was called */ +}; + /* Sbp2 host data structure (one per IEEE1394 host) */ struct sbp2scsi_host_info { struct hpsb_host *host; /* IEEE1394 host */ -- cgit v1.2.3 From b809289df06ff9453c1b19df74ea83aba311dfc6 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Wed, 30 Aug 2006 18:22:00 +0200 Subject: ieee1394: sbp2: more help in Kconfig Add some pointers to SCSI to the configuration menu item of sbp2. Signed-off-by: Stefan Richter --- drivers/ieee1394/Kconfig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/ieee1394/Kconfig b/drivers/ieee1394/Kconfig index 186737539cf..2769e505f05 100644 --- a/drivers/ieee1394/Kconfig +++ b/drivers/ieee1394/Kconfig @@ -120,12 +120,19 @@ config IEEE1394_VIDEO1394 this option only if you have an IEEE 1394 video device connected to an OHCI-1394 card. +comment "SBP-2 support (for storage devices) requires SCSI" + depends on IEEE1394 && SCSI=n + config IEEE1394_SBP2 tristate "SBP-2 support (Harddisks etc.)" depends on IEEE1394 && SCSI && (PCI || BROKEN) help - This option enables you to use SBP-2 devices connected to your IEEE - 1394 bus. SBP-2 devices include harddrives and DVD devices. + This option enables you to use SBP-2 devices connected to an IEEE + 1394 bus. SBP-2 devices include storage devices like harddisks and + DVD drives, also some other FireWire devices like scanners. + + You should also enable support for disks, CD-ROMs, etc. in the SCSI + configuration section. config IEEE1394_SBP2_PHYS_DMA bool "Enable replacement for physical DMA in SBP2" -- cgit v1.2.3 From 9b516010863195ba7db061233a3eeffe779130e8 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Wed, 6 Sep 2006 19:04:00 +0200 Subject: ieee1394: nodemgr: fix rwsem recursion nodemgr_update_pdrv grabbed an rw semaphore (as reader) which was already taken by its caller's caller, nodemgr_probe_ne (as reader too). Reported by Miles Lane, call path pointed out by Arjan van de Ven. FIXME: Shouldn't we rather use class->sem there, not class->subsys.rwsem? Signed-off-by: Stefan Richter --- drivers/ieee1394/nodemgr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index eabc51b23c0..f087f7e2b69 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -1316,6 +1316,7 @@ static void nodemgr_node_scan(struct host_info *hi, int generation) } +/* Caller needs to hold nodemgr_ud_class.subsys.rwsem as reader. */ static void nodemgr_suspend_ne(struct node_entry *ne) { struct class_device *cdev; @@ -1368,15 +1369,14 @@ static void nodemgr_resume_ne(struct node_entry *ne) } +/* Caller needs to hold nodemgr_ud_class.subsys.rwsem as reader. */ static void nodemgr_update_pdrv(struct node_entry *ne) { struct unit_directory *ud; struct hpsb_protocol_driver *pdrv; - struct class *class = &nodemgr_ud_class; struct class_device *cdev; - down_read(&class->subsys.rwsem); - list_for_each_entry(cdev, &class->children, node) { + list_for_each_entry(cdev, &nodemgr_ud_class.children, node) { ud = container_of(cdev, struct unit_directory, class_dev); if (ud->ne != ne || !ud->device.driver) continue; @@ -1389,7 +1389,6 @@ static void nodemgr_update_pdrv(struct node_entry *ne) up_write(&ud->device.bus->subsys.rwsem); } } - up_read(&class->subsys.rwsem); } @@ -1420,6 +1419,8 @@ static void nodemgr_irm_write_bc(struct node_entry *ne, int generation) } +/* Caller needs to hold nodemgr_ud_class.subsys.rwsem as reader because the + * calls to nodemgr_update_pdrv() and nodemgr_suspend_ne() here require it. */ static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int generation) { struct device *dev; -- cgit v1.2.3 From a1842be898a2295ef513ed0a5d26f65d6283cb11 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Wed, 6 Sep 2006 19:04:00 +0200 Subject: ieee1394: nodemgr: grab class.subsys.rwsem in nodemgr_resume_ne nodemgr_resume_ne was iterating over nodemgr_ud_class.children without protection by nodemgr_ud_class.subsys.rwsem. FIXME: Shouldn't we rather use class->sem there, not class->subsys.rwsem? Signed-off-by: Stefan Richter --- drivers/ieee1394/nodemgr.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c index f087f7e2b69..3e7974c5744 100644 --- a/drivers/ieee1394/nodemgr.c +++ b/drivers/ieee1394/nodemgr.c @@ -1352,6 +1352,7 @@ static void nodemgr_resume_ne(struct node_entry *ne) ne->in_limbo = 0; device_remove_file(&ne->device, &dev_attr_ne_in_limbo); + down_read(&nodemgr_ud_class.subsys.rwsem); down_read(&ne->device.bus->subsys.rwsem); list_for_each_entry(cdev, &nodemgr_ud_class.children, node) { ud = container_of(cdev, struct unit_directory, class_dev); @@ -1363,6 +1364,7 @@ static void nodemgr_resume_ne(struct node_entry *ne) ud->device.driver->resume(&ud->device); } up_read(&ne->device.bus->subsys.rwsem); + up_read(&nodemgr_ud_class.subsys.rwsem); HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]", NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid); -- cgit v1.2.3 From 98e238cd42be6c0852da519303cf0182690f8d9f Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Thu, 7 Sep 2006 01:06:00 +0200 Subject: ieee1394: sbp2: don't prefer MODE SENSE 10 In the old days, sbp2 used to coerce all MODE SENSE commands into the 10 bytes version. When all command set conversions were removed from sbp2 several months ago, sdev->use_10_for_ms = 1 was added. Meaning, higher SCSI layers preferred the 10 bytes version but would try the 6 bytes version if the former failed. Recently, a problem with the 10 bytes version was discovered. An Initio INIC-1530 firmware accepted the 10 bytes version but replied with bogus data, showing the HDD incorrectly as write-protected. Since RBC actually mandates MODE SENSE (6), I checked which version was sent by Windows XP and Mac OS X 10.3 to an SBP-2 target hosted by Linux --- it was the 6 bytes version. (Exception: OS X sent the 10 bytes version to an MMC target. RBC and SBC got MODE SENSE (6).) Therefore, drop the use_10_for_ms flag from sbp2. Now the upper layers will try MODE SENSE (6) before MODE SENSE (10) on all SBP-2 devices. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index 017259cc34f..f192596329e 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -2528,7 +2528,6 @@ static int sbp2scsi_slave_configure(struct scsi_device *sdev) blk_queue_dma_alignment(sdev->request_queue, (512 - 1)); sdev->use_10_for_rw = 1; - sdev->use_10_for_ms = 1; if (sdev->type == TYPE_DISK && scsi_id->workarounds & SBP2_WORKAROUND_MODE_SENSE_8) -- cgit v1.2.3 From cf82703dc6f8197341ca6be33cd38e80332685f0 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Thu, 7 Sep 2006 15:52:00 +0200 Subject: ieee1394: ohci1394: fix endianess bug in debug message The transaction labels were misprinted int the debug printk "Packet received from node..." due two byte-swapping once too often. Affected were big endian machines, except UniNorth based ones. Fix tested by Wolfgang Pfeiffer. Signed-off-by: Stefan Richter --- drivers/ieee1394/ohci1394.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index 9890ab73bb5..4622c99c12f 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c @@ -2739,7 +2739,7 @@ static void dma_rcv_tasklet (unsigned long data) (cond_le32_to_cpu(d->spb[length/4-1], ohci->no_swap_incoming)>>16)&0x1f, (cond_le32_to_cpu(d->spb[length/4-1], ohci->no_swap_incoming)>>21)&0x3, tcode, length, d->ctx, - (cond_le32_to_cpu(d->spb[0], ohci->no_swap_incoming)>>10)&0x3f); + (d->spb[0]>>10)&0x3f); ack = (((cond_le32_to_cpu(d->spb[length/4-1], ohci->no_swap_incoming)>>16)&0x1f) == 0x11) ? 1 : 0; -- cgit v1.2.3 From 9531f13ae56b136d0ad09e6e5c8308a7dc58f3f0 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Thu, 7 Sep 2006 20:36:00 +0200 Subject: ieee1394: ohci1394: more obvious endianess handling Rename ohci1394's packet_swab to header_le32_to_cpu to better reflect what it actually does. Also, define a constant array as 'const' and check the array index properly. Signed-off-by: Stefan Richter --- drivers/ieee1394/ohci1394.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index 4622c99c12f..8d92246bdc3 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c @@ -181,36 +181,35 @@ static int alloc_dma_trm_ctx(struct ti_ohci *ohci, struct dma_trm_ctx *d, static void ohci1394_pci_remove(struct pci_dev *pdev); #ifndef __LITTLE_ENDIAN -static unsigned hdr_sizes[] = -{ +const static size_t hdr_sizes[] = { 3, /* TCODE_WRITEQ */ 4, /* TCODE_WRITEB */ 3, /* TCODE_WRITE_RESPONSE */ - 0, /* ??? */ + 0, /* reserved */ 3, /* TCODE_READQ */ 4, /* TCODE_READB */ 3, /* TCODE_READQ_RESPONSE */ 4, /* TCODE_READB_RESPONSE */ - 1, /* TCODE_CYCLE_START (???) */ + 1, /* TCODE_CYCLE_START */ 4, /* TCODE_LOCK_REQUEST */ 2, /* TCODE_ISO_DATA */ 4, /* TCODE_LOCK_RESPONSE */ + /* rest is reserved or link-internal */ }; -/* Swap headers */ -static inline void packet_swab(quadlet_t *data, int tcode) +static inline void header_le32_to_cpu(quadlet_t *data, unsigned char tcode) { - size_t size = hdr_sizes[tcode]; + size_t size; - if (tcode > TCODE_LOCK_RESPONSE || hdr_sizes[tcode] == 0) + if (unlikely(tcode >= ARRAY_SIZE(hdr_sizes))) return; + size = hdr_sizes[tcode]; while (size--) - data[size] = swab32(data[size]); + data[size] = le32_to_cpu(data[size]); } #else -/* Don't waste cycles on same sex byte swaps */ -#define packet_swab(w,x) do {} while (0) +#define header_le32_to_cpu(w,x) do {} while (0) #endif /* !LITTLE_ENDIAN */ /*********************************** @@ -701,7 +700,7 @@ static void insert_packet(struct ti_ohci *ohci, d->prg_cpu[idx]->data[2] = packet->header[2]; d->prg_cpu[idx]->data[3] = packet->header[3]; } - packet_swab(d->prg_cpu[idx]->data, packet->tcode); + header_le32_to_cpu(d->prg_cpu[idx]->data, packet->tcode); } if (packet->data_size) { /* block transmit */ @@ -777,7 +776,7 @@ static void insert_packet(struct ti_ohci *ohci, d->prg_cpu[idx]->data[0] = packet->speed_code<<16 | (packet->header[0] & 0xFFFF); d->prg_cpu[idx]->data[1] = packet->header[0] & 0xFFFF0000; - packet_swab(d->prg_cpu[idx]->data, packet->tcode); + header_le32_to_cpu(d->prg_cpu[idx]->data, packet->tcode); d->prg_cpu[idx]->begin.control = cpu_to_le32(DMA_CTL_OUTPUT_MORE | @@ -2731,7 +2730,7 @@ static void dma_rcv_tasklet (unsigned long data) * bus reset. We always ignore it. */ if (tcode != OHCI1394_TCODE_PHY) { if (!ohci->no_swap_incoming) - packet_swab(d->spb, tcode); + header_le32_to_cpu(d->spb, tcode); DBGMSG("Packet received from node" " %d ack=0x%02X spd=%d tcode=0x%X" " length=%d ctx=%d tlabel=%d", -- cgit v1.2.3 From f0645e7720e0baacbde61d7d1f0180309451c695 Mon Sep 17 00:00:00 2001 From: Pavel Machek Date: Sun, 17 Sep 2006 19:39:06 +0200 Subject: set power state of firewire host during suspend Put firewire host controller in PCI Dx state for system suspend. (I was not able to measure any power savings, but it sounds like right thing to do, anyway.) Signed-off-by: Pavel Machek Update by stefanr: Shuffle with existing PPC_PMAC code. Set power state in the resume hook too. Signed-off-by: Stefan Richter --- drivers/ieee1394/ohci1394.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index 8d92246bdc3..54d686aed39 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c @@ -3532,6 +3532,7 @@ static void ohci1394_pci_remove(struct pci_dev *pdev) #ifdef CONFIG_PM static int ohci1394_pci_resume (struct pci_dev *pdev) { +/* PowerMac resume code comes first */ #ifdef CONFIG_PPC_PMAC if (machine_is(powermac)) { struct device_node *of_node; @@ -3543,17 +3544,19 @@ static int ohci1394_pci_resume (struct pci_dev *pdev) } #endif /* CONFIG_PPC_PMAC */ + pci_set_power_state(pdev, PCI_D0); pci_restore_state(pdev); pci_enable_device(pdev); return 0; } - static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) { pci_save_state(pdev); + pci_set_power_state(pdev, pci_choose_state(pdev, state)); +/* PowerMac suspend code comes last */ #ifdef CONFIG_PPC_PMAC if (machine_is(powermac)) { struct device_node *of_node; @@ -3563,11 +3566,10 @@ static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) if (of_node) pmac_call_feature(PMAC_FTR_1394_ENABLE, of_node, 0, 0); } -#endif - +#endif /* CONFIG_PPC_PMAC */ return 0; } -#endif +#endif /* CONFIG_PM */ #define PCI_CLASS_FIREWIRE_OHCI ((PCI_CLASS_SERIAL_FIREWIRE << 8) | 0x10) -- cgit v1.2.3 From ea6104c22468239083857fa07425c312b1ecb424 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sun, 17 Sep 2006 19:41:45 +0200 Subject: ieee1394: ohci1394: check for errors in suspend or resume Some of the suspend and resume litany may fail. Tell the PCI core about it. Signed-off-by: Stefan Richter --- drivers/ieee1394/ohci1394.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index 54d686aed39..8fd0030475b 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c @@ -3546,15 +3546,19 @@ static int ohci1394_pci_resume (struct pci_dev *pdev) pci_set_power_state(pdev, PCI_D0); pci_restore_state(pdev); - pci_enable_device(pdev); - - return 0; + return pci_enable_device(pdev); } static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) { - pci_save_state(pdev); - pci_set_power_state(pdev, pci_choose_state(pdev, state)); + int err; + + err = pci_save_state(pdev); + if (err) + goto out; + err = pci_set_power_state(pdev, pci_choose_state(pdev, state)); + if (err) + goto out; /* PowerMac suspend code comes last */ #ifdef CONFIG_PPC_PMAC @@ -3567,7 +3571,8 @@ static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) pmac_call_feature(PMAC_FTR_1394_ENABLE, of_node, 0, 0); } #endif /* CONFIG_PPC_PMAC */ - return 0; +out: + return err; } #endif /* CONFIG_PM */ -- cgit v1.2.3 From 87730d045913f28e636cf53ad35950069a85c7f2 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sat, 16 Sep 2006 12:24:00 +0200 Subject: MAINTAINERS: updates to IEEE 1394 subsystem maintainership - Stefan Richter snatches Jody's place - update path to linux1394.org's repo - remove now redundant entries of ohci1394 and sbp2 - promote eth1394 from Orphaned to Odd Fixes - Stefan takes patches to pcilynx but doesn't have the hardware Signed-off-by: Stefan Richter --- MAINTAINERS | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index 25cd7073a20..efc33baa49b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1365,36 +1365,29 @@ M: Gadi Oxman L: linux-kernel@vger.kernel.org S: Maintained -IEEE 1394 ETHERNET (eth1394) -L: linux1394-devel@lists.sourceforge.net -W: http://www.linux1394.org/ -S: Orphan - IEEE 1394 SUBSYSTEM P: Ben Collins M: bcollins@debian.org -P: Jody McIntyre -M: scjody@modernduck.com +P: Stefan Richter +M: stefanr@s5r6.in-berlin.de L: linux1394-devel@lists.sourceforge.net W: http://www.linux1394.org/ -T: git kernel.org:/pub/scm/linux/kernel/git/scjody/ieee1394.git +T: git kernel.org:/pub/scm/linux/kernel/git/ieee1394/linux1394-2.6.git S: Maintained -IEEE 1394 OHCI DRIVER -P: Ben Collins -M: bcollins@debian.org -P: Jody McIntyre -M: scjody@modernduck.com +IEEE 1394 IPV4 DRIVER (eth1394) +P: Stefan Richter +M: stefanr@s5r6.in-berlin.de L: linux1394-devel@lists.sourceforge.net -W: http://www.linux1394.org/ -S: Maintained +S: Odd Fixes IEEE 1394 PCILYNX DRIVER P: Jody McIntyre M: scjody@modernduck.com +P: Stefan Richter +M: stefanr@s5r6.in-berlin.de L: linux1394-devel@lists.sourceforge.net -W: http://www.linux1394.org/ -S: Maintained +S: Odd Fixes IEEE 1394 RAW I/O DRIVER P: Ben Collins @@ -1402,16 +1395,6 @@ M: bcollins@debian.org P: Dan Dennedy M: dan@dennedy.org L: linux1394-devel@lists.sourceforge.net -W: http://www.linux1394.org/ -S: Maintained - -IEEE 1394 SBP2 -P: Ben Collins -M: bcollins@debian.org -P: Stefan Richter -M: stefanr@s5r6.in-berlin.de -L: linux1394-devel@lists.sourceforge.net -W: http://www.linux1394.org/ S: Maintained IMS TWINTURBO FRAMEBUFFER DRIVER -- cgit v1.2.3 From c394f1eafef61c6666f5876afde6110a276c4c9f Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Mon, 7 Aug 2006 20:48:00 +0200 Subject: ieee1394: sbp2: enable auto spin-up for all SBP-2 devices This is a follow-up to patch "ieee1394: sbp2: enable auto spin-up for Maxtor disks". When I 'ejected' an OXUF922 based HDD from a Mac OS X box, it was spun down by the Mac and did not spin up by itself when attached to a Linux box right after that. The first SCSI command that required the bridge to access the drive ended in sda:<6>sd 18:0:0:0: Device not ready: <6>: Current: sense key: Not Ready Additional sense: Logical unit not ready, initializing cmd. required Therefore the flag which instructs scsi_mod to send START STOP UNIT with START=1 ("make medium ready") after such a condition is now enabled unconditionally for all FireWire storage devices. Signed-off-by: Stefan Richter --- drivers/ieee1394/sbp2.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c index f192596329e..6986ac18828 100644 --- a/drivers/ieee1394/sbp2.c +++ b/drivers/ieee1394/sbp2.c @@ -2515,6 +2515,7 @@ static int sbp2scsi_slave_alloc(struct scsi_device *sdev) (struct scsi_id_instance_data *)sdev->host->hostdata[0]; scsi_id->sdev = sdev; + sdev->allow_restart = 1; if (scsi_id->workarounds & SBP2_WORKAROUND_INQUIRY_36) sdev->inquiry_len = 36; @@ -2534,9 +2535,6 @@ static int sbp2scsi_slave_configure(struct scsi_device *sdev) sdev->skip_ms_page_8 = 1; if (scsi_id->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) sdev->fix_capacity = 1; - if (scsi_id->ne->guid_vendor_id == 0x0010b9 && /* Maxtor's OUI */ - (sdev->type == TYPE_DISK || sdev->type == TYPE_RBC)) - sdev->allow_restart = 1; return 0; } -- cgit v1.2.3 From 1b2e2b73b4c84c918686c04a00724197036c0847 Mon Sep 17 00:00:00 2001 From: Russell King Date: Mon, 21 Aug 2006 17:06:38 +0100 Subject: [ARM] Cleanup arch/arm/mm a little Move top_pmd into arch/arm/mm/mm.h - nothing outside arch/arm/mm references it. Move the repeated definition of TOP_PTE into mm/mm.h, as well as a few function prototypes. Signed-off-by: Russell King --- arch/arm/mm/copypage-v4mc.c | 4 ++-- arch/arm/mm/copypage-v6.c | 4 ++-- arch/arm/mm/copypage-xscale.c | 4 ++-- arch/arm/mm/flush.c | 4 ++-- arch/arm/mm/init.c | 20 +++++++------------- arch/arm/mm/mm-armv.c | 14 ++------------ arch/arm/mm/mm.h | 19 +++++++++++++++++++ include/asm-arm/page.h | 3 --- 8 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 arch/arm/mm/mm.h diff --git a/arch/arm/mm/copypage-v4mc.c b/arch/arm/mm/copypage-v4mc.c index fc69dccdace..df1645e14b4 100644 --- a/arch/arm/mm/copypage-v4mc.c +++ b/arch/arm/mm/copypage-v4mc.c @@ -20,6 +20,8 @@ #include #include +#include "mm.h" + /* * 0xffff8000 to 0xffffffff is reserved for any ARM architecture * specific hacks for copying pages efficiently. @@ -27,8 +29,6 @@ #define minicache_pgprot __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | \ L_PTE_CACHEABLE) -#define TOP_PTE(x) pte_offset_kernel(top_pmd, x) - static DEFINE_SPINLOCK(minicache_lock); /* diff --git a/arch/arm/mm/copypage-v6.c b/arch/arm/mm/copypage-v6.c index 269ce6913ee..3d0d3a963d2 100644 --- a/arch/arm/mm/copypage-v6.c +++ b/arch/arm/mm/copypage-v6.c @@ -17,6 +17,8 @@ #include #include +#include "mm.h" + #if SHMLBA > 16384 #error FIX ME #endif @@ -24,8 +26,6 @@ #define from_address (0xffff8000) #define to_address (0xffffc000) -#define TOP_PTE(x) pte_offset_kernel(top_pmd, x) - static DEFINE_SPINLOCK(v6_lock); /* diff --git a/arch/arm/mm/copypage-xscale.c b/arch/arm/mm/copypage-xscale.c index 42a6ee255ce..84ebe0aa379 100644 --- a/arch/arm/mm/copypage-xscale.c +++ b/arch/arm/mm/copypage-xscale.c @@ -20,6 +20,8 @@ #include #include +#include "mm.h" + /* * 0xffff8000 to 0xffffffff is reserved for any ARM architecture * specific hacks for copying pages efficiently. @@ -29,8 +31,6 @@ #define minicache_pgprot __pgprot(L_PTE_PRESENT | L_PTE_YOUNG | \ L_PTE_CACHEABLE) -#define TOP_PTE(x) pte_offset_kernel(top_pmd, x) - static DEFINE_SPINLOCK(minicache_lock); /* diff --git a/arch/arm/mm/flush.c b/arch/arm/mm/flush.c index d438ce41cdd..1efb05c64db 100644 --- a/arch/arm/mm/flush.c +++ b/arch/arm/mm/flush.c @@ -15,12 +15,12 @@ #include #include +#include "mm.h" + #ifdef CONFIG_CPU_CACHE_VIPT #define ALIAS_FLUSH_START 0xffff4000 -#define TOP_PTE(x) pte_offset_kernel(top_pmd, x) - static void flush_pfn_alias(unsigned long pfn, unsigned long vaddr) { unsigned long to = ALIAS_FLUSH_START + (CACHE_COLOUR(vaddr) << PAGE_SHIFT); diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index fe3f7f62500..1099af6d470 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -25,6 +25,8 @@ #include #include +#include "mm.h" + DEFINE_PER_CPU(struct mmu_gather, mmu_gathers); extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; @@ -44,6 +46,11 @@ static struct meminfo meminfo __initdata = { 0, }; */ struct page *empty_zero_page; +/* + * The pmd table for the upper-most set of pages. + */ +pmd_t *top_pmd; + void show_mem(void) { int free = 0, total = 0, reserved = 0; @@ -83,16 +90,6 @@ void show_mem(void) printk("%d pages swap cached\n", cached); } -static inline pmd_t *pmd_off(pgd_t *pgd, unsigned long virt) -{ - return pmd_offset(pgd, virt); -} - -static inline pmd_t *pmd_off_k(unsigned long virt) -{ - return pmd_off(pgd_offset_k(virt), virt); -} - #define for_each_nodebank(iter,mi,no) \ for (iter = 0; iter < mi->nr_banks; iter++) \ if (mi->bank[iter].node == no) @@ -229,9 +226,6 @@ static __init void reserve_node_zero(pg_data_t *pgdat) reserve_bootmem_node(pgdat, PHYS_OFFSET, res_size); } -void __init build_mem_type_table(void); -void __init create_mapping(struct map_desc *md); - static unsigned long __init bootmem_init_node(int node, int initrd_node, struct meminfo *mi) { diff --git a/arch/arm/mm/mm-armv.c b/arch/arm/mm/mm-armv.c index 38769f5862b..ee9647823fa 100644 --- a/arch/arm/mm/mm-armv.c +++ b/arch/arm/mm/mm-armv.c @@ -23,6 +23,8 @@ #include +#include "mm.h" + #define CPOLICY_UNCACHED 0 #define CPOLICY_BUFFERED 1 #define CPOLICY_WRITETHROUGH 2 @@ -35,8 +37,6 @@ pgprot_t pgprot_kernel; EXPORT_SYMBOL(pgprot_kernel); -pmd_t *top_pmd; - struct cachepolicy { const char policy[16]; unsigned int cr_mask; @@ -142,16 +142,6 @@ __setup("noalign", noalign_setup); #define FIRST_KERNEL_PGD_NR (FIRST_USER_PGD_NR + USER_PTRS_PER_PGD) -static inline pmd_t *pmd_off(pgd_t *pgd, unsigned long virt) -{ - return pmd_offset(pgd, virt); -} - -static inline pmd_t *pmd_off_k(unsigned long virt) -{ - return pmd_off(pgd_offset_k(virt), virt); -} - /* * need to get a 16k page for level 1 */ diff --git a/arch/arm/mm/mm.h b/arch/arm/mm/mm.h new file mode 100644 index 00000000000..8d73ffbce8d --- /dev/null +++ b/arch/arm/mm/mm.h @@ -0,0 +1,19 @@ +/* the upper-most page table pointer */ +extern pmd_t *top_pmd; + +#define TOP_PTE(x) pte_offset_kernel(top_pmd, x) + +static inline pmd_t *pmd_off(pgd_t *pgd, unsigned long virt) +{ + return pmd_offset(pgd, virt); +} + +static inline pmd_t *pmd_off_k(unsigned long virt) +{ + return pmd_off(pgd_offset_k(virt), virt); +} + +struct map_desc; + +void __init build_mem_type_table(void); +void __init create_mapping(struct map_desc *md); diff --git a/include/asm-arm/page.h b/include/asm-arm/page.h index b721270b998..af9c3fe7588 100644 --- a/include/asm-arm/page.h +++ b/include/asm-arm/page.h @@ -174,9 +174,6 @@ typedef unsigned long pgprot_t; #endif /* STRICT_MM_TYPECHECKS */ -/* the upper-most page table pointer */ -extern pmd_t *top_pmd; - #endif /* CONFIG_MMU */ #include -- cgit v1.2.3 From d84b47115a04d9f6b0da777e8aa8cd930d5b6b8b Mon Sep 17 00:00:00 2001 From: Russell King Date: Mon, 21 Aug 2006 19:23:38 +0100 Subject: [ARM] Move mmu.c out of the way Rename mmu.c to context.c - it's the ARMv6 ASID context handling code rather than generic "mmu" handling code. Signed-off-by: Russell King --- arch/arm/mm/Makefile | 2 +- arch/arm/mm/context.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ arch/arm/mm/mmu.c | 45 --------------------------------------------- 3 files changed, 46 insertions(+), 46 deletions(-) create mode 100644 arch/arm/mm/context.c delete mode 100644 arch/arm/mm/mmu.c diff --git a/arch/arm/mm/Makefile b/arch/arm/mm/Makefile index 21a2770226e..1a1563f859a 100644 --- a/arch/arm/mm/Makefile +++ b/arch/arm/mm/Makefile @@ -33,7 +33,7 @@ obj-$(CONFIG_CPU_CACHE_V6) += cache-v6.o obj-$(CONFIG_CPU_COPY_V3) += copypage-v3.o obj-$(CONFIG_CPU_COPY_V4WT) += copypage-v4wt.o obj-$(CONFIG_CPU_COPY_V4WB) += copypage-v4wb.o -obj-$(CONFIG_CPU_COPY_V6) += copypage-v6.o mmu.o +obj-$(CONFIG_CPU_COPY_V6) += copypage-v6.o context.o obj-$(CONFIG_CPU_SA1100) += copypage-v4mc.o obj-$(CONFIG_CPU_XSCALE) += copypage-xscale.o obj-$(CONFIG_CPU_XSC3) += copypage-xsc3.o diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c new file mode 100644 index 00000000000..79e80020242 --- /dev/null +++ b/arch/arm/mm/context.c @@ -0,0 +1,45 @@ +/* + * linux/arch/arm/mm/context.c + * + * Copyright (C) 2002-2003 Deep Blue Solutions Ltd, all rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ +#include +#include +#include + +#include +#include + +unsigned int cpu_last_asid = { 1 << ASID_BITS }; + +/* + * We fork()ed a process, and we need a new context for the child + * to run in. We reserve version 0 for initial tasks so we will + * always allocate an ASID. + */ +void __init_new_context(struct task_struct *tsk, struct mm_struct *mm) +{ + mm->context.id = 0; +} + +void __new_context(struct mm_struct *mm) +{ + unsigned int asid; + + asid = ++cpu_last_asid; + if (asid == 0) + asid = cpu_last_asid = 1 << ASID_BITS; + + /* + * If we've used up all our ASIDs, we need + * to start a new version and flush the TLB. + */ + if ((asid & ~ASID_MASK) == 0) + flush_tlb_all(); + + mm->context.id = asid; +} diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c deleted file mode 100644 index 0d90227a0a3..00000000000 --- a/arch/arm/mm/mmu.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * linux/arch/arm/mm/mmu.c - * - * Copyright (C) 2002-2003 Deep Blue Solutions Ltd, all rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ -#include -#include -#include - -#include -#include - -unsigned int cpu_last_asid = { 1 << ASID_BITS }; - -/* - * We fork()ed a process, and we need a new context for the child - * to run in. We reserve version 0 for initial tasks so we will - * always allocate an ASID. - */ -void __init_new_context(struct task_struct *tsk, struct mm_struct *mm) -{ - mm->context.id = 0; -} - -void __new_context(struct mm_struct *mm) -{ - unsigned int asid; - - asid = ++cpu_last_asid; - if (asid == 0) - asid = cpu_last_asid = 1 << ASID_BITS; - - /* - * If we've used up all our ASIDs, we need - * to start a new version and flush the TLB. - */ - if ((asid & ~ASID_MASK) == 0) - flush_tlb_all(); - - mm->context.id = asid; -} -- cgit v1.2.3 From 7ad1bcb25c5623f1f87c50fdf2272f58ff91db5a Mon Sep 17 00:00:00 2001 From: Russell King Date: Sun, 27 Aug 2006 12:07:02 +0100 Subject: [ARM] Add ARM irqtrace support This adds support for irqtrace for lockdep on ARM. Signed-off-by: Russell King --- arch/arm/Kconfig | 4 ++ arch/arm/kernel/entry-armv.S | 13 +++++ include/asm-arm/irqflags.h | 132 +++++++++++++++++++++++++++++++++++++++++++ include/asm-arm/system.h | 125 +--------------------------------------- 4 files changed, 150 insertions(+), 124 deletions(-) create mode 100644 include/asm-arm/irqflags.h diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index f81a62380ad..d9376f048ed 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -51,6 +51,10 @@ config GENERIC_HARDIRQS bool default y +config TRACE_IRQFLAGS_SUPPORT + bool + default y + config HARDIRQS_SW_RESEND bool default y diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S index de4e3313790..bd623b73445 100644 --- a/arch/arm/kernel/entry-armv.S +++ b/arch/arm/kernel/entry-armv.S @@ -191,6 +191,9 @@ __dabt_svc: __irq_svc: svc_entry +#ifdef CONFIG_TRACE_IRQFLAGS + bl trace_hardirqs_off +#endif #ifdef CONFIG_PREEMPT get_thread_info tsk ldr r8, [tsk, #TI_PREEMPT] @ get preempt count @@ -211,6 +214,10 @@ preempt_return: #endif ldr r0, [sp, #S_PSR] @ irqs are already disabled msr spsr_cxsf, r0 +#ifdef CONFIG_TRACE_IRQFLAGS + tst r0, #PSR_I_BIT + bleq trace_hardirqs_on +#endif ldmia sp, {r0 - pc}^ @ load r0 - pc, cpsr .ltorg @@ -398,6 +405,9 @@ __dabt_usr: __irq_usr: usr_entry +#ifdef CONFIG_TRACE_IRQFLAGS + bl trace_hardirqs_off +#endif get_thread_info tsk #ifdef CONFIG_PREEMPT ldr r8, [tsk, #TI_PREEMPT] @ get preempt count @@ -412,6 +422,9 @@ __irq_usr: teq r0, r7 strne r0, [r0, -r0] #endif +#ifdef CONFIG_TRACE_IRQFLAGS + bl trace_hardirqs_on +#endif mov why, #0 b ret_to_user diff --git a/include/asm-arm/irqflags.h b/include/asm-arm/irqflags.h new file mode 100644 index 00000000000..6d09974e664 --- /dev/null +++ b/include/asm-arm/irqflags.h @@ -0,0 +1,132 @@ +#ifndef __ASM_ARM_IRQFLAGS_H +#define __ASM_ARM_IRQFLAGS_H + +#ifdef __KERNEL__ + +#include + +/* + * CPU interrupt mask handling. + */ +#if __LINUX_ARM_ARCH__ >= 6 + +#define raw_local_irq_save(x) \ + ({ \ + __asm__ __volatile__( \ + "mrs %0, cpsr @ local_irq_save\n" \ + "cpsid i" \ + : "=r" (x) : : "memory", "cc"); \ + }) + +#define raw_local_irq_enable() __asm__("cpsie i @ __sti" : : : "memory", "cc") +#define raw_local_irq_disable() __asm__("cpsid i @ __cli" : : : "memory", "cc") +#define local_fiq_enable() __asm__("cpsie f @ __stf" : : : "memory", "cc") +#define local_fiq_disable() __asm__("cpsid f @ __clf" : : : "memory", "cc") + +#else + +/* + * Save the current interrupt enable state & disable IRQs + */ +#define raw_local_irq_save(x) \ + ({ \ + unsigned long temp; \ + (void) (&temp == &x); \ + __asm__ __volatile__( \ + "mrs %0, cpsr @ local_irq_save\n" \ +" orr %1, %0, #128\n" \ +" msr cpsr_c, %1" \ + : "=r" (x), "=r" (temp) \ + : \ + : "memory", "cc"); \ + }) + +/* + * Enable IRQs + */ +#define raw_local_irq_enable() \ + ({ \ + unsigned long temp; \ + __asm__ __volatile__( \ + "mrs %0, cpsr @ local_irq_enable\n" \ +" bic %0, %0, #128\n" \ +" msr cpsr_c, %0" \ + : "=r" (temp) \ + : \ + : "memory", "cc"); \ + }) + +/* + * Disable IRQs + */ +#define raw_local_irq_disable() \ + ({ \ + unsigned long temp; \ + __asm__ __volatile__( \ + "mrs %0, cpsr @ local_irq_disable\n" \ +" orr %0, %0, #128\n" \ +" msr cpsr_c, %0" \ + : "=r" (temp) \ + : \ + : "memory", "cc"); \ + }) + +/* + * Enable FIQs + */ +#define local_fiq_enable() \ + ({ \ + unsigned long temp; \ + __asm__ __volatile__( \ + "mrs %0, cpsr @ stf\n" \ +" bic %0, %0, #64\n" \ +" msr cpsr_c, %0" \ + : "=r" (temp) \ + : \ + : "memory", "cc"); \ + }) + +/* + * Disable FIQs + */ +#define local_fiq_disable() \ + ({ \ + unsigned long temp; \ + __asm__ __volatile__( \ + "mrs %0, cpsr @ clf\n" \ +" orr %0, %0, #64\n" \ +" msr cpsr_c, %0" \ + : "=r" (temp) \ + : \ + : "memory", "cc"); \ + }) + +#endif + +/* + * Save the current interrupt enable state. + */ +#define raw_local_save_flags(x) \ + ({ \ + __asm__ __volatile__( \ + "mrs %0, cpsr @ local_save_flags" \ + : "=r" (x) : : "memory", "cc"); \ + }) + +/* + * restore saved IRQ & FIQ state + */ +#define raw_local_irq_restore(x) \ + __asm__ __volatile__( \ + "msr cpsr_c, %0 @ local_irq_restore\n" \ + : \ + : "r" (x) \ + : "memory", "cc") + +#define raw_irqs_disabled_flags(flags) \ +({ \ + (int)((flags) & PSR_I_BIT); \ +}) + +#endif +#endif diff --git a/include/asm-arm/system.h b/include/asm-arm/system.h index 0947cbf9b69..174ff52661b 100644 --- a/include/asm-arm/system.h +++ b/include/asm-arm/system.h @@ -207,130 +207,7 @@ static inline void sched_cacheflush(void) { } -/* - * CPU interrupt mask handling. - */ -#if __LINUX_ARM_ARCH__ >= 6 - -#define local_irq_save(x) \ - ({ \ - __asm__ __volatile__( \ - "mrs %0, cpsr @ local_irq_save\n" \ - "cpsid i" \ - : "=r" (x) : : "memory", "cc"); \ - }) - -#define local_irq_enable() __asm__("cpsie i @ __sti" : : : "memory", "cc") -#define local_irq_disable() __asm__("cpsid i @ __cli" : : : "memory", "cc") -#define local_fiq_enable() __asm__("cpsie f @ __stf" : : : "memory", "cc") -#define local_fiq_disable() __asm__("cpsid f @ __clf" : : : "memory", "cc") - -#else - -/* - * Save the current interrupt enable state & disable IRQs - */ -#define local_irq_save(x) \ - ({ \ - unsigned long temp; \ - (void) (&temp == &x); \ - __asm__ __volatile__( \ - "mrs %0, cpsr @ local_irq_save\n" \ -" orr %1, %0, #128\n" \ -" msr cpsr_c, %1" \ - : "=r" (x), "=r" (temp) \ - : \ - : "memory", "cc"); \ - }) - -/* - * Enable IRQs - */ -#define local_irq_enable() \ - ({ \ - unsigned long temp; \ - __asm__ __volatile__( \ - "mrs %0, cpsr @ local_irq_enable\n" \ -" bic %0, %0, #128\n" \ -" msr cpsr_c, %0" \ - : "=r" (temp) \ - : \ - : "memory", "cc"); \ - }) - -/* - * Disable IRQs - */ -#define local_irq_disable() \ - ({ \ - unsigned long temp; \ - __asm__ __volatile__( \ - "mrs %0, cpsr @ local_irq_disable\n" \ -" orr %0, %0, #128\n" \ -" msr cpsr_c, %0" \ - : "=r" (temp) \ - : \ - : "memory", "cc"); \ - }) - -/* - * Enable FIQs - */ -#define local_fiq_enable() \ - ({ \ - unsigned long temp; \ - __asm__ __volatile__( \ - "mrs %0, cpsr @ stf\n" \ -" bic %0, %0, #64\n" \ -" msr cpsr_c, %0" \ - : "=r" (temp) \ - : \ - : "memory", "cc"); \ - }) - -/* - * Disable FIQs - */ -#define local_fiq_disable() \ - ({ \ - unsigned long temp; \ - __asm__ __volatile__( \ - "mrs %0, cpsr @ clf\n" \ -" orr %0, %0, #64\n" \ -" msr cpsr_c, %0" \ - : "=r" (temp) \ - : \ - : "memory", "cc"); \ - }) - -#endif - -/* - * Save the current interrupt enable state. - */ -#define local_save_flags(x) \ - ({ \ - __asm__ __volatile__( \ - "mrs %0, cpsr @ local_save_flags" \ - : "=r" (x) : : "memory", "cc"); \ - }) - -/* - * restore saved IRQ & FIQ state - */ -#define local_irq_restore(x) \ - __asm__ __volatile__( \ - "msr cpsr_c, %0 @ local_irq_restore\n" \ - : \ - : "r" (x) \ - : "memory", "cc") - -#define irqs_disabled() \ -({ \ - unsigned long flags; \ - local_save_flags(flags); \ - (int)(flags & PSR_I_BIT); \ -}) +#include #ifdef CONFIG_SMP -- cgit v1.2.3 From b36e4758dc1b9ff1f6d97e951edba22366230d11 Mon Sep 17 00:00:00 2001 From: Russell King Date: Sun, 27 Aug 2006 12:26:34 +0100 Subject: [ARM] Fix kernel/fork.c for lockdep on ARM ARM has interrupts enabled over context switches (iow, has __ARCH_WANT_INTERRUPTS_ON_CTXSW defined.) The lockdep code in fork.c assumes that interrupts are always disabled. Fix this wrong assumption by making the initialisation of 'p->hardirqs_enabled' depend on __ARCH_WANT_INTERRUPTS_ON_CTXSW. Acked-by: Ingo Molnar Signed-off-by: Russell King --- kernel/fork.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index f9b014e3e70..8f76adf1c6a 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1056,7 +1056,11 @@ static struct task_struct *copy_process(unsigned long clone_flags, #endif #ifdef CONFIG_TRACE_IRQFLAGS p->irq_events = 0; +#ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW + p->hardirqs_enabled = 1; +#else p->hardirqs_enabled = 0; +#endif p->hardirq_enable_ip = 0; p->hardirq_enable_event = 0; p->hardirq_disable_ip = _THIS_IP_; -- cgit v1.2.3 From 681a4991f83742a0d2325afbf7b7f22045ad5b30 Mon Sep 17 00:00:00 2001 From: Russell King Date: Sun, 27 Aug 2006 12:38:34 +0100 Subject: [ARM] Optimise VFP thread notify function a little The common case for the thread notifier is a context switch. Tell gcc that this is the most likely condition so it can optimise the function for this case. Signed-off-by: Russell King --- arch/arm/vfp/vfpmodule.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/arch/arm/vfp/vfpmodule.c b/arch/arm/vfp/vfpmodule.c index 4178f6cc3d3..dedbb449632 100644 --- a/arch/arm/vfp/vfpmodule.c +++ b/arch/arm/vfp/vfpmodule.c @@ -40,10 +40,19 @@ unsigned int VFP_arch; static int vfp_notifier(struct notifier_block *self, unsigned long cmd, void *v) { struct thread_info *thread = v; - union vfp_state *vfp = &thread->vfpstate; + union vfp_state *vfp; - switch (cmd) { - case THREAD_NOTIFY_FLUSH: + if (likely(cmd == THREAD_NOTIFY_SWITCH)) { + /* + * Always disable VFP so we can lazily save/restore the + * old state. + */ + fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_ENABLE); + return NOTIFY_DONE; + } + + vfp = &thread->vfpstate; + if (cmd == THREAD_NOTIFY_FLUSH) { /* * Per-thread VFP initialisation. */ @@ -56,29 +65,12 @@ static int vfp_notifier(struct notifier_block *self, unsigned long cmd, void *v) * Disable VFP to ensure we initialise it first. */ fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_ENABLE); - - /* - * FALLTHROUGH: Ensure we don't try to overwrite our newly - * initialised state information on the first fault. - */ - - case THREAD_NOTIFY_RELEASE: - /* - * Per-thread VFP cleanup. - */ - if (last_VFP_context == vfp) - last_VFP_context = NULL; - break; - - case THREAD_NOTIFY_SWITCH: - /* - * Always disable VFP so we can lazily save/restore the - * old state. - */ - fmxr(FPEXC, fmrx(FPEXC) & ~FPEXC_ENABLE); - break; } + /* flush and release case: Per-thread VFP cleanup. */ + if (last_VFP_context == vfp) + last_VFP_context = NULL; + return NOTIFY_DONE; } -- cgit v1.2.3 From 6a39dd6222dda5ee2414a1b42e8e62118742a49e Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Wed, 30 Aug 2006 15:02:08 +0100 Subject: [ARM] 3759/2: Remove uses of %? Patch from Daniel Jacobowitz The ARM kernel has several uses of asm("foo%?"). %? is a GCC internal modifier used to output conditional execution predicates. However, no version of GCC supports conditionalizing asm statements. GCC 4.2 will correctly expand %? to the empty string in user asms. Earlier versions may reuse the condition from the previous instruction. In 'if (foo) asm ("bar%?");' this is somewhat likely to be right... but not reliable. So, the only safe thing to do is to remove the uses of %?. I believe the tlbflush.h occurances were supposed to be removed before, based on the comment about %? not working at the top of that file. Old versions of GCC could omit branches around user asms if the asm didn't mark the condition codes as clobbered. This problem hasn't been seen on any recent (3.x or 4.x) GCC, but it could theoretically happen. So, where %? was removed a cc clobber was added. Signed-off-by: Daniel Jacobowitz Signed-off-by: Russell King --- arch/arm/kernel/traps.c | 2 +- arch/arm/mach-footbridge/dc21285.c | 27 ++++++++------ arch/arm/vfp/vfpinstr.h | 8 ++-- include/asm-arm/arch-l7200/io.h | 8 ++-- include/asm-arm/tlbflush.h | 76 +++++++++++++++++++------------------- 5 files changed, 62 insertions(+), 59 deletions(-) diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index aeeed806f99..bede380c07a 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -191,7 +191,7 @@ void show_stack(struct task_struct *tsk, unsigned long *sp) if (tsk != current) fp = thread_saved_fp(tsk); else - asm("mov%? %0, fp" : "=r" (fp)); + asm("mov %0, fp" : "=r" (fp) : : "cc"); c_backtrace(fp, 0x10); barrier(); diff --git a/arch/arm/mach-footbridge/dc21285.c b/arch/arm/mach-footbridge/dc21285.c index 823e25d4547..a1ae49df5c3 100644 --- a/arch/arm/mach-footbridge/dc21285.c +++ b/arch/arm/mach-footbridge/dc21285.c @@ -69,16 +69,16 @@ dc21285_read_config(struct pci_bus *bus, unsigned int devfn, int where, if (addr) switch (size) { case 1: - asm("ldr%?b %0, [%1, %2]" - : "=r" (v) : "r" (addr), "r" (where)); + asm("ldrb %0, [%1, %2]" + : "=r" (v) : "r" (addr), "r" (where) : "cc"); break; case 2: - asm("ldr%?h %0, [%1, %2]" - : "=r" (v) : "r" (addr), "r" (where)); + asm("ldrh %0, [%1, %2]" + : "=r" (v) : "r" (addr), "r" (where) : "cc"); break; case 4: - asm("ldr%? %0, [%1, %2]" - : "=r" (v) : "r" (addr), "r" (where)); + asm("ldr %0, [%1, %2]" + : "=r" (v) : "r" (addr), "r" (where) : "cc"); break; } @@ -103,16 +103,19 @@ dc21285_write_config(struct pci_bus *bus, unsigned int devfn, int where, if (addr) switch (size) { case 1: - asm("str%?b %0, [%1, %2]" - : : "r" (value), "r" (addr), "r" (where)); + asm("strb %0, [%1, %2]" + : : "r" (value), "r" (addr), "r" (where) + : "cc"); break; case 2: - asm("str%?h %0, [%1, %2]" - : : "r" (value), "r" (addr), "r" (where)); + asm("strh %0, [%1, %2]" + : : "r" (value), "r" (addr), "r" (where) + : "cc"); break; case 4: - asm("str%? %0, [%1, %2]" - : : "r" (value), "r" (addr), "r" (where)); + asm("str %0, [%1, %2]" + : : "r" (value), "r" (addr), "r" (where) + : "cc"); break; } diff --git a/arch/arm/vfp/vfpinstr.h b/arch/arm/vfp/vfpinstr.h index 6c819aeae00..7f343a4beca 100644 --- a/arch/arm/vfp/vfpinstr.h +++ b/arch/arm/vfp/vfpinstr.h @@ -73,14 +73,14 @@ #define fmrx(_vfp_) ({ \ u32 __v; \ - asm("mrc%? p10, 7, %0, " vfpreg(_vfp_) ", cr0, 0 @ fmrx %0, " #_vfp_ \ - : "=r" (__v)); \ + asm("mrc p10, 7, %0, " vfpreg(_vfp_) ", cr0, 0 @ fmrx %0, " #_vfp_ \ + : "=r" (__v) : : "cc"); \ __v; \ }) #define fmxr(_vfp_,_var_) \ - asm("mcr%? p10, 7, %0, " vfpreg(_vfp_) ", cr0, 0 @ fmxr " #_vfp_ ", %0" \ - : : "r" (_var_)) + asm("mcr p10, 7, %0, " vfpreg(_vfp_) ", cr0, 0 @ fmxr " #_vfp_ ", %0" \ + : : "r" (_var_) : "cc") u32 vfp_single_cpdo(u32 inst, u32 fpscr); u32 vfp_single_cprt(u32 inst, u32 fpscr, struct pt_regs *regs); diff --git a/include/asm-arm/arch-l7200/io.h b/include/asm-arm/arch-l7200/io.h index cd080d8384d..d744d97c18a 100644 --- a/include/asm-arm/arch-l7200/io.h +++ b/include/asm-arm/arch-l7200/io.h @@ -31,9 +31,9 @@ static inline unsigned int __arch_getw(unsigned long a) { unsigned int value; - __asm__ __volatile__("ldr%?h %0, [%1, #0] @ getw" + __asm__ __volatile__("ldrh %0, [%1, #0] @ getw" : "=&r" (value) - : "r" (a)); + : "r" (a) : "cc"); return value; } @@ -42,8 +42,8 @@ static inline unsigned int __arch_getw(unsigned long a) static inline void __arch_putw(unsigned int value, unsigned long a) { - __asm__ __volatile__("str%?h %0, [%1, #0] @ putw" - : : "r" (value), "r" (a)); + __asm__ __volatile__("strh %0, [%1, #0] @ putw" + : : "r" (value), "r" (a) : "cc"); } /* diff --git a/include/asm-arm/tlbflush.h b/include/asm-arm/tlbflush.h index d97fc76189a..cd10a0b5f8a 100644 --- a/include/asm-arm/tlbflush.h +++ b/include/asm-arm/tlbflush.h @@ -247,16 +247,16 @@ static inline void local_flush_tlb_all(void) const unsigned int __tlb_flag = __cpu_tlb_flags; if (tlb_flag(TLB_WB)) - asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero)); + asm("mcr p15, 0, %0, c7, c10, 4" : : "r" (zero) : "cc"); if (tlb_flag(TLB_V3_FULL)) - asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (zero)); + asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (zero) : "cc"); if (tlb_flag(TLB_V4_U_FULL | TLB_V6_U_FULL)) - asm("mcr%? p15, 0, %0, c8, c7, 0" : : "r" (zero)); + asm("mcr p15, 0, %0, c8, c7, 0" : : "r" (zero) : "cc"); if (tlb_flag(TLB_V4_D_FULL | TLB_V6_D_FULL)) - asm("mcr%? p15, 0, %0, c8, c6, 0" : : "r" (zero)); + asm("mcr p15, 0, %0, c8, c6, 0" : : "r" (zero) : "cc"); if (tlb_flag(TLB_V4_I_FULL | TLB_V6_I_FULL)) - asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero)); + asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc"); } static inline void local_flush_tlb_mm(struct mm_struct *mm) @@ -266,25 +266,25 @@ static inline void local_flush_tlb_mm(struct mm_struct *mm) const unsigned int __tlb_flag = __cpu_tlb_flags; if (tlb_flag(TLB_WB)) - asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero)); + asm("mcr p15, 0, %0, c7, c10, 4" : : "r" (zero) : "cc"); if (cpu_isset(smp_processor_id(), mm->cpu_vm_mask)) { if (tlb_flag(TLB_V3_FULL)) - asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (zero)); + asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (zero) : "cc"); if (tlb_flag(TLB_V4_U_FULL)) - asm("mcr%? p15, 0, %0, c8, c7, 0" : : "r" (zero)); + asm("mcr p15, 0, %0, c8, c7, 0" : : "r" (zero) : "cc"); if (tlb_flag(TLB_V4_D_FULL)) - asm("mcr%? p15, 0, %0, c8, c6, 0" : : "r" (zero)); + asm("mcr p15, 0, %0, c8, c6, 0" : : "r" (zero) : "cc"); if (tlb_flag(TLB_V4_I_FULL)) - asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero)); + asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc"); } if (tlb_flag(TLB_V6_U_ASID)) - asm("mcr%? p15, 0, %0, c8, c7, 2" : : "r" (asid)); + asm("mcr p15, 0, %0, c8, c7, 2" : : "r" (asid) : "cc"); if (tlb_flag(TLB_V6_D_ASID)) - asm("mcr%? p15, 0, %0, c8, c6, 2" : : "r" (asid)); + asm("mcr p15, 0, %0, c8, c6, 2" : : "r" (asid) : "cc"); if (tlb_flag(TLB_V6_I_ASID)) - asm("mcr%? p15, 0, %0, c8, c5, 2" : : "r" (asid)); + asm("mcr p15, 0, %0, c8, c5, 2" : : "r" (asid) : "cc"); } static inline void @@ -296,27 +296,27 @@ local_flush_tlb_page(struct vm_area_struct *vma, unsigned long uaddr) uaddr = (uaddr & PAGE_MASK) | ASID(vma->vm_mm); if (tlb_flag(TLB_WB)) - asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero)); + asm("mcr p15, 0, %0, c7, c10, 4" : : "r" (zero)); if (cpu_isset(smp_processor_id(), vma->vm_mm->cpu_vm_mask)) { if (tlb_flag(TLB_V3_PAGE)) - asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (uaddr)); + asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (uaddr) : "cc"); if (tlb_flag(TLB_V4_U_PAGE)) - asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (uaddr)); + asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (uaddr) : "cc"); if (tlb_flag(TLB_V4_D_PAGE)) - asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (uaddr)); + asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (uaddr) : "cc"); if (tlb_flag(TLB_V4_I_PAGE)) - asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (uaddr)); + asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (uaddr) : "cc"); if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL)) - asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero)); + asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc"); } if (tlb_flag(TLB_V6_U_PAGE)) - asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (uaddr)); + asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (uaddr) : "cc"); if (tlb_flag(TLB_V6_D_PAGE)) - asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (uaddr)); + asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (uaddr) : "cc"); if (tlb_flag(TLB_V6_I_PAGE)) - asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (uaddr)); + asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (uaddr) : "cc"); } static inline void local_flush_tlb_kernel_page(unsigned long kaddr) @@ -327,31 +327,31 @@ static inline void local_flush_tlb_kernel_page(unsigned long kaddr) kaddr &= PAGE_MASK; if (tlb_flag(TLB_WB)) - asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero)); + asm("mcr p15, 0, %0, c7, c10, 4" : : "r" (zero) : "cc"); if (tlb_flag(TLB_V3_PAGE)) - asm("mcr%? p15, 0, %0, c6, c0, 0" : : "r" (kaddr)); + asm("mcr p15, 0, %0, c6, c0, 0" : : "r" (kaddr) : "cc"); if (tlb_flag(TLB_V4_U_PAGE)) - asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (kaddr)); + asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (kaddr) : "cc"); if (tlb_flag(TLB_V4_D_PAGE)) - asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (kaddr)); + asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (kaddr) : "cc"); if (tlb_flag(TLB_V4_I_PAGE)) - asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (kaddr)); + asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (kaddr) : "cc"); if (!tlb_flag(TLB_V4_I_PAGE) && tlb_flag(TLB_V4_I_FULL)) - asm("mcr%? p15, 0, %0, c8, c5, 0" : : "r" (zero)); + asm("mcr p15, 0, %0, c8, c5, 0" : : "r" (zero) : "cc"); if (tlb_flag(TLB_V6_U_PAGE)) - asm("mcr%? p15, 0, %0, c8, c7, 1" : : "r" (kaddr)); + asm("mcr p15, 0, %0, c8, c7, 1" : : "r" (kaddr) : "cc"); if (tlb_flag(TLB_V6_D_PAGE)) - asm("mcr%? p15, 0, %0, c8, c6, 1" : : "r" (kaddr)); + asm("mcr p15, 0, %0, c8, c6, 1" : : "r" (kaddr) : "cc"); if (tlb_flag(TLB_V6_I_PAGE)) - asm("mcr%? p15, 0, %0, c8, c5, 1" : : "r" (kaddr)); + asm("mcr p15, 0, %0, c8, c5, 1" : : "r" (kaddr) : "cc"); /* The ARM ARM states that the completion of a TLB maintenance * operation is only guaranteed by a DSB instruction */ if (tlb_flag(TLB_V6_U_PAGE | TLB_V6_D_PAGE | TLB_V6_I_PAGE)) - asm("mcr%? p15, 0, %0, c7, c10, 4" : : "r" (zero)); + asm("mcr p15, 0, %0, c7, c10, 4" : : "r" (zero) : "cc"); } /* @@ -373,11 +373,11 @@ static inline void flush_pmd_entry(pmd_t *pmd) const unsigned int __tlb_flag = __cpu_tlb_flags; if (tlb_flag(TLB_DCLEAN)) - asm("mcr%? p15, 0, %0, c7, c10, 1 @ flush_pmd" - : : "r" (pmd)); + asm("mcr p15, 0, %0, c7, c10, 1 @ flush_pmd" + : : "r" (pmd) : "cc"); if (tlb_flag(TLB_WB)) - asm("mcr%? p15, 0, %0, c7, c10, 4 @ flush_pmd" - : : "r" (zero)); + asm("mcr p15, 0, %0, c7, c10, 4 @ flush_pmd" + : : "r" (zero) : "cc"); } static inline void clean_pmd_entry(pmd_t *pmd) @@ -385,8 +385,8 @@ static inline void clean_pmd_entry(pmd_t *pmd) const unsigned int __tlb_flag = __cpu_tlb_flags; if (tlb_flag(TLB_DCLEAN)) - asm("mcr%? p15, 0, %0, c7, c10, 1 @ flush_pmd" - : : "r" (pmd)); + asm("mcr p15, 0, %0, c7, c10, 1 @ flush_pmd" + : : "r" (pmd) : "cc"); } #undef tlb_flag -- cgit v1.2.3 From acc46c0144b6d1cf0d77bb8b4d1b7dcd5dc28d71 Mon Sep 17 00:00:00 2001 From: Greg Ungerer Date: Thu, 14 Sep 2006 00:28:26 +1000 Subject: [ARM] nommu: create flat.h to support uClinux flat binaries Create header with uClinux flat format binary support macros for ARM platforms. Derived from the m68knommu flat.h. Signed-off-by: Greg Ungerer Signed-off-by: Russell King --- include/asm-arm/flat.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 include/asm-arm/flat.h diff --git a/include/asm-arm/flat.h b/include/asm-arm/flat.h new file mode 100644 index 00000000000..96694647858 --- /dev/null +++ b/include/asm-arm/flat.h @@ -0,0 +1,16 @@ +/* + * include/asm-arm/flat.h -- uClinux flat-format executables + */ + +#ifndef __ARM_FLAT_H__ +#define __ARM_FLAT_H__ + +#define flat_stack_align(sp) /* nothing needed */ +#define flat_argvp_envp_on_stack() 1 +#define flat_old_ram_flag(flags) (flags) +#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) +#define flat_get_addr_from_rp(rp, relval, flags) get_unaligned(rp) +#define flat_put_addr_at_rp(rp, val, relval) put_unaligned(val,rp) +#define flat_get_relocate_addr(rel) (rel) + +#endif /* __ARM_FLAT_H__ */ -- cgit v1.2.3 From 3d77461ecd7fb92bb888f69478e3518b3c947ce3 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 7 Aug 2006 20:07:43 +1000 Subject: drm: cleanup old compat code and DRM fns from Linux only code This patch removes some of the old compatibility macros from the DRM, and removes use of DRM wrappers from Linux specific code. Signed-off-by: Dave Airlie --- drivers/char/drm/drmP.h | 12 ------------ drivers/char/drm/drm_drv.c | 2 +- drivers/char/drm/drm_fops.c | 2 +- drivers/char/drm/drm_ioc32.c | 2 +- drivers/char/drm/drm_ioctl.c | 8 +++++--- drivers/char/drm/drm_irq.c | 6 ++++-- drivers/char/drm/drm_proc.c | 2 +- drivers/char/drm/drm_vm.c | 12 ++++++------ drivers/char/drm/i810_dma.c | 2 +- drivers/char/drm/i830_dma.c | 2 +- 10 files changed, 21 insertions(+), 29 deletions(-) diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h index d2a56182bc3..cccfdb720e9 100644 --- a/drivers/char/drm/drmP.h +++ b/drivers/char/drm/drmP.h @@ -140,16 +140,6 @@ /*@}*/ -/***********************************************************************/ -/** \name Backward compatibility section */ -/*@{*/ - -#define DRM_RPR_ARG(vma) vma, - -#define VM_OFFSET(vma) ((vma)->vm_pgoff << PAGE_SHIFT) - -/*@}*/ - /***********************************************************************/ /** \name Macros to make printk easier */ /*@{*/ @@ -211,8 +201,6 @@ /*@{*/ #define DRM_ARRAY_SIZE(x) ARRAY_SIZE(x) -#define DRM_MIN(a,b) min(a,b) -#define DRM_MAX(a,b) max(a,b) #define DRM_LEFTCOUNT(x) (((x)->rp + (x)->count - (x)->wp) % ((x)->count + 1)) #define DRM_BUFCOUNT(x) ((x)->count - DRM_LEFTCOUNT(x)) diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c index 3c0b882a8e7..3da72f7364f 100644 --- a/drivers/char/drm/drm_drv.c +++ b/drivers/char/drm/drm_drv.c @@ -118,7 +118,7 @@ static drm_ioctl_desc_t drm_ioctls[] = { [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0}, }; -#define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( drm_ioctls ) +#define DRIVER_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) /** * Take down the DRM device. diff --git a/drivers/char/drm/drm_fops.c b/drivers/char/drm/drm_fops.c index b7f7951c458..51ccc82bf61 100644 --- a/drivers/char/drm/drm_fops.c +++ b/drivers/char/drm/drm_fops.c @@ -69,7 +69,7 @@ static int drm_setup(drm_device_t * dev) return i; } - for (i = 0; i < DRM_ARRAY_SIZE(dev->counts); i++) + for (i = 0; i < ARRAY_SIZE(dev->counts); i++) atomic_set(&dev->counts[i], 0); for (i = 0; i < DRM_HASH_SIZE; i++) { diff --git a/drivers/char/drm/drm_ioc32.c b/drivers/char/drm/drm_ioc32.c index e9e2db18952..d4f87452008 100644 --- a/drivers/char/drm/drm_ioc32.c +++ b/drivers/char/drm/drm_ioc32.c @@ -1051,7 +1051,7 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) drm_ioctl_compat_t *fn; int ret; - if (nr >= DRM_ARRAY_SIZE(drm_compat_ioctls)) + if (nr >= ARRAY_SIZE(drm_compat_ioctls)) return -ENOTTY; fn = drm_compat_ioctls[nr]; diff --git a/drivers/char/drm/drm_ioctl.c b/drivers/char/drm/drm_ioctl.c index 555f323b8a3..31dfe83141e 100644 --- a/drivers/char/drm/drm_ioctl.c +++ b/drivers/char/drm/drm_ioctl.c @@ -331,21 +331,23 @@ int drm_setversion(DRM_IOCTL_ARGS) int if_version; drm_set_version_t __user *argp = (void __user *)data; - DRM_COPY_FROM_USER_IOCTL(sv, argp, sizeof(sv)); + if (copy_from_user(&sv, argp, sizeof(sv))) + return -EFAULT; retv.drm_di_major = DRM_IF_MAJOR; retv.drm_di_minor = DRM_IF_MINOR; retv.drm_dd_major = dev->driver->major; retv.drm_dd_minor = dev->driver->minor; - DRM_COPY_TO_USER_IOCTL(argp, retv, sizeof(sv)); + if (copy_to_user(argp, &retv, sizeof(sv))) + return -EFAULT; if (sv.drm_di_major != -1) { if (sv.drm_di_major != DRM_IF_MAJOR || sv.drm_di_minor < 0 || sv.drm_di_minor > DRM_IF_MINOR) return EINVAL; if_version = DRM_IF_VERSION(sv.drm_di_major, sv.drm_di_minor); - dev->if_version = DRM_MAX(if_version, dev->if_version); + dev->if_version = max(if_version, dev->if_version); if (sv.drm_di_minor >= 1) { /* * Version 1.1 includes tying of DRM to specific device diff --git a/drivers/char/drm/drm_irq.c b/drivers/char/drm/drm_irq.c index ebdb7182c4f..8e484d23e12 100644 --- a/drivers/char/drm/drm_irq.c +++ b/drivers/char/drm/drm_irq.c @@ -255,7 +255,8 @@ int drm_wait_vblank(DRM_IOCTL_ARGS) if (!dev->irq) return -EINVAL; - DRM_COPY_FROM_USER_IOCTL(vblwait, argp, sizeof(vblwait)); + if (copy_from_user(&vblwait, argp, sizeof(vblwait))) + return -EFAULT; switch (vblwait.request.type & ~_DRM_VBLANK_FLAGS_MASK) { case _DRM_VBLANK_RELATIVE: @@ -329,7 +330,8 @@ int drm_wait_vblank(DRM_IOCTL_ARGS) } done: - DRM_COPY_TO_USER_IOCTL(argp, vblwait, sizeof(vblwait)); + if (copy_to_user(argp, &vblwait, sizeof(vblwait))) + return -EFAULT; return ret; } diff --git a/drivers/char/drm/drm_proc.c b/drivers/char/drm/drm_proc.c index 362a270af0f..62d5fe15f04 100644 --- a/drivers/char/drm/drm_proc.c +++ b/drivers/char/drm/drm_proc.c @@ -510,7 +510,7 @@ static int drm__vma_info(char *buf, char **start, off_t offset, int request, vma->vm_flags & VM_MAYSHARE ? 's' : 'p', vma->vm_flags & VM_LOCKED ? 'l' : '-', vma->vm_flags & VM_IO ? 'i' : '-', - VM_OFFSET(vma)); + vma->vm_pgoff << PAGE_SHIFT); #if defined(__i386__) pgprot = pgprot_val(vma->vm_page_prot); diff --git a/drivers/char/drm/drm_vm.c b/drivers/char/drm/drm_vm.c index ffd0800ed60..afb4f0a44b8 100644 --- a/drivers/char/drm/drm_vm.c +++ b/drivers/char/drm/drm_vm.c @@ -75,7 +75,7 @@ static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma, map = r_list->map; if (!map) continue; - if (r_list->user_token == VM_OFFSET(vma)) + if (r_list->user_token == (vma->vm_pgoff << PAGE_SHIFT)) break; } @@ -467,7 +467,7 @@ static int drm_mmap_dma(struct file *filp, struct vm_area_struct *vma) dev = priv->head->dev; dma = dev->dma; DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n", - vma->vm_start, vma->vm_end, VM_OFFSET(vma)); + vma->vm_start, vma->vm_end, vma->vm_pgoff << PAGE_SHIFT); /* Length must match exact page count */ if (!dma || (length >> PAGE_SHIFT) != dma->page_count) { @@ -526,7 +526,7 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma) struct list_head *list; DRM_DEBUG("start = 0x%lx, end = 0x%lx, offset = 0x%lx\n", - vma->vm_start, vma->vm_end, VM_OFFSET(vma)); + vma->vm_start, vma->vm_end, vma->vm_pgoff << PAGE_SHIFT); if (!priv->authenticated) return -EACCES; @@ -535,7 +535,7 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma) * the AGP mapped at physical address 0 * --BenH. */ - if (!VM_OFFSET(vma) + if (!(vma->vm_pgoff << PAGE_SHIFT) #if __OS_HAS_AGP && (!dev->agp || dev->agp->agp_info.device->vendor != PCI_VENDOR_ID_APPLE) @@ -556,7 +556,7 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma) map = r_list->map; if (!map) continue; - if (r_list->user_token == VM_OFFSET(vma)) + if (r_list->user_token == vma->vm_pgoff << PAGE_SHIFT) break; } @@ -620,7 +620,7 @@ int drm_mmap(struct file *filp, struct vm_area_struct *vma) offset = dev->driver->get_reg_ofs(dev); #ifdef __sparc__ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); - if (io_remap_pfn_range(DRM_RPR_ARG(vma) vma->vm_start, + if (io_remap_pfn_range(vma, vma->vm_start, (map->offset + offset) >> PAGE_SHIFT, vma->vm_end - vma->vm_start, vma->vm_page_prot)) diff --git a/drivers/char/drm/i810_dma.c b/drivers/char/drm/i810_dma.c index c658dde3633..28ee6e3f1d9 100644 --- a/drivers/char/drm/i810_dma.c +++ b/drivers/char/drm/i810_dma.c @@ -106,7 +106,7 @@ static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma) unlock_kernel(); if (io_remap_pfn_range(vma, vma->vm_start, - VM_OFFSET(vma) >> PAGE_SHIFT, + vma->vm_pgoff, vma->vm_end - vma->vm_start, vma->vm_page_prot)) return -EAGAIN; return 0; diff --git a/drivers/char/drm/i830_dma.c b/drivers/char/drm/i830_dma.c index b0f815d8cea..2cf3cc59ac6 100644 --- a/drivers/char/drm/i830_dma.c +++ b/drivers/char/drm/i830_dma.c @@ -108,7 +108,7 @@ static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma) unlock_kernel(); if (io_remap_pfn_range(vma, vma->vm_start, - VM_OFFSET(vma) >> PAGE_SHIFT, + vma->vm_pgoff, vma->vm_end - vma->vm_start, vma->vm_page_prot)) return -EAGAIN; return 0; -- cgit v1.2.3 From 242ef0e1e7e5bb7e80c3620c1aa55168819d6fb8 Mon Sep 17 00:00:00 2001 From: Dave Date: Tue, 18 Jul 2006 04:01:01 +1000 Subject: drm: remove local copies of pci bus/slot/func The drm keeps a local copy of these for little use. Signed-off-by: Dave Airlie --- drivers/char/drm/drmP.h | 3 --- drivers/char/drm/drm_ioctl.c | 9 ++++++--- drivers/char/drm/drm_irq.c | 4 ++-- drivers/char/drm/drm_stub.c | 3 --- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h index cccfdb720e9..9838e8ce6ff 100644 --- a/drivers/char/drm/drmP.h +++ b/drivers/char/drm/drmP.h @@ -700,9 +700,6 @@ typedef struct drm_device { struct pci_dev *pdev; /**< PCI device structure */ int pci_domain; /**< PCI bus domain number */ - int pci_bus; /**< PCI bus number */ - int pci_slot; /**< PCI slot number */ - int pci_func; /**< PCI function number */ #ifdef __alpha__ struct pci_controller *hose; #endif diff --git a/drivers/char/drm/drm_ioctl.c b/drivers/char/drm/drm_ioctl.c index 31dfe83141e..9f20c2b5a36 100644 --- a/drivers/char/drm/drm_ioctl.c +++ b/drivers/char/drm/drm_ioctl.c @@ -128,8 +128,9 @@ int drm_setunique(struct inode *inode, struct file *filp, bus &= 0xff; if ((domain != dev->pci_domain) || - (bus != dev->pci_bus) || - (slot != dev->pci_slot) || (func != dev->pci_func)) + (bus != dev->pdev->bus->number) || + (slot != PCI_SLOT(dev->pdev->devfn)) || + (func != PCI_FUNC(dev->pdev->devfn))) return -EINVAL; return 0; @@ -148,7 +149,9 @@ static int drm_set_busid(drm_device_t * dev) return ENOMEM; len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d", - dev->pci_domain, dev->pci_bus, dev->pci_slot, dev->pci_func); + dev->pci_domain, dev->pdev->bus->number, + PCI_SLOT(dev->pdev->devfn), + PCI_FUNC(dev->pdev->devfn)); if (len > dev->unique_len) DRM_ERROR("Unique buffer overflowed\n"); diff --git a/drivers/char/drm/drm_irq.c b/drivers/char/drm/drm_irq.c index 8e484d23e12..41c7020c93e 100644 --- a/drivers/char/drm/drm_irq.c +++ b/drivers/char/drm/drm_irq.c @@ -65,8 +65,8 @@ int drm_irq_by_busid(struct inode *inode, struct file *filp, return -EFAULT; if ((p.busnum >> 8) != dev->pci_domain || - (p.busnum & 0xff) != dev->pci_bus || - p.devnum != dev->pci_slot || p.funcnum != dev->pci_func) + (p.busnum & 0xff) != dev->pdev->bus->number || + p.devnum != PCI_SLOT(dev->pdev->devfn) || p.funcnum != PCI_FUNC(dev->pdev->devfn)) return -EINVAL; p.irq = dev->irq; diff --git a/drivers/char/drm/drm_stub.c b/drivers/char/drm/drm_stub.c index 9a842a36bb2..96449d538e1 100644 --- a/drivers/char/drm/drm_stub.c +++ b/drivers/char/drm/drm_stub.c @@ -72,9 +72,6 @@ static int drm_fill_in_dev(drm_device_t * dev, struct pci_dev *pdev, #else dev->pci_domain = 0; #endif - dev->pci_bus = pdev->bus->number; - dev->pci_slot = PCI_SLOT(pdev->devfn); - dev->pci_func = PCI_FUNC(pdev->devfn); dev->irq = pdev->irq; dev->maplist = drm_calloc(1, sizeof(*dev->maplist), DRM_MEM_MAPS); -- cgit v1.2.3 From 332296016ee2e808b362de66bf6bec49c396e5bf Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Mon, 7 Aug 2006 20:23:42 +1000 Subject: drm: remove the DRM pci domain This patch removes the pci_domain from the DRM device structure, and gets it via a macro that either asks the platform or does the alpha special case. jgarzik asked for this to just use the platform magic, but I've no alpha experience and I'd rather not just break it and wait for someone to give out. Signed-off-by: Dave Airlie --- drivers/char/drm/drmP.h | 7 ++++++- drivers/char/drm/drm_ioctl.c | 4 ++-- drivers/char/drm/drm_irq.c | 2 +- drivers/char/drm/drm_stub.c | 3 --- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h index 9838e8ce6ff..4f0de974c19 100644 --- a/drivers/char/drm/drmP.h +++ b/drivers/char/drm/drmP.h @@ -699,7 +699,6 @@ typedef struct drm_device { drm_agp_head_t *agp; /**< AGP data */ struct pci_dev *pdev; /**< PCI device structure */ - int pci_domain; /**< PCI bus domain number */ #ifdef __alpha__ struct pci_controller *hose; #endif @@ -721,6 +720,12 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev, return ((dev->driver->driver_features & feature) ? 1 : 0); } +#ifdef __alpha__ +#define drm_get_pci_domain(dev) dev->hose->bus->number +#else +#define drm_get_pci_domain(dev) pci_domain_nr(dev->pdev->bus) +#endif + #if __OS_HAS_AGP static inline int drm_core_has_AGP(struct drm_device *dev) { diff --git a/drivers/char/drm/drm_ioctl.c b/drivers/char/drm/drm_ioctl.c index 9f20c2b5a36..e1589983058 100644 --- a/drivers/char/drm/drm_ioctl.c +++ b/drivers/char/drm/drm_ioctl.c @@ -127,7 +127,7 @@ int drm_setunique(struct inode *inode, struct file *filp, domain = bus >> 8; bus &= 0xff; - if ((domain != dev->pci_domain) || + if ((domain != drm_get_pci_domain(dev)) || (bus != dev->pdev->bus->number) || (slot != PCI_SLOT(dev->pdev->devfn)) || (func != PCI_FUNC(dev->pdev->devfn))) @@ -149,7 +149,7 @@ static int drm_set_busid(drm_device_t * dev) return ENOMEM; len = snprintf(dev->unique, dev->unique_len, "pci:%04x:%02x:%02x.%d", - dev->pci_domain, dev->pdev->bus->number, + drm_get_pci_domain(dev), dev->pdev->bus->number, PCI_SLOT(dev->pdev->devfn), PCI_FUNC(dev->pdev->devfn)); diff --git a/drivers/char/drm/drm_irq.c b/drivers/char/drm/drm_irq.c index 41c7020c93e..4553a3a1e49 100644 --- a/drivers/char/drm/drm_irq.c +++ b/drivers/char/drm/drm_irq.c @@ -64,7 +64,7 @@ int drm_irq_by_busid(struct inode *inode, struct file *filp, if (copy_from_user(&p, argp, sizeof(p))) return -EFAULT; - if ((p.busnum >> 8) != dev->pci_domain || + if ((p.busnum >> 8) != drm_get_pci_domain(dev) || (p.busnum & 0xff) != dev->pdev->bus->number || p.devnum != PCI_SLOT(dev->pdev->devfn) || p.funcnum != PCI_FUNC(dev->pdev->devfn)) return -EINVAL; diff --git a/drivers/char/drm/drm_stub.c b/drivers/char/drm/drm_stub.c index 96449d538e1..b1ead37c51d 100644 --- a/drivers/char/drm/drm_stub.c +++ b/drivers/char/drm/drm_stub.c @@ -68,9 +68,6 @@ static int drm_fill_in_dev(drm_device_t * dev, struct pci_dev *pdev, #ifdef __alpha__ dev->hose = pdev->sysdata; - dev->pci_domain = dev->hose->bus->number; -#else - dev->pci_domain = 0; #endif dev->irq = pdev->irq; -- cgit v1.2.3 From 7a3f1f216b92724ff822fe3122272b7fd6a58f8c Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Mon, 7 Aug 2006 20:28:29 +1000 Subject: drm: missing mutex unlock Signed-off-by: Dave Airlie --- drivers/char/drm/drm_bufs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/char/drm/drm_bufs.c b/drivers/char/drm/drm_bufs.c index 006b06d2972..7775fb5dfb9 100644 --- a/drivers/char/drm/drm_bufs.c +++ b/drivers/char/drm/drm_bufs.c @@ -441,8 +441,10 @@ int drm_rmmap_ioctl(struct inode *inode, struct file *filp, return -EINVAL; } - if (!map) + if (!map) { + mutex_unlock(&dev->struct_mutex); return -EINVAL; + } /* Register and framebuffer maps are permanent */ if ((map->type == _DRM_REGISTERS) || (map->type == _DRM_FRAME_BUFFER)) { -- cgit v1.2.3 From 9ca941615ee6418cd38c13602960f29c7ac7d973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Mon, 7 Aug 2006 20:31:30 +1000 Subject: drm: radeon: add some debug output when getparam is called with unknown Signed-off-by: Dave Airlie --- drivers/char/drm/radeon_state.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c index 39a7f685e3f..99589fe0032 100644 --- a/drivers/char/drm/radeon_state.c +++ b/drivers/char/drm/radeon_state.c @@ -2997,6 +2997,7 @@ static int radeon_cp_getparam(DRM_IOCTL_ARGS) value = RADEON_CARD_PCI; break; default: + DRM_DEBUG("Invalid parameter %d\n", param.param); return DRM_ERR(EINVAL); } -- cgit v1.2.3 From 8624ecbf68e90e5a8124514a0b7f92767fb80a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Mon, 7 Aug 2006 20:33:57 +1000 Subject: drm: radeon: implement RADEON_PARAM_SCRATCH_OFFSET getparam When this succeeds, userspace can read the scratch register contents from th mapped writeback page directly. Signed-off-by: Dave Airlie --- drivers/char/drm/radeon_state.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c index 99589fe0032..0433ff80cb7 100644 --- a/drivers/char/drm/radeon_state.c +++ b/drivers/char/drm/radeon_state.c @@ -2987,7 +2987,11 @@ static int radeon_cp_getparam(DRM_IOCTL_ARGS) case RADEON_PARAM_GART_TEX_HANDLE: value = dev_priv->gart_textures_offset; break; - + case RADEON_PARAM_SCRATCH_OFFSET: + if (!dev_priv->writeback_works) + return DRM_ERR(EINVAL); + value = RADEON_SCRATCH_REG_OFFSET; + break; case RADEON_PARAM_CARD_TYPE: if (dev_priv->flags & CHIP_IS_PCIE) value = RADEON_CARD_PCIE; -- cgit v1.2.3 From ae1b1a4816ac11075d338af79a239f4c326d675c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Mon, 7 Aug 2006 20:37:46 +1000 Subject: drm: radeon: fix up bus mastering when writeback is disabled When writeback isn't used, actually disable it in the hardware. Not doing this might waste bus bandwidth or even cause memory corruption or system crashes on systems that check bus transfers. No such incident has been reported though. Signed-off-by: Dave Airlie --- drivers/char/drm/radeon_cp.c | 7 +++++++ drivers/char/drm/radeon_drv.h | 1 + 2 files changed, 8 insertions(+) diff --git a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c index 5ad43ba7b5a..3956628b257 100644 --- a/drivers/char/drm/radeon_cp.c +++ b/drivers/char/drm/radeon_cp.c @@ -1258,6 +1258,13 @@ static void radeon_test_writeback(drm_radeon_private_t * dev_priv) dev_priv->writeback_works = 0; DRM_INFO("writeback forced off\n"); } + + if (!dev_priv->writeback_works) { + /* Disable writeback to avoid unnecessary bus master transfer */ + RADEON_WRITE(RADEON_CP_RB_CNTL, RADEON_READ(RADEON_CP_RB_CNTL) | + RADEON_RB_NO_UPDATE); + RADEON_WRITE(RADEON_SCRATCH_UMSK, 0); + } } /* Enable or disable PCI-E GART on the chip */ diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h index e5a256f5429..b54b8967dcd 100644 --- a/drivers/char/drm/radeon_drv.h +++ b/drivers/char/drm/radeon_drv.h @@ -681,6 +681,7 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp, #define RADEON_CP_RB_BASE 0x0700 #define RADEON_CP_RB_CNTL 0x0704 # define RADEON_BUF_SWAP_32BIT (2 << 16) +# define RADEON_RB_NO_UPDATE (1 << 27) #define RADEON_CP_RB_RPTR_ADDR 0x070c #define RADEON_CP_RB_RPTR 0x0710 #define RADEON_CP_RB_WPTR 0x0714 -- cgit v1.2.3 From b9b603dd1c99a68e65ad51cda25379441df2e17b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Mon, 7 Aug 2006 20:41:53 +1000 Subject: drm: radeon: Use RADEON_RB3D_DSTCACHE_CTLSTAT instead of RADEON_RB2D_DSTCACHE_CTLSTAT. The latter seems to be a read-only mirror of the former. Signed-off-by: Dave Airlie --- drivers/char/drm/radeon_cp.c | 10 +++++----- drivers/char/drm/radeon_drv.h | 9 +++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c index 3956628b257..45f8044e9a3 100644 --- a/drivers/char/drm/radeon_cp.c +++ b/drivers/char/drm/radeon_cp.c @@ -864,13 +864,13 @@ static int radeon_do_pixcache_flush(drm_radeon_private_t * dev_priv) dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE; - tmp = RADEON_READ(RADEON_RB2D_DSTCACHE_CTLSTAT); - tmp |= RADEON_RB2D_DC_FLUSH_ALL; - RADEON_WRITE(RADEON_RB2D_DSTCACHE_CTLSTAT, tmp); + tmp = RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT); + tmp |= RADEON_RB3D_DC_FLUSH_ALL; + RADEON_WRITE(RADEON_RB3D_DSTCACHE_CTLSTAT, tmp); for (i = 0; i < dev_priv->usec_timeout; i++) { - if (!(RADEON_READ(RADEON_RB2D_DSTCACHE_CTLSTAT) - & RADEON_RB2D_DC_BUSY)) { + if (!(RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT) + & RADEON_RB3D_DC_BUSY)) { return 0; } DRM_UDELAY(1); diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h index b54b8967dcd..2f51d514773 100644 --- a/drivers/char/drm/radeon_drv.h +++ b/drivers/char/drm/radeon_drv.h @@ -545,6 +545,11 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp, # define RADEON_RB3D_ZC_FREE (1 << 2) # define RADEON_RB3D_ZC_FLUSH_ALL 0x5 # define RADEON_RB3D_ZC_BUSY (1 << 31) +#define RADEON_RB3D_DSTCACHE_CTLSTAT 0x325c +# define RADEON_RB3D_DC_FLUSH (3 << 0) +# define RADEON_RB3D_DC_FREE (3 << 2) +# define RADEON_RB3D_DC_FLUSH_ALL 0xf +# define RADEON_RB3D_DC_BUSY (1 << 31) #define RADEON_RB3D_ZSTENCILCNTL 0x1c2c # define RADEON_Z_TEST_MASK (7 << 4) # define RADEON_Z_TEST_ALWAYS (7 << 4) @@ -987,12 +992,12 @@ do { \ } while (0) #define RADEON_FLUSH_CACHE() do { \ - OUT_RING( CP_PACKET0( RADEON_RB2D_DSTCACHE_CTLSTAT, 0 ) ); \ + OUT_RING( CP_PACKET0( RADEON_RB3D_DSTCACHE_CTLSTAT, 0 ) ); \ OUT_RING( RADEON_RB2D_DC_FLUSH ); \ } while (0) #define RADEON_PURGE_CACHE() do { \ - OUT_RING( CP_PACKET0( RADEON_RB2D_DSTCACHE_CTLSTAT, 0 ) ); \ + OUT_RING( CP_PACKET0( RADEON_RB3D_DSTCACHE_CTLSTAT, 0 ) ); \ OUT_RING( RADEON_RB2D_DC_FLUSH_ALL ); \ } while (0) -- cgit v1.2.3 From 3a1bd924f36da202e480a0e0174b2878c0924a05 Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Mon, 7 Aug 2006 21:30:28 +1000 Subject: drm: add simple DRM memory manager, and hash table This adds the DRM hashtable and simple memory manager implementations from Tungsten Graphics, this is NOT the new memory manager, this is a replacement for the SIS and VIA memory managers. Signed-off-by: Dave Airlie --- drivers/char/drm/Makefile | 2 +- drivers/char/drm/drmP.h | 33 +++- drivers/char/drm/drm_hashtab.c | 190 ++++++++++++++++++++++ drivers/char/drm/drm_hashtab.h | 67 ++++++++ drivers/char/drm/drm_mm.c | 201 +++++++++++++++++++++++ drivers/char/drm/drm_sman.c | 352 +++++++++++++++++++++++++++++++++++++++++ drivers/char/drm/drm_sman.h | 176 +++++++++++++++++++++ 7 files changed, 1019 insertions(+), 2 deletions(-) create mode 100644 drivers/char/drm/drm_hashtab.c create mode 100644 drivers/char/drm/drm_hashtab.h create mode 100644 drivers/char/drm/drm_mm.c create mode 100644 drivers/char/drm/drm_sman.c create mode 100644 drivers/char/drm/drm_sman.h diff --git a/drivers/char/drm/Makefile b/drivers/char/drm/Makefile index 9d180c42816..5eb79f2d558 100644 --- a/drivers/char/drm/Makefile +++ b/drivers/char/drm/Makefile @@ -6,7 +6,7 @@ drm-objs := drm_auth.o drm_bufs.o drm_context.o drm_dma.o drm_drawable.o \ drm_drv.o drm_fops.o drm_ioctl.o drm_irq.o \ drm_lock.o drm_memory.o drm_proc.o drm_stub.o drm_vm.o \ drm_agpsupport.o drm_scatter.o ati_pcigart.o drm_pci.o \ - drm_sysfs.o + drm_sysfs.o drm_hashtab.o drm_sman.o drm_mm.o tdfx-objs := tdfx_drv.o r128-objs := r128_drv.o r128_cce.o r128_state.o r128_irq.o diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h index 4f0de974c19..c93985bb91a 100644 --- a/drivers/char/drm/drmP.h +++ b/drivers/char/drm/drmP.h @@ -79,6 +79,7 @@ #define __OS_HAS_MTRR (defined(CONFIG_MTRR)) #include "drm_os_linux.h" +#include "drm_hashtab.h" /***********************************************************************/ /** \name DRM template customization defaults */ @@ -134,7 +135,9 @@ #define DRM_MEM_CTXBITMAP 18 #define DRM_MEM_STUB 19 #define DRM_MEM_SGLISTS 20 -#define DRM_MEM_CTXLIST 21 +#define DRM_MEM_CTXLIST 21 +#define DRM_MEM_MM 22 +#define DRM_MEM_HASHTAB 23 #define DRM_MAX_CTXBITMAP (PAGE_SIZE * 8) @@ -515,6 +518,22 @@ typedef struct ati_pcigart_info { drm_local_map_t mapping; } drm_ati_pcigart_info; +/* + * Generic memory manager structs + */ +typedef struct drm_mm_node { + struct list_head fl_entry; + struct list_head ml_entry; + int free; + unsigned long start; + unsigned long size; + void *private; +} drm_mm_node_t; + +typedef struct drm_mm { + drm_mm_node_t root_node; +} drm_mm_t; + /** * DRM driver structure. This structure represent the common code for * a family of cards. There will one drm_device for each card present @@ -1001,6 +1020,18 @@ extern struct class_device *drm_sysfs_device_add(struct class *cs, drm_head_t *head); extern void drm_sysfs_device_remove(struct class_device *class_dev); +/* + * Basic memory manager support (drm_mm.c) + */ +extern drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent, + unsigned long size, + unsigned alignment); +extern void drm_mm_put_block(drm_mm_t *mm, drm_mm_node_t *cur); +extern drm_mm_node_t *drm_mm_search_free(const drm_mm_t *mm, unsigned long size, + unsigned alignment, int best_match); +extern int drm_mm_init(drm_mm_t *mm, unsigned long start, unsigned long size); +extern void drm_mm_takedown(drm_mm_t *mm); + /* Inline replacements for DRM_IOREMAP macros */ static __inline__ void drm_core_ioremap(struct drm_map *map, struct drm_device *dev) diff --git a/drivers/char/drm/drm_hashtab.c b/drivers/char/drm/drm_hashtab.c new file mode 100644 index 00000000000..48061139548 --- /dev/null +++ b/drivers/char/drm/drm_hashtab.c @@ -0,0 +1,190 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND. USA. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + **************************************************************************/ +/* + * Simple open hash tab implementation. + * + * Authors: + * Thomas Hellström + */ + +#include "drmP.h" +#include "drm_hashtab.h" +#include + +int drm_ht_create(drm_open_hash_t *ht, unsigned int order) +{ + unsigned int i; + + ht->size = 1 << order; + ht->order = order; + ht->fill = 0; + ht->table = vmalloc(ht->size*sizeof(*ht->table)); + if (!ht->table) { + DRM_ERROR("Out of memory for hash table\n"); + return -ENOMEM; + } + for (i=0; i< ht->size; ++i) { + INIT_HLIST_HEAD(&ht->table[i]); + } + return 0; +} + +void drm_ht_verbose_list(drm_open_hash_t *ht, unsigned long key) +{ + drm_hash_item_t *entry; + struct hlist_head *h_list; + struct hlist_node *list; + unsigned int hashed_key; + int count = 0; + + hashed_key = hash_long(key, ht->order); + DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key); + h_list = &ht->table[hashed_key]; + hlist_for_each(list, h_list) { + entry = hlist_entry(list, drm_hash_item_t, head); + DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key); + } +} + +static struct hlist_node *drm_ht_find_key(drm_open_hash_t *ht, + unsigned long key) +{ + drm_hash_item_t *entry; + struct hlist_head *h_list; + struct hlist_node *list; + unsigned int hashed_key; + + hashed_key = hash_long(key, ht->order); + h_list = &ht->table[hashed_key]; + hlist_for_each(list, h_list) { + entry = hlist_entry(list, drm_hash_item_t, head); + if (entry->key == key) + return list; + if (entry->key > key) + break; + } + return NULL; +} + + +int drm_ht_insert_item(drm_open_hash_t *ht, drm_hash_item_t *item) +{ + drm_hash_item_t *entry; + struct hlist_head *h_list; + struct hlist_node *list, *parent; + unsigned int hashed_key; + unsigned long key = item->key; + + hashed_key = hash_long(key, ht->order); + h_list = &ht->table[hashed_key]; + parent = NULL; + hlist_for_each(list, h_list) { + entry = hlist_entry(list, drm_hash_item_t, head); + if (entry->key == key) + return -1; + if (entry->key > key) + break; + parent = list; + } + if (parent) { + hlist_add_after(parent, &item->head); + } else { + hlist_add_head(&item->head, h_list); + } + return 0; +} + +/* + * Just insert an item and return any "bits" bit key that hasn't been + * used before. + */ +int drm_ht_just_insert_please(drm_open_hash_t *ht, drm_hash_item_t *item, + unsigned long seed, int bits, int shift, + unsigned long add) +{ + int ret; + unsigned long mask = (1 << bits) - 1; + unsigned long first, unshifted_key; + + unshifted_key = hash_long(seed, bits); + first = unshifted_key; + do { + item->key = (unshifted_key << shift) + add; + ret = drm_ht_insert_item(ht, item); + if (ret) + unshifted_key = (unshifted_key + 1) & mask; + } while(ret && (unshifted_key != first)); + + if (ret) { + DRM_ERROR("Available key bit space exhausted\n"); + return -EINVAL; + } + return 0; +} + +int drm_ht_find_item(drm_open_hash_t *ht, unsigned long key, + drm_hash_item_t **item) +{ + struct hlist_node *list; + + list = drm_ht_find_key(ht, key); + if (!list) + return -1; + + *item = hlist_entry(list, drm_hash_item_t, head); + return 0; +} + +int drm_ht_remove_key(drm_open_hash_t *ht, unsigned long key) +{ + struct hlist_node *list; + + list = drm_ht_find_key(ht, key); + if (list) { + hlist_del_init(list); + ht->fill--; + return 0; + } + return -1; +} + +int drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item) +{ + hlist_del_init(&item->head); + ht->fill--; + return 0; +} + +void drm_ht_remove(drm_open_hash_t *ht) +{ + if (ht->table) { + vfree(ht->table); + ht->table = NULL; + } +} + diff --git a/drivers/char/drm/drm_hashtab.h b/drivers/char/drm/drm_hashtab.h new file mode 100644 index 00000000000..40afec05bff --- /dev/null +++ b/drivers/char/drm/drm_hashtab.h @@ -0,0 +1,67 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Bismack, ND. USA. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + **************************************************************************/ +/* + * Simple open hash tab implementation. + * + * Authors: + * Thomas Hellström + */ + +#ifndef DRM_HASHTAB_H +#define DRM_HASHTAB_H + +#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member) + +typedef struct drm_hash_item{ + struct hlist_node head; + unsigned long key; +} drm_hash_item_t; + +typedef struct drm_open_hash{ + unsigned int size; + unsigned int order; + unsigned int fill; + struct hlist_head *table; +} drm_open_hash_t; + + +extern int drm_ht_create(drm_open_hash_t *ht, unsigned int order); +extern int drm_ht_insert_item(drm_open_hash_t *ht, drm_hash_item_t *item); +extern int drm_ht_just_insert_please(drm_open_hash_t *ht, drm_hash_item_t *item, + unsigned long seed, int bits, int shift, + unsigned long add); +extern int drm_ht_find_item(drm_open_hash_t *ht, unsigned long key, drm_hash_item_t **item); + +extern void drm_ht_verbose_list(drm_open_hash_t *ht, unsigned long key); +extern int drm_ht_remove_key(drm_open_hash_t *ht, unsigned long key); +extern int drm_ht_remove_item(drm_open_hash_t *ht, drm_hash_item_t *item); +extern void drm_ht_remove(drm_open_hash_t *ht); + + +#endif + diff --git a/drivers/char/drm/drm_mm.c b/drivers/char/drm/drm_mm.c new file mode 100644 index 00000000000..c55ed45a894 --- /dev/null +++ b/drivers/char/drm/drm_mm.c @@ -0,0 +1,201 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + **************************************************************************/ + +/* + * Generic simple memory manager implementation. Intended to be used as a base + * class implementation for more advanced memory managers. + * + * Note that the algorithm used is quite simple and there might be substantial + * performance gains if a smarter free list is implemented. Currently it is just an + * unordered stack of free regions. This could easily be improved if an RB-tree + * is used instead. At least if we expect heavy fragmentation. + * + * Aligned allocations can also see improvement. + * + * Authors: + * Thomas Hellström + */ + +#include "drmP.h" + +drm_mm_node_t *drm_mm_get_block(drm_mm_node_t * parent, + unsigned long size, unsigned alignment) +{ + + drm_mm_node_t *child; + + if (alignment) + size += alignment - 1; + + if (parent->size == size) { + list_del_init(&parent->fl_entry); + parent->free = FALSE; + return parent; + } else { + child = (drm_mm_node_t *) drm_alloc(sizeof(*child), DRM_MEM_MM); + if (!child) + return NULL; + + INIT_LIST_HEAD(&child->ml_entry); + INIT_LIST_HEAD(&child->fl_entry); + + child->free = FALSE; + child->size = size; + child->start = parent->start; + + list_add_tail(&child->ml_entry, &parent->ml_entry); + parent->size -= size; + parent->start += size; + } + return child; +} + +/* + * Put a block. Merge with the previous and / or next block if they are free. + * Otherwise add to the free stack. + */ + +void drm_mm_put_block(drm_mm_t * mm, drm_mm_node_t * cur) +{ + + drm_mm_node_t *list_root = &mm->root_node; + struct list_head *cur_head = &cur->ml_entry; + struct list_head *root_head = &list_root->ml_entry; + drm_mm_node_t *prev_node = NULL; + drm_mm_node_t *next_node; + + int merged = FALSE; + + if (cur_head->prev != root_head) { + prev_node = list_entry(cur_head->prev, drm_mm_node_t, ml_entry); + if (prev_node->free) { + prev_node->size += cur->size; + merged = TRUE; + } + } + if (cur_head->next != root_head) { + next_node = list_entry(cur_head->next, drm_mm_node_t, ml_entry); + if (next_node->free) { + if (merged) { + prev_node->size += next_node->size; + list_del(&next_node->ml_entry); + list_del(&next_node->fl_entry); + drm_free(next_node, sizeof(*next_node), + DRM_MEM_MM); + } else { + next_node->size += cur->size; + next_node->start = cur->start; + merged = TRUE; + } + } + } + if (!merged) { + cur->free = TRUE; + list_add(&cur->fl_entry, &list_root->fl_entry); + } else { + list_del(&cur->ml_entry); + drm_free(cur, sizeof(*cur), DRM_MEM_MM); + } +} + +drm_mm_node_t *drm_mm_search_free(const drm_mm_t * mm, + unsigned long size, + unsigned alignment, int best_match) +{ + struct list_head *list; + const struct list_head *free_stack = &mm->root_node.fl_entry; + drm_mm_node_t *entry; + drm_mm_node_t *best; + unsigned long best_size; + + best = NULL; + best_size = ~0UL; + + if (alignment) + size += alignment - 1; + + list_for_each(list, free_stack) { + entry = list_entry(list, drm_mm_node_t, fl_entry); + if (entry->size >= size) { + if (!best_match) + return entry; + if (size < best_size) { + best = entry; + best_size = entry->size; + } + } + } + + return best; +} + +int drm_mm_init(drm_mm_t * mm, unsigned long start, unsigned long size) +{ + drm_mm_node_t *child; + + INIT_LIST_HEAD(&mm->root_node.ml_entry); + INIT_LIST_HEAD(&mm->root_node.fl_entry); + child = (drm_mm_node_t *) drm_alloc(sizeof(*child), DRM_MEM_MM); + if (!child) + return -ENOMEM; + + INIT_LIST_HEAD(&child->ml_entry); + INIT_LIST_HEAD(&child->fl_entry); + + child->start = start; + child->size = size; + child->free = TRUE; + + list_add(&child->fl_entry, &mm->root_node.fl_entry); + list_add(&child->ml_entry, &mm->root_node.ml_entry); + + return 0; +} + +EXPORT_SYMBOL(drm_mm_init); + +void drm_mm_takedown(drm_mm_t * mm) +{ + struct list_head *bnode = mm->root_node.fl_entry.next; + drm_mm_node_t *entry; + + entry = list_entry(bnode, drm_mm_node_t, fl_entry); + + if (entry->ml_entry.next != &mm->root_node.ml_entry || + entry->fl_entry.next != &mm->root_node.fl_entry) { + DRM_ERROR("Memory manager not clean. Delaying takedown\n"); + return; + } + + list_del(&entry->fl_entry); + list_del(&entry->ml_entry); + + drm_free(entry, sizeof(*entry), DRM_MEM_MM); +} + +EXPORT_SYMBOL(drm_mm_takedown); diff --git a/drivers/char/drm/drm_sman.c b/drivers/char/drm/drm_sman.c new file mode 100644 index 00000000000..baba9139891 --- /dev/null +++ b/drivers/char/drm/drm_sman.c @@ -0,0 +1,352 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Bismarck., ND., USA. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * + **************************************************************************/ +/* + * Simple memory manager interface that keeps track on allocate regions on a + * per "owner" basis. All regions associated with an "owner" can be released + * with a simple call. Typically if the "owner" exists. The owner is any + * "unsigned long" identifier. Can typically be a pointer to a file private + * struct or a context identifier. + * + * Authors: + * Thomas Hellström + */ + +#include "drm_sman.h" + +typedef struct drm_owner_item { + drm_hash_item_t owner_hash; + struct list_head sman_list; + struct list_head mem_blocks; +} drm_owner_item_t; + +void drm_sman_takedown(drm_sman_t * sman) +{ + drm_ht_remove(&sman->user_hash_tab); + drm_ht_remove(&sman->owner_hash_tab); + if (sman->mm) + drm_free(sman->mm, sman->num_managers * sizeof(*sman->mm), + DRM_MEM_MM); +} + +EXPORT_SYMBOL(drm_sman_takedown); + +int +drm_sman_init(drm_sman_t * sman, unsigned int num_managers, + unsigned int user_order, unsigned int owner_order) +{ + int ret = 0; + + sman->mm = (drm_sman_mm_t *) drm_calloc(num_managers, sizeof(*sman->mm), + DRM_MEM_MM); + if (!sman->mm) { + ret = -ENOMEM; + goto out; + } + sman->num_managers = num_managers; + INIT_LIST_HEAD(&sman->owner_items); + ret = drm_ht_create(&sman->owner_hash_tab, owner_order); + if (ret) + goto out1; + ret = drm_ht_create(&sman->user_hash_tab, user_order); + if (!ret) + goto out; + + drm_ht_remove(&sman->owner_hash_tab); +out1: + drm_free(sman->mm, num_managers * sizeof(*sman->mm), DRM_MEM_MM); +out: + return ret; +} + +EXPORT_SYMBOL(drm_sman_init); + +static void *drm_sman_mm_allocate(void *private, unsigned long size, + unsigned alignment) +{ + drm_mm_t *mm = (drm_mm_t *) private; + drm_mm_node_t *tmp; + + tmp = drm_mm_search_free(mm, size, alignment, TRUE); + if (!tmp) { + return NULL; + } + tmp = drm_mm_get_block(tmp, size, alignment); + return tmp; +} + +static void drm_sman_mm_free(void *private, void *ref) +{ + drm_mm_t *mm = (drm_mm_t *) private; + drm_mm_node_t *node = (drm_mm_node_t *) ref; + + drm_mm_put_block(mm, node); +} + +static void drm_sman_mm_destroy(void *private) +{ + drm_mm_t *mm = (drm_mm_t *) private; + drm_mm_takedown(mm); + drm_free(mm, sizeof(*mm), DRM_MEM_MM); +} + +unsigned long drm_sman_mm_offset(void *private, void *ref) +{ + drm_mm_node_t *node = (drm_mm_node_t *) ref; + return node->start; +} + +int +drm_sman_set_range(drm_sman_t * sman, unsigned int manager, + unsigned long start, unsigned long size) +{ + drm_sman_mm_t *sman_mm; + drm_mm_t *mm; + int ret; + + BUG_ON(manager >= sman->num_managers); + + sman_mm = &sman->mm[manager]; + mm = drm_calloc(1, sizeof(*mm), DRM_MEM_MM); + if (!mm) { + return -ENOMEM; + } + sman_mm->private = mm; + ret = drm_mm_init(mm, start, size); + + if (ret) { + drm_free(mm, sizeof(*mm), DRM_MEM_MM); + return ret; + } + + sman_mm->allocate = drm_sman_mm_allocate; + sman_mm->free = drm_sman_mm_free; + sman_mm->destroy = drm_sman_mm_destroy; + sman_mm->offset = drm_sman_mm_offset; + + return 0; +} + +EXPORT_SYMBOL(drm_sman_set_range); + +int +drm_sman_set_manager(drm_sman_t * sman, unsigned int manager, + drm_sman_mm_t * allocator) +{ + BUG_ON(manager >= sman->num_managers); + sman->mm[manager] = *allocator; + + return 0; +} + +static drm_owner_item_t *drm_sman_get_owner_item(drm_sman_t * sman, + unsigned long owner) +{ + int ret; + drm_hash_item_t *owner_hash_item; + drm_owner_item_t *owner_item; + + ret = drm_ht_find_item(&sman->owner_hash_tab, owner, &owner_hash_item); + if (!ret) { + return drm_hash_entry(owner_hash_item, drm_owner_item_t, + owner_hash); + } + + owner_item = drm_calloc(1, sizeof(*owner_item), DRM_MEM_MM); + if (!owner_item) + goto out; + + INIT_LIST_HEAD(&owner_item->mem_blocks); + owner_item->owner_hash.key = owner; + if (drm_ht_insert_item(&sman->owner_hash_tab, &owner_item->owner_hash)) + goto out1; + + list_add_tail(&owner_item->sman_list, &sman->owner_items); + return owner_item; + +out1: + drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM); +out: + return NULL; +} + +drm_memblock_item_t *drm_sman_alloc(drm_sman_t *sman, unsigned int manager, + unsigned long size, unsigned alignment, + unsigned long owner) +{ + void *tmp; + drm_sman_mm_t *sman_mm; + drm_owner_item_t *owner_item; + drm_memblock_item_t *memblock; + + BUG_ON(manager >= sman->num_managers); + + sman_mm = &sman->mm[manager]; + tmp = sman_mm->allocate(sman_mm->private, size, alignment); + + if (!tmp) { + return NULL; + } + + memblock = drm_calloc(1, sizeof(*memblock), DRM_MEM_MM); + + if (!memblock) + goto out; + + memblock->mm_info = tmp; + memblock->mm = sman_mm; + memblock->sman = sman; + + if (drm_ht_just_insert_please + (&sman->user_hash_tab, &memblock->user_hash, + (unsigned long)memblock, 32, 0, 0)) + goto out1; + + owner_item = drm_sman_get_owner_item(sman, owner); + if (!owner_item) + goto out2; + + list_add_tail(&memblock->owner_list, &owner_item->mem_blocks); + + return memblock; + +out2: + drm_ht_remove_item(&sman->user_hash_tab, &memblock->user_hash); +out1: + drm_free(memblock, sizeof(*memblock), DRM_MEM_MM); +out: + sman_mm->free(sman_mm->private, tmp); + + return NULL; +} + +EXPORT_SYMBOL(drm_sman_alloc); + +static void drm_sman_free(drm_memblock_item_t *item) +{ + drm_sman_t *sman = item->sman; + + list_del(&item->owner_list); + drm_ht_remove_item(&sman->user_hash_tab, &item->user_hash); + item->mm->free(item->mm->private, item->mm_info); + drm_free(item, sizeof(*item), DRM_MEM_MM); +} + +int drm_sman_free_key(drm_sman_t *sman, unsigned int key) +{ + drm_hash_item_t *hash_item; + drm_memblock_item_t *memblock_item; + + if (drm_ht_find_item(&sman->user_hash_tab, key, &hash_item)) + return -EINVAL; + + memblock_item = drm_hash_entry(hash_item, drm_memblock_item_t, user_hash); + drm_sman_free(memblock_item); + return 0; +} + +EXPORT_SYMBOL(drm_sman_free_key); + +static void drm_sman_remove_owner(drm_sman_t *sman, + drm_owner_item_t *owner_item) +{ + list_del(&owner_item->sman_list); + drm_ht_remove_item(&sman->owner_hash_tab, &owner_item->owner_hash); + drm_free(owner_item, sizeof(*owner_item), DRM_MEM_MM); +} + +int drm_sman_owner_clean(drm_sman_t *sman, unsigned long owner) +{ + + drm_hash_item_t *hash_item; + drm_owner_item_t *owner_item; + + if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) { + return -1; + } + + owner_item = drm_hash_entry(hash_item, drm_owner_item_t, owner_hash); + if (owner_item->mem_blocks.next == &owner_item->mem_blocks) { + drm_sman_remove_owner(sman, owner_item); + return -1; + } + + return 0; +} + +EXPORT_SYMBOL(drm_sman_owner_clean); + +static void drm_sman_do_owner_cleanup(drm_sman_t *sman, + drm_owner_item_t *owner_item) +{ + drm_memblock_item_t *entry, *next; + + list_for_each_entry_safe(entry, next, &owner_item->mem_blocks, + owner_list) { + drm_sman_free(entry); + } + drm_sman_remove_owner(sman, owner_item); +} + +void drm_sman_owner_cleanup(drm_sman_t *sman, unsigned long owner) +{ + + drm_hash_item_t *hash_item; + drm_owner_item_t *owner_item; + + if (drm_ht_find_item(&sman->owner_hash_tab, owner, &hash_item)) { + + return; + } + + owner_item = drm_hash_entry(hash_item, drm_owner_item_t, owner_hash); + drm_sman_do_owner_cleanup(sman, owner_item); +} + +EXPORT_SYMBOL(drm_sman_owner_cleanup); + +void drm_sman_cleanup(drm_sman_t *sman) +{ + drm_owner_item_t *entry, *next; + unsigned int i; + drm_sman_mm_t *sman_mm; + + list_for_each_entry_safe(entry, next, &sman->owner_items, sman_list) { + drm_sman_do_owner_cleanup(sman, entry); + } + if (sman->mm) { + for (i = 0; i < sman->num_managers; ++i) { + sman_mm = &sman->mm[i]; + if (sman_mm->private) { + sman_mm->destroy(sman_mm->private); + sman_mm->private = NULL; + } + } + } +} + +EXPORT_SYMBOL(drm_sman_cleanup); diff --git a/drivers/char/drm/drm_sman.h b/drivers/char/drm/drm_sman.h new file mode 100644 index 00000000000..7c48360f114 --- /dev/null +++ b/drivers/char/drm/drm_sman.h @@ -0,0 +1,176 @@ +/************************************************************************** + * + * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * + **************************************************************************/ +/* + * Simple memory MANager interface that keeps track on allocate regions on a + * per "owner" basis. All regions associated with an "owner" can be released + * with a simple call. Typically if the "owner" exists. The owner is any + * "unsigned long" identifier. Can typically be a pointer to a file private + * struct or a context identifier. + * + * Authors: + * Thomas Hellström + */ + +#ifndef DRM_SMAN_H +#define DRM_SMAN_H + +#include "drmP.h" +#include "drm_hashtab.h" + +/* + * A class that is an abstration of a simple memory allocator. + * The sman implementation provides a default such allocator + * using the drm_mm.c implementation. But the user can replace it. + * See the SiS implementation, which may use the SiS FB kernel module + * for memory management. + */ + +typedef struct drm_sman_mm { + /* private info. If allocated, needs to be destroyed by the destroy + function */ + void *private; + + /* Allocate a memory block with given size and alignment. + Return an opaque reference to the memory block */ + + void *(*allocate) (void *private, unsigned long size, + unsigned alignment); + + /* Free a memory block. "ref" is the opaque reference that we got from + the "alloc" function */ + + void (*free) (void *private, void *ref); + + /* Free all resources associated with this allocator */ + + void (*destroy) (void *private); + + /* Return a memory offset from the opaque reference returned from the + "alloc" function */ + + unsigned long (*offset) (void *private, void *ref); +} drm_sman_mm_t; + +typedef struct drm_memblock_item { + struct list_head owner_list; + drm_hash_item_t user_hash; + void *mm_info; + drm_sman_mm_t *mm; + struct drm_sman *sman; +} drm_memblock_item_t; + +typedef struct drm_sman { + drm_sman_mm_t *mm; + int num_managers; + drm_open_hash_t owner_hash_tab; + drm_open_hash_t user_hash_tab; + struct list_head owner_items; +} drm_sman_t; + +/* + * Take down a memory manager. This function should only be called after a + * successful init and after a call to drm_sman_cleanup. + */ + +extern void drm_sman_takedown(drm_sman_t * sman); + +/* + * Allocate structures for a manager. + * num_managers are the number of memory pools to manage. (VRAM, AGP, ....) + * user_order is the log2 of the number of buckets in the user hash table. + * set this to approximately log2 of the max number of memory regions + * that will be allocated for _all_ pools together. + * owner_order is the log2 of the number of buckets in the owner hash table. + * set this to approximately log2 of + * the number of client file connections that will + * be using the manager. + * + */ + +extern int drm_sman_init(drm_sman_t * sman, unsigned int num_managers, + unsigned int user_order, unsigned int owner_order); + +/* + * Initialize a drm_mm.c allocator. Should be called only once for each + * manager unless a customized allogator is used. + */ + +extern int drm_sman_set_range(drm_sman_t * sman, unsigned int manager, + unsigned long start, unsigned long size); + +/* + * Initialize a customized allocator for one of the managers. + * (See the SiS module). The object pointed to by "allocator" is copied, + * so it can be destroyed after this call. + */ + +extern int drm_sman_set_manager(drm_sman_t * sman, unsigned int mananger, + drm_sman_mm_t * allocator); + +/* + * Allocate a memory block. Aligment is not implemented yet. + */ + +extern drm_memblock_item_t *drm_sman_alloc(drm_sman_t * sman, + unsigned int manager, + unsigned long size, + unsigned alignment, + unsigned long owner); +/* + * Free a memory block identified by its user hash key. + */ + +extern int drm_sman_free_key(drm_sman_t * sman, unsigned int key); + +/* + * returns TRUE iff there are no stale memory blocks associated with this owner. + * Typically called to determine if we need to idle the hardware and call + * drm_sman_owner_cleanup. If there are no stale memory blocks, it removes all + * resources associated with owner. + */ + +extern int drm_sman_owner_clean(drm_sman_t * sman, unsigned long owner); + +/* + * Frees all stale memory blocks associated with this owner. Note that this + * requires that the hardware is finished with all blocks, so the graphics engine + * should be idled before this call is made. This function also frees + * any resources associated with "owner" and should be called when owner + * is not going to be referenced anymore. + */ + +extern void drm_sman_owner_cleanup(drm_sman_t * sman, unsigned long owner); + +/* + * Frees all stale memory blocks associated with the memory manager. + * See idling above. + */ + +extern void drm_sman_cleanup(drm_sman_t * sman); + +#endif -- cgit v1.2.3 From ce65a44de07f73ceda1749812b75086b7add408d Mon Sep 17 00:00:00 2001 From: Thomas Hellstrom Date: Mon, 7 Aug 2006 22:03:22 +1000 Subject: drm: add drm simple memory manager support for SiS and VIA drivers This add support to the SiS and VIA drivers for the simple memory manager. This fixes a lot of problems with the current simple code these drivers used, including locking and SMP issues. Signed-off-by: Dave Airlie --- drivers/char/drm/Makefile | 4 +- drivers/char/drm/sis_drv.c | 38 +++- drivers/char/drm/sis_drv.h | 24 ++- drivers/char/drm/sis_ds.c | 299 ----------------------------- drivers/char/drm/sis_ds.h | 146 --------------- drivers/char/drm/sis_mm.c | 456 ++++++++++++++++----------------------------- drivers/char/drm/via_drv.c | 3 +- drivers/char/drm/via_drv.h | 16 +- drivers/char/drm/via_ds.c | 273 --------------------------- drivers/char/drm/via_ds.h | 104 ----------- drivers/char/drm/via_map.c | 9 +- drivers/char/drm/via_mm.c | 375 +++++++++++-------------------------- 12 files changed, 344 insertions(+), 1403 deletions(-) delete mode 100644 drivers/char/drm/sis_ds.c delete mode 100644 drivers/char/drm/sis_ds.h delete mode 100644 drivers/char/drm/via_ds.c delete mode 100644 drivers/char/drm/via_ds.h diff --git a/drivers/char/drm/Makefile b/drivers/char/drm/Makefile index 5eb79f2d558..3ad0f648c6b 100644 --- a/drivers/char/drm/Makefile +++ b/drivers/char/drm/Makefile @@ -16,9 +16,9 @@ i830-objs := i830_drv.o i830_dma.o i830_irq.o i915-objs := i915_drv.o i915_dma.o i915_irq.o i915_mem.o radeon-objs := radeon_drv.o radeon_cp.o radeon_state.o radeon_mem.o radeon_irq.o r300_cmdbuf.o ffb-objs := ffb_drv.o ffb_context.o -sis-objs := sis_drv.o sis_ds.o sis_mm.o +sis-objs := sis_drv.o sis_mm.o savage-objs := savage_drv.o savage_bci.o savage_state.o -via-objs := via_irq.o via_drv.o via_ds.o via_map.o via_mm.o via_dma.o via_verifier.o via_video.o via_dmablit.o +via-objs := via_irq.o via_drv.o via_map.o via_mm.o via_dma.o via_verifier.o via_video.o via_dmablit.o ifeq ($(CONFIG_COMPAT),y) drm-objs += drm_ioc32.o diff --git a/drivers/char/drm/sis_drv.c b/drivers/char/drm/sis_drv.c index 5e9dc86f295..93880e44920 100644 --- a/drivers/char/drm/sis_drv.c +++ b/drivers/char/drm/sis_drv.c @@ -35,11 +35,43 @@ static struct pci_device_id pciidlist[] = { sisdrv_PCI_IDS }; +static int sis_driver_load(drm_device_t *dev, unsigned long chipset) +{ + drm_sis_private_t *dev_priv; + int ret; + + dev_priv = drm_calloc(1, sizeof(drm_sis_private_t), DRM_MEM_DRIVER); + if (dev_priv == NULL) + return DRM_ERR(ENOMEM); + + dev->dev_private = (void *)dev_priv; + dev_priv->chipset = chipset; + ret = drm_sman_init(&dev_priv->sman, 2, 12, 8); + if (ret) { + drm_free(dev_priv, sizeof(dev_priv), DRM_MEM_DRIVER); + } + + return ret; +} + +static int sis_driver_unload(drm_device_t *dev) +{ + drm_sis_private_t *dev_priv = dev->dev_private; + + drm_sman_takedown(&dev_priv->sman); + drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER); + + return 0; +} + static struct drm_driver driver = { .driver_features = DRIVER_USE_AGP | DRIVER_USE_MTRR, - .context_ctor = sis_init_context, - .context_dtor = sis_final_context, - .reclaim_buffers = drm_core_reclaim_buffers, + .load = sis_driver_load, + .unload = sis_driver_unload, + .context_dtor = NULL, + .reclaim_buffers = NULL, + .reclaim_buffers_locked = sis_reclaim_buffers_locked, + .lastclose = sis_lastclose, .get_map_ofs = drm_core_get_map_ofs, .get_reg_ofs = drm_core_get_reg_ofs, .ioctls = sis_ioctls, diff --git a/drivers/char/drm/sis_drv.h b/drivers/char/drm/sis_drv.h index e218e526950..330a2c4eade 100644 --- a/drivers/char/drm/sis_drv.h +++ b/drivers/char/drm/sis_drv.h @@ -31,23 +31,29 @@ /* General customization: */ -#define DRIVER_AUTHOR "SIS" +#define DRIVER_AUTHOR "SIS, Tungsten Graphics" #define DRIVER_NAME "sis" #define DRIVER_DESC "SIS 300/630/540" -#define DRIVER_DATE "20030826" +#define DRIVER_DATE "20060529" #define DRIVER_MAJOR 1 -#define DRIVER_MINOR 1 -#define DRIVER_PATCHLEVEL 0 +#define DRIVER_MINOR 2 +#define DRIVER_PATCHLEVEL 1 -#include "sis_ds.h" +#include "drm_sman.h" typedef struct drm_sis_private { - memHeap_t *AGPHeap; - memHeap_t *FBHeap; + drm_local_map_t *mmio; + unsigned int idle_fault; + drm_sman_t sman; + unsigned int chipset; + int vram_initialized; + int agp_initialized; + unsigned long vram_offset; + unsigned long agp_offset; } drm_sis_private_t; -extern int sis_init_context(drm_device_t * dev, int context); -extern int sis_final_context(drm_device_t * dev, int context); +extern void sis_reclaim_buffers_locked(drm_device_t *dev, struct file *filp); +extern void sis_lastclose(drm_device_t *dev); extern drm_ioctl_desc_t sis_ioctls[]; extern int sis_max_ioctl; diff --git a/drivers/char/drm/sis_ds.c b/drivers/char/drm/sis_ds.c deleted file mode 100644 index 2e485d48294..00000000000 --- a/drivers/char/drm/sis_ds.c +++ /dev/null @@ -1,299 +0,0 @@ -/* sis_ds.c -- Private header for Direct Rendering Manager -*- linux-c -*- - * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw - * - * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Authors: - * Sung-Ching Lin - * - */ - -#include "drmP.h" -#include "drm.h" -#include "sis_ds.h" - -/* Set Data Structure, not check repeated value - * temporarily used - */ - -set_t *setInit(void) -{ - int i; - set_t *set; - - set = (set_t *) drm_alloc(sizeof(set_t), DRM_MEM_DRIVER); - if (set != NULL) { - for (i = 0; i < SET_SIZE; i++) { - set->list[i].free_next = i + 1; - set->list[i].alloc_next = -1; - } - set->list[SET_SIZE - 1].free_next = -1; - set->free = 0; - set->alloc = -1; - set->trace = -1; - } - return set; -} - -int setAdd(set_t * set, ITEM_TYPE item) -{ - int free = set->free; - - if (free != -1) { - set->list[free].val = item; - set->free = set->list[free].free_next; - } else { - return 0; - } - - set->list[free].alloc_next = set->alloc; - set->alloc = free; - set->list[free].free_next = -1; - - return 1; -} - -int setDel(set_t * set, ITEM_TYPE item) -{ - int alloc = set->alloc; - int prev = -1; - - while (alloc != -1) { - if (set->list[alloc].val == item) { - if (prev != -1) - set->list[prev].alloc_next = - set->list[alloc].alloc_next; - else - set->alloc = set->list[alloc].alloc_next; - break; - } - prev = alloc; - alloc = set->list[alloc].alloc_next; - } - - if (alloc == -1) - return 0; - - set->list[alloc].free_next = set->free; - set->free = alloc; - set->list[alloc].alloc_next = -1; - - return 1; -} - -/* setFirst -> setAdd -> setNext is wrong */ - -int setFirst(set_t * set, ITEM_TYPE * item) -{ - if (set->alloc == -1) - return 0; - - *item = set->list[set->alloc].val; - set->trace = set->list[set->alloc].alloc_next; - - return 1; -} - -int setNext(set_t * set, ITEM_TYPE * item) -{ - if (set->trace == -1) - return 0; - - *item = set->list[set->trace].val; - set->trace = set->list[set->trace].alloc_next; - - return 1; -} - -int setDestroy(set_t * set) -{ - drm_free(set, sizeof(set_t), DRM_MEM_DRIVER); - - return 1; -} - -/* - * GLX Hardware Device Driver common code - * Copyright (C) 1999 Wittawat Yamwong - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#define ISFREE(bptr) ((bptr)->free) - -memHeap_t *mmInit(int ofs, int size) -{ - PMemBlock blocks; - - if (size <= 0) - return NULL; - - blocks = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), DRM_MEM_DRIVER); - if (blocks != NULL) { - blocks->ofs = ofs; - blocks->size = size; - blocks->free = 1; - return (memHeap_t *) blocks; - } else - return NULL; -} - -/* Checks if a pointer 'b' is part of the heap 'heap' */ -int mmBlockInHeap(memHeap_t * heap, PMemBlock b) -{ - TMemBlock *p; - - if (heap == NULL || b == NULL) - return 0; - - p = heap; - while (p != NULL && p != b) { - p = p->next; - } - if (p == b) - return 1; - else - return 0; -} - -static TMemBlock *SliceBlock(TMemBlock * p, - int startofs, int size, - int reserved, int alignment) -{ - TMemBlock *newblock; - - /* break left */ - if (startofs > p->ofs) { - newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), - DRM_MEM_DRIVER); - newblock->ofs = startofs; - newblock->size = p->size - (startofs - p->ofs); - newblock->free = 1; - newblock->next = p->next; - p->size -= newblock->size; - p->next = newblock; - p = newblock; - } - - /* break right */ - if (size < p->size) { - newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), - DRM_MEM_DRIVER); - newblock->ofs = startofs + size; - newblock->size = p->size - size; - newblock->free = 1; - newblock->next = p->next; - p->size = size; - p->next = newblock; - } - - /* p = middle block */ - p->align = alignment; - p->free = 0; - p->reserved = reserved; - return p; -} - -PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch) -{ - int mask, startofs, endofs; - TMemBlock *p; - - if (heap == NULL || align2 < 0 || size <= 0) - return NULL; - - mask = (1 << align2) - 1; - startofs = 0; - p = (TMemBlock *) heap; - while (p != NULL) { - if (ISFREE(p)) { - startofs = (p->ofs + mask) & ~mask; - if (startofs < startSearch) { - startofs = startSearch; - } - endofs = startofs + size; - if (endofs <= (p->ofs + p->size)) - break; - } - p = p->next; - } - if (p == NULL) - return NULL; - p = SliceBlock(p, startofs, size, 0, mask + 1); - p->heap = heap; - return p; -} - -static __inline__ int Join2Blocks(TMemBlock * p) -{ - if (p->free && p->next && p->next->free) { - TMemBlock *q = p->next; - p->size += q->size; - p->next = q->next; - drm_free(q, sizeof(TMemBlock), DRM_MEM_DRIVER); - return 1; - } - return 0; -} - -int mmFreeMem(PMemBlock b) -{ - TMemBlock *p, *prev; - - if (b == NULL) - return 0; - if (b->heap == NULL) - return -1; - - p = b->heap; - prev = NULL; - while (p != NULL && p != b) { - prev = p; - p = p->next; - } - if (p == NULL || p->free || p->reserved) - return -1; - - p->free = 1; - Join2Blocks(p); - if (prev) - Join2Blocks(prev); - return 0; -} diff --git a/drivers/char/drm/sis_ds.h b/drivers/char/drm/sis_ds.h deleted file mode 100644 index 94f2b4728b6..00000000000 --- a/drivers/char/drm/sis_ds.h +++ /dev/null @@ -1,146 +0,0 @@ -/* sis_ds.h -- Private header for Direct Rendering Manager -*- linux-c -*- - * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw - */ -/* - * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. - * All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Authors: - * Sung-Ching Lin - * - */ - -#ifndef __SIS_DS_H__ -#define __SIS_DS_H__ - -/* Set Data Structure */ - -#define SET_SIZE 5000 - -typedef unsigned long ITEM_TYPE; - -typedef struct { - ITEM_TYPE val; - int alloc_next, free_next; -} list_item_t; - -typedef struct { - int alloc; - int free; - int trace; - list_item_t list[SET_SIZE]; -} set_t; - -set_t *setInit(void); -int setAdd(set_t * set, ITEM_TYPE item); -int setDel(set_t * set, ITEM_TYPE item); -int setFirst(set_t * set, ITEM_TYPE * item); -int setNext(set_t * set, ITEM_TYPE * item); -int setDestroy(set_t * set); - -/* - * GLX Hardware Device Driver common code - * Copyright (C) 1999 Wittawat Yamwong - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -struct mem_block_t { - struct mem_block_t *next; - struct mem_block_t *heap; - int ofs, size; - int align; - unsigned int free:1; - unsigned int reserved:1; -}; -typedef struct mem_block_t TMemBlock; -typedef struct mem_block_t *PMemBlock; - -/* a heap is just the first block in a chain */ -typedef struct mem_block_t memHeap_t; - -static __inline__ int mmBlockSize(PMemBlock b) -{ - return b->size; -} - -static __inline__ int mmOffset(PMemBlock b) -{ - return b->ofs; -} - -static __inline__ void mmMarkReserved(PMemBlock b) -{ - b->reserved = 1; -} - -/* - * input: total size in bytes - * return: a heap pointer if OK, NULL if error - */ -memHeap_t *mmInit(int ofs, int size); - -/* - * Allocate 'size' bytes with 2^align2 bytes alignment, - * restrict the search to free memory after 'startSearch' - * depth and back buffers should be in different 4mb banks - * to get better page hits if possible - * input: size = size of block - * align2 = 2^align2 bytes alignment - * startSearch = linear offset from start of heap to begin search - * return: pointer to the allocated block, 0 if error - */ -PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch); - -/* - * Returns 1 if the block 'b' is part of the heap 'heap' - */ -int mmBlockInHeap(PMemBlock heap, PMemBlock b); - -/* - * Free block starts at offset - * input: pointer to a block - * return: 0 if OK, -1 if error - */ -int mmFreeMem(PMemBlock b); - -/* For debuging purpose. */ -void mmDumpMemInfo(memHeap_t * mmInit); - -#endif /* __SIS_DS_H__ */ diff --git a/drivers/char/drm/sis_mm.c b/drivers/char/drm/sis_mm.c index 5e9936bc307..0eb1dca232b 100644 --- a/drivers/char/drm/sis_mm.c +++ b/drivers/char/drm/sis_mm.c @@ -1,414 +1,274 @@ -/* sis_mm.c -- Private header for Direct Rendering Manager -*- linux-c -*- - * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw +/************************************************************************** * - * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan. - * All rights reserved. + * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA. + * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. * - * Authors: - * Sung-Ching Lin * + **************************************************************************/ + +/* + * Authors: + * Thomas Hellström */ #include "drmP.h" #include "sis_drm.h" #include "sis_drv.h" -#include "sis_ds.h" -#if defined(__linux__) && defined(CONFIG_FB_SIS) + #include