aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/asm-alpha/current.h2
-rw-r--r--include/asm-alpha/dma-mapping.h2
-rw-r--r--include/asm-alpha/kvm.h6
-rw-r--r--include/asm-alpha/pci.h8
-rw-r--r--include/asm-arm/arch-omap/board-osk.h11
-rw-r--r--include/asm-arm/arch-omap/clock.h75
-rw-r--r--include/asm-arm/arch-omap/control.h191
-rw-r--r--include/asm-arm/arch-omap/entry-macro.S2
-rw-r--r--include/asm-arm/arch-omap/gpio.h57
-rw-r--r--include/asm-arm/arch-omap/io.h70
-rw-r--r--include/asm-arm/arch-omap/mux.h66
-rw-r--r--include/asm-arm/arch-omap/omap24xx.h96
-rw-r--r--include/asm-arm/arch-omap/sdrc.h75
-rw-r--r--include/asm-arm/arch-omap/usb.h5
-rw-r--r--include/asm-arm/kvm.h6
-rw-r--r--include/asm-avr32/byteorder.h6
-rw-r--r--include/asm-avr32/kvm.h6
-rw-r--r--include/asm-blackfin/kvm.h6
-rw-r--r--include/asm-cris/kvm.h6
-rw-r--r--include/asm-frv/kvm.h6
-rw-r--r--include/asm-frv/mem-layout.h2
-rw-r--r--include/asm-frv/pgtable.h19
-rw-r--r--include/asm-frv/spr-regs.h14
-rw-r--r--include/asm-frv/system.h25
-rw-r--r--include/asm-generic/Kbuild.asm2
-rw-r--r--include/asm-h8300/kvm.h6
-rw-r--r--include/asm-ia64/kvm.h6
-rw-r--r--include/asm-m32r/kvm.h6
-rw-r--r--include/asm-m68k/kvm.h6
-rw-r--r--include/asm-m68knommu/kvm.h6
-rw-r--r--include/asm-mips/cacheflush.h18
-rw-r--r--include/asm-mips/kvm.h6
-rw-r--r--include/asm-mips/mach-au1x00/au1000.h1
-rw-r--r--include/asm-mips/mach-pb1x00/pb1200.h2
-rw-r--r--include/asm-mn10300/kvm.h6
-rw-r--r--include/asm-parisc/kvm.h6
-rw-r--r--include/asm-powerpc/kvm.h6
-rw-r--r--include/asm-s390/kvm.h6
-rw-r--r--include/asm-sh/floppy.h268
-rw-r--r--include/asm-sh/fpu.h39
-rw-r--r--include/asm-sh/kvm.h6
-rw-r--r--include/asm-sh/processor.h1
-rw-r--r--include/asm-sh/processor_32.h1
-rw-r--r--include/asm-sh/processor_64.h1
-rw-r--r--include/asm-sparc/kvm.h6
-rw-r--r--include/asm-sparc64/cpudata.h2
-rw-r--r--include/asm-sparc64/dcu.h41
-rw-r--r--include/asm-sparc64/irq.h1
-rw-r--r--include/asm-sparc64/kvm.h6
-rw-r--r--include/asm-sparc64/pgtable.h12
-rw-r--r--include/asm-sparc64/processor.h3
-rw-r--r--include/asm-sparc64/stacktrace.h6
-rw-r--r--include/asm-sparc64/timer.h9
-rw-r--r--include/asm-um/kvm.h6
-rw-r--r--include/asm-v850/kvm.h6
-rw-r--r--include/asm-x86/irqflags.h29
-rw-r--r--include/asm-x86/lguest_hcall.h2
-rw-r--r--include/asm-x86/linkage.h35
-rw-r--r--include/asm-x86/mach-rdc321x/gpio.h9
-rw-r--r--include/asm-x86/mach-rdc321x/rdc321x_defs.h8
-rw-r--r--include/asm-x86/nops.h20
-rw-r--r--include/asm-x86/pgtable.h2
-rw-r--r--include/asm-xtensa/kvm.h6
-rw-r--r--include/linux/Kbuild4
-rw-r--r--include/linux/bitops.h40
-rw-r--r--include/linux/cgroup.h1
-rw-r--r--include/linux/compat.h4
-rw-r--r--include/linux/cpuidle.h4
-rw-r--r--include/linux/dmaengine.h2
-rw-r--r--include/linux/hardirq.h7
-rw-r--r--include/linux/hpet.h2
-rw-r--r--include/linux/i2c/tps65010.h30
-rw-r--r--include/linux/ide.h2
-rw-r--r--include/linux/input.h5
-rw-r--r--include/linux/iocontext.h3
-rw-r--r--include/linux/lguest_launcher.h6
-rw-r--r--include/linux/libata.h27
-rw-r--r--include/linux/linkage.h20
-rw-r--r--include/linux/mount.h2
-rw-r--r--include/linux/netdevice.h12
-rw-r--r--include/linux/pnp.h2
-rw-r--r--include/linux/spinlock.h3
-rw-r--r--include/linux/virtio.h5
-rw-r--r--include/net/llc.h1
-rw-r--r--include/net/llc_pdu.h4
-rw-r--r--include/net/llc_sap.h7
-rw-r--r--include/net/neighbour.h4
-rw-r--r--include/net/tcp.h2
-rw-r--r--include/net/xfrm.h29
89 files changed, 1106 insertions, 492 deletions
diff --git a/include/asm-alpha/current.h b/include/asm-alpha/current.h
index 8d88a13c1bec..094d285a1b34 100644
--- a/include/asm-alpha/current.h
+++ b/include/asm-alpha/current.h
@@ -3,7 +3,7 @@
3 3
4#include <linux/thread_info.h> 4#include <linux/thread_info.h>
5 5
6#define get_current() (current_thread_info()->task + 0) 6#define get_current() (current_thread_info()->task)
7#define current get_current() 7#define current get_current()
8 8
9#endif /* _ALPHA_CURRENT_H */ 9#endif /* _ALPHA_CURRENT_H */
diff --git a/include/asm-alpha/dma-mapping.h b/include/asm-alpha/dma-mapping.h
index 75a1aff5b57b..db351d1296f4 100644
--- a/include/asm-alpha/dma-mapping.h
+++ b/include/asm-alpha/dma-mapping.h
@@ -11,7 +11,7 @@
11#define dma_unmap_single(dev, addr, size, dir) \ 11#define dma_unmap_single(dev, addr, size, dir) \
12 pci_unmap_single(alpha_gendev_to_pci(dev), addr, size, dir) 12 pci_unmap_single(alpha_gendev_to_pci(dev), addr, size, dir)
13#define dma_alloc_coherent(dev, size, addr, gfp) \ 13#define dma_alloc_coherent(dev, size, addr, gfp) \
14 pci_alloc_consistent(alpha_gendev_to_pci(dev), size, addr) 14 __pci_alloc_consistent(alpha_gendev_to_pci(dev), size, addr, gfp)
15#define dma_free_coherent(dev, size, va, addr) \ 15#define dma_free_coherent(dev, size, va, addr) \
16 pci_free_consistent(alpha_gendev_to_pci(dev), size, va, addr) 16 pci_free_consistent(alpha_gendev_to_pci(dev), size, va, addr)
17#define dma_map_page(dev, page, off, size, dir) \ 17#define dma_map_page(dev, page, off, size, dir) \
diff --git a/include/asm-alpha/kvm.h b/include/asm-alpha/kvm.h
new file mode 100644
index 000000000000..b9daec429689
--- /dev/null
+++ b/include/asm-alpha/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_ALPHA_H
2#define __LINUX_KVM_ALPHA_H
3
4/* alpha does not support KVM */
5
6#endif
diff --git a/include/asm-alpha/pci.h b/include/asm-alpha/pci.h
index d5b10ef64364..d31fd49ff79a 100644
--- a/include/asm-alpha/pci.h
+++ b/include/asm-alpha/pci.h
@@ -76,7 +76,13 @@ extern inline void pcibios_penalize_isa_irq(int irq, int active)
76 successful and sets *DMA_ADDRP to the pci side dma address as well, 76 successful and sets *DMA_ADDRP to the pci side dma address as well,
77 else DMA_ADDRP is undefined. */ 77 else DMA_ADDRP is undefined. */
78 78
79extern void *pci_alloc_consistent(struct pci_dev *, size_t, dma_addr_t *); 79extern void *__pci_alloc_consistent(struct pci_dev *, size_t,
80 dma_addr_t *, gfp_t);
81static inline void *
82pci_alloc_consistent(struct pci_dev *dev, size_t size, dma_addr_t *dma)
83{
84 return __pci_alloc_consistent(dev, size, dma, GFP_ATOMIC);
85}
80 86
81/* Free and unmap a consistent DMA buffer. CPU_ADDR and DMA_ADDR must 87/* Free and unmap a consistent DMA buffer. CPU_ADDR and DMA_ADDR must
82 be values that were returned from pci_alloc_consistent. SIZE must 88 be values that were returned from pci_alloc_consistent. SIZE must
diff --git a/include/asm-arm/arch-omap/board-osk.h b/include/asm-arm/arch-omap/board-osk.h
index 2b1a8a4fe44e..94926090e475 100644
--- a/include/asm-arm/arch-omap/board-osk.h
+++ b/include/asm-arm/arch-omap/board-osk.h
@@ -32,5 +32,16 @@
32/* At OMAP5912 OSK the Ethernet is directly connected to CS1 */ 32/* At OMAP5912 OSK the Ethernet is directly connected to CS1 */
33#define OMAP_OSK_ETHR_START 0x04800300 33#define OMAP_OSK_ETHR_START 0x04800300
34 34
35/* TPS65010 has four GPIOs. nPG and LED2 can be treated like GPIOs with
36 * alternate pin configurations for hardware-controlled blinking.
37 */
38#define OSK_TPS_GPIO_BASE (OMAP_MAX_GPIO_LINES + 16 /* MPUIO */)
39# define OSK_TPS_GPIO_USB_PWR_EN (OSK_TPS_GPIO_BASE + 0)
40# define OSK_TPS_GPIO_LED_D3 (OSK_TPS_GPIO_BASE + 1)
41# define OSK_TPS_GPIO_LAN_RESET (OSK_TPS_GPIO_BASE + 2)
42# define OSK_TPS_GPIO_DSP_PWR_EN (OSK_TPS_GPIO_BASE + 3)
43# define OSK_TPS_GPIO_LED_D9 (OSK_TPS_GPIO_BASE + 4)
44# define OSK_TPS_GPIO_LED_D2 (OSK_TPS_GPIO_BASE + 5)
45
35#endif /* __ASM_ARCH_OMAP_OSK_H */ 46#endif /* __ASM_ARCH_OMAP_OSK_H */
36 47
diff --git a/include/asm-arm/arch-omap/clock.h b/include/asm-arm/arch-omap/clock.h
index fa6881049903..57523bdb642b 100644
--- a/include/asm-arm/arch-omap/clock.h
+++ b/include/asm-arm/arch-omap/clock.h
@@ -14,6 +14,35 @@
14#define __ARCH_ARM_OMAP_CLOCK_H 14#define __ARCH_ARM_OMAP_CLOCK_H
15 15
16struct module; 16struct module;
17struct clk;
18
19#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
20
21struct clksel_rate {
22 u8 div;
23 u32 val;
24 u8 flags;
25};
26
27struct clksel {
28 struct clk *parent;
29 const struct clksel_rate *rates;
30};
31
32struct dpll_data {
33 void __iomem *mult_div1_reg;
34 u32 mult_mask;
35 u32 div1_mask;
36# if defined(CONFIG_ARCH_OMAP3)
37 void __iomem *control_reg;
38 u32 enable_mask;
39 u8 auto_recal_bit;
40 u8 recal_en_bit;
41 u8 recal_st_bit;
42# endif
43};
44
45#endif
17 46
18struct clk { 47struct clk {
19 struct list_head node; 48 struct list_head node;
@@ -25,8 +54,6 @@ struct clk {
25 __u32 flags; 54 __u32 flags;
26 void __iomem *enable_reg; 55 void __iomem *enable_reg;
27 __u8 enable_bit; 56 __u8 enable_bit;
28 __u8 rate_offset;
29 __u8 src_offset;
30 __s8 usecount; 57 __s8 usecount;
31 void (*recalc)(struct clk *); 58 void (*recalc)(struct clk *);
32 int (*set_rate)(struct clk *, unsigned long); 59 int (*set_rate)(struct clk *, unsigned long);
@@ -34,6 +61,16 @@ struct clk {
34 void (*init)(struct clk *); 61 void (*init)(struct clk *);
35 int (*enable)(struct clk *); 62 int (*enable)(struct clk *);
36 void (*disable)(struct clk *); 63 void (*disable)(struct clk *);
64#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
65 u8 fixed_div;
66 void __iomem *clksel_reg;
67 u32 clksel_mask;
68 const struct clksel *clksel;
69 const struct dpll_data *dpll_data;
70#else
71 __u8 rate_offset;
72 __u8 src_offset;
73#endif
37}; 74};
38 75
39struct clk_functions { 76struct clk_functions {
@@ -54,10 +91,12 @@ extern int clk_init(struct clk_functions * custom_clocks);
54extern int clk_register(struct clk *clk); 91extern int clk_register(struct clk *clk);
55extern void clk_unregister(struct clk *clk); 92extern void clk_unregister(struct clk *clk);
56extern void propagate_rate(struct clk *clk); 93extern void propagate_rate(struct clk *clk);
94extern void recalculate_root_clocks(void);
57extern void followparent_recalc(struct clk * clk); 95extern void followparent_recalc(struct clk * clk);
58extern void clk_allow_idle(struct clk *clk); 96extern void clk_allow_idle(struct clk *clk);
59extern void clk_deny_idle(struct clk *clk); 97extern void clk_deny_idle(struct clk *clk);
60extern int clk_get_usecount(struct clk *clk); 98extern int clk_get_usecount(struct clk *clk);
99extern void clk_enable_init_clocks(void);
61 100
62/* Clock flags */ 101/* Clock flags */
63#define RATE_CKCTL (1 << 0) /* Main fixed ratio clocks */ 102#define RATE_CKCTL (1 << 0) /* Main fixed ratio clocks */
@@ -71,21 +110,33 @@ extern int clk_get_usecount(struct clk *clk);
71#define CLOCK_NO_IDLE_PARENT (1 << 8) 110#define CLOCK_NO_IDLE_PARENT (1 << 8)
72#define DELAYED_APP (1 << 9) /* Delay application of clock */ 111#define DELAYED_APP (1 << 9) /* Delay application of clock */
73#define CONFIG_PARTICIPANT (1 << 10) /* Fundamental clock */ 112#define CONFIG_PARTICIPANT (1 << 10) /* Fundamental clock */
74#define CM_MPU_SEL1 (1 << 11) /* Domain divider/source */ 113#define ENABLE_ON_INIT (1 << 11) /* Enable upon framework init */
75#define CM_DSP_SEL1 (1 << 12) 114#define INVERT_ENABLE (1 << 12) /* 0 enables, 1 disables */
76#define CM_GFX_SEL1 (1 << 13) 115/* bits 13-20 are currently free */
77#define CM_MODEM_SEL1 (1 << 14)
78#define CM_CORE_SEL1 (1 << 15) /* Sets divider for many */
79#define CM_CORE_SEL2 (1 << 16) /* sets parent for GPT */
80#define CM_WKUP_SEL1 (1 << 17)
81#define CM_PLL_SEL1 (1 << 18)
82#define CM_PLL_SEL2 (1 << 19)
83#define CM_SYSCLKOUT_SEL1 (1 << 20)
84#define CLOCK_IN_OMAP310 (1 << 21) 116#define CLOCK_IN_OMAP310 (1 << 21)
85#define CLOCK_IN_OMAP730 (1 << 22) 117#define CLOCK_IN_OMAP730 (1 << 22)
86#define CLOCK_IN_OMAP1510 (1 << 23) 118#define CLOCK_IN_OMAP1510 (1 << 23)
87#define CLOCK_IN_OMAP16XX (1 << 24) 119#define CLOCK_IN_OMAP16XX (1 << 24)
88#define CLOCK_IN_OMAP242X (1 << 25) 120#define CLOCK_IN_OMAP242X (1 << 25)
89#define CLOCK_IN_OMAP243X (1 << 26) 121#define CLOCK_IN_OMAP243X (1 << 26)
122#define CLOCK_IN_OMAP343X (1 << 27) /* clocks common to all 343X */
123#define PARENT_CONTROLS_CLOCK (1 << 28)
124#define CLOCK_IN_OMAP3430ES1 (1 << 29) /* 3430ES1 clocks only */
125#define CLOCK_IN_OMAP3430ES2 (1 << 30) /* 3430ES2 clocks only */
126
127/* Clksel_rate flags */
128#define DEFAULT_RATE (1 << 0)
129#define RATE_IN_242X (1 << 1)
130#define RATE_IN_243X (1 << 2)
131#define RATE_IN_343X (1 << 3) /* rates common to all 343X */
132#define RATE_IN_3430ES2 (1 << 4) /* 3430ES2 rates only */
133
134#define RATE_IN_24XX (RATE_IN_242X | RATE_IN_243X)
135
136
137/* CM_CLKSEL2_PLL.CORE_CLK_SRC options (24XX) */
138#define CORE_CLK_SRC_32K 0
139#define CORE_CLK_SRC_DPLL 1
140#define CORE_CLK_SRC_DPLL_X2 2
90 141
91#endif 142#endif
diff --git a/include/asm-arm/arch-omap/control.h b/include/asm-arm/arch-omap/control.h
new file mode 100644
index 000000000000..9944bb5d5330
--- /dev/null
+++ b/include/asm-arm/arch-omap/control.h
@@ -0,0 +1,191 @@
1#ifndef __ASM_ARCH_CONTROL_H
2#define __ASM_ARCH_CONTROL_H
3
4/*
5 * include/asm-arm/arch-omap/control.h
6 *
7 * OMAP2/3 System Control Module definitions
8 *
9 * Copyright (C) 2007 Texas Instruments, Inc.
10 * Copyright (C) 2007 Nokia Corporation
11 *
12 * Written by Paul Walmsley
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation.
17 */
18
19#include <asm/arch/io.h>
20
21#define OMAP242X_CTRL_REGADDR(reg) \
22 (void __iomem *)IO_ADDRESS(OMAP242X_CTRL_BASE + (reg))
23#define OMAP243X_CTRL_REGADDR(reg) \
24 (void __iomem *)IO_ADDRESS(OMAP243X_CTRL_BASE + (reg))
25#define OMAP343X_CTRL_REGADDR(reg) \
26 (void __iomem *)IO_ADDRESS(OMAP343X_CTRL_BASE + (reg))
27
28/*
29 * As elsewhere, the "OMAP2_" prefix indicates that the macro is valid for
30 * OMAP24XX and OMAP34XX.
31 */
32
33/* Control submodule offsets */
34
35#define OMAP2_CONTROL_INTERFACE 0x000
36#define OMAP2_CONTROL_PADCONFS 0x030
37#define OMAP2_CONTROL_GENERAL 0x270
38#define OMAP343X_CONTROL_MEM_WKUP 0x600
39#define OMAP343X_CONTROL_PADCONFS_WKUP 0xa00
40#define OMAP343X_CONTROL_GENERAL_WKUP 0xa60
41
42/* Control register offsets - read/write with omap_ctrl_{read,write}{bwl}() */
43
44#define OMAP2_CONTROL_SYSCONFIG (OMAP2_CONTROL_INTERFACE + 0x10)
45
46/* CONTROL_GENERAL register offsets common to OMAP2 & 3 */
47#define OMAP2_CONTROL_DEVCONF0 (OMAP2_CONTROL_GENERAL + 0x0004)
48#define OMAP2_CONTROL_MSUSPENDMUX_0 (OMAP2_CONTROL_GENERAL + 0x0020)
49#define OMAP2_CONTROL_MSUSPENDMUX_1 (OMAP2_CONTROL_GENERAL + 0x0024)
50#define OMAP2_CONTROL_MSUSPENDMUX_2 (OMAP2_CONTROL_GENERAL + 0x0028)
51#define OMAP2_CONTROL_MSUSPENDMUX_3 (OMAP2_CONTROL_GENERAL + 0x002c)
52#define OMAP2_CONTROL_MSUSPENDMUX_4 (OMAP2_CONTROL_GENERAL + 0x0030)
53#define OMAP2_CONTROL_MSUSPENDMUX_5 (OMAP2_CONTROL_GENERAL + 0x0034)
54#define OMAP2_CONTROL_SEC_CTRL (OMAP2_CONTROL_GENERAL + 0x0040)
55#define OMAP2_CONTROL_RPUB_KEY_H_0 (OMAP2_CONTROL_GENERAL + 0x0090)
56#define OMAP2_CONTROL_RPUB_KEY_H_1 (OMAP2_CONTROL_GENERAL + 0x0094)
57#define OMAP2_CONTROL_RPUB_KEY_H_2 (OMAP2_CONTROL_GENERAL + 0x0098)
58#define OMAP2_CONTROL_RPUB_KEY_H_3 (OMAP2_CONTROL_GENERAL + 0x009c)
59
60/* 242x-only CONTROL_GENERAL register offsets */
61#define OMAP242X_CONTROL_DEVCONF OMAP2_CONTROL_DEVCONF0 /* match TRM */
62#define OMAP242X_CONTROL_OCM_RAM_PERM (OMAP2_CONTROL_GENERAL + 0x0068)
63
64/* 243x-only CONTROL_GENERAL register offsets */
65/* CONTROL_IVA2_BOOT{ADDR,MOD} are at the same place on 343x - noted below */
66#define OMAP243X_CONTROL_DEVCONF1 (OMAP2_CONTROL_GENERAL + 0x0078)
67#define OMAP243X_CONTROL_CSIRXFE (OMAP2_CONTROL_GENERAL + 0x007c)
68#define OMAP243X_CONTROL_IVA2_BOOTADDR (OMAP2_CONTROL_GENERAL + 0x0190)
69#define OMAP243X_CONTROL_IVA2_BOOTMOD (OMAP2_CONTROL_GENERAL + 0x0194)
70#define OMAP243X_CONTROL_IVA2_GEMCFG (OMAP2_CONTROL_GENERAL + 0x0198)
71
72/* 24xx-only CONTROL_GENERAL register offsets */
73#define OMAP24XX_CONTROL_DEBOBS (OMAP2_CONTROL_GENERAL + 0x0000)
74#define OMAP24XX_CONTROL_EMU_SUPPORT (OMAP2_CONTROL_GENERAL + 0x0008)
75#define OMAP24XX_CONTROL_SEC_TEST (OMAP2_CONTROL_GENERAL + 0x0044)
76#define OMAP24XX_CONTROL_PSA_CTRL (OMAP2_CONTROL_GENERAL + 0x0048)
77#define OMAP24XX_CONTROL_PSA_CMD (OMAP2_CONTROL_GENERAL + 0x004c)
78#define OMAP24XX_CONTROL_PSA_VALUE (OMAP2_CONTROL_GENERAL + 0x0050)
79#define OMAP24XX_CONTROL_SEC_EMU (OMAP2_CONTROL_GENERAL + 0x0060)
80#define OMAP24XX_CONTROL_SEC_TAP (OMAP2_CONTROL_GENERAL + 0x0064)
81#define OMAP24XX_CONTROL_OCM_PUB_RAM_ADD (OMAP2_CONTROL_GENERAL + 0x006c)
82#define OMAP24XX_CONTROL_EXT_SEC_RAM_START_ADD (OMAP2_CONTROL_GENERAL + 0x0070)
83#define OMAP24XX_CONTROL_EXT_SEC_RAM_STOP_ADD (OMAP2_CONTROL_GENERAL + 0x0074
84#define OMAP24XX_CONTROL_SEC_STATUS (OMAP2_CONTROL_GENERAL + 0x0080)
85#define OMAP24XX_CONTROL_SEC_ERR_STATUS (OMAP2_CONTROL_GENERAL + 0x0084)
86#define OMAP24XX_CONTROL_STATUS (OMAP2_CONTROL_GENERAL + 0x0088)
87#define OMAP24XX_CONTROL_GENERAL_PURPOSE_STATUS (OMAP2_CONTROL_GENERAL + 0x008c)
88#define OMAP24XX_CONTROL_RAND_KEY_0 (OMAP2_CONTROL_GENERAL + 0x00a0)
89#define OMAP24XX_CONTROL_RAND_KEY_1 (OMAP2_CONTROL_GENERAL + 0x00a4)
90#define OMAP24XX_CONTROL_RAND_KEY_2 (OMAP2_CONTROL_GENERAL + 0x00a8)
91#define OMAP24XX_CONTROL_RAND_KEY_3 (OMAP2_CONTROL_GENERAL + 0x00ac)
92#define OMAP24XX_CONTROL_CUST_KEY_0 (OMAP2_CONTROL_GENERAL + 0x00b0)
93#define OMAP24XX_CONTROL_CUST_KEY_1 (OMAP2_CONTROL_GENERAL + 0x00b4)
94#define OMAP24XX_CONTROL_TEST_KEY_0 (OMAP2_CONTROL_GENERAL + 0x00c0)
95#define OMAP24XX_CONTROL_TEST_KEY_1 (OMAP2_CONTROL_GENERAL + 0x00c4)
96#define OMAP24XX_CONTROL_TEST_KEY_2 (OMAP2_CONTROL_GENERAL + 0x00c8)
97#define OMAP24XX_CONTROL_TEST_KEY_3 (OMAP2_CONTROL_GENERAL + 0x00cc)
98#define OMAP24XX_CONTROL_TEST_KEY_4 (OMAP2_CONTROL_GENERAL + 0x00d0)
99#define OMAP24XX_CONTROL_TEST_KEY_5 (OMAP2_CONTROL_GENERAL + 0x00d4)
100#define OMAP24XX_CONTROL_TEST_KEY_6 (OMAP2_CONTROL_GENERAL + 0x00d8)
101#define OMAP24XX_CONTROL_TEST_KEY_7 (OMAP2_CONTROL_GENERAL + 0x00dc)
102#define OMAP24XX_CONTROL_TEST_KEY_8 (OMAP2_CONTROL_GENERAL + 0x00e0)
103#define OMAP24XX_CONTROL_TEST_KEY_9 (OMAP2_CONTROL_GENERAL + 0x00e4)
104
105/* 34xx-only CONTROL_GENERAL register offsets */
106#define OMAP343X_CONTROL_PADCONF_OFF (OMAP2_CONTROL_GENERAL + 0x0000)
107#define OMAP343X_CONTROL_MEM_DFTRW0 (OMAP2_CONTROL_GENERAL + 0x0008)
108#define OMAP343X_CONTROL_MEM_DFTRW1 (OMAP2_CONTROL_GENERAL + 0x000c)
109#define OMAP343X_CONTROL_DEVCONF1 (OMAP2_CONTROL_GENERAL + 0x0068)
110#define OMAP343X_CONTROL_CSIRXFE (OMAP2_CONTROL_GENERAL + 0x006c)
111#define OMAP343X_CONTROL_SEC_STATUS (OMAP2_CONTROL_GENERAL + 0x0070)
112#define OMAP343X_CONTROL_SEC_ERR_STATUS (OMAP2_CONTROL_GENERAL + 0x0074)
113#define OMAP343X_CONTROL_SEC_ERR_STATUS_DEBUG (OMAP2_CONTROL_GENERAL + 0x0078)
114#define OMAP343X_CONTROL_STATUS (OMAP2_CONTROL_GENERAL + 0x0080)
115#define OMAP343X_CONTROL_GENERAL_PURPOSE_STATUS (OMAP2_CONTROL_GENERAL + 0x0084)
116#define OMAP343X_CONTROL_RPUB_KEY_H_4 (OMAP2_CONTROL_GENERAL + 0x00a0)
117#define OMAP343X_CONTROL_RAND_KEY_0 (OMAP2_CONTROL_GENERAL + 0x00a8)
118#define OMAP343X_CONTROL_RAND_KEY_1 (OMAP2_CONTROL_GENERAL + 0x00ac)
119#define OMAP343X_CONTROL_RAND_KEY_2 (OMAP2_CONTROL_GENERAL + 0x00b0)
120#define OMAP343X_CONTROL_RAND_KEY_3 (OMAP2_CONTROL_GENERAL + 0x00b4)
121#define OMAP343X_CONTROL_TEST_KEY_0 (OMAP2_CONTROL_GENERAL + 0x00c8)
122#define OMAP343X_CONTROL_TEST_KEY_1 (OMAP2_CONTROL_GENERAL + 0x00cc)
123#define OMAP343X_CONTROL_TEST_KEY_2 (OMAP2_CONTROL_GENERAL + 0x00d0)
124#define OMAP343X_CONTROL_TEST_KEY_3 (OMAP2_CONTROL_GENERAL + 0x00d4)
125#define OMAP343X_CONTROL_TEST_KEY_4 (OMAP2_CONTROL_GENERAL + 0x00d8)
126#define OMAP343X_CONTROL_TEST_KEY_5 (OMAP2_CONTROL_GENERAL + 0x00dc)
127#define OMAP343X_CONTROL_TEST_KEY_6 (OMAP2_CONTROL_GENERAL + 0x00e0)
128#define OMAP343X_CONTROL_TEST_KEY_7 (OMAP2_CONTROL_GENERAL + 0x00e4)
129#define OMAP343X_CONTROL_TEST_KEY_8 (OMAP2_CONTROL_GENERAL + 0x00e8)
130#define OMAP343X_CONTROL_TEST_KEY_9 (OMAP2_CONTROL_GENERAL + 0x00ec)
131#define OMAP343X_CONTROL_TEST_KEY_10 (OMAP2_CONTROL_GENERAL + 0x00f0)
132#define OMAP343X_CONTROL_TEST_KEY_11 (OMAP2_CONTROL_GENERAL + 0x00f4)
133#define OMAP343X_CONTROL_TEST_KEY_12 (OMAP2_CONTROL_GENERAL + 0x00f8)
134#define OMAP343X_CONTROL_TEST_KEY_13 (OMAP2_CONTROL_GENERAL + 0x00fc)
135#define OMAP343X_CONTROL_IVA2_BOOTADDR (OMAP2_CONTROL_GENERAL + 0x0190)
136#define OMAP343X_CONTROL_IVA2_BOOTMOD (OMAP2_CONTROL_GENERAL + 0x0194)
137
138/*
139 * REVISIT: This list of registers is not comprehensive - there are more
140 * that should be added.
141 */
142
143/*
144 * Control module register bit defines - these should eventually go into
145 * their own regbits file. Some of these will be complicated, depending
146 * on the device type (general-purpose, emulator, test, secure, bad, other)
147 * and the security mode (secure, non-secure, don't care)
148 */
149/* CONTROL_DEVCONF0 bits */
150#define OMAP24XX_USBSTANDBYCTRL (1 << 15)
151#define OMAP2_MCBSP2_CLKS_MASK (1 << 6)
152#define OMAP2_MCBSP1_CLKS_MASK (1 << 2)
153
154/* CONTROL_DEVCONF1 bits */
155#define OMAP2_MCBSP5_CLKS_MASK (1 << 4) /* > 242x */
156#define OMAP2_MCBSP4_CLKS_MASK (1 << 2) /* > 242x */
157#define OMAP2_MCBSP3_CLKS_MASK (1 << 0) /* > 242x */
158
159/* CONTROL_STATUS bits */
160#define OMAP2_DEVICETYPE_MASK (0x7 << 8)
161#define OMAP2_SYSBOOT_5_MASK (1 << 5)
162#define OMAP2_SYSBOOT_4_MASK (1 << 4)
163#define OMAP2_SYSBOOT_3_MASK (1 << 3)
164#define OMAP2_SYSBOOT_2_MASK (1 << 2)
165#define OMAP2_SYSBOOT_1_MASK (1 << 1)
166#define OMAP2_SYSBOOT_0_MASK (1 << 0)
167
168#ifndef __ASSEMBLY__
169#if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
170extern void omap_ctrl_base_set(u32 base);
171extern u32 omap_ctrl_base_get(void);
172extern u8 omap_ctrl_readb(u16 offset);
173extern u16 omap_ctrl_readw(u16 offset);
174extern u32 omap_ctrl_readl(u16 offset);
175extern void omap_ctrl_writeb(u8 val, u16 offset);
176extern void omap_ctrl_writew(u16 val, u16 offset);
177extern void omap_ctrl_writel(u32 val, u16 offset);
178#else
179#define omap_ctrl_base_set(x) WARN_ON(1)
180#define omap_ctrl_base_get() 0
181#define omap_ctrl_readb(x) 0
182#define omap_ctrl_readw(x) 0
183#define omap_ctrl_readl(x) 0
184#define omap_ctrl_writeb(x, y) WARN_ON(1)
185#define omap_ctrl_writew(x, y) WARN_ON(1)
186#define omap_ctrl_writel(x, y) WARN_ON(1)
187#endif
188#endif /* __ASSEMBLY__ */
189
190#endif /* __ASM_ARCH_CONTROL_H */
191
diff --git a/include/asm-arm/arch-omap/entry-macro.S b/include/asm-arm/arch-omap/entry-macro.S
index f6967c8df323..74cd57221c8e 100644
--- a/include/asm-arm/arch-omap/entry-macro.S
+++ b/include/asm-arm/arch-omap/entry-macro.S
@@ -68,7 +68,7 @@
68 .endm 68 .endm
69 69
70 .macro get_irqnr_and_base, irqnr, irqstat, base, tmp 70 .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
71 ldr \base, =VA_IC_BASE 71 ldr \base, =OMAP2_VA_IC_BASE
72 ldr \irqnr, [\base, #0x98] /* IRQ pending reg 1 */ 72 ldr \irqnr, [\base, #0x98] /* IRQ pending reg 1 */
73 cmp \irqnr, #0x0 73 cmp \irqnr, #0x0
74 bne 2222f 74 bne 2222f
diff --git a/include/asm-arm/arch-omap/gpio.h b/include/asm-arm/arch-omap/gpio.h
index 164da09be095..86621a04cd8f 100644
--- a/include/asm-arm/arch-omap/gpio.h
+++ b/include/asm-arm/arch-omap/gpio.h
@@ -82,62 +82,35 @@ extern void omap_set_gpio_debounce_time(int gpio, int enable);
82 82
83/*-------------------------------------------------------------------------*/ 83/*-------------------------------------------------------------------------*/
84 84
85/* wrappers for "new style" GPIO calls. the old OMAP-specfic ones should 85/* Wrappers for "new style" GPIO calls, using the new infrastructure
86 * eventually be removed (along with this errno.h inclusion), and maybe 86 * which lets us plug in FPGA, I2C, and other implementations.
87 * gpios should put MPUIOs last too. 87 * *
88 * The original OMAP-specfic calls should eventually be removed.
88 */ 89 */
89 90
90#include <asm/errno.h> 91#include <linux/errno.h>
91 92#include <asm-generic/gpio.h>
92static inline int gpio_request(unsigned gpio, const char *label)
93{
94 return omap_request_gpio(gpio);
95}
96
97static inline void gpio_free(unsigned gpio)
98{
99 omap_free_gpio(gpio);
100}
101
102static inline int __gpio_set_direction(unsigned gpio, int is_input)
103{
104 if (cpu_class_is_omap2()) {
105 if (gpio > OMAP_MAX_GPIO_LINES)
106 return -EINVAL;
107 } else {
108 if (gpio > (OMAP_MAX_GPIO_LINES + 16 /* MPUIO */))
109 return -EINVAL;
110 }
111 omap_set_gpio_direction(gpio, is_input);
112 return 0;
113}
114
115static inline int gpio_direction_input(unsigned gpio)
116{
117 return __gpio_set_direction(gpio, 1);
118}
119
120static inline int gpio_direction_output(unsigned gpio, int value)
121{
122 omap_set_gpio_dataout(gpio, value);
123 return __gpio_set_direction(gpio, 0);
124}
125 93
126static inline int gpio_get_value(unsigned gpio) 94static inline int gpio_get_value(unsigned gpio)
127{ 95{
128 return omap_get_gpio_datain(gpio); 96 return __gpio_get_value(gpio);
129} 97}
130 98
131static inline void gpio_set_value(unsigned gpio, int value) 99static inline void gpio_set_value(unsigned gpio, int value)
132{ 100{
133 omap_set_gpio_dataout(gpio, value); 101 __gpio_set_value(gpio, value);
134} 102}
135 103
136#include <asm-generic/gpio.h> /* cansleep wrappers */ 104static inline int gpio_cansleep(unsigned gpio)
105{
106 return __gpio_cansleep(gpio);
107}
137 108
138static inline int gpio_to_irq(unsigned gpio) 109static inline int gpio_to_irq(unsigned gpio)
139{ 110{
140 return OMAP_GPIO_IRQ(gpio); 111 if (gpio < (OMAP_MAX_GPIO_LINES + 16))
112 return OMAP_GPIO_IRQ(gpio);
113 return -EINVAL;
141} 114}
142 115
143static inline int irq_to_gpio(unsigned irq) 116static inline int irq_to_gpio(unsigned irq)
diff --git a/include/asm-arm/arch-omap/io.h b/include/asm-arm/arch-omap/io.h
index 289082d07f14..160578e1f557 100644
--- a/include/asm-arm/arch-omap/io.h
+++ b/include/asm-arm/arch-omap/io.h
@@ -80,6 +80,13 @@
80#define OMAP243X_GPMC_PHYS OMAP243X_GPMC_BASE /* 0x49000000 */ 80#define OMAP243X_GPMC_PHYS OMAP243X_GPMC_BASE /* 0x49000000 */
81#define OMAP243X_GPMC_VIRT 0xFE000000 81#define OMAP243X_GPMC_VIRT 0xFE000000
82#define OMAP243X_GPMC_SIZE SZ_1M 82#define OMAP243X_GPMC_SIZE SZ_1M
83#define OMAP243X_SDRC_PHYS OMAP243X_SDRC_BASE
84#define OMAP243X_SDRC_VIRT 0xFD000000
85#define OMAP243X_SDRC_SIZE SZ_1M
86#define OMAP243X_SMS_PHYS OMAP243X_SMS_BASE
87#define OMAP243X_SMS_VIRT 0xFC000000
88#define OMAP243X_SMS_SIZE SZ_1M
89
83#endif 90#endif
84 91
85#define IO_OFFSET 0x90000000 92#define IO_OFFSET 0x90000000
@@ -88,16 +95,73 @@
88#define io_v2p(va) ((va) - IO_OFFSET) /* Works for L3 and L4 */ 95#define io_v2p(va) ((va) - IO_OFFSET) /* Works for L3 and L4 */
89 96
90/* DSP */ 97/* DSP */
91#define DSP_MEM_24XX_PHYS OMAP24XX_DSP_MEM_BASE /* 0x58000000 */ 98#define DSP_MEM_24XX_PHYS OMAP2420_DSP_MEM_BASE /* 0x58000000 */
92#define DSP_MEM_24XX_VIRT 0xe0000000 99#define DSP_MEM_24XX_VIRT 0xe0000000
93#define DSP_MEM_24XX_SIZE 0x28000 100#define DSP_MEM_24XX_SIZE 0x28000
94#define DSP_IPI_24XX_PHYS OMAP24XX_DSP_IPI_BASE /* 0x59000000 */ 101#define DSP_IPI_24XX_PHYS OMAP2420_DSP_IPI_BASE /* 0x59000000 */
95#define DSP_IPI_24XX_VIRT 0xe1000000 102#define DSP_IPI_24XX_VIRT 0xe1000000
96#define DSP_IPI_24XX_SIZE SZ_4K 103#define DSP_IPI_24XX_SIZE SZ_4K
97#define DSP_MMU_24XX_PHYS OMAP24XX_DSP_MMU_BASE /* 0x5a000000 */ 104#define DSP_MMU_24XX_PHYS OMAP2420_DSP_MMU_BASE /* 0x5a000000 */
98#define DSP_MMU_24XX_VIRT 0xe2000000 105#define DSP_MMU_24XX_VIRT 0xe2000000
99#define DSP_MMU_24XX_SIZE SZ_4K 106#define DSP_MMU_24XX_SIZE SZ_4K
100 107
108#elif defined(CONFIG_ARCH_OMAP3)
109
110/* We map both L3 and L4 on OMAP3 */
111#define L3_34XX_PHYS L3_34XX_BASE /* 0x68000000 */
112#define L3_34XX_VIRT 0xf8000000
113#define L3_34XX_SIZE SZ_1M /* 44kB of 128MB used, want 1MB sect */
114
115#define L4_34XX_PHYS L4_34XX_BASE /* 0x48000000 */
116#define L4_34XX_VIRT 0xd8000000
117#define L4_34XX_SIZE SZ_4M /* 1MB of 128MB used, want 1MB sect */
118
119/*
120 * Need to look at the Size 4M for L4.
121 * VPOM3430 was not working for Int controller
122 */
123
124#define L4_WK_34XX_PHYS L4_WK_34XX_BASE /* 0x48300000 */
125#define L4_WK_34XX_VIRT 0xd8300000
126#define L4_WK_34XX_SIZE SZ_1M
127
128#define L4_PER_34XX_PHYS L4_PER_34XX_BASE /* 0x49000000 */
129#define L4_PER_34XX_VIRT 0xd9000000
130#define L4_PER_34XX_SIZE SZ_1M
131
132#define L4_EMU_34XX_PHYS L4_EMU_34XX_BASE /* 0x54000000 */
133#define L4_EMU_34XX_VIRT 0xe4000000
134#define L4_EMU_34XX_SIZE SZ_64M
135
136#define OMAP34XX_GPMC_PHYS OMAP34XX_GPMC_BASE /* 0x6E000000 */
137#define OMAP34XX_GPMC_VIRT 0xFE000000
138#define OMAP34XX_GPMC_SIZE SZ_1M
139
140#define OMAP343X_SMS_PHYS OMAP343X_SMS_BASE /* 0x6C000000 */
141#define OMAP343X_SMS_VIRT 0xFC000000
142#define OMAP343X_SMS_SIZE SZ_1M
143
144#define OMAP343X_SDRC_PHYS OMAP343X_SDRC_BASE /* 0x6D000000 */
145#define OMAP343X_SDRC_VIRT 0xFD000000
146#define OMAP343X_SDRC_SIZE SZ_1M
147
148
149#define IO_OFFSET 0x90000000
150#define IO_ADDRESS(pa) ((pa) + IO_OFFSET)/* Works for L3 and L4 */
151#define io_p2v(pa) ((pa) + IO_OFFSET)/* Works for L3 and L4 */
152#define io_v2p(va) ((va) - IO_OFFSET)/* Works for L3 and L4 */
153
154/* DSP */
155#define DSP_MEM_34XX_PHYS OMAP34XX_DSP_MEM_BASE /* 0x58000000 */
156#define DSP_MEM_34XX_VIRT 0xe0000000
157#define DSP_MEM_34XX_SIZE 0x28000
158#define DSP_IPI_34XX_PHYS OMAP34XX_DSP_IPI_BASE /* 0x59000000 */
159#define DSP_IPI_34XX_VIRT 0xe1000000
160#define DSP_IPI_34XX_SIZE SZ_4K
161#define DSP_MMU_34XX_PHYS OMAP34XX_DSP_MMU_BASE /* 0x5a000000 */
162#define DSP_MMU_34XX_VIRT 0xe2000000
163#define DSP_MMU_34XX_SIZE SZ_4K
164
101#endif 165#endif
102 166
103#ifndef __ASSEMBLER__ 167#ifndef __ASSEMBLER__
diff --git a/include/asm-arm/arch-omap/mux.h b/include/asm-arm/arch-omap/mux.h
index b8fff50e6a87..ff9a5b5575fd 100644
--- a/include/asm-arm/arch-omap/mux.h
+++ b/include/asm-arm/arch-omap/mux.h
@@ -4,9 +4,10 @@
4 * Table of the Omap register configurations for the FUNC_MUX and 4 * Table of the Omap register configurations for the FUNC_MUX and
5 * PULL_DWN combinations. 5 * PULL_DWN combinations.
6 * 6 *
7 * Copyright (C) 2003 - 2005 Nokia Corporation 7 * Copyright (C) 2004 - 2008 Texas Instruments Inc.
8 * Copyright (C) 2003 - 2008 Nokia Corporation
8 * 9 *
9 * Written by Tony Lindgren <tony.lindgren@nokia.com> 10 * Written by Tony Lindgren
10 * 11 *
11 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
@@ -27,14 +28,6 @@
27 * - W8 = ball 28 * - W8 = ball
28 * - 1610 = 1510 or 1610, none if common for both 1510 and 1610 29 * - 1610 = 1510 or 1610, none if common for both 1510 and 1610
29 * - MMC2_DAT0 = function 30 * - MMC2_DAT0 = function
30 *
31 * Change log:
32 * Added entry for the I2C interface. (02Feb 2004)
33 * Copyright (C) 2004 Texas Instruments
34 *
35 * Added entry for the keypad and uwire CS1. (09Mar 2004)
36 * Copyright (C) 2004 Texas Instruments
37 *
38 */ 31 */
39 32
40#ifndef __ASM_ARCH_MUX_H 33#ifndef __ASM_ARCH_MUX_H
@@ -469,7 +462,12 @@ enum omap24xx_index {
469 AA8_242X_GPIO58, 462 AA8_242X_GPIO58,
470 Y20_24XX_GPIO60, 463 Y20_24XX_GPIO60,
471 W4__24XX_GPIO74, 464 W4__24XX_GPIO74,
465 N15_24XX_GPIO85,
472 M15_24XX_GPIO92, 466 M15_24XX_GPIO92,
467 P20_24XX_GPIO93,
468 P18_24XX_GPIO95,
469 M18_24XX_GPIO96,
470 L14_24XX_GPIO97,
473 J15_24XX_GPIO99, 471 J15_24XX_GPIO99,
474 V14_24XX_GPIO117, 472 V14_24XX_GPIO117,
475 P14_24XX_GPIO125, 473 P14_24XX_GPIO125,
@@ -494,8 +492,6 @@ enum omap24xx_index {
494 D3_242X_DMAREQ4, 492 D3_242X_DMAREQ4,
495 E3_242X_DMAREQ5, 493 E3_242X_DMAREQ5,
496 494
497 P20_24XX_TSC_IRQ,
498
499 /* UART3 */ 495 /* UART3 */
500 K15_24XX_UART3_TX, 496 K15_24XX_UART3_TX,
501 K14_24XX_UART3_RX, 497 K14_24XX_UART3_RX,
@@ -557,13 +553,57 @@ enum omap24xx_index {
557 B3__24XX_KBR5, 553 B3__24XX_KBR5,
558 AA4_24XX_KBC2, 554 AA4_24XX_KBC2,
559 B13_24XX_KBC6, 555 B13_24XX_KBC6,
556
557 /* 2430 USB */
558 AD9_2430_USB0_PUEN,
559 Y11_2430_USB0_VP,
560 AD7_2430_USB0_VM,
561 AE7_2430_USB0_RCV,
562 AD4_2430_USB0_TXEN,
563 AF9_2430_USB0_SE0,
564 AE6_2430_USB0_DAT,
565 AD24_2430_USB1_SE0,
566 AB24_2430_USB1_RCV,
567 Y25_2430_USB1_TXEN,
568 AA26_2430_USB1_DAT,
569
570 /* 2430 HS-USB */
571 AD9_2430_USB0HS_DATA3,
572 Y11_2430_USB0HS_DATA4,
573 AD7_2430_USB0HS_DATA5,
574 AE7_2430_USB0HS_DATA6,
575 AD4_2430_USB0HS_DATA2,
576 AF9_2430_USB0HS_DATA0,
577 AE6_2430_USB0HS_DATA1,
578 AE8_2430_USB0HS_CLK,
579 AD8_2430_USB0HS_DIR,
580 AE5_2430_USB0HS_STP,
581 AE9_2430_USB0HS_NXT,
582 AC7_2430_USB0HS_DATA7,
583
584 /* 2430 McBSP */
585 AC10_2430_MCBSP2_FSX,
586 AD16_2430_MCBSP2_CLX,
587 AE13_2430_MCBSP2_DX,
588 AD13_2430_MCBSP2_DR,
589 AC10_2430_MCBSP2_FSX_OFF,
590 AD16_2430_MCBSP2_CLX_OFF,
591 AE13_2430_MCBSP2_DX_OFF,
592 AD13_2430_MCBSP2_DR_OFF,
593
594};
595
596struct omap_mux_cfg {
597 struct pin_config *pins;
598 unsigned long size;
599 int (*cfg_reg)(const struct pin_config *cfg);
560}; 600};
561 601
562#ifdef CONFIG_OMAP_MUX 602#ifdef CONFIG_OMAP_MUX
563/* setup pin muxing in Linux */ 603/* setup pin muxing in Linux */
564extern int omap1_mux_init(void); 604extern int omap1_mux_init(void);
565extern int omap2_mux_init(void); 605extern int omap2_mux_init(void);
566extern int omap_mux_register(struct pin_config * pins, unsigned long size); 606extern int omap_mux_register(struct omap_mux_cfg *);
567extern int omap_cfg_reg(unsigned long reg_cfg); 607extern int omap_cfg_reg(unsigned long reg_cfg);
568#else 608#else
569/* boot loader does it all (no warnings from CONFIG_OMAP_MUX_WARNINGS) */ 609/* boot loader does it all (no warnings from CONFIG_OMAP_MUX_WARNINGS) */
diff --git a/include/asm-arm/arch-omap/omap24xx.h b/include/asm-arm/arch-omap/omap24xx.h
index 14c0f9496579..b9fcaae287c8 100644
--- a/include/asm-arm/arch-omap/omap24xx.h
+++ b/include/asm-arm/arch-omap/omap24xx.h
@@ -1,3 +1,28 @@
1/*
2 * include/asm-arm/arch-omap/omap24xx.h
3 *
4 * This file contains the processor specific definitions
5 * of the TI OMAP24XX.
6 *
7 * Copyright (C) 2007 Texas Instruments.
8 * Copyright (C) 2007 Nokia Corporation.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
1#ifndef __ASM_ARCH_OMAP24XX_H 26#ifndef __ASM_ARCH_OMAP24XX_H
2#define __ASM_ARCH_OMAP24XX_H 27#define __ASM_ARCH_OMAP24XX_H
3 28
@@ -13,33 +38,70 @@
13 38
14/* interrupt controller */ 39/* interrupt controller */
15#define OMAP24XX_IC_BASE (L4_24XX_BASE + 0xfe000) 40#define OMAP24XX_IC_BASE (L4_24XX_BASE + 0xfe000)
16#define VA_IC_BASE IO_ADDRESS(OMAP24XX_IC_BASE)
17#define OMAP24XX_IVA_INTC_BASE 0x40000000 41#define OMAP24XX_IVA_INTC_BASE 0x40000000
18#define IRQ_SIR_IRQ 0x0040 42#define IRQ_SIR_IRQ 0x0040
19 43
20#ifdef CONFIG_ARCH_OMAP2420 44#define OMAP2420_CTRL_BASE L4_24XX_BASE
21#define OMAP24XX_32KSYNCT_BASE (L4_24XX_BASE + 0x4000) 45#define OMAP2420_32KSYNCT_BASE (L4_24XX_BASE + 0x4000)
22#define OMAP24XX_PRCM_BASE (L4_24XX_BASE + 0x8000) 46#define OMAP2420_PRCM_BASE (L4_24XX_BASE + 0x8000)
23#define OMAP24XX_SDRC_BASE (L3_24XX_BASE + 0x9000) 47#define OMAP2420_CM_BASE (L4_24XX_BASE + 0x8000)
24#define OMAP242X_CONTROL_STATUS (L4_24XX_BASE + 0x2f8) 48#define OMAP2420_PRM_BASE OMAP2420_CM_BASE
25#endif 49#define OMAP2420_SDRC_BASE (L3_24XX_BASE + 0x9000)
50#define OMAP2420_SMS_BASE 0x68008000
26 51
27#ifdef CONFIG_ARCH_OMAP2430 52#define OMAP2430_32KSYNCT_BASE (L4_WK_243X_BASE + 0x20000)
28#define OMAP24XX_32KSYNCT_BASE (L4_WK_243X_BASE + 0x20000) 53#define OMAP2430_PRCM_BASE (L4_WK_243X_BASE + 0x6000)
29#define OMAP24XX_PRCM_BASE (L4_WK_243X_BASE + 0x6000) 54#define OMAP2430_CM_BASE (L4_WK_243X_BASE + 0x6000)
30#define OMAP24XX_SDRC_BASE (0x6D000000) 55#define OMAP2430_PRM_BASE OMAP2430_CM_BASE
31#define OMAP242X_CONTROL_STATUS (L4_24XX_BASE + 0x2f8) 56
57#define OMAP243X_SMS_BASE 0x6C000000
58#define OMAP243X_SDRC_BASE 0x6D000000
32#define OMAP243X_GPMC_BASE 0x6E000000 59#define OMAP243X_GPMC_BASE 0x6E000000
33#endif 60#define OMAP243X_SCM_BASE (L4_WK_243X_BASE + 0x2000)
61#define OMAP243X_CTRL_BASE OMAP243X_SCM_BASE
62#define OMAP243X_HS_BASE (L4_24XX_BASE + 0x000ac000)
34 63
35/* DSP SS */ 64/* DSP SS */
36#define OMAP24XX_DSP_BASE 0x58000000 65#define OMAP2420_DSP_BASE 0x58000000
37#define OMAP24XX_DSP_MEM_BASE (OMAP24XX_DSP_BASE + 0x0) 66#define OMAP2420_DSP_MEM_BASE (OMAP2420_DSP_BASE + 0x0)
38#define OMAP24XX_DSP_IPI_BASE (OMAP24XX_DSP_BASE + 0x1000000) 67#define OMAP2420_DSP_IPI_BASE (OMAP2420_DSP_BASE + 0x1000000)
39#define OMAP24XX_DSP_MMU_BASE (OMAP24XX_DSP_BASE + 0x2000000) 68#define OMAP2420_DSP_MMU_BASE (OMAP2420_DSP_BASE + 0x2000000)
69
70#define OMAP243X_DSP_BASE 0x5C000000
71#define OMAP243X_DSP_MEM_BASE (OMAP243X_DSP_BASE + 0x0)
72#define OMAP243X_DSP_MMU_BASE (OMAP243X_DSP_BASE + 0x1000000)
40 73
41/* Mailbox */ 74/* Mailbox */
42#define OMAP24XX_MAILBOX_BASE (L4_24XX_BASE + 0x94000) 75#define OMAP24XX_MAILBOX_BASE (L4_24XX_BASE + 0x94000)
43 76
77/* Camera */
78#define OMAP24XX_CAMERA_BASE (L4_24XX_BASE + 0x52000)
79
80/* Security */
81#define OMAP24XX_SEC_BASE (L4_24XX_BASE + 0xA0000)
82#define OMAP24XX_SEC_RNG_BASE (OMAP24XX_SEC_BASE + 0x0000)
83#define OMAP24XX_SEC_DES_BASE (OMAP24XX_SEC_BASE + 0x2000)
84#define OMAP24XX_SEC_SHA1MD5_BASE (OMAP24XX_SEC_BASE + 0x4000)
85#define OMAP24XX_SEC_AES_BASE (OMAP24XX_SEC_BASE + 0x6000)
86#define OMAP24XX_SEC_PKA_BASE (OMAP24XX_SEC_BASE + 0x8000)
87
88#if defined(CONFIG_ARCH_OMAP2420)
89
90#define OMAP2_32KSYNCT_BASE OMAP2420_32KSYNCT_BASE
91#define OMAP2_PRCM_BASE OMAP2420_PRCM_BASE
92#define OMAP2_CM_BASE OMAP2420_CM_BASE
93#define OMAP2_PRM_BASE OMAP2420_PRM_BASE
94#define OMAP2_VA_IC_BASE IO_ADDRESS(OMAP24XX_IC_BASE)
95
96#elif defined(CONFIG_ARCH_OMAP2430)
97
98#define OMAP2_32KSYNCT_BASE OMAP2430_32KSYNCT_BASE
99#define OMAP2_PRCM_BASE OMAP2430_PRCM_BASE
100#define OMAP2_CM_BASE OMAP2430_CM_BASE
101#define OMAP2_PRM_BASE OMAP2430_PRM_BASE
102#define OMAP2_VA_IC_BASE IO_ADDRESS(OMAP24XX_IC_BASE)
103
104#endif
105
44#endif /* __ASM_ARCH_OMAP24XX_H */ 106#endif /* __ASM_ARCH_OMAP24XX_H */
45 107
diff --git a/include/asm-arm/arch-omap/sdrc.h b/include/asm-arm/arch-omap/sdrc.h
new file mode 100644
index 000000000000..673b3965befc
--- /dev/null
+++ b/include/asm-arm/arch-omap/sdrc.h
@@ -0,0 +1,75 @@
1#ifndef ____ASM_ARCH_SDRC_H
2#define ____ASM_ARCH_SDRC_H
3
4/*
5 * OMAP2/3 SDRC/SMS register definitions
6 *
7 * Copyright (C) 2007 Texas Instruments, Inc.
8 * Copyright (C) 2007 Nokia Corporation
9 *
10 * Written by Paul Walmsley
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
17#include <asm/arch/io.h>
18
19/* SDRC register offsets - read/write with sdrc_{read,write}_reg() */
20
21#define SDRC_SYSCONFIG 0x010
22#define SDRC_DLLA_CTRL 0x060
23#define SDRC_DLLA_STATUS 0x064
24#define SDRC_DLLB_CTRL 0x068
25#define SDRC_DLLB_STATUS 0x06C
26#define SDRC_POWER 0x070
27#define SDRC_MR_0 0x084
28#define SDRC_RFR_CTRL_0 0x0a4
29
30/*
31 * These values represent the number of memory clock cycles between
32 * autorefresh initiation. They assume 1 refresh per 64 ms (JEDEC), 8192
33 * rows per device, and include a subtraction of a 50 cycle window in the
34 * event that the autorefresh command is delayed due to other SDRC activity.
35 * The '| 1' sets the ARE field to send one autorefresh when the autorefresh
36 * counter reaches 0.
37 *
38 * These represent optimal values for common parts, it won't work for all.
39 * As long as you scale down, most parameters are still work, they just
40 * become sub-optimal. The RFR value goes in the opposite direction. If you
41 * don't adjust it down as your clock period increases the refresh interval
42 * will not be met. Setting all parameters for complete worst case may work,
43 * but may cut memory performance by 2x. Due to errata the DLLs need to be
44 * unlocked and their value needs run time calibration. A dynamic call is
45 * need for that as no single right value exists acorss production samples.
46 *
47 * Only the FULL speed values are given. Current code is such that rate
48 * changes must be made at DPLLoutx2. The actual value adjustment for low
49 * frequency operation will be handled by omap_set_performance()
50 *
51 * By having the boot loader boot up in the fastest L4 speed available likely
52 * will result in something which you can switch between.
53 */
54#define SDRC_RFR_CTRL_165MHz (0x00044c00 | 1)
55#define SDRC_RFR_CTRL_133MHz (0x0003de00 | 1)
56#define SDRC_RFR_CTRL_100MHz (0x0002da01 | 1)
57#define SDRC_RFR_CTRL_110MHz (0x0002da01 | 1) /* Need to calc */
58#define SDRC_RFR_CTRL_BYPASS (0x00005000 | 1) /* Need to calc */
59
60
61/*
62 * SMS register access
63 */
64
65
66#define OMAP242X_SMS_REGADDR(reg) (void __iomem *)IO_ADDRESS(OMAP2420_SMS_BASE + reg)
67#define OMAP243X_SMS_REGADDR(reg) (void __iomem *)IO_ADDRESS(OMAP243X_SMS_BASE + reg)
68#define OMAP343X_SMS_REGADDR(reg) (void __iomem *)IO_ADDRESS(OMAP343X_SMS_BASE + reg)
69
70/* SMS register offsets - read/write with sms_{read,write}_reg() */
71
72#define SMS_SYSCONFIG 0x010
73/* REVISIT: fill in other SMS registers here */
74
75#endif
diff --git a/include/asm-arm/arch-omap/usb.h b/include/asm-arm/arch-omap/usb.h
index 99ae9eabaf71..2147d18aaeae 100644
--- a/include/asm-arm/arch-omap/usb.h
+++ b/include/asm-arm/arch-omap/usb.h
@@ -132,14 +132,11 @@
132# define CONF_USB_PWRDN_DP_R (1 << 1) 132# define CONF_USB_PWRDN_DP_R (1 << 1)
133 133
134/* OMAP2 */ 134/* OMAP2 */
135#define CONTROL_DEVCONF_REG __REG32(L4_24XX_BASE + 0x0274)
136# define USB_UNIDIR 0x0 135# define USB_UNIDIR 0x0
137# define USB_UNIDIR_TLL 0x1 136# define USB_UNIDIR_TLL 0x1
138# define USB_BIDIR 0x2 137# define USB_BIDIR 0x2
139# define USB_BIDIR_TLL 0x3 138# define USB_BIDIR_TLL 0x3
140# define USBT0WRMODEI(x) ((x) << 22) 139# define USBTXWRMODEI(port, x) ((x) << (22 - (port * 2)))
141# define USBT1WRMODEI(x) ((x) << 20)
142# define USBT2WRMODEI(x) ((x) << 18)
143# define USBT2TLL5PI (1 << 17) 140# define USBT2TLL5PI (1 << 17)
144# define USB0PUENACTLOI (1 << 16) 141# define USB0PUENACTLOI (1 << 16)
145# define USBSTANDBYCTRL (1 << 15) 142# define USBSTANDBYCTRL (1 << 15)
diff --git a/include/asm-arm/kvm.h b/include/asm-arm/kvm.h
new file mode 100644
index 000000000000..cb3c08cbcb9e
--- /dev/null
+++ b/include/asm-arm/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_ARM_H
2#define __LINUX_KVM_ARM_H
3
4/* arm does not support KVM */
5
6#endif
diff --git a/include/asm-avr32/byteorder.h b/include/asm-avr32/byteorder.h
index 402ff4125cdc..d77b48ba7338 100644
--- a/include/asm-avr32/byteorder.h
+++ b/include/asm-avr32/byteorder.h
@@ -12,8 +12,14 @@ extern unsigned long __builtin_bswap_32(unsigned long x);
12extern unsigned short __builtin_bswap_16(unsigned short x); 12extern unsigned short __builtin_bswap_16(unsigned short x);
13#endif 13#endif
14 14
15/*
16 * avr32-linux-gcc versions earlier than 4.2 improperly sign-extends
17 * the result.
18 */
19#if !(__GNUC__ == 4 && __GNUC_MINOR__ < 2)
15#define __arch__swab32(x) __builtin_bswap_32(x) 20#define __arch__swab32(x) __builtin_bswap_32(x)
16#define __arch__swab16(x) __builtin_bswap_16(x) 21#define __arch__swab16(x) __builtin_bswap_16(x)
22#endif
17 23
18#if !defined(__STRICT_ANSI__) || defined(__KERNEL__) 24#if !defined(__STRICT_ANSI__) || defined(__KERNEL__)
19# define __BYTEORDER_HAS_U64__ 25# define __BYTEORDER_HAS_U64__
diff --git a/include/asm-avr32/kvm.h b/include/asm-avr32/kvm.h
new file mode 100644
index 000000000000..8c5777020e2c
--- /dev/null
+++ b/include/asm-avr32/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_AVR32_H
2#define __LINUX_KVM_AVR32_H
3
4/* avr32 does not support KVM */
5
6#endif
diff --git a/include/asm-blackfin/kvm.h b/include/asm-blackfin/kvm.h
new file mode 100644
index 000000000000..e3477d77c014
--- /dev/null
+++ b/include/asm-blackfin/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_BLACKFIN_H
2#define __LINUX_KVM_BLACKFIN_H
3
4/* blackfin does not support KVM */
5
6#endif
diff --git a/include/asm-cris/kvm.h b/include/asm-cris/kvm.h
new file mode 100644
index 000000000000..c860f51149f0
--- /dev/null
+++ b/include/asm-cris/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_CRIS_H
2#define __LINUX_KVM_CRIS_H
3
4/* cris does not support KVM */
5
6#endif
diff --git a/include/asm-frv/kvm.h b/include/asm-frv/kvm.h
new file mode 100644
index 000000000000..9c8a4f08d0a9
--- /dev/null
+++ b/include/asm-frv/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_FRV_H
2#define __LINUX_KVM_FRV_H
3
4/* frv does not support KVM */
5
6#endif
diff --git a/include/asm-frv/mem-layout.h b/include/asm-frv/mem-layout.h
index 83532252b8be..734a1d0583b6 100644
--- a/include/asm-frv/mem-layout.h
+++ b/include/asm-frv/mem-layout.h
@@ -60,7 +60,7 @@
60 */ 60 */
61#define BRK_BASE __UL(2 * 1024 * 1024 + PAGE_SIZE) 61#define BRK_BASE __UL(2 * 1024 * 1024 + PAGE_SIZE)
62#define STACK_TOP __UL(2 * 1024 * 1024) 62#define STACK_TOP __UL(2 * 1024 * 1024)
63#define STACK_TOP_MAX STACK_TOP 63#define STACK_TOP_MAX __UL(0xc0000000)
64 64
65/* userspace process size */ 65/* userspace process size */
66#ifdef CONFIG_MMU 66#ifdef CONFIG_MMU
diff --git a/include/asm-frv/pgtable.h b/include/asm-frv/pgtable.h
index 6c0682ed5fc9..4e219046fe42 100644
--- a/include/asm-frv/pgtable.h
+++ b/include/asm-frv/pgtable.h
@@ -507,13 +507,22 @@ static inline int pte_file(pte_t pte)
507 */ 507 */
508static inline void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte) 508static inline void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
509{ 509{
510 struct mm_struct *mm;
510 unsigned long ampr; 511 unsigned long ampr;
511 pgd_t *pge = pgd_offset(current->mm, address);
512 pud_t *pue = pud_offset(pge, address);
513 pmd_t *pme = pmd_offset(pue, address);
514 512
515 ampr = pme->ste[0] & 0xffffff00; 513 mm = current->mm;
516 ampr |= xAMPRx_L | xAMPRx_SS_16Kb | xAMPRx_S | xAMPRx_C | xAMPRx_V; 514 if (mm) {
515 pgd_t *pge = pgd_offset(mm, address);
516 pud_t *pue = pud_offset(pge, address);
517 pmd_t *pme = pmd_offset(pue, address);
518
519 ampr = pme->ste[0] & 0xffffff00;
520 ampr |= xAMPRx_L | xAMPRx_SS_16Kb | xAMPRx_S | xAMPRx_C |
521 xAMPRx_V;
522 } else {
523 address = ULONG_MAX;
524 ampr = 0;
525 }
517 526
518 asm volatile("movgs %0,scr0\n" 527 asm volatile("movgs %0,scr0\n"
519 "movgs %0,scr1\n" 528 "movgs %0,scr1\n"
diff --git a/include/asm-frv/spr-regs.h b/include/asm-frv/spr-regs.h
index c2a541ef828d..01e6af5e99b8 100644
--- a/include/asm-frv/spr-regs.h
+++ b/include/asm-frv/spr-regs.h
@@ -99,9 +99,23 @@
99#define TBR_TT_TRAP1 (0x81 << 4) 99#define TBR_TT_TRAP1 (0x81 << 4)
100#define TBR_TT_TRAP2 (0x82 << 4) 100#define TBR_TT_TRAP2 (0x82 << 4)
101#define TBR_TT_TRAP3 (0x83 << 4) 101#define TBR_TT_TRAP3 (0x83 << 4)
102#define TBR_TT_TRAP120 (0xf8 << 4)
103#define TBR_TT_TRAP121 (0xf9 << 4)
104#define TBR_TT_TRAP122 (0xfa << 4)
105#define TBR_TT_TRAP123 (0xfb << 4)
106#define TBR_TT_TRAP124 (0xfc << 4)
107#define TBR_TT_TRAP125 (0xfd << 4)
102#define TBR_TT_TRAP126 (0xfe << 4) 108#define TBR_TT_TRAP126 (0xfe << 4)
103#define TBR_TT_BREAK (0xff << 4) 109#define TBR_TT_BREAK (0xff << 4)
104 110
111#define TBR_TT_ATOMIC_CMPXCHG32 TBR_TT_TRAP120
112#define TBR_TT_ATOMIC_XCHG32 TBR_TT_TRAP121
113#define TBR_TT_ATOMIC_XOR TBR_TT_TRAP122
114#define TBR_TT_ATOMIC_OR TBR_TT_TRAP123
115#define TBR_TT_ATOMIC_AND TBR_TT_TRAP124
116#define TBR_TT_ATOMIC_SUB TBR_TT_TRAP125
117#define TBR_TT_ATOMIC_ADD TBR_TT_TRAP126
118
105#define __get_TBR() ({ unsigned long x; asm volatile("movsg tbr,%0" : "=r"(x)); x; }) 119#define __get_TBR() ({ unsigned long x; asm volatile("movsg tbr,%0" : "=r"(x)); x; })
106 120
107/* 121/*
diff --git a/include/asm-frv/system.h b/include/asm-frv/system.h
index b400cea81487..30a67a9da11a 100644
--- a/include/asm-frv/system.h
+++ b/include/asm-frv/system.h
@@ -179,14 +179,23 @@ do { \
179#define mb() asm volatile ("membar" : : :"memory") 179#define mb() asm volatile ("membar" : : :"memory")
180#define rmb() asm volatile ("membar" : : :"memory") 180#define rmb() asm volatile ("membar" : : :"memory")
181#define wmb() asm volatile ("membar" : : :"memory") 181#define wmb() asm volatile ("membar" : : :"memory")
182#define set_mb(var, value) do { var = value; mb(); } while (0) 182#define read_barrier_depends() barrier()
183 183
184#define smp_mb() mb() 184#ifdef CONFIG_SMP
185#define smp_rmb() rmb() 185#define smp_mb() mb()
186#define smp_wmb() wmb() 186#define smp_rmb() rmb()
187 187#define smp_wmb() wmb()
188#define read_barrier_depends() do {} while(0)
189#define smp_read_barrier_depends() read_barrier_depends() 188#define smp_read_barrier_depends() read_barrier_depends()
189#define set_mb(var, value) \
190 do { xchg(&var, (value)); } while (0)
191#else
192#define smp_mb() barrier()
193#define smp_rmb() barrier()
194#define smp_wmb() barrier()
195#define smp_read_barrier_depends() do {} while(0)
196#define set_mb(var, value) \
197 do { var = (value); barrier(); } while (0)
198#endif
190 199
191#define HARD_RESET_NOW() \ 200#define HARD_RESET_NOW() \
192do { \ 201do { \
@@ -234,7 +243,7 @@ extern void free_initmem(void);
234 break; \ 243 break; \
235 \ 244 \
236 default: \ 245 default: \
237 __xg_orig = 0; \ 246 __xg_orig = (__typeof__(__xg_orig))0; \
238 asm volatile("break"); \ 247 asm volatile("break"); \
239 break; \ 248 break; \
240 } \ 249 } \
@@ -259,7 +268,7 @@ extern uint32_t __cmpxchg_32(uint32_t *v, uint32_t test, uint32_t new);
259 (__force uint32_t)__xg_test, \ 268 (__force uint32_t)__xg_test, \
260 (__force uint32_t)__xg_new); break; \ 269 (__force uint32_t)__xg_new); break; \
261 default: \ 270 default: \
262 __xg_orig = 0; \ 271 __xg_orig = (__typeof__(__xg_orig))0; \
263 asm volatile("break"); \ 272 asm volatile("break"); \
264 break; \ 273 break; \
265 } \ 274 } \
diff --git a/include/asm-generic/Kbuild.asm b/include/asm-generic/Kbuild.asm
index fd9dcfd91c39..92a6d91d0c1a 100644
--- a/include/asm-generic/Kbuild.asm
+++ b/include/asm-generic/Kbuild.asm
@@ -1,3 +1,5 @@
1header-y += kvm.h
2
1ifeq ($(wildcard include/asm-$(SRCARCH)/a.out.h),include/asm-$(SRCARCH)/a.out.h) 3ifeq ($(wildcard include/asm-$(SRCARCH)/a.out.h),include/asm-$(SRCARCH)/a.out.h)
2unifdef-y += a.out.h 4unifdef-y += a.out.h
3endif 5endif
diff --git a/include/asm-h8300/kvm.h b/include/asm-h8300/kvm.h
new file mode 100644
index 000000000000..bdbed7b987e1
--- /dev/null
+++ b/include/asm-h8300/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_H8300_H
2#define __LINUX_KVM_H8300_H
3
4/* h8300 does not support KVM */
5
6#endif
diff --git a/include/asm-ia64/kvm.h b/include/asm-ia64/kvm.h
new file mode 100644
index 000000000000..030d29b4b26b
--- /dev/null
+++ b/include/asm-ia64/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_IA64_H
2#define __LINUX_KVM_IA64_H
3
4/* ia64 does not support KVM */
5
6#endif
diff --git a/include/asm-m32r/kvm.h b/include/asm-m32r/kvm.h
new file mode 100644
index 000000000000..99a40515b77e
--- /dev/null
+++ b/include/asm-m32r/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_M32R_H
2#define __LINUX_KVM_M32R_H
3
4/* m32r does not support KVM */
5
6#endif
diff --git a/include/asm-m68k/kvm.h b/include/asm-m68k/kvm.h
new file mode 100644
index 000000000000..7ed27fce5240
--- /dev/null
+++ b/include/asm-m68k/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_M68K_H
2#define __LINUX_KVM_M68K_H
3
4/* m68k does not support KVM */
5
6#endif
diff --git a/include/asm-m68knommu/kvm.h b/include/asm-m68knommu/kvm.h
new file mode 100644
index 000000000000..b49d4258dabb
--- /dev/null
+++ b/include/asm-m68knommu/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_M68KNOMMU_H
2#define __LINUX_KVM_M68KNOMMU_H
3
4/* m68knommu does not support KVM */
5
6#endif
diff --git a/include/asm-mips/cacheflush.h b/include/asm-mips/cacheflush.h
index 01e7eadc97e2..d5c0f2fda51b 100644
--- a/include/asm-mips/cacheflush.h
+++ b/include/asm-mips/cacheflush.h
@@ -63,8 +63,22 @@ static inline void flush_icache_page(struct vm_area_struct *vma,
63} 63}
64 64
65extern void (*flush_icache_range)(unsigned long start, unsigned long end); 65extern void (*flush_icache_range)(unsigned long start, unsigned long end);
66#define flush_cache_vmap(start, end) flush_cache_all() 66
67#define flush_cache_vunmap(start, end) flush_cache_all() 67extern void (*__flush_cache_vmap)(void);
68
69static inline void flush_cache_vmap(unsigned long start, unsigned long end)
70{
71 if (cpu_has_dc_aliases)
72 __flush_cache_vmap();
73}
74
75extern void (*__flush_cache_vunmap)(void);
76
77static inline void flush_cache_vunmap(unsigned long start, unsigned long end)
78{
79 if (cpu_has_dc_aliases)
80 __flush_cache_vunmap();
81}
68 82
69extern void copy_to_user_page(struct vm_area_struct *vma, 83extern void copy_to_user_page(struct vm_area_struct *vma,
70 struct page *page, unsigned long vaddr, void *dst, const void *src, 84 struct page *page, unsigned long vaddr, void *dst, const void *src,
diff --git a/include/asm-mips/kvm.h b/include/asm-mips/kvm.h
new file mode 100644
index 000000000000..093a5b7f796b
--- /dev/null
+++ b/include/asm-mips/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_MIPS_H
2#define __LINUX_KVM_MIPS_H
3
4/* mips does not support KVM */
5
6#endif
diff --git a/include/asm-mips/mach-au1x00/au1000.h b/include/asm-mips/mach-au1x00/au1000.h
index cb18af989645..5bb57bf2b9d7 100644
--- a/include/asm-mips/mach-au1x00/au1000.h
+++ b/include/asm-mips/mach-au1x00/au1000.h
@@ -1786,6 +1786,7 @@ struct cpu_spec {
1786 char *cpu_name; 1786 char *cpu_name;
1787 unsigned char cpu_od; /* Set Config[OD] */ 1787 unsigned char cpu_od; /* Set Config[OD] */
1788 unsigned char cpu_bclk; /* Enable BCLK switching */ 1788 unsigned char cpu_bclk; /* Enable BCLK switching */
1789 unsigned char cpu_pll_wo; /* sys_cpupll reg. write-only */
1789}; 1790};
1790 1791
1791extern struct cpu_spec cpu_specs[]; 1792extern struct cpu_spec cpu_specs[];
diff --git a/include/asm-mips/mach-pb1x00/pb1200.h b/include/asm-mips/mach-pb1x00/pb1200.h
index ed5fd7390678..72213e3d02c7 100644
--- a/include/asm-mips/mach-pb1x00/pb1200.h
+++ b/include/asm-mips/mach-pb1x00/pb1200.h
@@ -245,7 +245,7 @@ enum external_pb1200_ints {
245 PB1200_SD1_INSERT_INT, 245 PB1200_SD1_INSERT_INT,
246 PB1200_SD1_EJECT_INT, 246 PB1200_SD1_EJECT_INT,
247 247
248 PB1200_INT_END (PB1200_INT_BEGIN + 15) 248 PB1200_INT_END = PB1200_INT_BEGIN + 15
249}; 249};
250 250
251/* For drivers/pcmcia/au1000_db1x00.c */ 251/* For drivers/pcmcia/au1000_db1x00.c */
diff --git a/include/asm-mn10300/kvm.h b/include/asm-mn10300/kvm.h
new file mode 100644
index 000000000000..f6b609ff4a57
--- /dev/null
+++ b/include/asm-mn10300/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_MN10300_H
2#define __LINUX_KVM_MN10300_H
3
4/* mn10300 does not support KVM */
5
6#endif
diff --git a/include/asm-parisc/kvm.h b/include/asm-parisc/kvm.h
new file mode 100644
index 000000000000..00cc45812547
--- /dev/null
+++ b/include/asm-parisc/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_PARISC_H
2#define __LINUX_KVM_PARISC_H
3
4/* parisc does not support KVM */
5
6#endif
diff --git a/include/asm-powerpc/kvm.h b/include/asm-powerpc/kvm.h
new file mode 100644
index 000000000000..d1b530fbf8dd
--- /dev/null
+++ b/include/asm-powerpc/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_POWERPC_H
2#define __LINUX_KVM_POWERPC_H
3
4/* powerpc does not support KVM */
5
6#endif
diff --git a/include/asm-s390/kvm.h b/include/asm-s390/kvm.h
new file mode 100644
index 000000000000..573f2a351386
--- /dev/null
+++ b/include/asm-s390/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_S390_H
2#define __LINUX_KVM_S390_H
3
4/* s390 does not support KVM */
5
6#endif
diff --git a/include/asm-sh/floppy.h b/include/asm-sh/floppy.h
deleted file mode 100644
index 59fbfdc90dfb..000000000000
--- a/include/asm-sh/floppy.h
+++ /dev/null
@@ -1,268 +0,0 @@
1/*
2 * Architecture specific parts of the Floppy driver
3 * include/asm-i386/floppy.h
4 *
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
8 *
9 * Copyright (C) 1995
10 */
11#ifndef __ASM_SH_FLOPPY_H
12#define __ASM_SH_FLOPPY_H
13
14#include <linux/vmalloc.h>
15
16
17/*
18 * The DMA channel used by the floppy controller cannot access data at
19 * addresses >= 16MB
20 *
21 * Went back to the 1MB limit, as some people had problems with the floppy
22 * driver otherwise. It doesn't matter much for performance anyway, as most
23 * floppy accesses go through the track buffer.
24 */
25#define _CROSS_64KB(a,s,vdma) \
26(!vdma && ((unsigned long)(a)/K_64 != ((unsigned long)(a) + (s) - 1) / K_64))
27
28#define CROSS_64KB(a,s) _CROSS_64KB(a,s,use_virtual_dma & 1)
29
30
31#define SW fd_routine[use_virtual_dma&1]
32#define CSW fd_routine[can_use_virtual_dma & 1]
33
34
35#define fd_inb(port) inb_p(port)
36#define fd_outb(value,port) outb_p(value,port)
37
38#define fd_request_dma() CSW._request_dma(FLOPPY_DMA,"floppy")
39#define fd_free_dma() CSW._free_dma(FLOPPY_DMA)
40#define fd_enable_irq() enable_irq(FLOPPY_IRQ)
41#define fd_disable_irq() disable_irq(FLOPPY_IRQ)
42#define fd_free_irq() free_irq(FLOPPY_IRQ, NULL)
43#define fd_get_dma_residue() SW._get_dma_residue(FLOPPY_DMA)
44#define fd_dma_mem_alloc(size) SW._dma_mem_alloc(size)
45#define fd_dma_setup(addr, size, mode, io) SW._dma_setup(addr, size, mode, io)
46
47#define FLOPPY_CAN_FALLBACK_ON_NODMA
48
49static int virtual_dma_count;
50static int virtual_dma_residue;
51static char *virtual_dma_addr;
52static int virtual_dma_mode;
53static int doing_pdma;
54
55static void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
56{
57 register unsigned char st;
58
59#undef TRACE_FLPY_INT
60
61#ifdef TRACE_FLPY_INT
62 static int calls=0;
63 static int bytes=0;
64 static int dma_wait=0;
65#endif
66 if(!doing_pdma) {
67 floppy_interrupt(irq, dev_id, regs);
68 return;
69 }
70
71#ifdef TRACE_FLPY_INT
72 if(!calls)
73 bytes = virtual_dma_count;
74#endif
75
76 {
77 register int lcount;
78 register char *lptr;
79
80 st = 1;
81 for(lcount=virtual_dma_count, lptr=virtual_dma_addr;
82 lcount; lcount--, lptr++) {
83 st=inb(virtual_dma_port+4) & 0xa0 ;
84 if(st != 0xa0)
85 break;
86 if(virtual_dma_mode)
87 outb_p(*lptr, virtual_dma_port+5);
88 else
89 *lptr = inb_p(virtual_dma_port+5);
90 }
91 virtual_dma_count = lcount;
92 virtual_dma_addr = lptr;
93 st = inb(virtual_dma_port+4);
94 }
95
96#ifdef TRACE_FLPY_INT
97 calls++;
98#endif
99 if(st == 0x20)
100 return;
101 if(!(st & 0x20)) {
102 virtual_dma_residue += virtual_dma_count;
103 virtual_dma_count=0;
104#ifdef TRACE_FLPY_INT
105 printk("count=%x, residue=%x calls=%d bytes=%d dma_wait=%d\n",
106 virtual_dma_count, virtual_dma_residue, calls, bytes,
107 dma_wait);
108 calls = 0;
109 dma_wait=0;
110#endif
111 doing_pdma = 0;
112 floppy_interrupt(irq, dev_id, regs);
113 return;
114 }
115#ifdef TRACE_FLPY_INT
116 if(!virtual_dma_count)
117 dma_wait++;
118#endif
119}
120
121static void fd_disable_dma(void)
122{
123 if(! (can_use_virtual_dma & 1))
124 disable_dma(FLOPPY_DMA);
125 doing_pdma = 0;
126 virtual_dma_residue += virtual_dma_count;
127 virtual_dma_count=0;
128}
129
130static int vdma_request_dma(unsigned int dmanr, const char * device_id)
131{
132 return 0;
133}
134
135static void vdma_nop(unsigned int dummy)
136{
137}
138
139
140static int vdma_get_dma_residue(unsigned int dummy)
141{
142 return virtual_dma_count + virtual_dma_residue;
143}
144
145
146static int fd_request_irq(void)
147{
148 if(can_use_virtual_dma)
149 return request_irq(FLOPPY_IRQ, floppy_hardint,
150 IRQF_DISABLED, "floppy", NULL);
151 else
152 return request_irq(FLOPPY_IRQ, floppy_interrupt,
153 IRQF_DISABLED, "floppy", NULL);
154}
155
156static unsigned long dma_mem_alloc(unsigned long size)
157{
158 return __get_dma_pages(GFP_KERNEL,get_order(size));
159}
160
161
162static unsigned long vdma_mem_alloc(unsigned long size)
163{
164 return (unsigned long) vmalloc(size);
165
166}
167
168#define nodma_mem_alloc(size) vdma_mem_alloc(size)
169
170static void _fd_dma_mem_free(unsigned long addr, unsigned long size)
171{
172 if((unsigned int) addr >= (unsigned int) high_memory)
173 return vfree((void *)addr);
174 else
175 free_pages(addr, get_order(size));
176}
177
178#define fd_dma_mem_free(addr, size) _fd_dma_mem_free(addr, size)
179
180static void _fd_chose_dma_mode(char *addr, unsigned long size)
181{
182 if(can_use_virtual_dma == 2) {
183 if((unsigned int) addr >= (unsigned int) high_memory ||
184 virt_to_phys(addr) >= 0x10000000)
185 use_virtual_dma = 1;
186 else
187 use_virtual_dma = 0;
188 } else {
189 use_virtual_dma = can_use_virtual_dma & 1;
190 }
191}
192
193#define fd_chose_dma_mode(addr, size) _fd_chose_dma_mode(addr, size)
194
195
196static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
197{
198 doing_pdma = 1;
199 virtual_dma_port = io;
200 virtual_dma_mode = (mode == DMA_MODE_WRITE);
201 virtual_dma_addr = addr;
202 virtual_dma_count = size;
203 virtual_dma_residue = 0;
204 return 0;
205}
206
207static int hard_dma_setup(char *addr, unsigned long size, int mode, int io)
208{
209#ifdef FLOPPY_SANITY_CHECK
210 if (CROSS_64KB(addr, size)) {
211 printk("DMA crossing 64-K boundary %p-%p\n", addr, addr+size);
212 return -1;
213 }
214#endif
215
216 __flush_purge_region(addr, size);
217
218 /* actual, physical DMA */
219 doing_pdma = 0;
220 clear_dma_ff(FLOPPY_DMA);
221 set_dma_mode(FLOPPY_DMA,mode);
222 set_dma_addr(FLOPPY_DMA,virt_to_phys(addr));
223 set_dma_count(FLOPPY_DMA,size);
224 enable_dma(FLOPPY_DMA);
225 return 0;
226}
227
228static struct fd_routine_l {
229 int (*_request_dma)(unsigned int dmanr, const char * device_id);
230 void (*_free_dma)(unsigned int dmanr);
231 int (*_get_dma_residue)(unsigned int dummy);
232 unsigned long (*_dma_mem_alloc) (unsigned long size);
233 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
234} fd_routine[] = {
235 {
236 request_dma,
237 free_dma,
238 get_dma_residue,
239 dma_mem_alloc,
240 hard_dma_setup
241 },
242 {
243 vdma_request_dma,
244 vdma_nop,
245 vdma_get_dma_residue,
246 vdma_mem_alloc,
247 vdma_dma_setup
248 }
249};
250
251
252static int FDC1 = 0x3f0;
253static int FDC2 = -1;
254
255/*
256 * Floppy types are stored in the rtc's CMOS RAM and so rtc_lock
257 * is needed to prevent corrupted CMOS RAM in case "insmod floppy"
258 * coincides with another rtc CMOS user. Paul G.
259 */
260#define FLOPPY0_TYPE (4)
261#define FLOPPY1_TYPE (0)
262
263#define N_FDC 2
264#define N_DRIVE 8
265
266#define EXTRA_FLOPPY_PARAMS
267
268#endif /* __ASM_SH_FLOPPY_H */
diff --git a/include/asm-sh/fpu.h b/include/asm-sh/fpu.h
index f8429880a270..91462fea1507 100644
--- a/include/asm-sh/fpu.h
+++ b/include/asm-sh/fpu.h
@@ -1,9 +1,8 @@
1#ifndef __ASM_SH_FPU_H 1#ifndef __ASM_SH_FPU_H
2#define __ASM_SH_FPU_H 2#define __ASM_SH_FPU_H
3 3
4#define SR_FD 0x00008000
5
6#ifndef __ASSEMBLY__ 4#ifndef __ASSEMBLY__
5#include <linux/preempt.h>
7#include <asm/ptrace.h> 6#include <asm/ptrace.h>
8 7
9#ifdef CONFIG_SH_FPU 8#ifdef CONFIG_SH_FPU
@@ -21,25 +20,35 @@ struct task_struct;
21 20
22extern void save_fpu(struct task_struct *__tsk, struct pt_regs *regs); 21extern void save_fpu(struct task_struct *__tsk, struct pt_regs *regs);
23#else 22#else
23
24#define release_fpu(regs) do { } while (0) 24#define release_fpu(regs) do { } while (0)
25#define grab_fpu(regs) do { } while (0) 25#define grab_fpu(regs) do { } while (0)
26#define save_fpu(tsk, regs) do { } while (0) 26
27static inline void save_fpu(struct task_struct *tsk, struct pt_regs *regs)
28{
29 clear_tsk_thread_flag(tsk, TIF_USEDFPU);
30}
27#endif 31#endif
28 32
29extern int do_fpu_inst(unsigned short, struct pt_regs *); 33extern int do_fpu_inst(unsigned short, struct pt_regs *);
30 34
31#define unlazy_fpu(tsk, regs) do { \ 35static inline void unlazy_fpu(struct task_struct *tsk, struct pt_regs *regs)
32 if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) { \ 36{
33 save_fpu(tsk, regs); \ 37 preempt_disable();
34 } \ 38 if (test_tsk_thread_flag(tsk, TIF_USEDFPU))
35} while (0) 39 save_fpu(tsk, regs);
36 40 preempt_enable();
37#define clear_fpu(tsk, regs) do { \ 41}
38 if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) { \ 42
39 clear_tsk_thread_flag(tsk, TIF_USEDFPU); \ 43static inline void clear_fpu(struct task_struct *tsk, struct pt_regs *regs)
40 release_fpu(regs); \ 44{
41 } \ 45 preempt_disable();
42} while (0) 46 if (test_tsk_thread_flag(tsk, TIF_USEDFPU)) {
47 clear_tsk_thread_flag(tsk, TIF_USEDFPU);
48 release_fpu(regs);
49 }
50 preempt_enable();
51}
43 52
44#endif /* __ASSEMBLY__ */ 53#endif /* __ASSEMBLY__ */
45 54
diff --git a/include/asm-sh/kvm.h b/include/asm-sh/kvm.h
new file mode 100644
index 000000000000..6af51dbab2d0
--- /dev/null
+++ b/include/asm-sh/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_SH_H
2#define __LINUX_KVM_SH_H
3
4/* sh does not support KVM */
5
6#endif
diff --git a/include/asm-sh/processor.h b/include/asm-sh/processor.h
index 19fe47c1ca17..ec707b98e5b9 100644
--- a/include/asm-sh/processor.h
+++ b/include/asm-sh/processor.h
@@ -2,7 +2,6 @@
2#define __ASM_SH_PROCESSOR_H 2#define __ASM_SH_PROCESSOR_H
3 3
4#include <asm/cpu-features.h> 4#include <asm/cpu-features.h>
5#include <asm/fpu.h>
6 5
7#ifndef __ASSEMBLY__ 6#ifndef __ASSEMBLY__
8/* 7/*
diff --git a/include/asm-sh/processor_32.h b/include/asm-sh/processor_32.h
index df2d5b039ef4..c09305d6a9d9 100644
--- a/include/asm-sh/processor_32.h
+++ b/include/asm-sh/processor_32.h
@@ -70,6 +70,7 @@ extern struct sh_cpuinfo cpu_data[];
70 */ 70 */
71#define SR_DSP 0x00001000 71#define SR_DSP 0x00001000
72#define SR_IMASK 0x000000f0 72#define SR_IMASK 0x000000f0
73#define SR_FD 0x00008000
73 74
74/* 75/*
75 * FPU structure and data 76 * FPU structure and data
diff --git a/include/asm-sh/processor_64.h b/include/asm-sh/processor_64.h
index eda4bef448e9..88a2edf8fa5d 100644
--- a/include/asm-sh/processor_64.h
+++ b/include/asm-sh/processor_64.h
@@ -112,6 +112,7 @@ extern struct sh_cpuinfo cpu_data[];
112#endif 112#endif
113 113
114#define SR_IMASK 0x000000f0 114#define SR_IMASK 0x000000f0
115#define SR_FD 0x00008000
115#define SR_SSTEP 0x08000000 116#define SR_SSTEP 0x08000000
116 117
117#ifndef __ASSEMBLY__ 118#ifndef __ASSEMBLY__
diff --git a/include/asm-sparc/kvm.h b/include/asm-sparc/kvm.h
new file mode 100644
index 000000000000..2e5478da3819
--- /dev/null
+++ b/include/asm-sparc/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_SPARC_H
2#define __LINUX_KVM_SPARC_H
3
4/* sparc does not support KVM */
5
6#endif
diff --git a/include/asm-sparc64/cpudata.h b/include/asm-sparc64/cpudata.h
index 542421460a12..532975ecfe10 100644
--- a/include/asm-sparc64/cpudata.h
+++ b/include/asm-sparc64/cpudata.h
@@ -86,6 +86,8 @@ extern struct trap_per_cpu trap_block[NR_CPUS];
86extern void init_cur_cpu_trap(struct thread_info *); 86extern void init_cur_cpu_trap(struct thread_info *);
87extern void setup_tba(void); 87extern void setup_tba(void);
88extern int ncpus_probed; 88extern int ncpus_probed;
89extern void __init cpu_probe(void);
90extern const struct seq_operations cpuinfo_op;
89 91
90extern unsigned long real_hard_smp_processor_id(void); 92extern unsigned long real_hard_smp_processor_id(void);
91 93
diff --git a/include/asm-sparc64/dcu.h b/include/asm-sparc64/dcu.h
index ecbed2ae548f..0f704e106a1b 100644
--- a/include/asm-sparc64/dcu.h
+++ b/include/asm-sparc64/dcu.h
@@ -1,26 +1,27 @@
1/* $Id: dcu.h,v 1.2 2001/03/01 23:23:33 davem Exp $ */
2#ifndef _SPARC64_DCU_H 1#ifndef _SPARC64_DCU_H
3#define _SPARC64_DCU_H 2#define _SPARC64_DCU_H
4 3
4#include <linux/const.h>
5
5/* UltraSparc-III Data Cache Unit Control Register */ 6/* UltraSparc-III Data Cache Unit Control Register */
6#define DCU_CP 0x0002000000000000 /* Physical Cache Enable w/o mmu*/ 7#define DCU_CP _AC(0x0002000000000000,UL) /* Phys Cache Enable w/o mmu */
7#define DCU_CV 0x0001000000000000 /* Virtual Cache Enable w/o mmu */ 8#define DCU_CV _AC(0x0001000000000000,UL) /* Virt Cache Enable w/o mmu */
8#define DCU_ME 0x0000800000000000 /* NC-store Merging Enable */ 9#define DCU_ME _AC(0x0000800000000000,UL) /* NC-store Merging Enable */
9#define DCU_RE 0x0000400000000000 /* RAW bypass Enable */ 10#define DCU_RE _AC(0x0000400000000000,UL) /* RAW bypass Enable */
10#define DCU_PE 0x0000200000000000 /* PCache Enable */ 11#define DCU_PE _AC(0x0000200000000000,UL) /* PCache Enable */
11#define DCU_HPE 0x0000100000000000 /* HW prefetch Enable */ 12#define DCU_HPE _AC(0x0000100000000000,UL) /* HW prefetch Enable */
12#define DCU_SPE 0x0000080000000000 /* SW prefetch Enable */ 13#define DCU_SPE _AC(0x0000080000000000,UL) /* SW prefetch Enable */
13#define DCU_SL 0x0000040000000000 /* Secondary load steering Enab */ 14#define DCU_SL _AC(0x0000040000000000,UL) /* Secondary ld-steering Enab*/
14#define DCU_WE 0x0000020000000000 /* WCache enable */ 15#define DCU_WE _AC(0x0000020000000000,UL) /* WCache enable */
15#define DCU_PM 0x000001fe00000000 /* PA Watchpoint Byte Mask */ 16#define DCU_PM _AC(0x000001fe00000000,UL) /* PA Watchpoint Byte Mask */
16#define DCU_VM 0x00000001fe000000 /* VA Watchpoint Byte Mask */ 17#define DCU_VM _AC(0x00000001fe000000,UL) /* VA Watchpoint Byte Mask */
17#define DCU_PR 0x0000000001000000 /* PA Watchpoint Read Enable */ 18#define DCU_PR _AC(0x0000000001000000,UL) /* PA Watchpoint Read Enable */
18#define DCU_PW 0x0000000000800000 /* PA Watchpoint Write Enable */ 19#define DCU_PW _AC(0x0000000000800000,UL) /* PA Watchpoint Write Enable*/
19#define DCU_VR 0x0000000000400000 /* VA Watchpoint Read Enable */ 20#define DCU_VR _AC(0x0000000000400000,UL) /* VA Watchpoint Read Enable */
20#define DCU_VW 0x0000000000200000 /* VA Watchpoint Write Enable */ 21#define DCU_VW _AC(0x0000000000200000,UL) /* VA Watchpoint Write Enable*/
21#define DCU_DM 0x0000000000000008 /* DMMU Enable */ 22#define DCU_DM _AC(0x0000000000000008,UL) /* DMMU Enable */
22#define DCU_IM 0x0000000000000004 /* IMMU Enable */ 23#define DCU_IM _AC(0x0000000000000004,UL) /* IMMU Enable */
23#define DCU_DC 0x0000000000000002 /* Data Cache Enable */ 24#define DCU_DC _AC(0x0000000000000002,UL) /* Data Cache Enable */
24#define DCU_IC 0x0000000000000001 /* Instruction Cache Enable */ 25#define DCU_IC _AC(0x0000000000000001,UL) /* Instruction Cache Enable */
25 26
26#endif /* _SPARC64_DCU_H */ 27#endif /* _SPARC64_DCU_H */
diff --git a/include/asm-sparc64/irq.h b/include/asm-sparc64/irq.h
index 30cb76b47be1..0bb9bf531745 100644
--- a/include/asm-sparc64/irq.h
+++ b/include/asm-sparc64/irq.h
@@ -64,6 +64,7 @@ extern unsigned char virt_irq_alloc(unsigned int dev_handle,
64extern void virt_irq_free(unsigned int virt_irq); 64extern void virt_irq_free(unsigned int virt_irq);
65#endif 65#endif
66 66
67extern void __init init_IRQ(void);
67extern void fixup_irqs(void); 68extern void fixup_irqs(void);
68 69
69static inline void set_softint(unsigned long bits) 70static inline void set_softint(unsigned long bits)
diff --git a/include/asm-sparc64/kvm.h b/include/asm-sparc64/kvm.h
new file mode 100644
index 000000000000..380537a77bf9
--- /dev/null
+++ b/include/asm-sparc64/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_SPARC64_H
2#define __LINUX_KVM_SPARC64_H
3
4/* sparc64 does not support KVM */
5
6#endif
diff --git a/include/asm-sparc64/pgtable.h b/include/asm-sparc64/pgtable.h
index 3167ccff64f8..549e45266b68 100644
--- a/include/asm-sparc64/pgtable.h
+++ b/include/asm-sparc64/pgtable.h
@@ -23,9 +23,9 @@
23#include <asm/page.h> 23#include <asm/page.h>
24#include <asm/processor.h> 24#include <asm/processor.h>
25 25
26/* The kernel image occupies 0x4000000 to 0x1000000 (4MB --> 32MB). 26/* The kernel image occupies 0x4000000 to 0x6000000 (4MB --> 96MB).
27 * The page copy blockops can use 0x2000000 to 0x4000000. 27 * The page copy blockops can use 0x6000000 to 0x8000000.
28 * The TSB is mapped in the 0x4000000 to 0x6000000 range. 28 * The TSB is mapped in the 0x8000000 to 0xa000000 range.
29 * The PROM resides in an area spanning 0xf0000000 to 0x100000000. 29 * The PROM resides in an area spanning 0xf0000000 to 0x100000000.
30 * The vmalloc area spans 0x100000000 to 0x200000000. 30 * The vmalloc area spans 0x100000000 to 0x200000000.
31 * Since modules need to be in the lowest 32-bits of the address space, 31 * Since modules need to be in the lowest 32-bits of the address space,
@@ -33,8 +33,8 @@
33 * There is a single static kernel PMD which maps from 0x0 to address 33 * There is a single static kernel PMD which maps from 0x0 to address
34 * 0x400000000. 34 * 0x400000000.
35 */ 35 */
36#define TLBTEMP_BASE _AC(0x0000000002000000,UL) 36#define TLBTEMP_BASE _AC(0x0000000006000000,UL)
37#define TSBMAP_BASE _AC(0x0000000004000000,UL) 37#define TSBMAP_BASE _AC(0x0000000008000000,UL)
38#define MODULES_VADDR _AC(0x0000000010000000,UL) 38#define MODULES_VADDR _AC(0x0000000010000000,UL)
39#define MODULES_LEN _AC(0x00000000e0000000,UL) 39#define MODULES_LEN _AC(0x00000000e0000000,UL)
40#define MODULES_END _AC(0x00000000f0000000,UL) 40#define MODULES_END _AC(0x00000000f0000000,UL)
@@ -761,6 +761,8 @@ extern unsigned long get_fb_unmapped_area(struct file *filp, unsigned long,
761extern void pgtable_cache_init(void); 761extern void pgtable_cache_init(void);
762extern void sun4v_register_fault_status(void); 762extern void sun4v_register_fault_status(void);
763extern void sun4v_ktsb_register(void); 763extern void sun4v_ktsb_register(void);
764extern void __init cheetah_ecache_flush_init(void);
765extern void sun4v_patch_tlb_handlers(void);
764 766
765extern unsigned long cmdline_memory_size; 767extern unsigned long cmdline_memory_size;
766 768
diff --git a/include/asm-sparc64/processor.h b/include/asm-sparc64/processor.h
index 8da484c19822..885b6a1dcae4 100644
--- a/include/asm-sparc64/processor.h
+++ b/include/asm-sparc64/processor.h
@@ -37,6 +37,9 @@
37#endif 37#endif
38 38
39#define TASK_SIZE ((unsigned long)-VPTE_SIZE) 39#define TASK_SIZE ((unsigned long)-VPTE_SIZE)
40#define TASK_SIZE_OF(tsk) \
41 (test_tsk_thread_flag(tsk,TIF_32BIT) ? \
42 (1UL << 32UL) : TASK_SIZE)
40#ifdef __KERNEL__ 43#ifdef __KERNEL__
41 44
42#define STACK_TOP32 ((1UL << 32UL) - PAGE_SIZE) 45#define STACK_TOP32 ((1UL << 32UL) - PAGE_SIZE)
diff --git a/include/asm-sparc64/stacktrace.h b/include/asm-sparc64/stacktrace.h
new file mode 100644
index 000000000000..6cee39adf6d6
--- /dev/null
+++ b/include/asm-sparc64/stacktrace.h
@@ -0,0 +1,6 @@
1#ifndef _SPARC64_STACKTRACE_H
2#define _SPARC64_STACKTRACE_H
3
4extern void stack_trace_flush(void);
5
6#endif /* _SPARC64_STACKTRACE_H */
diff --git a/include/asm-sparc64/timer.h b/include/asm-sparc64/timer.h
index ccbd69448866..5b779fd1f788 100644
--- a/include/asm-sparc64/timer.h
+++ b/include/asm-sparc64/timer.h
@@ -1,14 +1,13 @@
1/* $Id: timer.h,v 1.3 2000/05/09 17:40:15 davem Exp $ 1/* timer.h: System timer definitions for sun5.
2 * timer.h: System timer definitions for sun5.
3 * 2 *
4 * Copyright (C) 1997 David S. Miller (davem@caip.rutgers.edu) 3 * Copyright (C) 1997, 2008 David S. Miller (davem@davemloft.net)
5 */ 4 */
6 5
7#ifndef _SPARC64_TIMER_H 6#ifndef _SPARC64_TIMER_H
8#define _SPARC64_TIMER_H 7#define _SPARC64_TIMER_H
9 8
10#include <linux/types.h> 9#include <linux/types.h>
11 10#include <linux/init.h>
12 11
13struct sparc64_tick_ops { 12struct sparc64_tick_ops {
14 unsigned long (*get_tick)(void); 13 unsigned long (*get_tick)(void);
@@ -25,5 +24,7 @@ struct sparc64_tick_ops {
25extern struct sparc64_tick_ops *tick_ops; 24extern struct sparc64_tick_ops *tick_ops;
26 25
27extern unsigned long sparc64_get_clock_tick(unsigned int cpu); 26extern unsigned long sparc64_get_clock_tick(unsigned int cpu);
27extern void __devinit setup_sparc64_timer(void);
28extern void __init time_init(void);
28 29
29#endif /* _SPARC64_TIMER_H */ 30#endif /* _SPARC64_TIMER_H */
diff --git a/include/asm-um/kvm.h b/include/asm-um/kvm.h
new file mode 100644
index 000000000000..66aa77094551
--- /dev/null
+++ b/include/asm-um/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_UM_H
2#define __LINUX_KVM_UM_H
3
4/* um does not support KVM */
5
6#endif
diff --git a/include/asm-v850/kvm.h b/include/asm-v850/kvm.h
new file mode 100644
index 000000000000..3f729b79febc
--- /dev/null
+++ b/include/asm-v850/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_V850_H
2#define __LINUX_KVM_V850_H
3
4/* v850 does not support KVM */
5
6#endif
diff --git a/include/asm-x86/irqflags.h b/include/asm-x86/irqflags.h
index 92021c1ffa3a..0e2292483b35 100644
--- a/include/asm-x86/irqflags.h
+++ b/include/asm-x86/irqflags.h
@@ -70,6 +70,26 @@ static inline void raw_local_irq_restore(unsigned long flags)
70 native_restore_fl(flags); 70 native_restore_fl(flags);
71} 71}
72 72
73#ifdef CONFIG_X86_VSMP
74
75/*
76 * Interrupt control for the VSMP architecture:
77 */
78
79static inline void raw_local_irq_disable(void)
80{
81 unsigned long flags = __raw_local_save_flags();
82 raw_local_irq_restore((flags & ~X86_EFLAGS_IF) | X86_EFLAGS_AC);
83}
84
85static inline void raw_local_irq_enable(void)
86{
87 unsigned long flags = __raw_local_save_flags();
88 raw_local_irq_restore((flags | X86_EFLAGS_IF) & (~X86_EFLAGS_AC));
89}
90
91#else
92
73static inline void raw_local_irq_disable(void) 93static inline void raw_local_irq_disable(void)
74{ 94{
75 native_irq_disable(); 95 native_irq_disable();
@@ -80,6 +100,8 @@ static inline void raw_local_irq_enable(void)
80 native_irq_enable(); 100 native_irq_enable();
81} 101}
82 102
103#endif
104
83/* 105/*
84 * Used in the idle loop; sti takes one instruction cycle 106 * Used in the idle loop; sti takes one instruction cycle
85 * to complete: 107 * to complete:
@@ -137,10 +159,17 @@ static inline unsigned long __raw_local_irq_save(void)
137#define raw_local_irq_save(flags) \ 159#define raw_local_irq_save(flags) \
138 do { (flags) = __raw_local_irq_save(); } while (0) 160 do { (flags) = __raw_local_irq_save(); } while (0)
139 161
162#ifdef CONFIG_X86_VSMP
163static inline int raw_irqs_disabled_flags(unsigned long flags)
164{
165 return !(flags & X86_EFLAGS_IF) || (flags & X86_EFLAGS_AC);
166}
167#else
140static inline int raw_irqs_disabled_flags(unsigned long flags) 168static inline int raw_irqs_disabled_flags(unsigned long flags)
141{ 169{
142 return !(flags & X86_EFLAGS_IF); 170 return !(flags & X86_EFLAGS_IF);
143} 171}
172#endif
144 173
145static inline int raw_irqs_disabled(void) 174static inline int raw_irqs_disabled(void)
146{ 175{
diff --git a/include/asm-x86/lguest_hcall.h b/include/asm-x86/lguest_hcall.h
index 758b9a5d4539..f239e7069cab 100644
--- a/include/asm-x86/lguest_hcall.h
+++ b/include/asm-x86/lguest_hcall.h
@@ -27,7 +27,7 @@
27#ifndef __ASSEMBLY__ 27#ifndef __ASSEMBLY__
28#include <asm/hw_irq.h> 28#include <asm/hw_irq.h>
29 29
30/*G:031 First, how does our Guest contact the Host to ask for privileged 30/*G:031 But first, how does our Guest contact the Host to ask for privileged
31 * operations? There are two ways: the direct way is to make a "hypercall", 31 * operations? There are two ways: the direct way is to make a "hypercall",
32 * to make requests of the Host Itself. 32 * to make requests of the Host Itself.
33 * 33 *
diff --git a/include/asm-x86/linkage.h b/include/asm-x86/linkage.h
index 31739c7d66a9..c048353f4b85 100644
--- a/include/asm-x86/linkage.h
+++ b/include/asm-x86/linkage.h
@@ -8,12 +8,45 @@
8 8
9#ifdef CONFIG_X86_32 9#ifdef CONFIG_X86_32
10#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0))) 10#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
11#define prevent_tail_call(ret) __asm__ ("" : "=r" (ret) : "0" (ret))
12/* 11/*
13 * For 32-bit UML - mark functions implemented in assembly that use 12 * For 32-bit UML - mark functions implemented in assembly that use
14 * regparm input parameters: 13 * regparm input parameters:
15 */ 14 */
16#define asmregparm __attribute__((regparm(3))) 15#define asmregparm __attribute__((regparm(3)))
16
17/*
18 * Make sure the compiler doesn't do anything stupid with the
19 * arguments on the stack - they are owned by the *caller*, not
20 * the callee. This just fools gcc into not spilling into them,
21 * and keeps it from doing tailcall recursion and/or using the
22 * stack slots for temporaries, since they are live and "used"
23 * all the way to the end of the function.
24 *
25 * NOTE! On x86-64, all the arguments are in registers, so this
26 * only matters on a 32-bit kernel.
27 */
28#define asmlinkage_protect(n, ret, args...) \
29 __asmlinkage_protect##n(ret, ##args)
30#define __asmlinkage_protect_n(ret, args...) \
31 __asm__ __volatile__ ("" : "=r" (ret) : "0" (ret), ##args)
32#define __asmlinkage_protect0(ret) \
33 __asmlinkage_protect_n(ret)
34#define __asmlinkage_protect1(ret, arg1) \
35 __asmlinkage_protect_n(ret, "g" (arg1))
36#define __asmlinkage_protect2(ret, arg1, arg2) \
37 __asmlinkage_protect_n(ret, "g" (arg1), "g" (arg2))
38#define __asmlinkage_protect3(ret, arg1, arg2, arg3) \
39 __asmlinkage_protect_n(ret, "g" (arg1), "g" (arg2), "g" (arg3))
40#define __asmlinkage_protect4(ret, arg1, arg2, arg3, arg4) \
41 __asmlinkage_protect_n(ret, "g" (arg1), "g" (arg2), "g" (arg3), \
42 "g" (arg4))
43#define __asmlinkage_protect5(ret, arg1, arg2, arg3, arg4, arg5) \
44 __asmlinkage_protect_n(ret, "g" (arg1), "g" (arg2), "g" (arg3), \
45 "g" (arg4), "g" (arg5))
46#define __asmlinkage_protect6(ret, arg1, arg2, arg3, arg4, arg5, arg6) \
47 __asmlinkage_protect_n(ret, "g" (arg1), "g" (arg2), "g" (arg3), \
48 "g" (arg4), "g" (arg5), "g" (arg6))
49
17#endif 50#endif
18 51
19#ifdef CONFIG_X86_ALIGNMENT_16 52#ifdef CONFIG_X86_ALIGNMENT_16
diff --git a/include/asm-x86/mach-rdc321x/gpio.h b/include/asm-x86/mach-rdc321x/gpio.h
index db31b929b990..acce0b7d397b 100644
--- a/include/asm-x86/mach-rdc321x/gpio.h
+++ b/include/asm-x86/mach-rdc321x/gpio.h
@@ -5,19 +5,20 @@ extern int rdc_gpio_get_value(unsigned gpio);
5extern void rdc_gpio_set_value(unsigned gpio, int value); 5extern void rdc_gpio_set_value(unsigned gpio, int value);
6extern int rdc_gpio_direction_input(unsigned gpio); 6extern int rdc_gpio_direction_input(unsigned gpio);
7extern int rdc_gpio_direction_output(unsigned gpio, int value); 7extern int rdc_gpio_direction_output(unsigned gpio, int value);
8 8extern int rdc_gpio_request(unsigned gpio, const char *label);
9extern void rdc_gpio_free(unsigned gpio);
10extern void __init rdc321x_gpio_setup(void);
9 11
10/* Wrappers for the arch-neutral GPIO API */ 12/* Wrappers for the arch-neutral GPIO API */
11 13
12static inline int gpio_request(unsigned gpio, const char *label) 14static inline int gpio_request(unsigned gpio, const char *label)
13{ 15{
14 /* Not yet implemented */ 16 return rdc_gpio_request(gpio, label);
15 return 0;
16} 17}
17 18
18static inline void gpio_free(unsigned gpio) 19static inline void gpio_free(unsigned gpio)
19{ 20{
20 /* Not yet implemented */ 21 rdc_gpio_free(gpio);
21} 22}
22 23
23static inline int gpio_direction_input(unsigned gpio) 24static inline int gpio_direction_input(unsigned gpio)
diff --git a/include/asm-x86/mach-rdc321x/rdc321x_defs.h b/include/asm-x86/mach-rdc321x/rdc321x_defs.h
index 838ba8f64fd3..c8e9c8bed3d0 100644
--- a/include/asm-x86/mach-rdc321x/rdc321x_defs.h
+++ b/include/asm-x86/mach-rdc321x/rdc321x_defs.h
@@ -3,4 +3,10 @@
3/* General purpose configuration and data registers */ 3/* General purpose configuration and data registers */
4#define RDC3210_CFGREG_ADDR 0x0CF8 4#define RDC3210_CFGREG_ADDR 0x0CF8
5#define RDC3210_CFGREG_DATA 0x0CFC 5#define RDC3210_CFGREG_DATA 0x0CFC
6#define RDC_MAX_GPIO 0x3A 6
7#define RDC321X_GPIO_CTRL_REG1 0x48
8#define RDC321X_GPIO_CTRL_REG2 0x84
9#define RDC321X_GPIO_DATA_REG1 0x4c
10#define RDC321X_GPIO_DATA_REG2 0x88
11
12#define RDC321X_MAX_GPIO 58
diff --git a/include/asm-x86/nops.h b/include/asm-x86/nops.h
index e3b2bce0aff8..b3930ae539b3 100644
--- a/include/asm-x86/nops.h
+++ b/include/asm-x86/nops.h
@@ -73,16 +73,7 @@
73#define P6_NOP7 ".byte 0x0f,0x1f,0x80,0,0,0,0\n" 73#define P6_NOP7 ".byte 0x0f,0x1f,0x80,0,0,0,0\n"
74#define P6_NOP8 ".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n" 74#define P6_NOP8 ".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
75 75
76#if defined(CONFIG_MK8) 76#if defined(CONFIG_MK7)
77#define ASM_NOP1 K8_NOP1
78#define ASM_NOP2 K8_NOP2
79#define ASM_NOP3 K8_NOP3
80#define ASM_NOP4 K8_NOP4
81#define ASM_NOP5 K8_NOP5
82#define ASM_NOP6 K8_NOP6
83#define ASM_NOP7 K8_NOP7
84#define ASM_NOP8 K8_NOP8
85#elif defined(CONFIG_MK7)
86#define ASM_NOP1 K7_NOP1 77#define ASM_NOP1 K7_NOP1
87#define ASM_NOP2 K7_NOP2 78#define ASM_NOP2 K7_NOP2
88#define ASM_NOP3 K7_NOP3 79#define ASM_NOP3 K7_NOP3
@@ -100,6 +91,15 @@
100#define ASM_NOP6 P6_NOP6 91#define ASM_NOP6 P6_NOP6
101#define ASM_NOP7 P6_NOP7 92#define ASM_NOP7 P6_NOP7
102#define ASM_NOP8 P6_NOP8 93#define ASM_NOP8 P6_NOP8
94#elif defined(CONFIG_X86_64)
95#define ASM_NOP1 K8_NOP1
96#define ASM_NOP2 K8_NOP2
97#define ASM_NOP3 K8_NOP3
98#define ASM_NOP4 K8_NOP4
99#define ASM_NOP5 K8_NOP5
100#define ASM_NOP6 K8_NOP6
101#define ASM_NOP7 K8_NOP7
102#define ASM_NOP8 K8_NOP8
103#else 103#else
104#define ASM_NOP1 GENERIC_NOP1 104#define ASM_NOP1 GENERIC_NOP1
105#define ASM_NOP2 GENERIC_NOP2 105#define ASM_NOP2 GENERIC_NOP2
diff --git a/include/asm-x86/pgtable.h b/include/asm-x86/pgtable.h
index 174b87738714..9cf472aeb9ce 100644
--- a/include/asm-x86/pgtable.h
+++ b/include/asm-x86/pgtable.h
@@ -85,6 +85,7 @@ extern pteval_t __PAGE_KERNEL, __PAGE_KERNEL_EXEC;
85#define __PAGE_KERNEL_RX (__PAGE_KERNEL_EXEC & ~_PAGE_RW) 85#define __PAGE_KERNEL_RX (__PAGE_KERNEL_EXEC & ~_PAGE_RW)
86#define __PAGE_KERNEL_EXEC_NOCACHE (__PAGE_KERNEL_EXEC | _PAGE_PCD | _PAGE_PWT) 86#define __PAGE_KERNEL_EXEC_NOCACHE (__PAGE_KERNEL_EXEC | _PAGE_PCD | _PAGE_PWT)
87#define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT) 87#define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
88#define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
88#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER) 89#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
89#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT) 90#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
90#define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE) 91#define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
@@ -101,6 +102,7 @@ extern pteval_t __PAGE_KERNEL, __PAGE_KERNEL_EXEC;
101#define PAGE_KERNEL_EXEC MAKE_GLOBAL(__PAGE_KERNEL_EXEC) 102#define PAGE_KERNEL_EXEC MAKE_GLOBAL(__PAGE_KERNEL_EXEC)
102#define PAGE_KERNEL_RX MAKE_GLOBAL(__PAGE_KERNEL_RX) 103#define PAGE_KERNEL_RX MAKE_GLOBAL(__PAGE_KERNEL_RX)
103#define PAGE_KERNEL_NOCACHE MAKE_GLOBAL(__PAGE_KERNEL_NOCACHE) 104#define PAGE_KERNEL_NOCACHE MAKE_GLOBAL(__PAGE_KERNEL_NOCACHE)
105#define PAGE_KERNEL_UC_MINUS MAKE_GLOBAL(__PAGE_KERNEL_UC_MINUS)
104#define PAGE_KERNEL_EXEC_NOCACHE MAKE_GLOBAL(__PAGE_KERNEL_EXEC_NOCACHE) 106#define PAGE_KERNEL_EXEC_NOCACHE MAKE_GLOBAL(__PAGE_KERNEL_EXEC_NOCACHE)
105#define PAGE_KERNEL_LARGE MAKE_GLOBAL(__PAGE_KERNEL_LARGE) 107#define PAGE_KERNEL_LARGE MAKE_GLOBAL(__PAGE_KERNEL_LARGE)
106#define PAGE_KERNEL_LARGE_EXEC MAKE_GLOBAL(__PAGE_KERNEL_LARGE_EXEC) 108#define PAGE_KERNEL_LARGE_EXEC MAKE_GLOBAL(__PAGE_KERNEL_LARGE_EXEC)
diff --git a/include/asm-xtensa/kvm.h b/include/asm-xtensa/kvm.h
new file mode 100644
index 000000000000..bda4e331e98c
--- /dev/null
+++ b/include/asm-xtensa/kvm.h
@@ -0,0 +1,6 @@
1#ifndef __LINUX_KVM_XTENSA_H
2#define __LINUX_KVM_XTENSA_H
3
4/* xtensa does not support KVM */
5
6#endif
diff --git a/include/linux/Kbuild b/include/linux/Kbuild
index 4108b38ebb16..9cdd12a9e843 100644
--- a/include/linux/Kbuild
+++ b/include/linux/Kbuild
@@ -195,7 +195,6 @@ unifdef-y += ethtool.h
195unifdef-y += eventpoll.h 195unifdef-y += eventpoll.h
196unifdef-y += signalfd.h 196unifdef-y += signalfd.h
197unifdef-y += ext2_fs.h 197unifdef-y += ext2_fs.h
198unifdef-y += ext3_fs.h
199unifdef-y += fb.h 198unifdef-y += fb.h
200unifdef-y += fcntl.h 199unifdef-y += fcntl.h
201unifdef-y += filter.h 200unifdef-y += filter.h
@@ -248,14 +247,13 @@ unifdef-y += isdn.h
248unifdef-y += isdnif.h 247unifdef-y += isdnif.h
249unifdef-y += isdn_divertif.h 248unifdef-y += isdn_divertif.h
250unifdef-y += isdn_ppp.h 249unifdef-y += isdn_ppp.h
251unifdef-y += jbd.h
252unifdef-y += joystick.h 250unifdef-y += joystick.h
253unifdef-y += kdev_t.h 251unifdef-y += kdev_t.h
254unifdef-y += kd.h 252unifdef-y += kd.h
255unifdef-y += kernelcapi.h 253unifdef-y += kernelcapi.h
256unifdef-y += kernel.h 254unifdef-y += kernel.h
257unifdef-y += keyboard.h 255unifdef-y += keyboard.h
258unifdef-$(CONFIG_HAVE_KVM) += kvm.h 256unifdef-y += kvm.h
259unifdef-y += llc.h 257unifdef-y += llc.h
260unifdef-y += loop.h 258unifdef-y += loop.h
261unifdef-y += lp.h 259unifdef-y += lp.h
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 69c1edb9fe54..40d54731de7e 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -65,6 +65,46 @@ static inline __u32 ror32(__u32 word, unsigned int shift)
65 return (word >> shift) | (word << (32 - shift)); 65 return (word >> shift) | (word << (32 - shift));
66} 66}
67 67
68/**
69 * rol16 - rotate a 16-bit value left
70 * @word: value to rotate
71 * @shift: bits to roll
72 */
73static inline __u16 rol16(__u16 word, unsigned int shift)
74{
75 return (word << shift) | (word >> (16 - shift));
76}
77
78/**
79 * ror16 - rotate a 16-bit value right
80 * @word: value to rotate
81 * @shift: bits to roll
82 */
83static inline __u16 ror16(__u16 word, unsigned int shift)
84{
85 return (word >> shift) | (word << (16 - shift));
86}
87
88/**
89 * rol8 - rotate an 8-bit value left
90 * @word: value to rotate
91 * @shift: bits to roll
92 */
93static inline __u8 rol8(__u8 word, unsigned int shift)
94{
95 return (word << shift) | (word >> (8 - shift));
96}
97
98/**
99 * ror8 - rotate an 8-bit value right
100 * @word: value to rotate
101 * @shift: bits to roll
102 */
103static inline __u8 ror8(__u8 word, unsigned int shift)
104{
105 return (word >> shift) | (word << (8 - shift));
106}
107
68static inline unsigned fls_long(unsigned long l) 108static inline unsigned fls_long(unsigned long l)
69{ 109{
70 if (sizeof(l) == 4) 110 if (sizeof(l) == 4)
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 028ba3b523b1..a6a6035a4e1e 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -256,6 +256,7 @@ struct cgroup_subsys {
256 void (*bind)(struct cgroup_subsys *ss, struct cgroup *root); 256 void (*bind)(struct cgroup_subsys *ss, struct cgroup *root);
257 int subsys_id; 257 int subsys_id;
258 int active; 258 int active;
259 int disabled;
259 int early_init; 260 int early_init;
260#define MAX_CGROUP_TYPE_NAMELEN 32 261#define MAX_CGROUP_TYPE_NAMELEN 32
261 const char *name; 262 const char *name;
diff --git a/include/linux/compat.h b/include/linux/compat.h
index a671dbff7a1f..8fa7857e153b 100644
--- a/include/linux/compat.h
+++ b/include/linux/compat.h
@@ -192,8 +192,8 @@ asmlinkage long compat_sys_select(int n, compat_ulong_t __user *inp,
192 struct compat_timeval __user *tvp); 192 struct compat_timeval __user *tvp);
193 193
194asmlinkage long compat_sys_wait4(compat_pid_t pid, 194asmlinkage long compat_sys_wait4(compat_pid_t pid,
195 compat_uint_t *stat_addr, int options, 195 compat_uint_t __user *stat_addr, int options,
196 struct compat_rusage *ru); 196 struct compat_rusage __user *ru);
197 197
198#define BITS_PER_COMPAT_LONG (8*sizeof(compat_long_t)) 198#define BITS_PER_COMPAT_LONG (8*sizeof(compat_long_t))
199 199
diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
index 6b72a4584086..51e6b1e520e6 100644
--- a/include/linux/cpuidle.h
+++ b/include/linux/cpuidle.h
@@ -38,8 +38,8 @@ struct cpuidle_state {
38 unsigned int power_usage; /* in mW */ 38 unsigned int power_usage; /* in mW */
39 unsigned int target_residency; /* in US */ 39 unsigned int target_residency; /* in US */
40 40
41 unsigned int usage; 41 unsigned long long usage;
42 unsigned int time; /* in US */ 42 unsigned long long time; /* in US */
43 43
44 int (*enter) (struct cpuidle_device *dev, 44 int (*enter) (struct cpuidle_device *dev,
45 struct cpuidle_state *state); 45 struct cpuidle_state *state);
diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
index 261e43a4c873..34d440698293 100644
--- a/include/linux/dmaengine.h
+++ b/include/linux/dmaengine.h
@@ -423,7 +423,7 @@ void dma_async_device_unregister(struct dma_device *device);
423/* --- Helper iov-locking functions --- */ 423/* --- Helper iov-locking functions --- */
424 424
425struct dma_page_list { 425struct dma_page_list {
426 char *base_address; 426 char __user *base_address;
427 int nr_pages; 427 int nr_pages;
428 struct page **pages; 428 struct page **pages;
429}; 429};
diff --git a/include/linux/hardirq.h b/include/linux/hardirq.h
index 49829988bfa0..897f723bd222 100644
--- a/include/linux/hardirq.h
+++ b/include/linux/hardirq.h
@@ -72,6 +72,13 @@
72#define in_softirq() (softirq_count()) 72#define in_softirq() (softirq_count())
73#define in_interrupt() (irq_count()) 73#define in_interrupt() (irq_count())
74 74
75/*
76 * Are we running in atomic context? WARNING: this macro cannot
77 * always detect atomic context; in particular, it cannot know about
78 * held spinlocks in non-preemptible kernels. Thus it should not be
79 * used in the general case to determine whether sleeping is possible.
80 * Do not use in_atomic() in driver code.
81 */
75#define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != 0) 82#define in_atomic() ((preempt_count() & ~PREEMPT_ACTIVE) != 0)
76 83
77#ifdef CONFIG_PREEMPT 84#ifdef CONFIG_PREEMPT
diff --git a/include/linux/hpet.h b/include/linux/hpet.h
index 9cd94bfd07e5..2dc29ce6c8e4 100644
--- a/include/linux/hpet.h
+++ b/include/linux/hpet.h
@@ -64,7 +64,7 @@ struct hpet {
64 */ 64 */
65 65
66#define Tn_INT_ROUTE_CAP_MASK (0xffffffff00000000ULL) 66#define Tn_INT_ROUTE_CAP_MASK (0xffffffff00000000ULL)
67#define Tn_INT_ROUTE_CAP_SHIFT (32UL) 67#define Tn_INI_ROUTE_CAP_SHIFT (32UL)
68#define Tn_FSB_INT_DELCAP_MASK (0x8000UL) 68#define Tn_FSB_INT_DELCAP_MASK (0x8000UL)
69#define Tn_FSB_INT_DELCAP_SHIFT (15) 69#define Tn_FSB_INT_DELCAP_SHIFT (15)
70#define Tn_FSB_EN_CNF_MASK (0x4000UL) 70#define Tn_FSB_EN_CNF_MASK (0x4000UL)
diff --git a/include/linux/i2c/tps65010.h b/include/linux/i2c/tps65010.h
index 7021635ed6a0..918c5354d9b8 100644
--- a/include/linux/i2c/tps65010.h
+++ b/include/linux/i2c/tps65010.h
@@ -152,5 +152,35 @@ extern int tps65010_config_vregs1(unsigned value);
152 */ 152 */
153extern int tps65013_set_low_pwr(unsigned mode); 153extern int tps65013_set_low_pwr(unsigned mode);
154 154
155
156struct i2c_client;
157
158/**
159 * struct tps65010_board - packages GPIO and LED lines
160 * @base: the GPIO number to assign to GPIO-1
161 * @outmask: bit (N-1) is set to allow GPIO-N to be used as an
162 * (open drain) output
163 * @setup: optional callback issued once the GPIOs are valid
164 * @teardown: optional callback issued before the GPIOs are invalidated
165 * @context: optional parameter passed to setup() and teardown()
166 *
167 * Board data may be used to package the GPIO (and LED) lines for use
168 * in by the generic GPIO and LED frameworks. The first four GPIOs
169 * starting at gpio_base are GPIO1..GPIO4. The next two are LED1/nPG
170 * and LED2 (with hardware blinking capability, not currently exposed).
171 *
172 * The @setup callback may be used with the kind of board-specific glue
173 * which hands the (now-valid) GPIOs to other drivers, or which puts
174 * devices in their initial states using these GPIOs.
175 */
176struct tps65010_board {
177 int base;
178 unsigned outmask;
179
180 int (*setup)(struct i2c_client *client, void *context);
181 int (*teardown)(struct i2c_client *client, void *context);
182 void *context;
183};
184
155#endif /* __LINUX_I2C_TPS65010_H */ 185#endif /* __LINUX_I2C_TPS65010_H */
156 186
diff --git a/include/linux/ide.h b/include/linux/ide.h
index a3b69c10d667..bc26b2f27359 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -26,7 +26,7 @@
26#include <asm/semaphore.h> 26#include <asm/semaphore.h>
27#include <asm/mutex.h> 27#include <asm/mutex.h>
28 28
29#if defined(CRIS) || defined(FRV) 29#if defined(CONFIG_CRIS) || defined(CONFIG_FRV)
30# define SUPPORT_VLB_SYNC 0 30# define SUPPORT_VLB_SYNC 0
31#else 31#else
32# define SUPPORT_VLB_SYNC 1 32# define SUPPORT_VLB_SYNC 1
diff --git a/include/linux/input.h b/include/linux/input.h
index 1bdc39a8c76c..cae2c35d1206 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -1227,12 +1227,13 @@ void input_free_device(struct input_dev *dev);
1227 1227
1228static inline struct input_dev *input_get_device(struct input_dev *dev) 1228static inline struct input_dev *input_get_device(struct input_dev *dev)
1229{ 1229{
1230 return to_input_dev(get_device(&dev->dev)); 1230 return dev ? to_input_dev(get_device(&dev->dev)) : NULL;
1231} 1231}
1232 1232
1233static inline void input_put_device(struct input_dev *dev) 1233static inline void input_put_device(struct input_dev *dev)
1234{ 1234{
1235 put_device(&dev->dev); 1235 if (dev)
1236 put_device(&dev->dev);
1236} 1237}
1237 1238
1238static inline void *input_get_drvdata(struct input_dev *dev) 1239static inline void *input_get_drvdata(struct input_dev *dev)
diff --git a/include/linux/iocontext.h b/include/linux/iocontext.h
index 1b4ccf25b4d2..cac4b364cd40 100644
--- a/include/linux/iocontext.h
+++ b/include/linux/iocontext.h
@@ -2,6 +2,7 @@
2#define IOCONTEXT_H 2#define IOCONTEXT_H
3 3
4#include <linux/radix-tree.h> 4#include <linux/radix-tree.h>
5#include <linux/rcupdate.h>
5 6
6/* 7/*
7 * This is the per-process anticipatory I/O scheduler state. 8 * This is the per-process anticipatory I/O scheduler state.
@@ -54,6 +55,8 @@ struct cfq_io_context {
54 55
55 void (*dtor)(struct io_context *); /* destructor */ 56 void (*dtor)(struct io_context *); /* destructor */
56 void (*exit)(struct io_context *); /* called on task exit */ 57 void (*exit)(struct io_context *); /* called on task exit */
58
59 struct rcu_head rcu_head;
57}; 60};
58 61
59/* 62/*
diff --git a/include/linux/lguest_launcher.h b/include/linux/lguest_launcher.h
index 589be3e1f3ac..e7217dc58f39 100644
--- a/include/linux/lguest_launcher.h
+++ b/include/linux/lguest_launcher.h
@@ -16,6 +16,10 @@
16 * a new device, we simply need to write a new virtio driver and create support 16 * a new device, we simply need to write a new virtio driver and create support
17 * for it in the Launcher: this code won't need to change. 17 * for it in the Launcher: this code won't need to change.
18 * 18 *
19 * Virtio devices are also used by kvm, so we can simply reuse their optimized
20 * device drivers. And one day when everyone uses virtio, my plan will be
21 * complete. Bwahahahah!
22 *
19 * Devices are described by a simplified ID, a status byte, and some "config" 23 * Devices are described by a simplified ID, a status byte, and some "config"
20 * bytes which describe this device's configuration. This is placed by the 24 * bytes which describe this device's configuration. This is placed by the
21 * Launcher just above the top of physical memory: 25 * Launcher just above the top of physical memory:
@@ -26,7 +30,7 @@ struct lguest_device_desc {
26 /* The number of virtqueues (first in config array) */ 30 /* The number of virtqueues (first in config array) */
27 __u8 num_vq; 31 __u8 num_vq;
28 /* The number of bytes of feature bits. Multiply by 2: one for host 32 /* The number of bytes of feature bits. Multiply by 2: one for host
29 * features and one for guest acknowledgements. */ 33 * features and one for Guest acknowledgements. */
30 __u8 feature_len; 34 __u8 feature_len;
31 /* The number of bytes of the config array after virtqueues. */ 35 /* The number of bytes of the config array after virtqueues. */
32 __u8 config_len; 36 __u8 config_len;
diff --git a/include/linux/libata.h b/include/linux/libata.h
index 269cdba09578..37ee881c42ac 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -295,6 +295,7 @@ enum {
295 ATA_EH_SOFTRESET = (1 << 1), 295 ATA_EH_SOFTRESET = (1 << 1),
296 ATA_EH_HARDRESET = (1 << 2), 296 ATA_EH_HARDRESET = (1 << 2),
297 ATA_EH_ENABLE_LINK = (1 << 3), 297 ATA_EH_ENABLE_LINK = (1 << 3),
298 ATA_EH_LPM = (1 << 4), /* link power management action */
298 299
299 ATA_EH_RESET_MASK = ATA_EH_SOFTRESET | ATA_EH_HARDRESET, 300 ATA_EH_RESET_MASK = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
300 ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE, 301 ATA_EH_PERDEV_MASK = ATA_EH_REVALIDATE,
@@ -304,7 +305,6 @@ enum {
304 ATA_EHI_RESUME_LINK = (1 << 1), /* resume link (reset modifier) */ 305 ATA_EHI_RESUME_LINK = (1 << 1), /* resume link (reset modifier) */
305 ATA_EHI_NO_AUTOPSY = (1 << 2), /* no autopsy */ 306 ATA_EHI_NO_AUTOPSY = (1 << 2), /* no autopsy */
306 ATA_EHI_QUIET = (1 << 3), /* be quiet */ 307 ATA_EHI_QUIET = (1 << 3), /* be quiet */
307 ATA_EHI_LPM = (1 << 4), /* link power management action */
308 308
309 ATA_EHI_DID_SOFTRESET = (1 << 16), /* already soft-reset this port */ 309 ATA_EHI_DID_SOFTRESET = (1 << 16), /* already soft-reset this port */
310 ATA_EHI_DID_HARDRESET = (1 << 17), /* already soft-reset this port */ 310 ATA_EHI_DID_HARDRESET = (1 << 17), /* already soft-reset this port */
@@ -350,7 +350,8 @@ enum {
350 ATAPI_READ = 0, /* READs */ 350 ATAPI_READ = 0, /* READs */
351 ATAPI_WRITE = 1, /* WRITEs */ 351 ATAPI_WRITE = 1, /* WRITEs */
352 ATAPI_READ_CD = 2, /* READ CD [MSF] */ 352 ATAPI_READ_CD = 2, /* READ CD [MSF] */
353 ATAPI_MISC = 3, /* the rest */ 353 ATAPI_PASS_THRU = 3, /* SAT pass-thru */
354 ATAPI_MISC = 4, /* the rest */
354}; 355};
355 356
356enum ata_xfer_mask { 357enum ata_xfer_mask {
@@ -849,6 +850,7 @@ extern unsigned int ata_dev_try_classify(struct ata_device *dev, int present,
849 */ 850 */
850extern void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf); 851extern void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf);
851extern void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf); 852extern void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf);
853extern int atapi_cmd_type(u8 opcode);
852extern void ata_tf_to_fis(const struct ata_taskfile *tf, 854extern void ata_tf_to_fis(const struct ata_taskfile *tf,
853 u8 pmp, int is_cmd, u8 *fis); 855 u8 pmp, int is_cmd, u8 *fis);
854extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf); 856extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf);
@@ -1379,27 +1381,6 @@ static inline int ata_try_flush_cache(const struct ata_device *dev)
1379 ata_id_has_flush_ext(dev->id); 1381 ata_id_has_flush_ext(dev->id);
1380} 1382}
1381 1383
1382static inline int atapi_cmd_type(u8 opcode)
1383{
1384 switch (opcode) {
1385 case GPCMD_READ_10:
1386 case GPCMD_READ_12:
1387 return ATAPI_READ;
1388
1389 case GPCMD_WRITE_10:
1390 case GPCMD_WRITE_12:
1391 case GPCMD_WRITE_AND_VERIFY_10:
1392 return ATAPI_WRITE;
1393
1394 case GPCMD_READ_CD:
1395 case GPCMD_READ_CD_MSF:
1396 return ATAPI_READ_CD;
1397
1398 default:
1399 return ATAPI_MISC;
1400 }
1401}
1402
1403static inline unsigned int ac_err_mask(u8 status) 1384static inline unsigned int ac_err_mask(u8 status)
1404{ 1385{
1405 if (status & (ATA_BUSY | ATA_DRQ)) 1386 if (status & (ATA_BUSY | ATA_DRQ))
diff --git a/include/linux/linkage.h b/include/linux/linkage.h
index 0592936344c4..2119610b24f8 100644
--- a/include/linux/linkage.h
+++ b/include/linux/linkage.h
@@ -17,8 +17,24 @@
17# define asmregparm 17# define asmregparm
18#endif 18#endif
19 19
20#ifndef prevent_tail_call 20/*
21# define prevent_tail_call(ret) do { } while (0) 21 * This is used by architectures to keep arguments on the stack
22 * untouched by the compiler by keeping them live until the end.
23 * The argument stack may be owned by the assembly-language
24 * caller, not the callee, and gcc doesn't always understand
25 * that.
26 *
27 * We have the return value, and a maximum of six arguments.
28 *
29 * This should always be followed by a "return ret" for the
30 * protection to work (ie no more work that the compiler might
31 * end up needing stack temporaries for).
32 */
33/* Assembly files may be compiled with -traditional .. */
34#ifndef __ASSEMBLY__
35#ifndef asmlinkage_protect
36# define asmlinkage_protect(n, ret, args...) do { } while (0)
37#endif
22#endif 38#endif
23 39
24#ifndef __ALIGN 40#ifndef __ALIGN
diff --git a/include/linux/mount.h b/include/linux/mount.h
index 6d3047d8c91c..5ee2df217cdf 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -61,6 +61,7 @@ struct vfsmount {
61 atomic_t mnt_count; 61 atomic_t mnt_count;
62 int mnt_expiry_mark; /* true if marked for expiry */ 62 int mnt_expiry_mark; /* true if marked for expiry */
63 int mnt_pinned; 63 int mnt_pinned;
64 int mnt_ghosts;
64}; 65};
65 66
66static inline struct vfsmount *mntget(struct vfsmount *mnt) 67static inline struct vfsmount *mntget(struct vfsmount *mnt)
@@ -98,7 +99,6 @@ extern int do_add_mount(struct vfsmount *newmnt, struct nameidata *nd,
98 int mnt_flags, struct list_head *fslist); 99 int mnt_flags, struct list_head *fslist);
99 100
100extern void mark_mounts_for_expiry(struct list_head *mounts); 101extern void mark_mounts_for_expiry(struct list_head *mounts);
101extern void shrink_submounts(struct vfsmount *mountpoint, struct list_head *mounts);
102 102
103extern spinlock_t vfsmount_lock; 103extern spinlock_t vfsmount_lock;
104extern dev_t name_to_dev_t(char *name); 104extern dev_t name_to_dev_t(char *name);
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index a2f003239c85..ee81906b5164 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -383,9 +383,11 @@ static inline void __napi_complete(struct napi_struct *n)
383 383
384static inline void napi_complete(struct napi_struct *n) 384static inline void napi_complete(struct napi_struct *n)
385{ 385{
386 local_irq_disable(); 386 unsigned long flags;
387
388 local_irq_save(flags);
387 __napi_complete(n); 389 __napi_complete(n);
388 local_irq_enable(); 390 local_irq_restore(flags);
389} 391}
390 392
391/** 393/**
@@ -1072,12 +1074,14 @@ static inline int netif_is_multiqueue(const struct net_device *dev)
1072} 1074}
1073 1075
1074/* Use this variant when it is known for sure that it 1076/* Use this variant when it is known for sure that it
1075 * is executing from interrupt context. 1077 * is executing from hardware interrupt context or with hardware interrupts
1078 * disabled.
1076 */ 1079 */
1077extern void dev_kfree_skb_irq(struct sk_buff *skb); 1080extern void dev_kfree_skb_irq(struct sk_buff *skb);
1078 1081
1079/* Use this variant in places where it could be invoked 1082/* Use this variant in places where it could be invoked
1080 * either from interrupt or non-interrupt context. 1083 * from either hardware interrupt or other context, with hardware interrupts
1084 * either disabled or enabled.
1081 */ 1085 */
1082extern void dev_kfree_skb_any(struct sk_buff *skb); 1086extern void dev_kfree_skb_any(struct sk_buff *skb);
1083 1087
diff --git a/include/linux/pnp.h b/include/linux/pnp.h
index 29dd55838e84..b2f05c230f4b 100644
--- a/include/linux/pnp.h
+++ b/include/linux/pnp.h
@@ -175,7 +175,7 @@ static inline void pnp_set_card_drvdata(struct pnp_card_link *pcard, void *data)
175struct pnp_dev { 175struct pnp_dev {
176 struct device dev; /* Driver Model device interface */ 176 struct device dev; /* Driver Model device interface */
177 u64 dma_mask; 177 u64 dma_mask;
178 unsigned char number; /* used as an index, must be unique */ 178 unsigned int number; /* used as an index, must be unique */
179 int status; 179 int status;
180 180
181 struct list_head global_list; /* node in global list of devices */ 181 struct list_head global_list; /* node in global list of devices */
diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index 576a5f77d3bd..1129ee0a7180 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -341,6 +341,9 @@ static inline void double_spin_unlock(spinlock_t *l1, spinlock_t *l2,
341 * atomic_dec_and_lock - lock on reaching reference count zero 341 * atomic_dec_and_lock - lock on reaching reference count zero
342 * @atomic: the atomic counter 342 * @atomic: the atomic counter
343 * @lock: the spinlock in question 343 * @lock: the spinlock in question
344 *
345 * Decrements @atomic by 1. If the result is 0, returns true and locks
346 * @lock. Returns false for all other cases.
344 */ 347 */
345extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock); 348extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);
346#define atomic_dec_and_lock(atomic, lock) \ 349#define atomic_dec_and_lock(atomic, lock) \
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 12c18ac1b973..e7d10845b3c1 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -41,6 +41,8 @@ struct virtqueue
41 * Returns NULL or the "data" token handed to add_buf. 41 * Returns NULL or the "data" token handed to add_buf.
42 * @disable_cb: disable callbacks 42 * @disable_cb: disable callbacks
43 * vq: the struct virtqueue we're talking about. 43 * vq: the struct virtqueue we're talking about.
44 * Note that this is not necessarily synchronous, hence unreliable and only
45 * useful as an optimization.
44 * @enable_cb: restart callbacks after disable_cb. 46 * @enable_cb: restart callbacks after disable_cb.
45 * vq: the struct virtqueue we're talking about. 47 * vq: the struct virtqueue we're talking about.
46 * This re-enables callbacks; it returns "false" if there are pending 48 * This re-enables callbacks; it returns "false" if there are pending
@@ -48,7 +50,8 @@ struct virtqueue
48 * checking for more work, and enabling callbacks. 50 * checking for more work, and enabling callbacks.
49 * 51 *
50 * Locking rules are straightforward: the driver is responsible for 52 * Locking rules are straightforward: the driver is responsible for
51 * locking. No two operations may be invoked simultaneously. 53 * locking. No two operations may be invoked simultaneously, with the exception
54 * of @disable_cb.
52 * 55 *
53 * All operations can be called in any context. 56 * All operations can be called in any context.
54 */ 57 */
diff --git a/include/net/llc.h b/include/net/llc.h
index f5024583fc8b..7940da1606e7 100644
--- a/include/net/llc.h
+++ b/include/net/llc.h
@@ -65,7 +65,6 @@ struct llc_sap {
65 65
66extern struct list_head llc_sap_list; 66extern struct list_head llc_sap_list;
67extern rwlock_t llc_sap_list_lock; 67extern rwlock_t llc_sap_list_lock;
68extern unsigned char llc_station_mac_sa[ETH_ALEN];
69 68
70extern int llc_rcv(struct sk_buff *skb, struct net_device *dev, 69extern int llc_rcv(struct sk_buff *skb, struct net_device *dev,
71 struct packet_type *pt, struct net_device *orig_dev); 70 struct packet_type *pt, struct net_device *orig_dev);
diff --git a/include/net/llc_pdu.h b/include/net/llc_pdu.h
index 4a8f58b17e43..75b8e2968c9b 100644
--- a/include/net/llc_pdu.h
+++ b/include/net/llc_pdu.h
@@ -381,7 +381,7 @@ static inline void llc_pdu_init_as_xid_cmd(struct sk_buff *skb,
381 xid_info->fmt_id = LLC_XID_FMT_ID; /* 0x81 */ 381 xid_info->fmt_id = LLC_XID_FMT_ID; /* 0x81 */
382 xid_info->type = svcs_supported; 382 xid_info->type = svcs_supported;
383 xid_info->rw = rx_window << 1; /* size of receive window */ 383 xid_info->rw = rx_window << 1; /* size of receive window */
384 skb_put(skb, 3); 384 skb_put(skb, sizeof(struct llc_xid_info));
385} 385}
386 386
387/** 387/**
@@ -406,7 +406,7 @@ static inline void llc_pdu_init_as_xid_rsp(struct sk_buff *skb,
406 xid_info->fmt_id = LLC_XID_FMT_ID; 406 xid_info->fmt_id = LLC_XID_FMT_ID;
407 xid_info->type = svcs_supported; 407 xid_info->type = svcs_supported;
408 xid_info->rw = rx_window << 1; 408 xid_info->rw = rx_window << 1;
409 skb_put(skb, 3); 409 skb_put(skb, sizeof(struct llc_xid_info));
410} 410}
411 411
412/* LLC Type 2 FRMR response information field format */ 412/* LLC Type 2 FRMR response information field format */
diff --git a/include/net/llc_sap.h b/include/net/llc_sap.h
index 2c56dbece729..ed25bec2f648 100644
--- a/include/net/llc_sap.h
+++ b/include/net/llc_sap.h
@@ -1,5 +1,8 @@
1#ifndef LLC_SAP_H 1#ifndef LLC_SAP_H
2#define LLC_SAP_H 2#define LLC_SAP_H
3
4#include <asm/types.h>
5
3/* 6/*
4 * Copyright (c) 1997 by Procom Technology,Inc. 7 * Copyright (c) 1997 by Procom Technology,Inc.
5 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br> 8 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
@@ -19,8 +22,8 @@ struct sock;
19extern void llc_sap_rtn_pdu(struct llc_sap *sap, struct sk_buff *skb); 22extern void llc_sap_rtn_pdu(struct llc_sap *sap, struct sk_buff *skb);
20extern void llc_save_primitive(struct sock *sk, struct sk_buff* skb, 23extern void llc_save_primitive(struct sock *sk, struct sk_buff* skb,
21 unsigned char prim); 24 unsigned char prim);
22extern struct sk_buff *llc_alloc_frame(struct sock *sk, 25extern struct sk_buff *llc_alloc_frame(struct sock *sk, struct net_device *dev,
23 struct net_device *dev); 26 u8 type, u32 data_size);
24 27
25extern void llc_build_and_send_test_pkt(struct llc_sap *sap, 28extern void llc_build_and_send_test_pkt(struct llc_sap *sap,
26 struct sk_buff *skb, 29 struct sk_buff *skb,
diff --git a/include/net/neighbour.h b/include/net/neighbour.h
index ebbfb509822e..64a5f0120b52 100644
--- a/include/net/neighbour.h
+++ b/include/net/neighbour.h
@@ -218,6 +218,10 @@ extern unsigned long neigh_rand_reach_time(unsigned long base);
218extern void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p, 218extern void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
219 struct sk_buff *skb); 219 struct sk_buff *skb);
220extern struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net, const void *key, struct net_device *dev, int creat); 220extern struct pneigh_entry *pneigh_lookup(struct neigh_table *tbl, struct net *net, const void *key, struct net_device *dev, int creat);
221extern struct pneigh_entry *__pneigh_lookup(struct neigh_table *tbl,
222 struct net *net,
223 const void *key,
224 struct net_device *dev);
221extern int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key, struct net_device *dev); 225extern int pneigh_delete(struct neigh_table *tbl, struct net *net, const void *key, struct net_device *dev);
222 226
223extern void neigh_app_ns(struct neighbour *n); 227extern void neigh_app_ns(struct neighbour *n);
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 7de4ea3a04d9..4fd3eb2f8ec2 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -752,6 +752,8 @@ static inline unsigned int tcp_packets_in_flight(const struct tcp_sock *tp)
752 return tp->packets_out - tcp_left_out(tp) + tp->retrans_out; 752 return tp->packets_out - tcp_left_out(tp) + tp->retrans_out;
753} 753}
754 754
755extern int tcp_limit_reno_sacked(struct tcp_sock *tp);
756
755/* If cwnd > ssthresh, we may raise ssthresh to be half-way to cwnd. 757/* If cwnd > ssthresh, we may raise ssthresh to be half-way to cwnd.
756 * The exception is rate halving phase, when cwnd is decreasing towards 758 * The exception is rate halving phase, when cwnd is decreasing towards
757 * ssthresh. 759 * ssthresh.
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 619c53bc3cd2..0d255ae008b6 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -204,6 +204,7 @@ struct xfrm_state
204 * transformer. */ 204 * transformer. */
205 const struct xfrm_type *type; 205 const struct xfrm_type *type;
206 struct xfrm_mode *inner_mode; 206 struct xfrm_mode *inner_mode;
207 struct xfrm_mode *inner_mode_iaf;
207 struct xfrm_mode *outer_mode; 208 struct xfrm_mode *outer_mode;
208 209
209 /* Security context */ 210 /* Security context */
@@ -387,6 +388,27 @@ enum {
387extern int xfrm_register_mode(struct xfrm_mode *mode, int family); 388extern int xfrm_register_mode(struct xfrm_mode *mode, int family);
388extern int xfrm_unregister_mode(struct xfrm_mode *mode, int family); 389extern int xfrm_unregister_mode(struct xfrm_mode *mode, int family);
389 390
391static inline int xfrm_af2proto(unsigned int family)
392{
393 switch(family) {
394 case AF_INET:
395 return IPPROTO_IPIP;
396 case AF_INET6:
397 return IPPROTO_IPV6;
398 default:
399 return 0;
400 }
401}
402
403static inline struct xfrm_mode *xfrm_ip2inner_mode(struct xfrm_state *x, int ipproto)
404{
405 if ((ipproto == IPPROTO_IPIP && x->props.family == AF_INET) ||
406 (ipproto == IPPROTO_IPV6 && x->props.family == AF_INET6))
407 return x->inner_mode;
408 else
409 return x->inner_mode_iaf;
410}
411
390struct xfrm_tmpl 412struct xfrm_tmpl
391{ 413{
392/* id in template is interpreted as: 414/* id in template is interpreted as:
@@ -530,6 +552,9 @@ struct xfrm_mode_skb_cb {
530 __be16 id; 552 __be16 id;
531 __be16 frag_off; 553 __be16 frag_off;
532 554
555 /* IP header length (excluding options or extension headers). */
556 u8 ihl;
557
533 /* TOS for IPv4, class for IPv6. */ 558 /* TOS for IPv4, class for IPv6. */
534 u8 tos; 559 u8 tos;
535 560
@@ -539,6 +564,9 @@ struct xfrm_mode_skb_cb {
539 /* Protocol for IPv4, NH for IPv6. */ 564 /* Protocol for IPv4, NH for IPv6. */
540 u8 protocol; 565 u8 protocol;
541 566
567 /* Option length for IPv4, zero for IPv6. */
568 u8 optlen;
569
542 /* Used by IPv6 only, zero for IPv4. */ 570 /* Used by IPv6 only, zero for IPv4. */
543 u8 flow_lbl[3]; 571 u8 flow_lbl[3];
544}; 572};
@@ -1253,6 +1281,7 @@ extern int xfrm_input(struct sk_buff *skb, int nexthdr, __be32 spi,
1253extern int xfrm_input_resume(struct sk_buff *skb, int nexthdr); 1281extern int xfrm_input_resume(struct sk_buff *skb, int nexthdr);
1254extern int xfrm_output_resume(struct sk_buff *skb, int err); 1282extern int xfrm_output_resume(struct sk_buff *skb, int err);
1255extern int xfrm_output(struct sk_buff *skb); 1283extern int xfrm_output(struct sk_buff *skb);
1284extern int xfrm_inner_extract_output(struct xfrm_state *x, struct sk_buff *skb);
1256extern int xfrm4_extract_header(struct sk_buff *skb); 1285extern int xfrm4_extract_header(struct sk_buff *skb);
1257extern int xfrm4_extract_input(struct xfrm_state *x, struct sk_buff *skb); 1286extern int xfrm4_extract_input(struct xfrm_state *x, struct sk_buff *skb);
1258extern int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, 1287extern int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
lass="hl com"> */ int tty_prepare_flip_string_flags(struct tty_struct *tty, unsigned char **chars, char **flags, size_t size) { int space = tty_buffer_request_room(tty, size); if (likely(space)) { struct tty_buffer *tb = tty->buf.tail; *chars = tb->char_buf_ptr + tb->used; *flags = tb->flag_buf_ptr + tb->used; tb->used += space; } return space; } EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags); /** * tty_set_termios_ldisc - set ldisc field * @tty: tty structure * @num: line discipline number * * This is probably overkill for real world processors but * they are not on hot paths so a little discipline won't do * any harm. * * Locking: takes termios_mutex */ static void tty_set_termios_ldisc(struct tty_struct *tty, int num) { mutex_lock(&tty->termios_mutex); tty->termios->c_line = num; mutex_unlock(&tty->termios_mutex); } /* * This guards the refcounted line discipline lists. The lock * must be taken with irqs off because there are hangup path * callers who will do ldisc lookups and cannot sleep. */ static DEFINE_SPINLOCK(tty_ldisc_lock); static DECLARE_WAIT_QUEUE_HEAD(tty_ldisc_wait); /* Line disc dispatch table */ static struct tty_ldisc tty_ldiscs[NR_LDISCS]; /** * tty_register_ldisc - install a line discipline * @disc: ldisc number * @new_ldisc: pointer to the ldisc object * * Installs a new line discipline into the kernel. The discipline * is set up as unreferenced and then made available to the kernel * from this point onwards. * * Locking: * takes tty_ldisc_lock to guard against ldisc races */ int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc) { unsigned long flags; int ret = 0; if (disc < N_TTY || disc >= NR_LDISCS) return -EINVAL; spin_lock_irqsave(&tty_ldisc_lock, flags); tty_ldiscs[disc] = *new_ldisc; tty_ldiscs[disc].num = disc; tty_ldiscs[disc].flags |= LDISC_FLAG_DEFINED; tty_ldiscs[disc].refcount = 0; spin_unlock_irqrestore(&tty_ldisc_lock, flags); return ret; } EXPORT_SYMBOL(tty_register_ldisc); /** * tty_unregister_ldisc - unload a line discipline * @disc: ldisc number * @new_ldisc: pointer to the ldisc object * * Remove a line discipline from the kernel providing it is not * currently in use. * * Locking: * takes tty_ldisc_lock to guard against ldisc races */ int tty_unregister_ldisc(int disc) { unsigned long flags; int ret = 0; if (disc < N_TTY || disc >= NR_LDISCS) return -EINVAL; spin_lock_irqsave(&tty_ldisc_lock, flags); if (tty_ldiscs[disc].refcount) ret = -EBUSY; else tty_ldiscs[disc].flags &= ~LDISC_FLAG_DEFINED; spin_unlock_irqrestore(&tty_ldisc_lock, flags); return ret; } EXPORT_SYMBOL(tty_unregister_ldisc); /** * tty_ldisc_get - take a reference to an ldisc * @disc: ldisc number * * Takes a reference to a line discipline. Deals with refcounts and * module locking counts. Returns NULL if the discipline is not available. * Returns a pointer to the discipline and bumps the ref count if it is * available * * Locking: * takes tty_ldisc_lock to guard against ldisc races */ struct tty_ldisc *tty_ldisc_get(int disc) { unsigned long flags; struct tty_ldisc *ld; if (disc < N_TTY || disc >= NR_LDISCS) return NULL; spin_lock_irqsave(&tty_ldisc_lock, flags); ld = &tty_ldiscs[disc]; /* Check the entry is defined */ if (ld->flags & LDISC_FLAG_DEFINED) { /* If the module is being unloaded we can't use it */ if (!try_module_get(ld->owner)) ld = NULL; else /* lock it */ ld->refcount++; } else ld = NULL; spin_unlock_irqrestore(&tty_ldisc_lock, flags); return ld; } EXPORT_SYMBOL_GPL(tty_ldisc_get); /** * tty_ldisc_put - drop ldisc reference * @disc: ldisc number * * Drop a reference to a line discipline. Manage refcounts and * module usage counts * * Locking: * takes tty_ldisc_lock to guard against ldisc races */ void tty_ldisc_put(int disc) { struct tty_ldisc *ld; unsigned long flags; BUG_ON(disc < N_TTY || disc >= NR_LDISCS); spin_lock_irqsave(&tty_ldisc_lock, flags); ld = &tty_ldiscs[disc]; BUG_ON(ld->refcount == 0); ld->refcount--; module_put(ld->owner); spin_unlock_irqrestore(&tty_ldisc_lock, flags); } EXPORT_SYMBOL_GPL(tty_ldisc_put); /** * tty_ldisc_assign - set ldisc on a tty * @tty: tty to assign * @ld: line discipline * * Install an instance of a line discipline into a tty structure. The * ldisc must have a reference count above zero to ensure it remains/ * The tty instance refcount starts at zero. * * Locking: * Caller must hold references */ static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) { tty->ldisc = *ld; tty->ldisc.refcount = 0; } /** * tty_ldisc_try - internal helper * @tty: the tty * * Make a single attempt to grab and bump the refcount on * the tty ldisc. Return 0 on failure or 1 on success. This is * used to implement both the waiting and non waiting versions * of tty_ldisc_ref * * Locking: takes tty_ldisc_lock */ static int tty_ldisc_try(struct tty_struct *tty) { unsigned long flags; struct tty_ldisc *ld; int ret = 0; spin_lock_irqsave(&tty_ldisc_lock, flags); ld = &tty->ldisc; if (test_bit(TTY_LDISC, &tty->flags)) { ld->refcount++; ret = 1; } spin_unlock_irqrestore(&tty_ldisc_lock, flags); return ret; } /** * tty_ldisc_ref_wait - wait for the tty ldisc * @tty: tty device * * Dereference the line discipline for the terminal and take a * reference to it. If the line discipline is in flux then * wait patiently until it changes. * * Note: Must not be called from an IRQ/timer context. The caller * must also be careful not to hold other locks that will deadlock * against a discipline change, such as an existing ldisc reference * (which we check for) * * Locking: call functions take tty_ldisc_lock */ struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty) { /* wait_event is a macro */ wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); if (tty->ldisc.refcount == 0) printk(KERN_ERR "tty_ldisc_ref_wait\n"); return &tty->ldisc; } EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); /** * tty_ldisc_ref - get the tty ldisc * @tty: tty device * * Dereference the line discipline for the terminal and take a * reference to it. If the line discipline is in flux then * return NULL. Can be called from IRQ and timer functions. * * Locking: called functions take tty_ldisc_lock */ struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) { if (tty_ldisc_try(tty)) return &tty->ldisc; return NULL; } EXPORT_SYMBOL_GPL(tty_ldisc_ref); /** * tty_ldisc_deref - free a tty ldisc reference * @ld: reference to free up * * Undoes the effect of tty_ldisc_ref or tty_ldisc_ref_wait. May * be called in IRQ context. * * Locking: takes tty_ldisc_lock */ void tty_ldisc_deref(struct tty_ldisc *ld) { unsigned long flags; BUG_ON(ld == NULL); spin_lock_irqsave(&tty_ldisc_lock, flags); if (ld->refcount == 0) printk(KERN_ERR "tty_ldisc_deref: no references.\n"); else ld->refcount--; if (ld->refcount == 0) wake_up(&tty_ldisc_wait); spin_unlock_irqrestore(&tty_ldisc_lock, flags); } EXPORT_SYMBOL_GPL(tty_ldisc_deref); /** * tty_ldisc_enable - allow ldisc use * @tty: terminal to activate ldisc on * * Set the TTY_LDISC flag when the line discipline can be called * again. Do necessary wakeups for existing sleepers. * * Note: nobody should set this bit except via this function. Clearing * directly is allowed. */ static void tty_ldisc_enable(struct tty_struct *tty) { set_bit(TTY_LDISC, &tty->flags); wake_up(&tty_ldisc_wait); } /** * tty_set_ldisc - set line discipline * @tty: the terminal to set * @ldisc: the line discipline * * Set the discipline of a tty line. Must be called from a process * context. * * Locking: takes tty_ldisc_lock. * called functions take termios_mutex */ static int tty_set_ldisc(struct tty_struct *tty, int ldisc) { int retval = 0; struct tty_ldisc o_ldisc; char buf[64]; int work; unsigned long flags; struct tty_ldisc *ld; struct tty_struct *o_tty; if ((ldisc < N_TTY) || (ldisc >= NR_LDISCS)) return -EINVAL; restart: ld = tty_ldisc_get(ldisc); /* Eduardo Blanco <ejbs@cs.cs.com.uy> */ /* Cyrus Durgin <cider@speakeasy.org> */ if (ld == NULL) { request_module("tty-ldisc-%d", ldisc); ld = tty_ldisc_get(ldisc); } if (ld == NULL) return -EINVAL; /* * Problem: What do we do if this blocks ? */ tty_wait_until_sent(tty, 0); if (tty->ldisc.num == ldisc) { tty_ldisc_put(ldisc); return 0; } /* * No more input please, we are switching. The new ldisc * will update this value in the ldisc open function */ tty->receive_room = 0; o_ldisc = tty->ldisc; o_tty = tty->link; /* * Make sure we don't change while someone holds a * reference to the line discipline. The TTY_LDISC bit * prevents anyone taking a reference once it is clear. * We need the lock to avoid racing reference takers. */ spin_lock_irqsave(&tty_ldisc_lock, flags); if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) { if (tty->ldisc.refcount) { /* Free the new ldisc we grabbed. Must drop the lock first. */ spin_unlock_irqrestore(&tty_ldisc_lock, flags); tty_ldisc_put(ldisc); /* * There are several reasons we may be busy, including * random momentary I/O traffic. We must therefore * retry. We could distinguish between blocking ops * and retries if we made tty_ldisc_wait() smarter. * That is up for discussion. */ if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0) return -ERESTARTSYS; goto restart; } if (o_tty && o_tty->ldisc.refcount) { spin_unlock_irqrestore(&tty_ldisc_lock, flags); tty_ldisc_put(ldisc); if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0) return -ERESTARTSYS; goto restart; } } /* * If the TTY_LDISC bit is set, then we are racing against * another ldisc change */ if (!test_bit(TTY_LDISC, &tty->flags)) { spin_unlock_irqrestore(&tty_ldisc_lock, flags); tty_ldisc_put(ldisc); ld = tty_ldisc_ref_wait(tty); tty_ldisc_deref(ld); goto restart; } clear_bit(TTY_LDISC, &tty->flags); if (o_tty) clear_bit(TTY_LDISC, &o_tty->flags); spin_unlock_irqrestore(&tty_ldisc_lock, flags); /* * From this point on we know nobody has an ldisc * usage reference, nor can they obtain one until * we say so later on. */ work = cancel_delayed_work(&tty->buf.work); /* * Wait for ->hangup_work and ->buf.work handlers to terminate */ flush_scheduled_work(); /* Shutdown the current discipline. */ if (tty->ldisc.close) (tty->ldisc.close)(tty); /* Now set up the new line discipline. */ tty_ldisc_assign(tty, ld); tty_set_termios_ldisc(tty, ldisc); if (tty->ldisc.open) retval = (tty->ldisc.open)(tty); if (retval < 0) { tty_ldisc_put(ldisc); /* There is an outstanding reference here so this is safe */ tty_ldisc_assign(tty, tty_ldisc_get(o_ldisc.num)); tty_set_termios_ldisc(tty, tty->ldisc.num); if (tty->ldisc.open && (tty->ldisc.open(tty) < 0)) { tty_ldisc_put(o_ldisc.num); /* This driver is always present */ tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); tty_set_termios_ldisc(tty, N_TTY); if (tty->ldisc.open) { int r = tty->ldisc.open(tty); if (r < 0) panic("Couldn't open N_TTY ldisc for " "%s --- error %d.", tty_name(tty, buf), r); } } } /* At this point we hold a reference to the new ldisc and a a reference to the old ldisc. If we ended up flipping back to the existing ldisc we have two references to it */ if (tty->ldisc.num != o_ldisc.num && tty->driver->set_ldisc) tty->driver->set_ldisc(tty); tty_ldisc_put(o_ldisc.num); /* * Allow ldisc referencing to occur as soon as the driver * ldisc callback completes. */ tty_ldisc_enable(tty); if (o_tty) tty_ldisc_enable(o_tty); /* Restart it in case no characters kick it off. Safe if already running */ if (work) schedule_delayed_work(&tty->buf.work, 1); return retval; } /** * get_tty_driver - find device of a tty * @dev_t: device identifier * @index: returns the index of the tty * * This routine returns a tty driver structure, given a device number * and also passes back the index number. * * Locking: caller must hold tty_mutex */ static struct tty_driver *get_tty_driver(dev_t device, int *index) { struct tty_driver *p; list_for_each_entry(p, &tty_drivers, tty_drivers) { dev_t base = MKDEV(p->major, p->minor_start); if (device < base || device >= base + p->num) continue; *index = device - base; return p; } return NULL; } #ifdef CONFIG_CONSOLE_POLL /** * tty_find_polling_driver - find device of a polled tty * @name: name string to match * @line: pointer to resulting tty line nr * * This routine returns a tty driver structure, given a name * and the condition that the tty driver is capable of polled * operation. */ struct tty_driver *tty_find_polling_driver(char *name, int *line) { struct tty_driver *p, *res = NULL; int tty_line = 0; char *str; mutex_lock(&tty_mutex); /* Search through the tty devices to look for a match */ list_for_each_entry(p, &tty_drivers, tty_drivers) { str = name + strlen(p->name); tty_line = simple_strtoul(str, &str, 10); if (*str == ',') str++; if (*str == '\0') str = 0; if (tty_line >= 0 && tty_line <= p->num && p->poll_init && !p->poll_init(p, tty_line, str)) { res = p; *line = tty_line; break; } } mutex_unlock(&tty_mutex); return res; } EXPORT_SYMBOL_GPL(tty_find_polling_driver); #endif /** * tty_check_change - check for POSIX terminal changes * @tty: tty to check * * If we try to write to, or set the state of, a terminal and we're * not in the foreground, send a SIGTTOU. If the signal is blocked or * ignored, go ahead and perform the operation. (POSIX 7.2) * * Locking: none */ int tty_check_change(struct tty_struct *tty) { if (current->signal->tty != tty) return 0; if (!tty->pgrp) { printk(KERN_WARNING "tty_check_change: tty->pgrp == NULL!\n"); return 0; } if (task_pgrp(current) == tty->pgrp) return 0; if (is_ignored(SIGTTOU)) return 0; if (is_current_pgrp_orphaned()) return -EIO; kill_pgrp(task_pgrp(current), SIGTTOU, 1); set_thread_flag(TIF_SIGPENDING); return -ERESTARTSYS; } EXPORT_SYMBOL(tty_check_change); static ssize_t hung_up_tty_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { return 0; } static ssize_t hung_up_tty_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { return -EIO; } /* No kernel lock held - none needed ;) */ static unsigned int hung_up_tty_poll(struct file *filp, poll_table *wait) { return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM; } static int hung_up_tty_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { return cmd == TIOCSPGRP ? -ENOTTY : -EIO; } static long hung_up_tty_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { return cmd == TIOCSPGRP ? -ENOTTY : -EIO; } static const struct file_operations tty_fops = { .llseek = no_llseek, .read = tty_read, .write = tty_write, .poll = tty_poll, .ioctl = tty_ioctl, .compat_ioctl = tty_compat_ioctl, .open = tty_open, .release = tty_release, .fasync = tty_fasync, }; #ifdef CONFIG_UNIX98_PTYS static const struct file_operations ptmx_fops = { .llseek = no_llseek, .read = tty_read, .write = tty_write, .poll = tty_poll, .ioctl = tty_ioctl, .compat_ioctl = tty_compat_ioctl, .open = ptmx_open, .release = tty_release, .fasync = tty_fasync, }; #endif static const struct file_operations console_fops = { .llseek = no_llseek, .read = tty_read, .write = redirected_tty_write, .poll = tty_poll, .ioctl = tty_ioctl, .compat_ioctl = tty_compat_ioctl, .open = tty_open, .release = tty_release, .fasync = tty_fasync, }; static const struct file_operations hung_up_tty_fops = { .llseek = no_llseek, .read = hung_up_tty_read, .write = hung_up_tty_write, .poll = hung_up_tty_poll, .ioctl = hung_up_tty_ioctl, .compat_ioctl = hung_up_tty_compat_ioctl, .release = tty_release, }; static DEFINE_SPINLOCK(redirect_lock); static struct file *redirect; /** * tty_wakeup - request more data * @tty: terminal * * Internal and external helper for wakeups of tty. This function * informs the line discipline if present that the driver is ready * to receive more output data. */ void tty_wakeup(struct tty_struct *tty) { struct tty_ldisc *ld; if (test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) { ld = tty_ldisc_ref(tty); if (ld) { if (ld->write_wakeup) ld->write_wakeup(tty); tty_ldisc_deref(ld); } } wake_up_interruptible(&tty->write_wait); } EXPORT_SYMBOL_GPL(tty_wakeup); /** * tty_ldisc_flush - flush line discipline queue * @tty: tty * * Flush the line discipline queue (if any) for this tty. If there * is no line discipline active this is a no-op. */ void tty_ldisc_flush(struct tty_struct *tty) { struct tty_ldisc *ld = tty_ldisc_ref(tty); if (ld) { if (ld->flush_buffer) ld->flush_buffer(tty); tty_ldisc_deref(ld); } tty_buffer_flush(tty); } EXPORT_SYMBOL_GPL(tty_ldisc_flush); /** * tty_reset_termios - reset terminal state * @tty: tty to reset * * Restore a terminal to the driver default state */ static void tty_reset_termios(struct tty_struct *tty) { mutex_lock(&tty->termios_mutex); *tty->termios = tty->driver->init_termios; tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios); tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios); mutex_unlock(&tty->termios_mutex); } /** * do_tty_hangup - actual handler for hangup events * @work: tty device * * This can be called by the "eventd" kernel thread. That is process * synchronous but doesn't hold any locks, so we need to make sure we * have the appropriate locks for what we're doing. * * The hangup event clears any pending redirections onto the hung up * device. It ensures future writes will error and it does the needed * line discipline hangup and signal delivery. The tty object itself * remains intact. * * Locking: * BKL * redirect lock for undoing redirection * file list lock for manipulating list of ttys * tty_ldisc_lock from called functions * termios_mutex resetting termios data * tasklist_lock to walk task list for hangup event * ->siglock to protect ->signal/->sighand */ static void do_tty_hangup(struct work_struct *work) { struct tty_struct *tty = container_of(work, struct tty_struct, hangup_work); struct file *cons_filp = NULL; struct file *filp, *f = NULL; struct task_struct *p; struct tty_ldisc *ld; int closecount = 0, n; if (!tty) return; /* inuse_filps is protected by the single kernel lock */ lock_kernel(); spin_lock(&redirect_lock); if (redirect && redirect->private_data == tty) { f = redirect; redirect = NULL; } spin_unlock(&redirect_lock); check_tty_count(tty, "do_tty_hangup"); file_list_lock(); /* This breaks for file handles being sent over AF_UNIX sockets ? */ list_for_each_entry(filp, &tty->tty_files, f_u.fu_list) { if (filp->f_op->write == redirected_tty_write) cons_filp = filp; if (filp->f_op->write != tty_write) continue; closecount++; tty_fasync(-1, filp, 0); /* can't block */ filp->f_op = &hung_up_tty_fops; } file_list_unlock(); /* * FIXME! What are the locking issues here? This may me overdoing * things... This question is especially important now that we've * removed the irqlock. */ ld = tty_ldisc_ref(tty); if (ld != NULL) { /* We may have no line discipline at this point */ if (ld->flush_buffer) ld->flush_buffer(tty); if (tty->driver->flush_buffer) tty->driver->flush_buffer(tty); if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) && ld->write_wakeup) ld->write_wakeup(tty); if (ld->hangup) ld->hangup(tty); } /* * FIXME: Once we trust the LDISC code better we can wait here for * ldisc completion and fix the driver call race */ wake_up_interruptible(&tty->write_wait); wake_up_interruptible(&tty->read_wait); /* * Shutdown the current line discipline, and reset it to * N_TTY. */ if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) tty_reset_termios(tty); /* Defer ldisc switch */ /* tty_deferred_ldisc_switch(N_TTY); This should get done automatically when the port closes and tty_release is called */ read_lock(&tasklist_lock); if (tty->session) { do_each_pid_task(tty->session, PIDTYPE_SID, p) { spin_lock_irq(&p->sighand->siglock); if (p->signal->tty == tty) p->signal->tty = NULL; if (!p->signal->leader) { spin_unlock_irq(&p->sighand->siglock); continue; } __group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p); __group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p); put_pid(p->signal->tty_old_pgrp); /* A noop */ if (tty->pgrp) p->signal->tty_old_pgrp = get_pid(tty->pgrp); spin_unlock_irq(&p->sighand->siglock); } while_each_pid_task(tty->session, PIDTYPE_SID, p); } read_unlock(&tasklist_lock); tty->flags = 0; put_pid(tty->session); put_pid(tty->pgrp); tty->session = NULL; tty->pgrp = NULL; tty->ctrl_status = 0; /* * If one of the devices matches a console pointer, we * cannot just call hangup() because that will cause * tty->count and state->count to go out of sync. * So we just call close() the right number of times. */ if (cons_filp) { if (tty->driver->close) for (n = 0; n < closecount; n++) tty->driver->close(tty, cons_filp); } else if (tty->driver->hangup) (tty->driver->hangup)(tty); /* * We don't want to have driver/ldisc interactions beyond * the ones we did here. The driver layer expects no * calls after ->hangup() from the ldisc side. However we * can't yet guarantee all that. */ set_bit(TTY_HUPPED, &tty->flags); if (ld) { tty_ldisc_enable(tty); tty_ldisc_deref(ld); } unlock_kernel(); if (f) fput(f); } /** * tty_hangup - trigger a hangup event * @tty: tty to hangup * * A carrier loss (virtual or otherwise) has occurred on this like * schedule a hangup sequence to run after this event. */ void tty_hangup(struct tty_struct *tty) { #ifdef TTY_DEBUG_HANGUP char buf[64]; printk(KERN_DEBUG "%s hangup...\n", tty_name(tty, buf)); #endif schedule_work(&tty->hangup_work); } EXPORT_SYMBOL(tty_hangup); /** * tty_vhangup - process vhangup * @tty: tty to hangup * * The user has asked via system call for the terminal to be hung up. * We do this synchronously so that when the syscall returns the process * is complete. That guarantee is necessary for security reasons. */ void tty_vhangup(struct tty_struct *tty) { #ifdef TTY_DEBUG_HANGUP char buf[64]; printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf)); #endif do_tty_hangup(&tty->hangup_work); } EXPORT_SYMBOL(tty_vhangup); /** * tty_hung_up_p - was tty hung up * @filp: file pointer of tty * * Return true if the tty has been subject to a vhangup or a carrier * loss */ int tty_hung_up_p(struct file *filp) { return (filp->f_op == &hung_up_tty_fops); } EXPORT_SYMBOL(tty_hung_up_p); /** * is_tty - checker whether file is a TTY * @filp: file handle that may be a tty * * Check if the file handle is a tty handle. */ int is_tty(struct file *filp) { return filp->f_op->read == tty_read || filp->f_op->read == hung_up_tty_read; } static void session_clear_tty(struct pid *session) { struct task_struct *p; do_each_pid_task(session, PIDTYPE_SID, p) { proc_clear_tty(p); } while_each_pid_task(session, PIDTYPE_SID, p); } /** * disassociate_ctty - disconnect controlling tty * @on_exit: true if exiting so need to "hang up" the session * * This function is typically called only by the session leader, when * it wants to disassociate itself from its controlling tty. * * It performs the following functions: * (1) Sends a SIGHUP and SIGCONT to the foreground process group * (2) Clears the tty from being controlling the session * (3) Clears the controlling tty for all processes in the * session group. * * The argument on_exit is set to 1 if called when a process is * exiting; it is 0 if called by the ioctl TIOCNOTTY. * * Locking: * BKL is taken for hysterical raisins * tty_mutex is taken to protect tty * ->siglock is taken to protect ->signal/->sighand * tasklist_lock is taken to walk process list for sessions * ->siglock is taken to protect ->signal/->sighand */ void disassociate_ctty(int on_exit) { struct tty_struct *tty; struct pid *tty_pgrp = NULL; lock_kernel(); mutex_lock(&tty_mutex); tty = get_current_tty(); if (tty) { tty_pgrp = get_pid(tty->pgrp); mutex_unlock(&tty_mutex); /* XXX: here we race, there is nothing protecting tty */ if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) tty_vhangup(tty); } else if (on_exit) { struct pid *old_pgrp; spin_lock_irq(&current->sighand->siglock); old_pgrp = current->signal->tty_old_pgrp; current->signal->tty_old_pgrp = NULL; spin_unlock_irq(&current->sighand->siglock); if (old_pgrp) { kill_pgrp(old_pgrp, SIGHUP, on_exit); kill_pgrp(old_pgrp, SIGCONT, on_exit); put_pid(old_pgrp); } mutex_unlock(&tty_mutex); unlock_kernel(); return; } if (tty_pgrp) { kill_pgrp(tty_pgrp, SIGHUP, on_exit); if (!on_exit) kill_pgrp(tty_pgrp, SIGCONT, on_exit); put_pid(tty_pgrp); } spin_lock_irq(&current->sighand->siglock); put_pid(current->signal->tty_old_pgrp); current->signal->tty_old_pgrp = NULL; spin_unlock_irq(&current->sighand->siglock); mutex_lock(&tty_mutex); /* It is possible that do_tty_hangup has free'd this tty */ tty = get_current_tty(); if (tty) { put_pid(tty->session); put_pid(tty->pgrp); tty->session = NULL; tty->pgrp = NULL; } else { #ifdef TTY_DEBUG_HANGUP printk(KERN_DEBUG "error attempted to write to tty [0x%p]" " = NULL", tty); #endif } mutex_unlock(&tty_mutex); /* Now clear signal->tty under the lock */ read_lock(&tasklist_lock); session_clear_tty(task_session(current)); read_unlock(&tasklist_lock); unlock_kernel(); } /** * * no_tty - Ensure the current process does not have a controlling tty */ void no_tty(void) { struct task_struct *tsk = current; if (tsk->signal->leader) disassociate_ctty(0); proc_clear_tty(tsk); } /** * stop_tty - propagate flow control * @tty: tty to stop * * Perform flow control to the driver. For PTY/TTY pairs we * must also propagate the TIOCKPKT status. May be called * on an already stopped device and will not re-call the driver * method. * * This functionality is used by both the line disciplines for * halting incoming flow and by the driver. It may therefore be * called from any context, may be under the tty atomic_write_lock * but not always. * * Locking: * Broken. Relies on BKL which is unsafe here. */ void stop_tty(struct tty_struct *tty) { if (tty->stopped) return; tty->stopped = 1; if (tty->link && tty->link->packet) { tty->ctrl_status &= ~TIOCPKT_START; tty->ctrl_status |= TIOCPKT_STOP; wake_up_interruptible(&tty->link->read_wait); } if (tty->driver->stop) (tty->driver->stop)(tty); } EXPORT_SYMBOL(stop_tty); /** * start_tty - propagate flow control * @tty: tty to start * * Start a tty that has been stopped if at all possible. Perform * any necessary wakeups and propagate the TIOCPKT status. If this * is the tty was previous stopped and is being started then the * driver start method is invoked and the line discipline woken. * * Locking: * Broken. Relies on BKL which is unsafe here. */ void start_tty(struct tty_struct *tty) { if (!tty->stopped || tty->flow_stopped) return; tty->stopped = 0; if (tty->link && tty->link->packet) { tty->ctrl_status &= ~TIOCPKT_STOP; tty->ctrl_status |= TIOCPKT_START; wake_up_interruptible(&tty->link->read_wait); } if (tty->driver->start) (tty->driver->start)(tty); /* If we have a running line discipline it may need kicking */ tty_wakeup(tty); } EXPORT_SYMBOL(start_tty); /** * tty_read - read method for tty device files * @file: pointer to tty file * @buf: user buffer * @count: size of user buffer * @ppos: unused * * Perform the read system call function on this terminal device. Checks * for hung up devices before calling the line discipline method. * * Locking: * Locks the line discipline internally while needed * For historical reasons the line discipline read method is * invoked under the BKL. This will go away in time so do not rely on it * in new code. Multiple read calls may be outstanding in parallel. */ static ssize_t tty_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) { int i; struct tty_struct *tty; struct inode *inode; struct tty_ldisc *ld; tty = (struct tty_struct *)file->private_data; inode = file->f_path.dentry->d_inode; if (tty_paranoia_check(tty, inode, "tty_read")) return -EIO; if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags))) return -EIO; /* We want to wait for the line discipline to sort out in this situation */ ld = tty_ldisc_ref_wait(tty); lock_kernel(); if (ld->read) i = (ld->read)(tty, file, buf, count); else i = -EIO; tty_ldisc_deref(ld); unlock_kernel(); if (i > 0) inode->i_atime = current_fs_time(inode->i_sb); return i; } void tty_write_unlock(struct tty_struct *tty) { mutex_unlock(&tty->atomic_write_lock); wake_up_interruptible(&tty->write_wait); } int tty_write_lock(struct tty_struct *tty, int ndelay) { if (!mutex_trylock(&tty->atomic_write_lock)) { if (ndelay) return -EAGAIN; if (mutex_lock_interruptible(&tty->atomic_write_lock)) return -ERESTARTSYS; } return 0; } /* * Split writes up in sane blocksizes to avoid * denial-of-service type attacks */ static inline ssize_t do_tty_write( ssize_t (*write)(struct tty_struct *, struct file *, const unsigned char *, size_t), struct tty_struct *tty, struct file *file, const char __user *buf, size_t count) { ssize_t ret, written = 0; unsigned int chunk; ret = tty_write_lock(tty, file->f_flags & O_NDELAY); if (ret < 0) return ret; /* * We chunk up writes into a temporary buffer. This * simplifies low-level drivers immensely, since they * don't have locking issues and user mode accesses. * * But if TTY_NO_WRITE_SPLIT is set, we should use a * big chunk-size.. * * The default chunk-size is 2kB, because the NTTY * layer has problems with bigger chunks. It will * claim to be able to handle more characters than * it actually does. * * FIXME: This can probably go away now except that 64K chunks * are too likely to fail unless switched to vmalloc... */ chunk = 2048; if (test_bit(TTY_NO_WRITE_SPLIT, &tty->flags)) chunk = 65536; if (count < chunk) chunk = count; /* write_buf/write_cnt is protected by the atomic_write_lock mutex */ if (tty->write_cnt < chunk) { unsigned char *buf; if (chunk < 1024) chunk = 1024; buf = kmalloc(chunk, GFP_KERNEL); if (!buf) { ret = -ENOMEM; goto out; } kfree(tty->write_buf); tty->write_cnt = chunk; tty->write_buf = buf; } /* Do the write .. */ for (;;) { size_t size = count; if (size > chunk) size = chunk; ret = -EFAULT; if (copy_from_user(tty->write_buf, buf, size)) break; lock_kernel(); ret = write(tty, file, tty->write_buf, size); unlock_kernel(); if (ret <= 0) break; written += ret; buf += ret; count -= ret; if (!count) break; ret = -ERESTARTSYS; if (signal_pending(current)) break; cond_resched(); } if (written) { struct inode *inode = file->f_path.dentry->d_inode; inode->i_mtime = current_fs_time(inode->i_sb); ret = written; } out: tty_write_unlock(tty); return ret; } /** * tty_write - write method for tty device file * @file: tty file pointer * @buf: user data to write * @count: bytes to write * @ppos: unused * * Write data to a tty device via the line discipline. * * Locking: * Locks the line discipline as required * Writes to the tty driver are serialized by the atomic_write_lock * and are then processed in chunks to the device. The line discipline * write method will not be involked in parallel for each device * The line discipline write method is called under the big * kernel lock for historical reasons. New code should not rely on this. */ static ssize_t tty_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { struct tty_struct *tty; struct inode *inode = file->f_path.dentry->d_inode; ssize_t ret; struct tty_ldisc *ld; tty = (struct tty_struct *)file->private_data; if (tty_paranoia_check(tty, inode, "tty_write")) return -EIO; if (!tty || !tty->driver->write || (test_bit(TTY_IO_ERROR, &tty->flags))) return -EIO; ld = tty_ldisc_ref_wait(tty); if (!ld->write) ret = -EIO; else ret = do_tty_write(ld->write, tty, file, buf, count); tty_ldisc_deref(ld); return ret; } ssize_t redirected_tty_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { struct file *p = NULL; spin_lock(&redirect_lock); if (redirect) { get_file(redirect); p = redirect; } spin_unlock(&redirect_lock); if (p) { ssize_t res; res = vfs_write(p, buf, count, &p->f_pos); fput(p); return res; } return tty_write(file, buf, count, ppos); } static char ptychar[] = "pqrstuvwxyzabcde"; /** * pty_line_name - generate name for a pty * @driver: the tty driver in use * @index: the minor number * @p: output buffer of at least 6 bytes * * Generate a name from a driver reference and write it to the output * buffer. * * Locking: None */ static void pty_line_name(struct tty_driver *driver, int index, char *p) { int i = index + driver->name_base; /* ->name is initialized to "ttyp", but "tty" is expected */ sprintf(p, "%s%c%x", driver->subtype == PTY_TYPE_SLAVE ? "tty" : driver->name, ptychar[i >> 4 & 0xf], i & 0xf); } /** * pty_line_name - generate name for a tty * @driver: the tty driver in use * @index: the minor number * @p: output buffer of at least 7 bytes * * Generate a name from a driver reference and write it to the output * buffer. * * Locking: None */ static void tty_line_name(struct tty_driver *driver, int index, char *p) { sprintf(p, "%s%d", driver->name, index + driver->name_base); } /** * init_dev - initialise a tty device * @driver: tty driver we are opening a device on * @idx: device index * @tty: returned tty structure * * Prepare a tty device. This may not be a "new" clean device but * could also be an active device. The pty drivers require special * handling because of this. * * Locking: * The function is called under the tty_mutex, which * protects us from the tty struct or driver itself going away. * * On exit the tty device has the line discipline attached and * a reference count of 1. If a pair was created for pty/tty use * and the other was a pty master then it too has a reference count of 1. * * WSH 06/09/97: Rewritten to remove races and properly clean up after a * failed open. The new code protects the open with a mutex, so it's * really quite straightforward. The mutex locking can probably be * relaxed for the (most common) case of reopening a tty. */ static int init_dev(struct tty_driver *driver, int idx, struct tty_struct **ret_tty) { struct tty_struct *tty, *o_tty; struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc; struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; int retval = 0; /* check whether we're reopening an existing tty */ if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { tty = devpts_get_tty(idx); /* * If we don't have a tty here on a slave open, it's because * the master already started the close process and there's * no relation between devpts file and tty anymore. */ if (!tty && driver->subtype == PTY_TYPE_SLAVE) { retval = -EIO; goto end_init; } /* * It's safe from now on because init_dev() is called with * tty_mutex held and release_dev() won't change tty->count * or tty->flags without having to grab tty_mutex */ if (tty && driver->subtype == PTY_TYPE_MASTER) tty = tty->link; } else { tty = driver->ttys[idx]; } if (tty) goto fast_track; /* * First time open is complex, especially for PTY devices. * This code guarantees that either everything succeeds and the * TTY is ready for operation, or else the table slots are vacated * and the allocated memory released. (Except that the termios * and locked termios may be retained.) */ if (!try_module_get(driver->owner)) { retval = -ENODEV; goto end_init; } o_tty = NULL; tp = o_tp = NULL; ltp = o_ltp = NULL; tty = alloc_tty_struct(); if (!tty) goto fail_no_mem; initialize_tty_struct(tty); tty->driver = driver; tty->index = idx; tty_line_name(driver, idx, tty->name); if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { tp_loc = &tty->termios; ltp_loc = &tty->termios_locked; } else { tp_loc = &driver->termios[idx]; ltp_loc = &driver->termios_locked[idx]; } if (!*tp_loc) { tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL); if (!tp) goto free_mem_out; *tp = driver->init_termios; } if (!*ltp_loc) { ltp = kzalloc(sizeof(struct ktermios), GFP_KERNEL); if (!ltp) goto free_mem_out; } if (driver->type == TTY_DRIVER_TYPE_PTY) { o_tty = alloc_tty_struct(); if (!o_tty) goto free_mem_out; initialize_tty_struct(o_tty); o_tty->driver = driver->other; o_tty->index = idx; tty_line_name(driver->other, idx, o_tty->name); if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { o_tp_loc = &o_tty->termios; o_ltp_loc = &o_tty->termios_locked; } else { o_tp_loc = &driver->other->termios[idx]; o_ltp_loc = &driver->other->termios_locked[idx]; } if (!*o_tp_loc) { o_tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL); if (!o_tp) goto free_mem_out; *o_tp = driver->other->init_termios; } if (!*o_ltp_loc) { o_ltp = kzalloc(sizeof(struct ktermios), GFP_KERNEL); if (!o_ltp) goto free_mem_out; } /* * Everything allocated ... set up the o_tty structure. */ if (!(driver->other->flags & TTY_DRIVER_DEVPTS_MEM)) driver->other->ttys[idx] = o_tty; if (!*o_tp_loc) *o_tp_loc = o_tp; if (!*o_ltp_loc) *o_ltp_loc = o_ltp; o_tty->termios = *o_tp_loc; o_tty->termios_locked = *o_ltp_loc; driver->other->refcount++; if (driver->subtype == PTY_TYPE_MASTER) o_tty->count++; /* Establish the links in both directions */ tty->link = o_tty; o_tty->link = tty; } /* * All structures have been allocated, so now we install them. * Failures after this point use release_tty to clean up, so * there's no need to null out the local pointers. */ if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) driver->ttys[idx] = tty; if (!*tp_loc) *tp_loc = tp; if (!*ltp_loc) *ltp_loc = ltp; tty->termios = *tp_loc; tty->termios_locked = *ltp_loc; /* Compatibility until drivers always set this */ tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios); tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios); driver->refcount++; tty->count++; /* * Structures all installed ... call the ldisc open routines. * If we fail here just call release_tty to clean up. No need * to decrement the use counts, as release_tty doesn't care. */ if (tty->ldisc.open) { retval = (tty->ldisc.open)(tty); if (retval) goto release_mem_out; } if (o_tty && o_tty->ldisc.open) { retval = (o_tty->ldisc.open)(o_tty); if (retval) { if (tty->ldisc.close) (tty->ldisc.close)(tty); goto release_mem_out; } tty_ldisc_enable(o_tty); } tty_ldisc_enable(tty); goto success; /* * This fast open can be used if the tty is already open. * No memory is allocated, and the only failures are from * attempting to open a closing tty or attempting multiple * opens on a pty master. */ fast_track: if (test_bit(TTY_CLOSING, &tty->flags)) { retval = -EIO; goto end_init; } if (driver->type == TTY_DRIVER_TYPE_PTY && driver->subtype == PTY_TYPE_MASTER) { /* * special case for PTY masters: only one open permitted, * and the slave side open count is incremented as well. */ if (tty->count) { retval = -EIO; goto end_init; } tty->link->count++; } tty->count++; tty->driver = driver; /* N.B. why do this every time?? */ /* FIXME */ if (!test_bit(TTY_LDISC, &tty->flags)) printk(KERN_ERR "init_dev but no ldisc\n"); success: *ret_tty = tty; /* All paths come through here to release the mutex */ end_init: return retval; /* Release locally allocated memory ... nothing placed in slots */ free_mem_out: kfree(o_tp); if (o_tty) free_tty_struct(o_tty); kfree(ltp); kfree(tp); free_tty_struct(tty); fail_no_mem: module_put(driver->owner); retval = -ENOMEM; goto end_init; /* call the tty release_tty routine to clean out this slot */ release_mem_out: if (printk_ratelimit()) printk(KERN_INFO "init_dev: ldisc open failed, " "clearing slot %d\n", idx); release_tty(tty, idx); goto end_init; } /** * release_one_tty - release tty structure memory * * Releases memory associated with a tty structure, and clears out the * driver table slots. This function is called when a device is no longer * in use. It also gets called when setup of a device fails. * * Locking: * tty_mutex - sometimes only * takes the file list lock internally when working on the list * of ttys that the driver keeps. * FIXME: should we require tty_mutex is held here ?? */ static void release_one_tty(struct tty_struct *tty, int idx) { int devpts = tty->driver->flags & TTY_DRIVER_DEVPTS_MEM; struct ktermios *tp; if (!devpts) tty->driver->ttys[idx] = NULL; if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) { tp = tty->termios; if (!devpts) tty->driver->termios[idx] = NULL; kfree(tp); tp = tty->termios_locked; if (!devpts) tty->driver->termios_locked[idx] = NULL; kfree(tp); } tty->magic = 0; tty->driver->refcount--; file_list_lock(); list_del_init(&tty->tty_files); file_list_unlock(); free_tty_struct(tty); } /** * release_tty - release tty structure memory * * Release both @tty and a possible linked partner (think pty pair), * and decrement the refcount of the backing module. * * Locking: * tty_mutex - sometimes only * takes the file list lock internally when working on the list * of ttys that the driver keeps. * FIXME: should we require tty_mutex is held here ?? */ static void release_tty(struct tty_struct *tty, int idx) { struct tty_driver *driver = tty->driver; if (tty->link) release_one_tty(tty->link, idx); release_one_tty(tty, idx); module_put(driver->owner); } /* * Even releasing the tty structures is a tricky business.. We have * to be very careful that the structures are all released at the * same time, as interrupts might otherwise get the wrong pointers. * * WSH 09/09/97: rewritten to avoid some nasty race conditions that could * lead to double frees or releasing memory still in use. */ static void release_dev(struct file *filp) { struct tty_struct *tty, *o_tty; int pty_master, tty_closing, o_tty_closing, do_sleep; int devpts; int idx; char buf[64]; unsigned long flags; tty = (struct tty_struct *)filp->private_data; if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "release_dev")) return; check_tty_count(tty, "release_dev"); tty_fasync(-1, filp, 0); idx = tty->index; pty_master = (tty->driver->type == TTY_DRIVER_TYPE_PTY && tty->driver->subtype == PTY_TYPE_MASTER); devpts = (tty->driver->flags & TTY_DRIVER_DEVPTS_MEM) != 0; o_tty = tty->link; #ifdef TTY_PARANOIA_CHECK if (idx < 0 || idx >= tty->driver->num) { printk(KERN_DEBUG "release_dev: bad idx when trying to " "free (%s)\n", tty->name); return; } if (!(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) { if (tty != tty->driver->ttys[idx]) { printk(KERN_DEBUG "release_dev: driver.table[%d] not tty " "for (%s)\n", idx, tty->name); return; } if (tty->termios != tty->driver->termios[idx]) { printk(KERN_DEBUG "release_dev: driver.termios[%d] not termios " "for (%s)\n", idx, tty->name); return; } if (tty->termios_locked != tty->driver->termios_locked[idx]) { printk(KERN_DEBUG "release_dev: driver.termios_locked[%d] not " "termios_locked for (%s)\n", idx, tty->name); return; } } #endif #ifdef TTY_DEBUG_HANGUP printk(KERN_DEBUG "release_dev of %s (tty count=%d)...", tty_name(tty, buf), tty->count); #endif #ifdef TTY_PARANOIA_CHECK if (tty->driver->other && !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) { if (o_tty != tty->driver->other->ttys[idx]) { printk(KERN_DEBUG "release_dev: other->table[%d] " "not o_tty for (%s)\n", idx, tty->name); return; } if (o_tty->termios != tty->driver->other->termios[idx]) { printk(KERN_DEBUG "release_dev: other->termios[%d] " "not o_termios for (%s)\n", idx, tty->name); return; } if (o_tty->termios_locked != tty->driver->other->termios_locked[idx]) { printk(KERN_DEBUG "release_dev: other->termios_locked[" "%d] not o_termios_locked for (%s)\n", idx, tty->name); return; } if (o_tty->link != tty) { printk(KERN_DEBUG "release_dev: bad pty pointers\n"); return; } } #endif if (tty->driver->close) tty->driver->close(tty, filp); /* * Sanity check: if tty->count is going to zero, there shouldn't be * any waiters on tty->read_wait or tty->write_wait. We test the * wait queues and kick everyone out _before_ actually starting to * close. This ensures that we won't block while releasing the tty * structure. * * The test for the o_tty closing is necessary, since the master and * slave sides may close in any order. If the slave side closes out * first, its count will be one, since the master side holds an open. * Thus this test wouldn't be triggered at the time the slave closes, * so we do it now. * * Note that it's possible for the tty to be opened again while we're * flushing out waiters. By recalculating the closing flags before * each iteration we avoid any problems. */ while (1) { /* Guard against races with tty->count changes elsewhere and opens on /dev/tty */ mutex_lock(&tty_mutex); tty_closing = tty->count <= 1; o_tty_closing = o_tty && (o_tty->count <= (pty_master ? 1 : 0)); do_sleep = 0; if (tty_closing) { if (waitqueue_active(&tty->read_wait)) { wake_up(&tty->read_wait); do_sleep++; } if (waitqueue_active(&tty->write_wait)) { wake_up(&tty->write_wait); do_sleep++; } } if (o_tty_closing) { if (waitqueue_active(&o_tty->read_wait)) { wake_up(&o_tty->read_wait); do_sleep++; } if (waitqueue_active(&o_tty->write_wait)) { wake_up(&o_tty->write_wait); do_sleep++; } } if (!do_sleep) break; printk(KERN_WARNING "release_dev: %s: read/write wait queue " "active!\n", tty_name(tty, buf)); mutex_unlock(&tty_mutex); schedule(); } /* * The closing flags are now consistent with the open counts on * both sides, and we've completed the last operation that could * block, so it's safe to proceed with closing. */ if (pty_master) { if (--o_tty->count < 0) { printk(KERN_WARNING "release_dev: bad pty slave count " "(%d) for %s\n", o_tty->count, tty_name(o_tty, buf)); o_tty->count = 0; } } if (--tty->count < 0) { printk(KERN_WARNING "release_dev: bad tty->count (%d) for %s\n", tty->count, tty_name(tty, buf)); tty->count = 0; } /* * We've decremented tty->count, so we need to remove this file * descriptor off the tty->tty_files list; this serves two * purposes: * - check_tty_count sees the correct number of file descriptors * associated with this tty. * - do_tty_hangup no longer sees this file descriptor as * something that needs to be handled for hangups. */ file_kill(filp); filp->private_data = NULL; /* * Perform some housekeeping before deciding whether to return. * * Set the TTY_CLOSING flag if this was the last open. In the * case of a pty we may have to wait around for the other side * to close, and TTY_CLOSING makes sure we can't be reopened. */ if (tty_closing) set_bit(TTY_CLOSING, &tty->flags); if (o_tty_closing) set_bit(TTY_CLOSING, &o_tty->flags); /* * If _either_ side is closing, make sure there aren't any * processes that still think tty or o_tty is their controlling * tty. */ if (tty_closing || o_tty_closing) { read_lock(&tasklist_lock); session_clear_tty(tty->session); if (o_tty) session_clear_tty(o_tty->session); read_unlock(&tasklist_lock); } mutex_unlock(&tty_mutex); /* check whether both sides are closing ... */ if (!tty_closing || (o_tty && !o_tty_closing)) return; #ifdef TTY_DEBUG_HANGUP printk(KERN_DEBUG "freeing tty structure..."); #endif /* * Prevent flush_to_ldisc() from rescheduling the work for later. Then * kill any delayed work. As this is the final close it does not * race with the set_ldisc code path. */ clear_bit(TTY_LDISC, &tty->flags); cancel_delayed_work(&tty->buf.work); /* * Wait for ->hangup_work and ->buf.work handlers to terminate */ flush_scheduled_work(); /* * Wait for any short term users (we know they are just driver * side waiters as the file is closing so user count on the file * side is zero. */ spin_lock_irqsave(&tty_ldisc_lock, flags); while (tty->ldisc.refcount) { spin_unlock_irqrestore(&tty_ldisc_lock, flags); wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0); spin_lock_irqsave(&tty_ldisc_lock, flags); } spin_unlock_irqrestore(&tty_ldisc_lock, flags); /* * Shutdown the current line discipline, and reset it to N_TTY. * N.B. why reset ldisc when we're releasing the memory?? * * FIXME: this MUST get fixed for the new reflocking */ if (tty->ldisc.close) (tty->ldisc.close)(tty); tty_ldisc_put(tty->ldisc.num); /* * Switch the line discipline back */ tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); tty_set_termios_ldisc(tty, N_TTY); if (o_tty) { /* FIXME: could o_tty be in setldisc here ? */ clear_bit(TTY_LDISC, &o_tty->flags); if (o_tty->ldisc.close) (o_tty->ldisc.close)(o_tty); tty_ldisc_put(o_tty->ldisc.num); tty_ldisc_assign(o_tty, tty_ldisc_get(N_TTY)); tty_set_termios_ldisc(o_tty, N_TTY); } /* * The release_tty function takes care of the details of clearing * the slots and preserving the termios structure. */ release_tty(tty, idx); #ifdef CONFIG_UNIX98_PTYS /* Make this pty number available for reallocation */ if (devpts) { mutex_lock(&allocated_ptys_lock); idr_remove(&allocated_ptys, idx); mutex_unlock(&allocated_ptys_lock); } #endif } /** * tty_open - open a tty device * @inode: inode of device file * @filp: file pointer to tty * * tty_open and tty_release keep up the tty count that contains the * number of opens done on a tty. We cannot use the inode-count, as * different inodes might point to the same tty. * * Open-counting is needed for pty masters, as well as for keeping * track of serial lines: DTR is dropped when the last close happens. * (This is not done solely through tty->count, now. - Ted 1/27/92) * * The termios state of a pty is reset on first open so that * settings don't persist across reuse. * * Locking: tty_mutex protects tty, get_tty_driver and init_dev work. * tty->count should protect the rest. * ->siglock protects ->signal/->sighand */ static int tty_open(struct inode *inode, struct file *filp) { struct tty_struct *tty; int noctty, retval; struct tty_driver *driver; int index; dev_t device = inode->i_rdev; unsigned short saved_flags = filp->f_flags; nonseekable_open(inode, filp); retry_open: noctty = filp->f_flags & O_NOCTTY; index = -1; retval = 0; mutex_lock(&tty_mutex); if (device == MKDEV(TTYAUX_MAJOR, 0)) { tty = get_current_tty(); if (!tty) { mutex_unlock(&tty_mutex); return -ENXIO; } driver = tty->driver; index = tty->index; filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */ /* noctty = 1; */ goto got_driver; } #ifdef CONFIG_VT if (device == MKDEV(TTY_MAJOR, 0)) { extern struct tty_driver *console_driver; driver = console_driver; index = fg_console; noctty = 1; goto got_driver; } #endif if (device == MKDEV(TTYAUX_MAJOR, 1)) { driver = console_device(&index); if (driver) { /* Don't let /dev/console block */ filp->f_flags |= O_NONBLOCK; noctty = 1; goto got_driver; } mutex_unlock(&tty_mutex); return -ENODEV; } driver = get_tty_driver(device, &index); if (!driver) { mutex_unlock(&tty_mutex); return -ENODEV; } got_driver: retval = init_dev(driver, index, &tty); mutex_unlock(&tty_mutex); if (retval) return retval; filp->private_data = tty; file_move(filp, &tty->tty_files); check_tty_count(tty, "tty_open"); if (tty->driver->type == TTY_DRIVER_TYPE_PTY && tty->driver->subtype == PTY_TYPE_MASTER) noctty = 1; #ifdef TTY_DEBUG_HANGUP printk(KERN_DEBUG "opening %s...", tty->name); #endif if (!retval) { if (tty->driver->open) retval = tty->driver->open(tty, filp); else retval = -ENODEV; } filp->f_flags = saved_flags; if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !capable(CAP_SYS_ADMIN)) retval = -EBUSY; if (retval) { #ifdef TTY_DEBUG_HANGUP printk(KERN_DEBUG "error %d in opening %s...", retval, tty->name); #endif release_dev(filp); if (retval != -ERESTARTSYS) return retval; if (signal_pending(current)) return retval; schedule(); /* * Need to reset f_op in case a hangup happened. */ if (filp->f_op == &hung_up_tty_fops) filp->f_op = &tty_fops; goto retry_open; } mutex_lock(&tty_mutex); spin_lock_irq(&current->sighand->siglock); if (!noctty && current->signal->leader && !current->signal->tty && tty->session == NULL) __proc_set_tty(current, tty); spin_unlock_irq(&current->sighand->siglock); mutex_unlock(&tty_mutex); tty_audit_opening(); return 0; } #ifdef CONFIG_UNIX98_PTYS /** * ptmx_open - open a unix 98 pty master * @inode: inode of device file * @filp: file pointer to tty * * Allocate a unix98 pty master device from the ptmx driver. * * Locking: tty_mutex protects theinit_dev work. tty->count should * protect the rest. * allocated_ptys_lock handles the list of free pty numbers */ static int ptmx_open(struct inode *inode, struct file *filp) { struct tty_struct *tty; int retval; int index; int idr_ret; nonseekable_open(inode, filp); /* find a device that is not in use. */ mutex_lock(&allocated_ptys_lock); if (!idr_pre_get(&allocated_ptys, GFP_KERNEL)) { mutex_unlock(&allocated_ptys_lock); return -ENOMEM; } idr_ret = idr_get_new(&allocated_ptys, NULL, &index); if (idr_ret < 0) { mutex_unlock(&allocated_ptys_lock); if (idr_ret == -EAGAIN) return -ENOMEM; return -EIO; } if (index >= pty_limit) { idr_remove(&allocated_ptys, index); mutex_unlock(&allocated_ptys_lock); return -EIO; } mutex_unlock(&allocated_ptys_lock); mutex_lock(&tty_mutex); retval = init_dev(ptm_driver, index, &tty); mutex_unlock(&tty_mutex); if (retval) goto out; set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ filp->private_data = tty; file_move(filp, &tty->tty_files); retval = -ENOMEM; if (devpts_pty_new(tty->link)) goto out1; check_tty_count(tty, "tty_open"); retval = ptm_driver->open(tty, filp); if (!retval) { tty_audit_opening(); return 0; } out1: release_dev(filp); return retval; out: mutex_lock(&allocated_ptys_lock); idr_remove(&allocated_ptys, index); mutex_unlock(&allocated_ptys_lock); return retval; } #endif /** * tty_release - vfs callback for close * @inode: inode of tty * @filp: file pointer for handle to tty * * Called the last time each file handle is closed that references * this tty. There may however be several such references. * * Locking: * Takes bkl. See release_dev */ static int tty_release(struct inode *inode, struct file *filp) { lock_kernel(); release_dev(filp); unlock_kernel(); return 0; } /** * tty_poll - check tty status * @filp: file being polled * @wait: poll wait structures to update * * Call the line discipline polling method to obtain the poll * status of the device. * * Locking: locks called line discipline but ldisc poll method * may be re-entered freely by other callers. */ static unsigned int tty_poll(struct file *filp, poll_table *wait) { struct tty_struct *tty; struct tty_ldisc *ld; int ret = 0; tty = (struct tty_struct *)filp->private_data; if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_poll")) return 0; ld = tty_ldisc_ref_wait(tty); if (ld->poll) ret = (ld->poll)(tty, filp, wait); tty_ldisc_deref(ld); return ret; } static int tty_fasync(int fd, struct file *filp, int on) { struct tty_struct *tty; int retval; tty = (struct tty_struct *)filp->private_data; if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, "tty_fasync")) return 0; retval = fasync_helper(fd, filp, on, &tty->fasync); if (retval <= 0) return retval; if (on) { enum pid_type type; struct pid *pid; if (!waitqueue_active(&tty->read_wait)) tty->minimum_to_wake = 1; if (tty->pgrp) { pid = tty->pgrp; type = PIDTYPE_PGID; } else { pid = task_pid(current); type = PIDTYPE_PID; } retval = __f_setown(filp, pid, type, 0); if (retval) return retval; } else { if (!tty->fasync && !waitqueue_active(&tty->read_wait)) tty->minimum_to_wake = N_TTY_BUF_SIZE; } return 0; } /** * tiocsti - fake input character * @tty: tty to fake input into * @p: pointer to character * * Fake input to a tty device. Does the necessary locking and * input management. * * FIXME: does not honour flow control ?? * * Locking: * Called functions take tty_ldisc_lock * current->signal->tty check is safe without locks * * FIXME: may race normal receive processing */ static int tiocsti(struct tty_struct *tty, char __user *p) { char ch, mbz = 0; struct tty_ldisc *ld; if ((current->signal->tty != tty) && !capable(CAP_SYS_ADMIN)) return -EPERM; if (get_user(ch, p)) return -EFAULT; ld = tty_ldisc_ref_wait(tty); ld->receive_buf(tty, &ch, &mbz, 1); tty_ldisc_deref(ld); return 0; } /** * tiocgwinsz - implement window query ioctl * @tty; tty * @arg: user buffer for result * * Copies the kernel idea of the window size into the user buffer. * * Locking: tty->termios_mutex is taken to ensure the winsize data * is consistent. */ static int tiocgwinsz(struct tty_struct *tty, struct winsize __user *arg) { int err; mutex_lock(&tty->termios_mutex); err = copy_to_user(arg, &tty->winsize, sizeof(*arg)); mutex_unlock(&tty->termios_mutex); return err ? -EFAULT: 0; } /** * tiocswinsz - implement window size set ioctl * @tty; tty * @arg: user buffer for result * * Copies the user idea of the window size to the kernel. Traditionally * this is just advisory information but for the Linux console it * actually has driver level meaning and triggers a VC resize. * * Locking: * Called function use the console_sem is used to ensure we do * not try and resize the console twice at once. * The tty->termios_mutex is used to ensure we don't double * resize and get confused. Lock order - tty->termios_mutex before * console sem */ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty, struct winsize __user *arg) { struct winsize tmp_ws; if (copy_from_user(&tmp_ws, arg, sizeof(*arg))) return -EFAULT; mutex_lock(&tty->termios_mutex); if (!memcmp(&tmp_ws, &tty->winsize, sizeof(*arg))) goto done; #ifdef CONFIG_VT if (tty->driver->type == TTY_DRIVER_TYPE_CONSOLE) { if (vc_lock_resize(tty->driver_data, tmp_ws.ws_col, tmp_ws.ws_row)) { mutex_unlock(&tty->termios_mutex); return -ENXIO; } } #endif if (tty->pgrp) kill_pgrp(tty->pgrp, SIGWINCH, 1); if ((real_tty->pgrp != tty->pgrp) && real_tty->pgrp) kill_pgrp(real_tty->pgrp, SIGWINCH, 1); tty->winsize = tmp_ws; real_tty->winsize = tmp_ws; done: mutex_unlock(&tty->termios_mutex); return 0; } /** * tioccons - allow admin to move logical console * @file: the file to become console * * Allow the adminstrator to move the redirected console device * * Locking: uses redirect_lock to guard the redirect information */ static int tioccons(struct file *file) { if (!capable(CAP_SYS_ADMIN)) return -EPERM; if (file->f_op->write == redirected_tty_write) { struct file *f; spin_lock(&redirect_lock); f = redirect; redirect = NULL; spin_unlock(&redirect_lock); if (f) fput(f); return 0; } spin_lock(&redirect_lock); if (redirect) { spin_unlock(&redirect_lock); return -EBUSY; } get_file(file); redirect = file; spin_unlock(&redirect_lock); return 0; } /** * fionbio - non blocking ioctl * @file: file to set blocking value * @p: user parameter * * Historical tty interfaces had a blocking control ioctl before * the generic functionality existed. This piece of history is preserved * in the expected tty API of posix OS's. * * Locking: none, the open fle handle ensures it won't go away. */ static int fionbio(struct file *file, int __user *p) { int nonblock; if (get_user(nonblock, p)) return -EFAULT; if (nonblock) file->f_flags |= O_NONBLOCK; else file->f_flags &= ~O_NONBLOCK; return 0; } /** * tiocsctty - set controlling tty * @tty: tty structure * @arg: user argument * * This ioctl is used to manage job control. It permits a session * leader to set this tty as the controlling tty for the session. * * Locking: * Takes tty_mutex() to protect tty instance * Takes tasklist_lock internally to walk sessions * Takes ->siglock() when updating signal->tty */ static int tiocsctty(struct tty_struct *tty, int arg) { int ret = 0; if (current->signal->leader && (task_session(current) == tty->session)) return ret; mutex_lock(&tty_mutex); /* * The process must be a session leader and * not have a controlling tty already. */ if (!current->signal->leader || current->signal->tty) { ret = -EPERM; goto unlock; } if (tty->session) { /* * This tty is already the controlling * tty for another session group! */ if (arg == 1 && capable(CAP_SYS_ADMIN)) { /* * Steal it away */ read_lock(&tasklist_lock); session_clear_tty(tty->session); read_unlock(&tasklist_lock); } else { ret = -EPERM; goto unlock; } } proc_set_tty(current, tty); unlock: mutex_unlock(&tty_mutex); return ret; } /** * tiocgpgrp - get process group * @tty: tty passed by user * @real_tty: tty side of the tty pased by the user if a pty else the tty * @p: returned pid * * Obtain the process group of the tty. If there is no process group * return an error. * * Locking: none. Reference to current->signal->tty is safe. */ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) { /* * (tty == real_tty) is a cheap way of * testing if the tty is NOT a master pty. */ if (tty == real_tty && current->signal->tty != real_tty) return -ENOTTY; return put_user(pid_vnr(real_tty->pgrp), p); } /** * tiocspgrp - attempt to set process group * @tty: tty passed by user * @real_tty: tty side device matching tty passed by user * @p: pid pointer * * Set the process group of the tty to the session passed. Only * permitted where the tty session is our session. * * Locking: None */ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) { struct pid *pgrp; pid_t pgrp_nr; int retval = tty_check_change(real_tty); if (retval == -EIO) return -ENOTTY; if (retval) return retval; if (!current->signal->tty || (current->signal->tty != real_tty) || (real_tty->session != task_session(current))) return -ENOTTY; if (get_user(pgrp_nr, p)) return -EFAULT; if (pgrp_nr < 0) return -EINVAL; rcu_read_lock(); pgrp = find_vpid(pgrp_nr); retval = -ESRCH; if (!pgrp) goto out_unlock; retval = -EPERM; if (session_of_pgrp(pgrp) != task_session(current)) goto out_unlock; retval = 0; put_pid(real_tty->pgrp); real_tty->pgrp = get_pid(pgrp); out_unlock: rcu_read_unlock(); return retval; } /** * tiocgsid - get session id * @tty: tty passed by user * @real_tty: tty side of the tty pased by the user if a pty else the tty * @p: pointer to returned session id * * Obtain the session id of the tty. If there is no session * return an error. * * Locking: none. Reference to current->signal->tty is safe. */ static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) { /* * (tty == real_tty) is a cheap way of * testing if the tty is NOT a master pty. */ if (tty == real_tty && current->signal->tty != real_tty) return -ENOTTY; if (!real_tty->session) return -ENOTTY; return put_user(pid_vnr(real_tty->session), p); } /** * tiocsetd - set line discipline * @tty: tty device * @p: pointer to user data * * Set the line discipline according to user request. * * Locking: see tty_set_ldisc, this function is just a helper */ static int tiocsetd(struct tty_struct *tty, int __user *p) { int ldisc; if (get_user(ldisc, p)) return -EFAULT; return tty_set_ldisc(tty, ldisc); } /** * send_break - performed time break * @tty: device to break on * @duration: timeout in mS * * Perform a timed break on hardware that lacks its own driver level * timed break functionality. * * Locking: * atomic_write_lock serializes * */ static int send_break(struct tty_struct *tty, unsigned int duration) { if (tty_write_lock(tty, 0) < 0) return -EINTR; tty->driver->break_ctl(tty, -1); if (!signal_pending(current)) msleep_interruptible(duration); tty->driver->break_ctl(tty, 0); tty_write_unlock(tty); if (signal_pending(current)) return -EINTR; return 0; } /** * tiocmget - get modem status * @tty: tty device * @file: user file pointer * @p: pointer to result * * Obtain the modem status bits from the tty driver if the feature * is supported. Return -EINVAL if it is not available. * * Locking: none (up to the driver) */ static int tty_tiocmget(struct tty_struct *tty, struct file *file, int __user *p) { int retval = -EINVAL; if (tty->driver->tiocmget) { retval = tty->driver->tiocmget(tty, file); if (retval >= 0) retval = put_user(retval, p); } return retval; } /** * tiocmset - set modem status * @tty: tty device * @file: user file pointer * @cmd: command - clear bits, set bits or set all * @p: pointer to desired bits * * Set the modem status bits from the tty driver if the feature * is supported. Return -EINVAL if it is not available. * * Locking: none (up to the driver) */ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned __user *p) { int retval = -EINVAL; if (tty->driver->tiocmset) { unsigned int set, clear, val; retval = get_user(val, p); if (retval) return retval; set = clear = 0; switch (cmd) { case TIOCMBIS: set = val; break; case TIOCMBIC: clear = val; break; case TIOCMSET: set = val; clear = ~val; break; } set &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; clear &= TIOCM_DTR|TIOCM_RTS|TIOCM_OUT1|TIOCM_OUT2|TIOCM_LOOP; retval = tty->driver->tiocmset(tty, file, set, clear); } return retval; } /* * Split this up, as gcc can choke on it otherwise.. */ int tty_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) { struct tty_struct *tty, *real_tty; void __user *p = (void __user *)arg; int retval; struct tty_ldisc *ld; tty = (struct tty_struct *)file->private_data; if (tty_paranoia_check(tty, inode, "tty_ioctl")) return -EINVAL; /* CHECKME: is this safe as one end closes ? */ real_tty = tty; if (tty->driver->type == TTY_DRIVER_TYPE_PTY && tty->driver->subtype == PTY_TYPE_MASTER) real_tty = tty->link; /* * Break handling by driver */ if (!tty->driver->break_ctl) { switch (cmd) { case TIOCSBRK: case TIOCCBRK: if (tty->driver->ioctl) return tty->driver->ioctl(tty, file, cmd, arg); return -EINVAL; /* These two ioctl's always return success; even if */ /* the driver doesn't support them. */ case TCSBRK: case TCSBRKP: if (!tty->driver->ioctl) return 0; retval = tty->driver->ioctl(tty, file, cmd, arg); if (retval == -ENOIOCTLCMD) retval = 0; return retval; } } /* * Factor out some common prep work */ switch (cmd) { case TIOCSETD: case TIOCSBRK: case TIOCCBRK: case TCSBRK: case TCSBRKP: retval = tty_check_change(tty); if (retval) return retval; if (cmd != TIOCCBRK) { tty_wait_until_sent(tty, 0); if (signal_pending(current)) return -EINTR; } break; } switch (cmd) { case TIOCSTI: return tiocsti(tty, p); case TIOCGWINSZ: return tiocgwinsz(tty, p); case TIOCSWINSZ: return tiocswinsz(tty, real_tty, p); case TIOCCONS: return real_tty != tty ? -EINVAL : tioccons(file); case FIONBIO: return fionbio(file, p); case TIOCEXCL: set_bit(TTY_EXCLUSIVE, &tty->flags); return 0; case TIOCNXCL: clear_bit(TTY_EXCLUSIVE, &tty->flags); return 0; case TIOCNOTTY: if (current->signal->tty != tty) return -ENOTTY; no_tty(); return 0; case TIOCSCTTY: return tiocsctty(tty, arg); case TIOCGPGRP: return tiocgpgrp(tty, real_tty, p); case TIOCSPGRP: return tiocspgrp(tty, real_tty, p); case TIOCGSID: return tiocgsid(tty, real_tty, p); case TIOCGETD: /* FIXME: check this is ok */ return put_user(tty->ldisc.num, (int __user *)p); case TIOCSETD: return tiocsetd(tty, p); #ifdef CONFIG_VT case TIOCLINUX: return tioclinux(tty, arg); #endif /* * Break handling */ case TIOCSBRK: /* Turn break on, unconditionally */ tty->driver->break_ctl(tty, -1); return 0; case TIOCCBRK: /* Turn break off, unconditionally */ tty->driver->break_ctl(tty, 0); return 0; case TCSBRK: /* SVID version: non-zero arg --> no break */ /* non-zero arg means wait for all output data * to be sent (performed above) but don't send break. * This is used by the tcdrain() termios function. */ if (!arg) return send_break(tty, 250); return 0; case TCSBRKP: /* support for POSIX tcsendbreak() */ return send_break(tty, arg ? arg*100 : 250); case TIOCMGET: return tty_tiocmget(tty, file, p); case TIOCMSET: case TIOCMBIC: case TIOCMBIS: return tty_tiocmset(tty, file, cmd, p); case TCFLSH: switch (arg) { case TCIFLUSH: case TCIOFLUSH: /* flush tty buffer and allow ldisc to process ioctl */ tty_buffer_flush(tty); break; } break; } if (tty->driver->ioctl) { retval = (tty->driver->ioctl)(tty, file, cmd, arg); if (retval != -ENOIOCTLCMD) return retval; } ld = tty_ldisc_ref_wait(tty); retval = -EINVAL; if (ld->ioctl) { retval = ld->ioctl(tty, file, cmd, arg); if (retval == -ENOIOCTLCMD) retval = -EINVAL; } tty_ldisc_deref(ld); return retval; } #ifdef CONFIG_COMPAT static long tty_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct inode *inode = file->f_dentry->d_inode; struct tty_struct *tty = file->private_data; struct tty_ldisc *ld; int retval = -ENOIOCTLCMD; if (tty_paranoia_check(tty, inode, "tty_ioctl")) return -EINVAL; if (tty->driver->compat_ioctl) { retval = (tty->driver->compat_ioctl)(tty, file, cmd, arg); if (retval != -ENOIOCTLCMD) return retval; } ld = tty_ldisc_ref_wait(tty); if (ld->compat_ioctl) retval = ld->compat_ioctl(tty, file, cmd, arg); tty_ldisc_deref(ld); return retval; } #endif /* * This implements the "Secure Attention Key" --- the idea is to * prevent trojan horses by killing all processes associated with this * tty when the user hits the "Secure Attention Key". Required for * super-paranoid applications --- see the Orange Book for more details. * * This code could be nicer; ideally it should send a HUP, wait a few * seconds, then send a INT, and then a KILL signal. But you then * have to coordinate with the init process, since all processes associated * with the current tty must be dead before the new getty is allowed * to spawn. * * Now, if it would be correct ;-/ The current code has a nasty hole - * it doesn't catch files in flight. We may send the descriptor to ourselves * via AF_UNIX socket, close it and later fetch from socket. FIXME. * * Nasty bug: do_SAK is being called in interrupt context. This can * deadlock. We punt it up to process context. AKPM - 16Mar2001 */ void __do_SAK(struct tty_struct *tty) { #ifdef TTY_SOFT_SAK tty_hangup(tty); #else struct task_struct *g, *p; struct pid *session; int i; struct file *filp; struct fdtable *fdt; if (!tty) return; session = tty->session; tty_ldisc_flush(tty); if (tty->driver->flush_buffer) tty->driver->flush_buffer(tty); read_lock(&tasklist_lock); /* Kill the entire session */ do_each_pid_task(session, PIDTYPE_SID, p) { printk(KERN_NOTICE "SAK: killed process %d" " (%s): task_session_nr(p)==tty->session\n", task_pid_nr(p), p->comm); send_sig(SIGKILL, p, 1); } while_each_pid_task(session, PIDTYPE_SID, p); /* Now kill any processes that happen to have the * tty open. */ do_each_thread(g, p) { if (p->signal->tty == tty) { printk(KERN_NOTICE "SAK: killed process %d" " (%s): task_session_nr(p)==tty->session\n", task_pid_nr(p), p->comm); send_sig(SIGKILL, p, 1); continue; } task_lock(p); if (p->files) { /* * We don't take a ref to the file, so we must * hold ->file_lock instead. */ spin_lock(&p->files->file_lock); fdt = files_fdtable(p->files); for (i = 0; i < fdt->max_fds; i++) { filp = fcheck_files(p->files, i); if (!filp) continue; if (filp->f_op->read == tty_read && filp->private_data == tty) { printk(KERN_NOTICE "SAK: killed process %d" " (%s): fd#%d opened to the tty\n", task_pid_nr(p), p->comm, i); force_sig(SIGKILL, p); break; } } spin_unlock(&p->files->file_lock); } task_unlock(p); } while_each_thread(g, p); read_unlock(&tasklist_lock); #endif } static void do_SAK_work(struct work_struct *work) { struct tty_struct *tty = container_of(work, struct tty_struct, SAK_work); __do_SAK(tty); } /* * The tq handling here is a little racy - tty->SAK_work may already be queued. * Fortunately we don't need to worry, because if ->SAK_work is already queued, * the values which we write to it will be identical to the values which it * already has. --akpm */ void do_SAK(struct tty_struct *tty) { if (!tty) return; schedule_work(&tty->SAK_work); } EXPORT_SYMBOL(do_SAK); /** * flush_to_ldisc * @work: tty structure passed from work queue. * * This routine is called out of the software interrupt to flush data * from the buffer chain to the line discipline. * * Locking: holds tty->buf.lock to guard buffer list. Drops the lock * while invoking the line discipline receive_buf method. The * receive_buf method is single threaded for each tty instance. */ static void flush_to_ldisc(struct work_struct *work) { struct tty_struct *tty = container_of(work, struct tty_struct, buf.work.work); unsigned long flags; struct tty_ldisc *disc; struct tty_buffer *tbuf, *head; char *char_buf; unsigned char *flag_buf; disc = tty_ldisc_ref(tty); if (disc == NULL) /* !TTY_LDISC */ return; spin_lock_irqsave(&tty->buf.lock, flags); /* So we know a flush is running */ set_bit(TTY_FLUSHING, &tty->flags); head = tty->buf.head; if (head != NULL) { tty->buf.head = NULL; for (;;) { int count = head->commit - head->read; if (!count) { if (head->next == NULL) break; tbuf = head; head = head->next; tty_buffer_free(tty, tbuf); continue; } /* Ldisc or user is trying to flush the buffers we are feeding to the ldisc, stop feeding the line discipline as we want to empty the queue */ if (test_bit(TTY_FLUSHPENDING, &tty->flags)) break; if (!tty->receive_room) { schedule_delayed_work(&tty->buf.work, 1); break; } if (count > tty->receive_room) count = tty->receive_room; char_buf = head->char_buf_ptr + head->read; flag_buf = head->flag_buf_ptr + head->read; head->read += count; spin_unlock_irqrestore(&tty->buf.lock, flags); disc->receive_buf(tty, char_buf, flag_buf, count); spin_lock_irqsave(&tty->buf.lock, flags); } /* Restore the queue head */ tty->buf.head = head; } /* We may have a deferred request to flush the input buffer, if so pull the chain under the lock and empty the queue */ if (test_bit(TTY_FLUSHPENDING, &tty->flags)) { __tty_buffer_flush(tty); clear_bit(TTY_FLUSHPENDING, &tty->flags); wake_up(&tty->read_wait); } clear_bit(TTY_FLUSHING, &tty->flags); spin_unlock_irqrestore(&tty->buf.lock, flags); tty_ldisc_deref(disc); } /** * tty_flip_buffer_push - terminal * @tty: tty to push * * Queue a push of the terminal flip buffers to the line discipline. This * function must not be called from IRQ context if tty->low_latency is set. * * In the event of the queue being busy for flipping the work will be * held off and retried later. * * Locking: tty buffer lock. Driver locks in low latency mode. */ void tty_flip_buffer_push(struct tty_struct *tty) { unsigned long flags; spin_lock_irqsave(&tty->buf.lock, flags); if (tty->buf.tail != NULL) tty->buf.tail->commit = tty->buf.tail->used; spin_unlock_irqrestore(&tty->buf.lock, flags); if (tty->low_latency) flush_to_ldisc(&tty->buf.work.work); else schedule_delayed_work(&tty->buf.work, 1); } EXPORT_SYMBOL(tty_flip_buffer_push); /** * initialize_tty_struct * @tty: tty to initialize * * This subroutine initializes a tty structure that has been newly * allocated. * * Locking: none - tty in question must not be exposed at this point */ static void initialize_tty_struct(struct tty_struct *tty) { memset(tty, 0, sizeof(struct tty_struct)); tty->magic = TTY_MAGIC; tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); tty->session = NULL; tty->pgrp = NULL; tty->overrun_time = jiffies; tty->buf.head = tty->buf.tail = NULL; tty_buffer_init(tty); INIT_DELAYED_WORK(&tty->buf.work, flush_to_ldisc); mutex_init(&tty->termios_mutex); init_waitqueue_head(&tty->write_wait); init_waitqueue_head(&tty->read_wait); INIT_WORK(&tty->hangup_work, do_tty_hangup); mutex_init(&tty->atomic_read_lock); mutex_init(&tty->atomic_write_lock); spin_lock_init(&tty->read_lock); INIT_LIST_HEAD(&tty->tty_files); INIT_WORK(&tty->SAK_work, do_SAK_work); } /* * The default put_char routine if the driver did not define one. */ static void tty_default_put_char(struct tty_struct *tty, unsigned char ch) { tty->driver->write(tty, &ch, 1); } static struct class *tty_class; /** * tty_register_device - register a tty device * @driver: the tty driver that describes the tty device * @index: the index in the tty driver for this tty device * @device: a struct device that is associated with this tty device. * This field is optional, if there is no known struct device * for this tty device it can be set to NULL safely. * * Returns a pointer to the struct device for this tty device * (or ERR_PTR(-EFOO) on error). * * This call is required to be made to register an individual tty device * if the tty driver's flags have the TTY_DRIVER_DYNAMIC_DEV bit set. If * that bit is not set, this function should not be called by a tty * driver. * * Locking: ?? */ struct device *tty_register_device(struct tty_driver *driver, unsigned index, struct device *device) { char name[64]; dev_t dev = MKDEV(driver->major, driver->minor_start) + index; if (index >= driver->num) { printk(KERN_ERR "Attempt to register invalid tty line number " " (%d).\n", index); return ERR_PTR(-EINVAL); } if (driver->type == TTY_DRIVER_TYPE_PTY) pty_line_name(driver, index, name); else tty_line_name(driver, index, name); return device_create(tty_class, device, dev, name); } /** * tty_unregister_device - unregister a tty device * @driver: the tty driver that describes the tty device * @index: the index in the tty driver for this tty device * * If a tty device is registered with a call to tty_register_device() then * this function must be called when the tty device is gone. * * Locking: ?? */ void tty_unregister_device(struct tty_driver *driver, unsigned index) { device_destroy(tty_class, MKDEV(driver->major, driver->minor_start) + index); } EXPORT_SYMBOL(tty_register_device); EXPORT_SYMBOL(tty_unregister_device); struct tty_driver *alloc_tty_driver(int lines) { struct tty_driver *driver; driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL); if (driver) { driver->magic = TTY_DRIVER_MAGIC; driver->num = lines; /* later we'll move allocation of tables here */ } return driver; } void put_tty_driver(struct tty_driver *driver) { kfree(driver); } void tty_set_operations(struct tty_driver *driver, const struct tty_operations *op) { driver->open = op->open; driver->close = op->close; driver->write = op->write; driver->put_char = op->put_char; driver->flush_chars = op->flush_chars; driver->write_room = op->write_room; driver->chars_in_buffer = op->chars_in_buffer; driver->ioctl = op->ioctl; driver->compat_ioctl = op->compat_ioctl; driver->set_termios = op->set_termios; driver->throttle = op->throttle; driver->unthrottle = op->unthrottle; driver->stop = op->stop; driver->start = op->start; driver->hangup = op->hangup; driver->break_ctl = op->break_ctl; driver->flush_buffer = op->flush_buffer; driver->set_ldisc = op->set_ldisc; driver->wait_until_sent = op->wait_until_sent; driver->send_xchar = op->send_xchar; driver->read_proc = op->read_proc; driver->write_proc = op->write_proc; driver->tiocmget = op->tiocmget; driver->tiocmset = op->tiocmset; #ifdef CONFIG_CONSOLE_POLL driver->poll_init = op->poll_init; driver->poll_get_char = op->poll_get_char; driver->poll_put_char = op->poll_put_char; #endif } EXPORT_SYMBOL(alloc_tty_driver); EXPORT_SYMBOL(put_tty_driver); EXPORT_SYMBOL(tty_set_operations); /* * Called by a tty driver to register itself. */ int tty_register_driver(struct tty_driver *driver) { int error; int i; dev_t dev; void **p = NULL; if (driver->flags & TTY_DRIVER_INSTALLED) return 0; if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM) && driver->num) { p = kzalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL); if (!p) return -ENOMEM; } if (!driver->major) { error = alloc_chrdev_region(&dev, driver->minor_start, driver->num, driver->name); if (!error) { driver->major = MAJOR(dev); driver->minor_start = MINOR(dev); } } else { dev = MKDEV(driver->major, driver->minor_start); error = register_chrdev_region(dev, driver->num, driver->name); } if (error < 0) { kfree(p); return error; } if (p) { driver->ttys = (struct tty_struct **)p; driver->termios = (struct ktermios **)(p + driver->num); driver->termios_locked = (struct ktermios **) (p + driver->num * 2); } else { driver->ttys = NULL; driver->termios = NULL; driver->termios_locked = NULL; } cdev_init(&driver->cdev, &tty_fops); driver->cdev.owner = driver->owner; error = cdev_add(&driver->cdev, dev, driver->num); if (error) { unregister_chrdev_region(dev, driver->num); driver->ttys = NULL; driver->termios = driver->termios_locked = NULL; kfree(p); return error; } if (!driver->put_char) driver->put_char = tty_default_put_char; mutex_lock(&tty_mutex); list_add(&driver->tty_drivers, &tty_drivers); mutex_unlock(&tty_mutex); if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV)) { for (i = 0; i < driver->num; i++) tty_register_device(driver, i, NULL); } proc_tty_register_driver(driver); return 0; } EXPORT_SYMBOL(tty_register_driver); /* * Called by a tty driver to unregister itself. */ int tty_unregister_driver(struct tty_driver *driver) { int i; struct ktermios *tp; void *p; if (driver->refcount) return -EBUSY; unregister_chrdev_region(MKDEV(driver->major, driver->minor_start), driver->num); mutex_lock(&tty_mutex); list_del(&driver->tty_drivers); mutex_unlock(&tty_mutex); /* * Free the termios and termios_locked structures because * we don't want to get memory leaks when modular tty * drivers are removed from the kernel. */ for (i = 0; i < driver->num; i++) { tp = driver->termios[i]; if (tp) { driver->termios[i] = NULL; kfree(tp); } tp = driver->termios_locked[i]; if (tp) { driver->termios_locked[i] = NULL; kfree(tp); } if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV)) tty_unregister_device(driver, i); } p = driver->ttys; proc_tty_unregister_driver(driver); driver->ttys = NULL; driver->termios = driver->termios_locked = NULL; kfree(p); cdev_del(&driver->cdev); return 0; } EXPORT_SYMBOL(tty_unregister_driver); dev_t tty_devnum(struct tty_struct *tty) { return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index; } EXPORT_SYMBOL(tty_devnum); void proc_clear_tty(struct task_struct *p) { spin_lock_irq(&p->sighand->siglock); p->signal->tty = NULL; spin_unlock_irq(&p->sighand->siglock); } EXPORT_SYMBOL(proc_clear_tty); static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) { if (tty) { /* We should not have a session or pgrp to here but.... */ put_pid(tty->session); put_pid(tty->pgrp); tty->session = get_pid(task_session(tsk)); tty->pgrp = get_pid(task_pgrp(tsk)); } put_pid(tsk->signal->tty_old_pgrp); tsk->signal->tty = tty; tsk->signal->tty_old_pgrp = NULL; } static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) { spin_lock_irq(&tsk->sighand->siglock); __proc_set_tty(tsk, tty); spin_unlock_irq(&tsk->sighand->siglock); } struct tty_struct *get_current_tty(void) { struct tty_struct *tty; WARN_ON_ONCE(!mutex_is_locked(&tty_mutex)); tty = current->signal->tty; /* * session->tty can be changed/cleared from under us, make sure we * issue the load. The obtained pointer, when not NULL, is valid as * long as we hold tty_mutex. */ barrier(); return tty; } EXPORT_SYMBOL_GPL(get_current_tty); /* * Initialize the console device. This is called *early*, so * we can't necessarily depend on lots of kernel help here. * Just do some early initializations, and do the complex setup * later. */ void __init console_init(void) { initcall_t *call; /* Setup the default TTY line discipline. */ (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY); /* * set up the console device so that later boot sequences can * inform about problems etc.. */ call = __con_initcall_start; while (call < __con_initcall_end) { (*call)(); call++; } } static int __init tty_class_init(void) { tty_class = class_create(THIS_MODULE, "tty"); if (IS_ERR(tty_class)) return PTR_ERR(tty_class); return 0; } postcore_initcall(tty_class_init); /* 3/2004 jmc: why do these devices exist? */ static struct cdev tty_cdev, console_cdev; #ifdef CONFIG_UNIX98_PTYS static struct cdev ptmx_cdev; #endif #ifdef CONFIG_VT static struct cdev vc0_cdev; #endif /* * Ok, now we can initialize the rest of the tty devices and can count * on memory allocations, interrupts etc.. */ static int __init tty_init(void) { cdev_init(&tty_cdev, &tty_fops); if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) || register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) panic("Couldn't register /dev/tty driver\n"); device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), "tty"); cdev_init(&console_cdev, &console_fops); if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) || register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0) panic("Couldn't register /dev/console driver\n"); device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), "console"); #ifdef CONFIG_UNIX98_PTYS cdev_init(&ptmx_cdev, &ptmx_fops); if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) || register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0) panic("Couldn't register /dev/ptmx driver\n"); device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), "ptmx"); #endif #ifdef CONFIG_VT cdev_init(&vc0_cdev, &console_fops); if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) || register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) panic("Couldn't register /dev/tty0 driver\n"); device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), "tty0"); vty_init(); #endif return 0; } module_init(tty_init);