aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2009-09-08 20:55:21 -0400
committerDan Williams <dan.j.williams@intel.com>2009-09-08 20:55:21 -0400
commitbbb20089a3275a19e475dbc21320c3742e3ca423 (patch)
tree216fdc1cbef450ca688135c5b8969169482d9a48 /drivers/char
parent3e48e656903e9fd8bc805c6a2c4264d7808d315b (diff)
parent657a77fa7284d8ae28dfa48f1dc5d919bf5b2843 (diff)
Merge branch 'dmaengine' into async-tx-next
Conflicts: crypto/async_tx/async_xor.c drivers/dma/ioat/dma_v2.h drivers/dma/ioat/pci.c drivers/md/raid5.c
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/Kconfig19
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/agp/agp.h12
-rw-r--r--drivers/char/agp/ali-agp.c28
-rw-r--r--drivers/char/agp/amd-k7-agp.c2
-rw-r--r--drivers/char/agp/amd64-agp.c2
-rw-r--r--drivers/char/agp/ati-agp.c23
-rw-r--r--drivers/char/agp/backend.c8
-rw-r--r--drivers/char/agp/efficeon-agp.c5
-rw-r--r--drivers/char/agp/generic.c69
-rw-r--r--drivers/char/agp/hp-agp.c14
-rw-r--r--drivers/char/agp/i460-agp.c47
-rw-r--r--drivers/char/agp/intel-agp.c65
-rw-r--r--drivers/char/agp/nvidia-agp.c2
-rw-r--r--drivers/char/agp/parisc-agp.c20
-rw-r--r--drivers/char/agp/sgi-agp.c9
-rw-r--r--drivers/char/agp/sworks-agp.c2
-rw-r--r--drivers/char/agp/uninorth-agp.c30
-rw-r--r--drivers/char/amiserial.c2
-rw-r--r--drivers/char/bfin_jtag_comm.c365
-rw-r--r--drivers/char/cyclades.c290
-rw-r--r--drivers/char/dtlk.c6
-rw-r--r--drivers/char/epca.c17
-rw-r--r--drivers/char/hpet.c4
-rw-r--r--drivers/char/hvc_iseries.c2
-rw-r--r--drivers/char/hvc_iucv.c204
-rw-r--r--drivers/char/hvc_vio.c2
-rw-r--r--drivers/char/hvcs.c8
-rw-r--r--drivers/char/hw_random/Kconfig27
-rw-r--r--drivers/char/hw_random/Makefile2
-rw-r--r--drivers/char/hw_random/core.c1
-rw-r--r--drivers/char/hw_random/mxc-rnga.c247
-rw-r--r--drivers/char/hw_random/omap-rng.c2
-rw-r--r--drivers/char/hw_random/timeriomem-rng.c26
-rw-r--r--drivers/char/hw_random/tx4939-rng.c184
-rw-r--r--drivers/char/hw_random/via-rng.c15
-rw-r--r--drivers/char/hw_random/virtio-rng.c30
-rw-r--r--drivers/char/ip2/i2lib.c4
-rw-r--r--drivers/char/ip2/ip2main.c4
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c4
-rw-r--r--drivers/char/isicom.c21
-rw-r--r--drivers/char/istallion.c10
-rw-r--r--drivers/char/keyboard.c2
-rw-r--r--drivers/char/mem.c120
-rw-r--r--drivers/char/misc.c15
-rw-r--r--drivers/char/moxa.c5
-rw-r--r--drivers/char/mxser.c14
-rw-r--r--drivers/char/n_hdlc.c46
-rw-r--r--drivers/char/n_r3964.c26
-rw-r--r--drivers/char/n_tty.c29
-rw-r--r--drivers/char/nozomi.c2
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c3
-rw-r--r--drivers/char/pcmcia/synclink_cs.c11
-rw-r--r--drivers/char/ppdev.c29
-rw-r--r--drivers/char/ps3flash.c296
-rw-r--r--drivers/char/pty.c56
-rw-r--r--drivers/char/raw.c8
-rw-r--r--drivers/char/rocket.c19
-rw-r--r--drivers/char/selection.c2
-rw-r--r--drivers/char/stallion.c6
-rw-r--r--drivers/char/synclink.c9
-rw-r--r--drivers/char/synclink_gt.c158
-rw-r--r--drivers/char/synclinkmp.c9
-rw-r--r--drivers/char/sysrq.c17
-rw-r--r--drivers/char/tty_audit.c10
-rw-r--r--drivers/char/tty_io.c124
-rw-r--r--drivers/char/tty_ioctl.c91
-rw-r--r--drivers/char/tty_ldisc.c556
-rw-r--r--drivers/char/tty_port.c49
-rw-r--r--drivers/char/viotape.c2
-rw-r--r--drivers/char/virtio_console.c26
-rw-r--r--drivers/char/vt.c21
-rw-r--r--drivers/char/vt_ioctl.c3
73 files changed, 2433 insertions, 1166 deletions
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 735bbe2be51a..0bd01f49cfd8 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -97,6 +97,19 @@ config DEVKMEM
97 kind of kernel debugging operations. 97 kind of kernel debugging operations.
98 When in doubt, say "N". 98 When in doubt, say "N".
99 99
100config BFIN_JTAG_COMM
101 tristate "Blackfin JTAG Communication"
102 depends on BLACKFIN
103 help
104 Add support for emulating a TTY device over the Blackfin JTAG.
105
106 To compile this driver as a module, choose M here: the
107 module will be called bfin_jtag_comm.
108
109config BFIN_JTAG_COMM_CONSOLE
110 bool "Console on Blackfin JTAG"
111 depends on BFIN_JTAG_COMM=y
112
100config SERIAL_NONSTANDARD 113config SERIAL_NONSTANDARD
101 bool "Non-standard serial port support" 114 bool "Non-standard serial port support"
102 depends on HAS_IOMEM 115 depends on HAS_IOMEM
@@ -679,7 +692,7 @@ config HVCS
679 this driver. 692 this driver.
680 693
681 To compile this driver as a module, choose M here: the 694 To compile this driver as a module, choose M here: the
682 module will be called hvcs.ko. Additionally, this module 695 module will be called hvcs. Additionally, this module
683 will depend on arch specific APIs exported from hvcserver.ko 696 will depend on arch specific APIs exported from hvcserver.ko
684 which will also be compiled when this driver is built as a 697 which will also be compiled when this driver is built as a
685 module. 698 module.
@@ -794,7 +807,7 @@ if RTC_LIB=n
794config RTC 807config RTC
795 tristate "Enhanced Real Time Clock Support (legacy PC RTC driver)" 808 tristate "Enhanced Real Time Clock Support (legacy PC RTC driver)"
796 depends on !PPC && !PARISC && !IA64 && !M68K && !SPARC && !FRV \ 809 depends on !PPC && !PARISC && !IA64 && !M68K && !SPARC && !FRV \
797 && !ARM && !SUPERH && !S390 && !AVR32 810 && !ARM && !SUPERH && !S390 && !AVR32 && !BLACKFIN
798 ---help--- 811 ---help---
799 If you say Y here and create a character special file /dev/rtc with 812 If you say Y here and create a character special file /dev/rtc with
800 major number 10 and minor number 135 using mknod ("man mknod"), you 813 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -893,7 +906,7 @@ config DTLK
893 906
894config XILINX_HWICAP 907config XILINX_HWICAP
895 tristate "Xilinx HWICAP Support" 908 tristate "Xilinx HWICAP Support"
896 depends on XILINX_VIRTEX 909 depends on XILINX_VIRTEX || MICROBLAZE
897 help 910 help
898 This option enables support for Xilinx Internal Configuration 911 This option enables support for Xilinx Internal Configuration
899 Access Port (ICAP) driver. The ICAP is used on Xilinx Virtex 912 Access Port (ICAP) driver. The ICAP is used on Xilinx Virtex
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 9caf5b5ad1c0..189efcff08ce 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_LEGACY_PTYS) += pty.o
13obj-$(CONFIG_UNIX98_PTYS) += pty.o 13obj-$(CONFIG_UNIX98_PTYS) += pty.o
14obj-y += misc.o 14obj-y += misc.o
15obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o 15obj-$(CONFIG_VT) += vt_ioctl.o vc_screen.o selection.o keyboard.o
16obj-$(CONFIG_BFIN_JTAG_COMM) += bfin_jtag_comm.o
16obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o 17obj-$(CONFIG_CONSOLE_TRANSLATIONS) += consolemap.o consolemap_deftbl.o
17obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o 18obj-$(CONFIG_HW_CONSOLE) += vt.o defkeymap.o
18obj-$(CONFIG_AUDIT) += tty_audit.o 19obj-$(CONFIG_AUDIT) += tty_audit.o
diff --git a/drivers/char/agp/agp.h b/drivers/char/agp/agp.h
index 46f507531177..178e2e9e9f09 100644
--- a/drivers/char/agp/agp.h
+++ b/drivers/char/agp/agp.h
@@ -107,7 +107,7 @@ struct agp_bridge_driver {
107 void (*agp_enable)(struct agp_bridge_data *, u32); 107 void (*agp_enable)(struct agp_bridge_data *, u32);
108 void (*cleanup)(void); 108 void (*cleanup)(void);
109 void (*tlb_flush)(struct agp_memory *); 109 void (*tlb_flush)(struct agp_memory *);
110 unsigned long (*mask_memory)(struct agp_bridge_data *, unsigned long, int); 110 unsigned long (*mask_memory)(struct agp_bridge_data *, struct page *, int);
111 void (*cache_flush)(void); 111 void (*cache_flush)(void);
112 int (*create_gatt_table)(struct agp_bridge_data *); 112 int (*create_gatt_table)(struct agp_bridge_data *);
113 int (*free_gatt_table)(struct agp_bridge_data *); 113 int (*free_gatt_table)(struct agp_bridge_data *);
@@ -115,9 +115,9 @@ struct agp_bridge_driver {
115 int (*remove_memory)(struct agp_memory *, off_t, int); 115 int (*remove_memory)(struct agp_memory *, off_t, int);
116 struct agp_memory *(*alloc_by_type) (size_t, int); 116 struct agp_memory *(*alloc_by_type) (size_t, int);
117 void (*free_by_type)(struct agp_memory *); 117 void (*free_by_type)(struct agp_memory *);
118 void *(*agp_alloc_page)(struct agp_bridge_data *); 118 struct page *(*agp_alloc_page)(struct agp_bridge_data *);
119 int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t); 119 int (*agp_alloc_pages)(struct agp_bridge_data *, struct agp_memory *, size_t);
120 void (*agp_destroy_page)(void *, int flags); 120 void (*agp_destroy_page)(struct page *, int flags);
121 void (*agp_destroy_pages)(struct agp_memory *); 121 void (*agp_destroy_pages)(struct agp_memory *);
122 int (*agp_type_to_mask_type) (struct agp_bridge_data *, int); 122 int (*agp_type_to_mask_type) (struct agp_bridge_data *, int);
123 void (*chipset_flush)(struct agp_bridge_data *); 123 void (*chipset_flush)(struct agp_bridge_data *);
@@ -278,10 +278,10 @@ int agp_generic_insert_memory(struct agp_memory *mem, off_t pg_start, int type);
278int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type); 278int agp_generic_remove_memory(struct agp_memory *mem, off_t pg_start, int type);
279struct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type); 279struct agp_memory *agp_generic_alloc_by_type(size_t page_count, int type);
280void agp_generic_free_by_type(struct agp_memory *curr); 280void agp_generic_free_by_type(struct agp_memory *curr);
281void *agp_generic_alloc_page(struct agp_bridge_data *bridge); 281struct page *agp_generic_alloc_page(struct agp_bridge_data *bridge);
282int agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge, 282int agp_generic_alloc_pages(struct agp_bridge_data *agp_bridge,
283 struct agp_memory *memory, size_t page_count); 283 struct agp_memory *memory, size_t page_count);
284void agp_generic_destroy_page(void *addr, int flags); 284void agp_generic_destroy_page(struct page *page, int flags);
285void agp_generic_destroy_pages(struct agp_memory *memory); 285void agp_generic_destroy_pages(struct agp_memory *memory);
286void agp_free_key(int key); 286void agp_free_key(int key);
287int agp_num_entries(void); 287int agp_num_entries(void);
@@ -291,7 +291,7 @@ int agp_3_5_enable(struct agp_bridge_data *bridge);
291void global_cache_flush(void); 291void global_cache_flush(void);
292void get_agp_version(struct agp_bridge_data *bridge); 292void get_agp_version(struct agp_bridge_data *bridge);
293unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge, 293unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
294 unsigned long addr, int type); 294 struct page *page, int type);
295int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge, 295int agp_generic_type_to_mask_type(struct agp_bridge_data *bridge,
296 int type); 296 int type);
297struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev); 297struct agp_bridge_data *agp_generic_find_bridge(struct pci_dev *pdev);
diff --git a/drivers/char/agp/ali-agp.c b/drivers/char/agp/ali-agp.c
index dc8d1a90971f..201ef3ffd484 100644
--- a/drivers/char/agp/ali-agp.c
+++ b/drivers/char/agp/ali-agp.c
@@ -141,37 +141,37 @@ static void m1541_cache_flush(void)
141 } 141 }
142} 142}
143 143
144static void *m1541_alloc_page(struct agp_bridge_data *bridge) 144static struct page *m1541_alloc_page(struct agp_bridge_data *bridge)
145{ 145{
146 void *addr = agp_generic_alloc_page(agp_bridge); 146 struct page *page = agp_generic_alloc_page(agp_bridge);
147 u32 temp; 147 u32 temp;
148 148
149 if (!addr) 149 if (!page)
150 return NULL; 150 return NULL;
151 151
152 pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp); 152 pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp);
153 pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, 153 pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL,
154 (((temp & ALI_CACHE_FLUSH_ADDR_MASK) | 154 (((temp & ALI_CACHE_FLUSH_ADDR_MASK) |
155 virt_to_gart(addr)) | ALI_CACHE_FLUSH_EN )); 155 phys_to_gart(page_to_phys(page))) | ALI_CACHE_FLUSH_EN ));
156 return addr; 156 return page;
157} 157}
158 158
159static void ali_destroy_page(void * addr, int flags) 159static void ali_destroy_page(struct page *page, int flags)
160{ 160{
161 if (addr) { 161 if (page) {
162 if (flags & AGP_PAGE_DESTROY_UNMAP) { 162 if (flags & AGP_PAGE_DESTROY_UNMAP) {
163 global_cache_flush(); /* is this really needed? --hch */ 163 global_cache_flush(); /* is this really needed? --hch */
164 agp_generic_destroy_page(addr, flags); 164 agp_generic_destroy_page(page, flags);
165 } else 165 } else
166 agp_generic_destroy_page(addr, flags); 166 agp_generic_destroy_page(page, flags);
167 } 167 }
168} 168}
169 169
170static void m1541_destroy_page(void * addr, int flags) 170static void m1541_destroy_page(struct page *page, int flags)
171{ 171{
172 u32 temp; 172 u32 temp;
173 173
174 if (addr == NULL) 174 if (page == NULL)
175 return; 175 return;
176 176
177 if (flags & AGP_PAGE_DESTROY_UNMAP) { 177 if (flags & AGP_PAGE_DESTROY_UNMAP) {
@@ -180,9 +180,9 @@ static void m1541_destroy_page(void * addr, int flags)
180 pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp); 180 pci_read_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, &temp);
181 pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL, 181 pci_write_config_dword(agp_bridge->dev, ALI_CACHE_FLUSH_CTRL,
182 (((temp & ALI_CACHE_FLUSH_ADDR_MASK) | 182 (((temp & ALI_CACHE_FLUSH_ADDR_MASK) |
183 virt_to_gart(addr)) | ALI_CACHE_FLUSH_EN)); 183 phys_to_gart(page_to_phys(page))) | ALI_CACHE_FLUSH_EN));
184 } 184 }
185 agp_generic_destroy_page(addr, flags); 185 agp_generic_destroy_page(page, flags);
186} 186}
187 187
188 188
@@ -346,7 +346,7 @@ found:
346 devs[j].chipset_name = "M1641"; 346 devs[j].chipset_name = "M1641";
347 break; 347 break;
348 case 0x43: 348 case 0x43:
349 devs[j].chipset_name = "M????"; 349 devs[j].chipset_name = "M1621";
350 break; 350 break;
351 case 0x47: 351 case 0x47:
352 devs[j].chipset_name = "M1647"; 352 devs[j].chipset_name = "M1647";
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
index 3f98254b911f..ba9bde71eaaf 100644
--- a/drivers/char/agp/amd-k7-agp.c
+++ b/drivers/char/agp/amd-k7-agp.c
@@ -325,7 +325,7 @@ static int amd_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
325 addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr; 325 addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr;
326 cur_gatt = GET_GATT(addr); 326 cur_gatt = GET_GATT(addr);
327 writel(agp_generic_mask_memory(agp_bridge, 327 writel(agp_generic_mask_memory(agp_bridge,
328 mem->memory[i], mem->type), cur_gatt+GET_GATT_OFF(addr)); 328 mem->pages[i], mem->type), cur_gatt+GET_GATT_OFF(addr));
329 readl(cur_gatt+GET_GATT_OFF(addr)); /* PCI Posting. */ 329 readl(cur_gatt+GET_GATT_OFF(addr)); /* PCI Posting. */
330 } 330 }
331 amd_irongate_tlbflush(mem); 331 amd_irongate_tlbflush(mem);
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index d765afda9c2a..3bf5dda90f4a 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -79,7 +79,7 @@ static int amd64_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
79 79
80 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 80 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
81 tmp = agp_bridge->driver->mask_memory(agp_bridge, 81 tmp = agp_bridge->driver->mask_memory(agp_bridge,
82 mem->memory[i], mask_type); 82 mem->pages[i], mask_type);
83 83
84 BUG_ON(tmp & 0xffffff0000000ffcULL); 84 BUG_ON(tmp & 0xffffff0000000ffcULL);
85 pte = (tmp & 0x000000ff00000000ULL) >> 28; 85 pte = (tmp & 0x000000ff00000000ULL) >> 28;
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index f1537eece07f..33656e144cc5 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -269,12 +269,17 @@ static int ati_insert_memory(struct agp_memory * mem,
269 int i, j, num_entries; 269 int i, j, num_entries;
270 unsigned long __iomem *cur_gatt; 270 unsigned long __iomem *cur_gatt;
271 unsigned long addr; 271 unsigned long addr;
272 int mask_type;
272 273
273 num_entries = A_SIZE_LVL2(agp_bridge->current_size)->num_entries; 274 num_entries = A_SIZE_LVL2(agp_bridge->current_size)->num_entries;
274 275
275 if (type != 0 || mem->type != 0) 276 mask_type = agp_generic_type_to_mask_type(mem->bridge, type);
277 if (mask_type != 0 || type != mem->type)
276 return -EINVAL; 278 return -EINVAL;
277 279
280 if (mem->page_count == 0)
281 return 0;
282
278 if ((pg_start + mem->page_count) > num_entries) 283 if ((pg_start + mem->page_count) > num_entries)
279 return -EINVAL; 284 return -EINVAL;
280 285
@@ -296,10 +301,11 @@ static int ati_insert_memory(struct agp_memory * mem,
296 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 301 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
297 addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr; 302 addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr;
298 cur_gatt = GET_GATT(addr); 303 cur_gatt = GET_GATT(addr);
299 writel(agp_bridge->driver->mask_memory(agp_bridge, 304 writel(agp_bridge->driver->mask_memory(agp_bridge,
300 mem->memory[i], mem->type), cur_gatt+GET_GATT_OFF(addr)); 305 mem->pages[i], mem->type),
301 readl(cur_gatt+GET_GATT_OFF(addr)); /* PCI Posting. */ 306 cur_gatt+GET_GATT_OFF(addr));
302 } 307 }
308 readl(GET_GATT(agp_bridge->gart_bus_addr)); /* PCI posting */
303 agp_bridge->driver->tlb_flush(mem); 309 agp_bridge->driver->tlb_flush(mem);
304 return 0; 310 return 0;
305} 311}
@@ -310,17 +316,22 @@ static int ati_remove_memory(struct agp_memory * mem, off_t pg_start,
310 int i; 316 int i;
311 unsigned long __iomem *cur_gatt; 317 unsigned long __iomem *cur_gatt;
312 unsigned long addr; 318 unsigned long addr;
319 int mask_type;
313 320
314 if (type != 0 || mem->type != 0) 321 mask_type = agp_generic_type_to_mask_type(mem->bridge, type);
322 if (mask_type != 0 || type != mem->type)
315 return -EINVAL; 323 return -EINVAL;
316 324
325 if (mem->page_count == 0)
326 return 0;
327
317 for (i = pg_start; i < (mem->page_count + pg_start); i++) { 328 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
318 addr = (i * PAGE_SIZE) + agp_bridge->gart_bus_addr; 329 addr = (i * PAGE_SIZE) + agp_bridge->gart_bus_addr;
319 cur_gatt = GET_GATT(addr); 330 cur_gatt = GET_GATT(addr);
320 writel(agp_bridge->scratch_page, cur_gatt+GET_GATT_OFF(addr)); 331 writel(agp_bridge->scratch_page, cur_gatt+GET_GATT_OFF(addr));
321 readl(cur_gatt+GET_GATT_OFF(addr)); /* PCI Posting. */
322 } 332 }
323 333
334 readl(GET_GATT(agp_bridge->gart_bus_addr)); /* PCI posting */
324 agp_bridge->driver->tlb_flush(mem); 335 agp_bridge->driver->tlb_flush(mem);
325 return 0; 336 return 0;
326} 337}
diff --git a/drivers/char/agp/backend.c b/drivers/char/agp/backend.c
index 8c617ad7497f..cfa5a649dfe7 100644
--- a/drivers/char/agp/backend.c
+++ b/drivers/char/agp/backend.c
@@ -141,17 +141,17 @@ static int agp_backend_initialize(struct agp_bridge_data *bridge)
141 bridge->version = &agp_current_version; 141 bridge->version = &agp_current_version;
142 142
143 if (bridge->driver->needs_scratch_page) { 143 if (bridge->driver->needs_scratch_page) {
144 void *addr = bridge->driver->agp_alloc_page(bridge); 144 struct page *page = bridge->driver->agp_alloc_page(bridge);
145 145
146 if (!addr) { 146 if (!page) {
147 dev_err(&bridge->dev->dev, 147 dev_err(&bridge->dev->dev,
148 "can't get memory for scratch page\n"); 148 "can't get memory for scratch page\n");
149 return -ENOMEM; 149 return -ENOMEM;
150 } 150 }
151 151
152 bridge->scratch_page_real = virt_to_gart(addr); 152 bridge->scratch_page_real = phys_to_gart(page_to_phys(page));
153 bridge->scratch_page = 153 bridge->scratch_page =
154 bridge->driver->mask_memory(bridge, bridge->scratch_page_real, 0); 154 bridge->driver->mask_memory(bridge, page, 0);
155 } 155 }
156 156
157 size_value = bridge->driver->fetch_size(); 157 size_value = bridge->driver->fetch_size();
diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-agp.c
index 453543a1f293..35d50f2861b6 100644
--- a/drivers/char/agp/efficeon-agp.c
+++ b/drivers/char/agp/efficeon-agp.c
@@ -65,8 +65,9 @@ static const struct gatt_mask efficeon_generic_masks[] =
65}; 65};
66 66
67/* This function does the same thing as mask_memory() for this chipset... */ 67/* This function does the same thing as mask_memory() for this chipset... */
68static inline unsigned long efficeon_mask_memory(unsigned long addr) 68static inline unsigned long efficeon_mask_memory(struct page *page)
69{ 69{
70 unsigned long addr = phys_to_gart(page_to_phys(page));
70 return addr | 0x00000001; 71 return addr | 0x00000001;
71} 72}
72 73
@@ -257,7 +258,7 @@ static int efficeon_insert_memory(struct agp_memory * mem, off_t pg_start, int t
257 last_page = NULL; 258 last_page = NULL;
258 for (i = 0; i < count; i++) { 259 for (i = 0; i < count; i++) {
259 int index = pg_start + i; 260 int index = pg_start + i;
260 unsigned long insert = efficeon_mask_memory(mem->memory[i]); 261 unsigned long insert = efficeon_mask_memory(mem->pages[i]);
261 262
262 page = (unsigned int *) efficeon_private.l1_table[index >> 10]; 263 page = (unsigned int *) efficeon_private.l1_table[index >> 10];
263 264
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index 2224b762b7fb..1e8b461b91f1 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -95,13 +95,13 @@ EXPORT_SYMBOL(agp_flush_chipset);
95 95
96void agp_alloc_page_array(size_t size, struct agp_memory *mem) 96void agp_alloc_page_array(size_t size, struct agp_memory *mem)
97{ 97{
98 mem->memory = NULL; 98 mem->pages = NULL;
99 mem->vmalloc_flag = false; 99 mem->vmalloc_flag = false;
100 100
101 if (size <= 2*PAGE_SIZE) 101 if (size <= 2*PAGE_SIZE)
102 mem->memory = kmalloc(size, GFP_KERNEL | __GFP_NORETRY); 102 mem->pages = kmalloc(size, GFP_KERNEL | __GFP_NORETRY);
103 if (mem->memory == NULL) { 103 if (mem->pages == NULL) {
104 mem->memory = vmalloc(size); 104 mem->pages = vmalloc(size);
105 mem->vmalloc_flag = true; 105 mem->vmalloc_flag = true;
106 } 106 }
107} 107}
@@ -110,9 +110,9 @@ EXPORT_SYMBOL(agp_alloc_page_array);
110void agp_free_page_array(struct agp_memory *mem) 110void agp_free_page_array(struct agp_memory *mem)
111{ 111{
112 if (mem->vmalloc_flag) { 112 if (mem->vmalloc_flag) {
113 vfree(mem->memory); 113 vfree(mem->pages);
114 } else { 114 } else {
115 kfree(mem->memory); 115 kfree(mem->pages);
116 } 116 }
117} 117}
118EXPORT_SYMBOL(agp_free_page_array); 118EXPORT_SYMBOL(agp_free_page_array);
@@ -136,7 +136,7 @@ static struct agp_memory *agp_create_user_memory(unsigned long num_agp_pages)
136 136
137 agp_alloc_page_array(alloc_size, new); 137 agp_alloc_page_array(alloc_size, new);
138 138
139 if (new->memory == NULL) { 139 if (new->pages == NULL) {
140 agp_free_key(new->key); 140 agp_free_key(new->key);
141 kfree(new); 141 kfree(new);
142 return NULL; 142 return NULL;
@@ -162,7 +162,7 @@ struct agp_memory *agp_create_memory(int scratch_pages)
162 162
163 agp_alloc_page_array(PAGE_SIZE * scratch_pages, new); 163 agp_alloc_page_array(PAGE_SIZE * scratch_pages, new);
164 164
165 if (new->memory == NULL) { 165 if (new->pages == NULL) {
166 agp_free_key(new->key); 166 agp_free_key(new->key);
167 kfree(new); 167 kfree(new);
168 return NULL; 168 return NULL;
@@ -206,15 +206,13 @@ void agp_free_memory(struct agp_memory *curr)
206 } else { 206 } else {
207 207
208 for (i = 0; i < curr->page_count; i++) { 208 for (i = 0; i < curr->page_count; i++) {
209 curr->memory[i] = (unsigned long)gart_to_virt(
210 curr->memory[i]);
211 curr->bridge->driver->agp_destroy_page( 209 curr->bridge->driver->agp_destroy_page(
212 (void *)curr->memory[i], 210 curr->pages[i],
213 AGP_PAGE_DESTROY_UNMAP); 211 AGP_PAGE_DESTROY_UNMAP);
214 } 212 }
215 for (i = 0; i < curr->page_count; i++) { 213 for (i = 0; i < curr->page_count; i++) {
216 curr->bridge->driver->agp_destroy_page( 214 curr->bridge->driver->agp_destroy_page(
217 (void *)curr->memory[i], 215 curr->pages[i],
218 AGP_PAGE_DESTROY_FREE); 216 AGP_PAGE_DESTROY_FREE);
219 } 217 }
220 } 218 }
@@ -282,13 +280,13 @@ struct agp_memory *agp_allocate_memory(struct agp_bridge_data *bridge,
282 } 280 }
283 281
284 for (i = 0; i < page_count; i++) { 282 for (i = 0; i < page_count; i++) {
285 void *addr = bridge->driver->agp_alloc_page(bridge); 283 struct page *page = bridge->driver->agp_alloc_page(bridge);
286 284
287 if (addr == NULL) { 285 if (page == NULL) {
288 agp_free_memory(new); 286 agp_free_memory(new);
289 return NULL; 287 return NULL;
290 } 288 }
291 new->memory[i] = virt_to_gart(addr); 289 new->pages[i] = page;
292 new->page_count++; 290 new->page_count++;
293 } 291 }
294 new->bridge = bridge; 292 new->bridge = bridge;
@@ -1134,7 +1132,7 @@ int agp_generic_insert_memory(struct agp_memory * mem, off_t pg_start, int type)
1134 } 1132 }
1135 1133
1136 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 1134 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
1137 writel(bridge->driver->mask_memory(bridge, mem->memory[i], mask_type), 1135 writel(bridge->driver->mask_memory(bridge, mem->pages[i], mask_type),
1138 bridge->gatt_table+j); 1136 bridge->gatt_table+j);
1139 } 1137 }
1140 readl(bridge->gatt_table+j-1); /* PCI Posting. */ 1138 readl(bridge->gatt_table+j-1); /* PCI Posting. */
@@ -1204,7 +1202,7 @@ struct agp_memory *agp_generic_alloc_user(size_t page_count, int type)
1204 return NULL; 1202 return NULL;
1205 1203
1206 for (i = 0; i < page_count; i++) 1204 for (i = 0; i < page_count; i++)
1207 new->memory[i] = 0; 1205 new->pages[i] = 0;
1208 new->page_count = 0; 1206 new->page_count = 0;
1209 new->type = type; 1207 new->type = type;
1210 new->num_scratch_pages = pages; 1208 new->num_scratch_pages = pages;
@@ -1237,23 +1235,20 @@ int agp_generic_alloc_pages(struct agp_bridge_data *bridge, struct agp_memory *m
1237 get_page(page); 1235 get_page(page);
1238 atomic_inc(&agp_bridge->current_memory_agp); 1236 atomic_inc(&agp_bridge->current_memory_agp);
1239 1237
1240 /* set_memory_array_uc() needs virtual address */ 1238 mem->pages[i] = page;
1241 mem->memory[i] = (unsigned long)page_address(page);
1242 mem->page_count++; 1239 mem->page_count++;
1243 } 1240 }
1244 1241
1245#ifdef CONFIG_X86 1242#ifdef CONFIG_X86
1246 set_memory_array_uc(mem->memory, num_pages); 1243 set_pages_array_uc(mem->pages, num_pages);
1247#endif 1244#endif
1248 ret = 0; 1245 ret = 0;
1249out: 1246out:
1250 for (i = 0; i < mem->page_count; i++)
1251 mem->memory[i] = virt_to_gart((void *)mem->memory[i]);
1252 return ret; 1247 return ret;
1253} 1248}
1254EXPORT_SYMBOL(agp_generic_alloc_pages); 1249EXPORT_SYMBOL(agp_generic_alloc_pages);
1255 1250
1256void *agp_generic_alloc_page(struct agp_bridge_data *bridge) 1251struct page *agp_generic_alloc_page(struct agp_bridge_data *bridge)
1257{ 1252{
1258 struct page * page; 1253 struct page * page;
1259 1254
@@ -1265,56 +1260,47 @@ void *agp_generic_alloc_page(struct agp_bridge_data *bridge)
1265 1260
1266 get_page(page); 1261 get_page(page);
1267 atomic_inc(&agp_bridge->current_memory_agp); 1262 atomic_inc(&agp_bridge->current_memory_agp);
1268 return page_address(page); 1263 return page;
1269} 1264}
1270EXPORT_SYMBOL(agp_generic_alloc_page); 1265EXPORT_SYMBOL(agp_generic_alloc_page);
1271 1266
1272void agp_generic_destroy_pages(struct agp_memory *mem) 1267void agp_generic_destroy_pages(struct agp_memory *mem)
1273{ 1268{
1274 int i; 1269 int i;
1275 void *addr;
1276 struct page *page; 1270 struct page *page;
1277 1271
1278 if (!mem) 1272 if (!mem)
1279 return; 1273 return;
1280 1274
1281 for (i = 0; i < mem->page_count; i++)
1282 mem->memory[i] = (unsigned long)gart_to_virt(mem->memory[i]);
1283
1284#ifdef CONFIG_X86 1275#ifdef CONFIG_X86
1285 set_memory_array_wb(mem->memory, mem->page_count); 1276 set_pages_array_wb(mem->pages, mem->page_count);
1286#endif 1277#endif
1287 1278
1288 for (i = 0; i < mem->page_count; i++) { 1279 for (i = 0; i < mem->page_count; i++) {
1289 addr = (void *)mem->memory[i]; 1280 page = mem->pages[i];
1290 page = virt_to_page(addr);
1291 1281
1292#ifndef CONFIG_X86 1282#ifndef CONFIG_X86
1293 unmap_page_from_agp(page); 1283 unmap_page_from_agp(page);
1294#endif 1284#endif
1295
1296 put_page(page); 1285 put_page(page);
1297 free_page((unsigned long)addr); 1286 __free_page(page);
1298 atomic_dec(&agp_bridge->current_memory_agp); 1287 atomic_dec(&agp_bridge->current_memory_agp);
1299 mem->memory[i] = 0; 1288 mem->pages[i] = NULL;
1300 } 1289 }
1301} 1290}
1302EXPORT_SYMBOL(agp_generic_destroy_pages); 1291EXPORT_SYMBOL(agp_generic_destroy_pages);
1303 1292
1304void agp_generic_destroy_page(void *addr, int flags) 1293void agp_generic_destroy_page(struct page *page, int flags)
1305{ 1294{
1306 struct page *page; 1295 if (page == NULL)
1307
1308 if (addr == NULL)
1309 return; 1296 return;
1310 1297
1311 page = virt_to_page(addr);
1312 if (flags & AGP_PAGE_DESTROY_UNMAP) 1298 if (flags & AGP_PAGE_DESTROY_UNMAP)
1313 unmap_page_from_agp(page); 1299 unmap_page_from_agp(page);
1314 1300
1315 if (flags & AGP_PAGE_DESTROY_FREE) { 1301 if (flags & AGP_PAGE_DESTROY_FREE) {
1316 put_page(page); 1302 put_page(page);
1317 free_page((unsigned long)addr); 1303 __free_page(page);
1318 atomic_dec(&agp_bridge->current_memory_agp); 1304 atomic_dec(&agp_bridge->current_memory_agp);
1319 } 1305 }
1320} 1306}
@@ -1361,8 +1347,9 @@ void global_cache_flush(void)
1361EXPORT_SYMBOL(global_cache_flush); 1347EXPORT_SYMBOL(global_cache_flush);
1362 1348
1363unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge, 1349unsigned long agp_generic_mask_memory(struct agp_bridge_data *bridge,
1364 unsigned long addr, int type) 1350 struct page *page, int type)
1365{ 1351{
1352 unsigned long addr = phys_to_gart(page_to_phys(page));
1366 /* memory type is ignored in the generic routine */ 1353 /* memory type is ignored in the generic routine */
1367 if (bridge->driver->masks) 1354 if (bridge->driver->masks)
1368 return addr | bridge->driver->masks[0].mask; 1355 return addr | bridge->driver->masks[0].mask;
diff --git a/drivers/char/agp/hp-agp.c b/drivers/char/agp/hp-agp.c
index 183ac3fe44fb..8f3d4c184914 100644
--- a/drivers/char/agp/hp-agp.c
+++ b/drivers/char/agp/hp-agp.c
@@ -361,13 +361,11 @@ hp_zx1_insert_memory (struct agp_memory *mem, off_t pg_start, int type)
361 for (i = 0, j = io_pg_start; i < mem->page_count; i++) { 361 for (i = 0, j = io_pg_start; i < mem->page_count; i++) {
362 unsigned long paddr; 362 unsigned long paddr;
363 363
364 paddr = mem->memory[i]; 364 paddr = page_to_phys(mem->pages[i]);
365 for (k = 0; 365 for (k = 0;
366 k < hp->io_pages_per_kpage; 366 k < hp->io_pages_per_kpage;
367 k++, j++, paddr += hp->io_page_size) { 367 k++, j++, paddr += hp->io_page_size) {
368 hp->gatt[j] = 368 hp->gatt[j] = HP_ZX1_PDIR_VALID_BIT | paddr;
369 agp_bridge->driver->mask_memory(agp_bridge,
370 paddr, type);
371 } 369 }
372 } 370 }
373 371
@@ -397,8 +395,9 @@ hp_zx1_remove_memory (struct agp_memory *mem, off_t pg_start, int type)
397 395
398static unsigned long 396static unsigned long
399hp_zx1_mask_memory (struct agp_bridge_data *bridge, 397hp_zx1_mask_memory (struct agp_bridge_data *bridge,
400 unsigned long addr, int type) 398 struct page *page, int type)
401{ 399{
400 unsigned long addr = phys_to_gart(page_to_phys(page));
402 return HP_ZX1_PDIR_VALID_BIT | addr; 401 return HP_ZX1_PDIR_VALID_BIT | addr;
403} 402}
404 403
@@ -518,8 +517,9 @@ zx1_gart_probe (acpi_handle obj, u32 depth, void *context, void **ret)
518 if (hp_zx1_setup(sba_hpa + HP_ZX1_IOC_OFFSET, lba_hpa)) 517 if (hp_zx1_setup(sba_hpa + HP_ZX1_IOC_OFFSET, lba_hpa))
519 return AE_OK; 518 return AE_OK;
520 519
521 printk(KERN_INFO PFX "Detected HP ZX1 %s AGP chipset (ioc=%lx, lba=%lx)\n", 520 printk(KERN_INFO PFX "Detected HP ZX1 %s AGP chipset "
522 (char *) context, sba_hpa + HP_ZX1_IOC_OFFSET, lba_hpa); 521 "(ioc=%llx, lba=%llx)\n", (char *)context,
522 sba_hpa + HP_ZX1_IOC_OFFSET, lba_hpa);
523 523
524 hp_zx1_gart_found = 1; 524 hp_zx1_gart_found = 1;
525 return AE_CTRL_TERMINATE; /* we only support one bridge; quit looking */ 525 return AE_CTRL_TERMINATE; /* we only support one bridge; quit looking */
diff --git a/drivers/char/agp/i460-agp.c b/drivers/char/agp/i460-agp.c
index 10da687d131a..60cc35bb5db7 100644
--- a/drivers/char/agp/i460-agp.c
+++ b/drivers/char/agp/i460-agp.c
@@ -60,6 +60,9 @@
60 */ 60 */
61#define WR_FLUSH_GATT(index) RD_GATT(index) 61#define WR_FLUSH_GATT(index) RD_GATT(index)
62 62
63static unsigned long i460_mask_memory (struct agp_bridge_data *bridge,
64 unsigned long addr, int type);
65
63static struct { 66static struct {
64 void *gatt; /* ioremap'd GATT area */ 67 void *gatt; /* ioremap'd GATT area */
65 68
@@ -74,6 +77,7 @@ static struct {
74 unsigned long *alloced_map; /* bitmap of kernel-pages in use */ 77 unsigned long *alloced_map; /* bitmap of kernel-pages in use */
75 int refcount; /* number of kernel pages using the large page */ 78 int refcount; /* number of kernel pages using the large page */
76 u64 paddr; /* physical address of large page */ 79 u64 paddr; /* physical address of large page */
80 struct page *page; /* page pointer */
77 } *lp_desc; 81 } *lp_desc;
78} i460; 82} i460;
79 83
@@ -294,7 +298,7 @@ static int i460_insert_memory_small_io_page (struct agp_memory *mem,
294 void *temp; 298 void *temp;
295 299
296 pr_debug("i460_insert_memory_small_io_page(mem=%p, pg_start=%ld, type=%d, paddr0=0x%lx)\n", 300 pr_debug("i460_insert_memory_small_io_page(mem=%p, pg_start=%ld, type=%d, paddr0=0x%lx)\n",
297 mem, pg_start, type, mem->memory[0]); 301 mem, pg_start, type, page_to_phys(mem->pages[0]));
298 302
299 if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES) 303 if (type >= AGP_USER_TYPES || mem->type >= AGP_USER_TYPES)
300 return -EINVAL; 304 return -EINVAL;
@@ -321,10 +325,9 @@ static int i460_insert_memory_small_io_page (struct agp_memory *mem,
321 325
322 io_page_size = 1UL << I460_IO_PAGE_SHIFT; 326 io_page_size = 1UL << I460_IO_PAGE_SHIFT;
323 for (i = 0, j = io_pg_start; i < mem->page_count; i++) { 327 for (i = 0, j = io_pg_start; i < mem->page_count; i++) {
324 paddr = mem->memory[i]; 328 paddr = phys_to_gart(page_to_phys(mem->pages[i]));
325 for (k = 0; k < I460_IOPAGES_PER_KPAGE; k++, j++, paddr += io_page_size) 329 for (k = 0; k < I460_IOPAGES_PER_KPAGE; k++, j++, paddr += io_page_size)
326 WR_GATT(j, agp_bridge->driver->mask_memory(agp_bridge, 330 WR_GATT(j, i460_mask_memory(agp_bridge, paddr, mem->type));
327 paddr, mem->type));
328 } 331 }
329 WR_FLUSH_GATT(j - 1); 332 WR_FLUSH_GATT(j - 1);
330 return 0; 333 return 0;
@@ -364,10 +367,9 @@ static int i460_alloc_large_page (struct lp_desc *lp)
364{ 367{
365 unsigned long order = I460_IO_PAGE_SHIFT - PAGE_SHIFT; 368 unsigned long order = I460_IO_PAGE_SHIFT - PAGE_SHIFT;
366 size_t map_size; 369 size_t map_size;
367 void *lpage;
368 370
369 lpage = (void *) __get_free_pages(GFP_KERNEL, order); 371 lp->page = alloc_pages(GFP_KERNEL, order);
370 if (!lpage) { 372 if (!lp->page) {
371 printk(KERN_ERR PFX "Couldn't alloc 4M GART page...\n"); 373 printk(KERN_ERR PFX "Couldn't alloc 4M GART page...\n");
372 return -ENOMEM; 374 return -ENOMEM;
373 } 375 }
@@ -375,12 +377,12 @@ static int i460_alloc_large_page (struct lp_desc *lp)
375 map_size = ((I460_KPAGES_PER_IOPAGE + BITS_PER_LONG - 1) & -BITS_PER_LONG)/8; 377 map_size = ((I460_KPAGES_PER_IOPAGE + BITS_PER_LONG - 1) & -BITS_PER_LONG)/8;
376 lp->alloced_map = kzalloc(map_size, GFP_KERNEL); 378 lp->alloced_map = kzalloc(map_size, GFP_KERNEL);
377 if (!lp->alloced_map) { 379 if (!lp->alloced_map) {
378 free_pages((unsigned long) lpage, order); 380 __free_pages(lp->page, order);
379 printk(KERN_ERR PFX "Out of memory, we're in trouble...\n"); 381 printk(KERN_ERR PFX "Out of memory, we're in trouble...\n");
380 return -ENOMEM; 382 return -ENOMEM;
381 } 383 }
382 384
383 lp->paddr = virt_to_gart(lpage); 385 lp->paddr = phys_to_gart(page_to_phys(lp->page));
384 lp->refcount = 0; 386 lp->refcount = 0;
385 atomic_add(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp); 387 atomic_add(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp);
386 return 0; 388 return 0;
@@ -391,7 +393,7 @@ static void i460_free_large_page (struct lp_desc *lp)
391 kfree(lp->alloced_map); 393 kfree(lp->alloced_map);
392 lp->alloced_map = NULL; 394 lp->alloced_map = NULL;
393 395
394 free_pages((unsigned long) gart_to_virt(lp->paddr), I460_IO_PAGE_SHIFT - PAGE_SHIFT); 396 __free_pages(lp->page, I460_IO_PAGE_SHIFT - PAGE_SHIFT);
395 atomic_sub(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp); 397 atomic_sub(I460_KPAGES_PER_IOPAGE, &agp_bridge->current_memory_agp);
396} 398}
397 399
@@ -439,8 +441,8 @@ static int i460_insert_memory_large_io_page (struct agp_memory *mem,
439 if (i460_alloc_large_page(lp) < 0) 441 if (i460_alloc_large_page(lp) < 0)
440 return -ENOMEM; 442 return -ENOMEM;
441 pg = lp - i460.lp_desc; 443 pg = lp - i460.lp_desc;
442 WR_GATT(pg, agp_bridge->driver->mask_memory(agp_bridge, 444 WR_GATT(pg, i460_mask_memory(agp_bridge,
443 lp->paddr, 0)); 445 lp->paddr, 0));
444 WR_FLUSH_GATT(pg); 446 WR_FLUSH_GATT(pg);
445 } 447 }
446 448
@@ -448,7 +450,7 @@ static int i460_insert_memory_large_io_page (struct agp_memory *mem,
448 idx < ((lp == end) ? (end_offset + 1) : I460_KPAGES_PER_IOPAGE); 450 idx < ((lp == end) ? (end_offset + 1) : I460_KPAGES_PER_IOPAGE);
449 idx++, i++) 451 idx++, i++)
450 { 452 {
451 mem->memory[i] = lp->paddr + idx*PAGE_SIZE; 453 mem->pages[i] = lp->page;
452 __set_bit(idx, lp->alloced_map); 454 __set_bit(idx, lp->alloced_map);
453 ++lp->refcount; 455 ++lp->refcount;
454 } 456 }
@@ -463,7 +465,7 @@ static int i460_remove_memory_large_io_page (struct agp_memory *mem,
463 struct lp_desc *start, *end, *lp; 465 struct lp_desc *start, *end, *lp;
464 void *temp; 466 void *temp;
465 467
466 temp = agp_bridge->driver->current_size; 468 temp = agp_bridge->current_size;
467 num_entries = A_SIZE_8(temp)->num_entries; 469 num_entries = A_SIZE_8(temp)->num_entries;
468 470
469 /* Figure out what pg_start means in terms of our large GART pages */ 471 /* Figure out what pg_start means in terms of our large GART pages */
@@ -477,7 +479,7 @@ static int i460_remove_memory_large_io_page (struct agp_memory *mem,
477 idx < ((lp == end) ? (end_offset + 1) : I460_KPAGES_PER_IOPAGE); 479 idx < ((lp == end) ? (end_offset + 1) : I460_KPAGES_PER_IOPAGE);
478 idx++, i++) 480 idx++, i++)
479 { 481 {
480 mem->memory[i] = 0; 482 mem->pages[i] = NULL;
481 __clear_bit(idx, lp->alloced_map); 483 __clear_bit(idx, lp->alloced_map);
482 --lp->refcount; 484 --lp->refcount;
483 } 485 }
@@ -521,7 +523,7 @@ static int i460_remove_memory (struct agp_memory *mem,
521 * Let's just hope nobody counts on the allocated AGP memory being there before bind time 523 * Let's just hope nobody counts on the allocated AGP memory being there before bind time
522 * (I don't think current drivers do)... 524 * (I don't think current drivers do)...
523 */ 525 */
524static void *i460_alloc_page (struct agp_bridge_data *bridge) 526static struct page *i460_alloc_page (struct agp_bridge_data *bridge)
525{ 527{
526 void *page; 528 void *page;
527 529
@@ -534,7 +536,7 @@ static void *i460_alloc_page (struct agp_bridge_data *bridge)
534 return page; 536 return page;
535} 537}
536 538
537static void i460_destroy_page (void *page, int flags) 539static void i460_destroy_page (struct page *page, int flags)
538{ 540{
539 if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT) { 541 if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT) {
540 agp_generic_destroy_page(page, flags); 542 agp_generic_destroy_page(page, flags);
@@ -544,13 +546,20 @@ static void i460_destroy_page (void *page, int flags)
544#endif /* I460_LARGE_IO_PAGES */ 546#endif /* I460_LARGE_IO_PAGES */
545 547
546static unsigned long i460_mask_memory (struct agp_bridge_data *bridge, 548static unsigned long i460_mask_memory (struct agp_bridge_data *bridge,
547 unsigned long addr, int type) 549 unsigned long addr, int type)
548{ 550{
549 /* Make sure the returned address is a valid GATT entry */ 551 /* Make sure the returned address is a valid GATT entry */
550 return bridge->driver->masks[0].mask 552 return bridge->driver->masks[0].mask
551 | (((addr & ~((1 << I460_IO_PAGE_SHIFT) - 1)) & 0xfffff000) >> 12); 553 | (((addr & ~((1 << I460_IO_PAGE_SHIFT) - 1)) & 0xfffff000) >> 12);
552} 554}
553 555
556static unsigned long i460_page_mask_memory(struct agp_bridge_data *bridge,
557 struct page *page, int type)
558{
559 unsigned long addr = phys_to_gart(page_to_phys(page));
560 return i460_mask_memory(bridge, addr, type);
561}
562
554const struct agp_bridge_driver intel_i460_driver = { 563const struct agp_bridge_driver intel_i460_driver = {
555 .owner = THIS_MODULE, 564 .owner = THIS_MODULE,
556 .aperture_sizes = i460_sizes, 565 .aperture_sizes = i460_sizes,
@@ -560,7 +569,7 @@ const struct agp_bridge_driver intel_i460_driver = {
560 .fetch_size = i460_fetch_size, 569 .fetch_size = i460_fetch_size,
561 .cleanup = i460_cleanup, 570 .cleanup = i460_cleanup,
562 .tlb_flush = i460_tlb_flush, 571 .tlb_flush = i460_tlb_flush,
563 .mask_memory = i460_mask_memory, 572 .mask_memory = i460_page_mask_memory,
564 .masks = i460_masks, 573 .masks = i460_masks,
565 .agp_enable = agp_generic_enable, 574 .agp_enable = agp_generic_enable,
566 .cache_flush = global_cache_flush, 575 .cache_flush = global_cache_flush,
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 3686912427ba..8c9d50db5c3a 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -46,6 +46,10 @@
46#define PCI_DEVICE_ID_INTEL_G45_IG 0x2E22 46#define PCI_DEVICE_ID_INTEL_G45_IG 0x2E22
47#define PCI_DEVICE_ID_INTEL_G41_HB 0x2E30 47#define PCI_DEVICE_ID_INTEL_G41_HB 0x2E30
48#define PCI_DEVICE_ID_INTEL_G41_IG 0x2E32 48#define PCI_DEVICE_ID_INTEL_G41_IG 0x2E32
49#define PCI_DEVICE_ID_INTEL_IGDNG_D_HB 0x0040
50#define PCI_DEVICE_ID_INTEL_IGDNG_D_IG 0x0042
51#define PCI_DEVICE_ID_INTEL_IGDNG_M_HB 0x0044
52#define PCI_DEVICE_ID_INTEL_IGDNG_M_IG 0x0046
49 53
50/* cover 915 and 945 variants */ 54/* cover 915 and 945 variants */
51#define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \ 55#define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \
@@ -75,7 +79,9 @@
75 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \ 79 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \
76 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \ 80 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \
77 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB || \ 81 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB || \
78 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G41_HB) 82 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G41_HB || \
83 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDNG_D_HB || \
84 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGDNG_M_HB)
79 85
80extern int agp_memory_reserved; 86extern int agp_memory_reserved;
81 87
@@ -251,7 +257,7 @@ static void intel_i810_agp_enable(struct agp_bridge_data *bridge, u32 mode)
251} 257}
252 258
253/* Exists to support ARGB cursors */ 259/* Exists to support ARGB cursors */
254static void *i8xx_alloc_pages(void) 260static struct page *i8xx_alloc_pages(void)
255{ 261{
256 struct page *page; 262 struct page *page;
257 263
@@ -266,17 +272,14 @@ static void *i8xx_alloc_pages(void)
266 } 272 }
267 get_page(page); 273 get_page(page);
268 atomic_inc(&agp_bridge->current_memory_agp); 274 atomic_inc(&agp_bridge->current_memory_agp);
269 return page_address(page); 275 return page;
270} 276}
271 277
272static void i8xx_destroy_pages(void *addr) 278static void i8xx_destroy_pages(struct page *page)
273{ 279{
274 struct page *page; 280 if (page == NULL)
275
276 if (addr == NULL)
277 return; 281 return;
278 282
279 page = virt_to_page(addr);
280 set_pages_wb(page, 4); 283 set_pages_wb(page, 4);
281 put_page(page); 284 put_page(page);
282 __free_pages(page, 2); 285 __free_pages(page, 2);
@@ -340,7 +343,7 @@ static int intel_i810_insert_entries(struct agp_memory *mem, off_t pg_start,
340 global_cache_flush(); 343 global_cache_flush();
341 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 344 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
342 writel(agp_bridge->driver->mask_memory(agp_bridge, 345 writel(agp_bridge->driver->mask_memory(agp_bridge,
343 mem->memory[i], 346 mem->pages[i],
344 mask_type), 347 mask_type),
345 intel_private.registers+I810_PTE_BASE+(j*4)); 348 intel_private.registers+I810_PTE_BASE+(j*4));
346 } 349 }
@@ -383,37 +386,37 @@ static int intel_i810_remove_entries(struct agp_memory *mem, off_t pg_start,
383static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type) 386static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
384{ 387{
385 struct agp_memory *new; 388 struct agp_memory *new;
386 void *addr; 389 struct page *page;
387 390
388 switch (pg_count) { 391 switch (pg_count) {
389 case 1: addr = agp_bridge->driver->agp_alloc_page(agp_bridge); 392 case 1: page = agp_bridge->driver->agp_alloc_page(agp_bridge);
390 break; 393 break;
391 case 4: 394 case 4:
392 /* kludge to get 4 physical pages for ARGB cursor */ 395 /* kludge to get 4 physical pages for ARGB cursor */
393 addr = i8xx_alloc_pages(); 396 page = i8xx_alloc_pages();
394 break; 397 break;
395 default: 398 default:
396 return NULL; 399 return NULL;
397 } 400 }
398 401
399 if (addr == NULL) 402 if (page == NULL)
400 return NULL; 403 return NULL;
401 404
402 new = agp_create_memory(pg_count); 405 new = agp_create_memory(pg_count);
403 if (new == NULL) 406 if (new == NULL)
404 return NULL; 407 return NULL;
405 408
406 new->memory[0] = virt_to_gart(addr); 409 new->pages[0] = page;
407 if (pg_count == 4) { 410 if (pg_count == 4) {
408 /* kludge to get 4 physical pages for ARGB cursor */ 411 /* kludge to get 4 physical pages for ARGB cursor */
409 new->memory[1] = new->memory[0] + PAGE_SIZE; 412 new->pages[1] = new->pages[0] + 1;
410 new->memory[2] = new->memory[1] + PAGE_SIZE; 413 new->pages[2] = new->pages[1] + 1;
411 new->memory[3] = new->memory[2] + PAGE_SIZE; 414 new->pages[3] = new->pages[2] + 1;
412 } 415 }
413 new->page_count = pg_count; 416 new->page_count = pg_count;
414 new->num_scratch_pages = pg_count; 417 new->num_scratch_pages = pg_count;
415 new->type = AGP_PHYS_MEMORY; 418 new->type = AGP_PHYS_MEMORY;
416 new->physical = new->memory[0]; 419 new->physical = page_to_phys(new->pages[0]);
417 return new; 420 return new;
418} 421}
419 422
@@ -445,13 +448,11 @@ static void intel_i810_free_by_type(struct agp_memory *curr)
445 agp_free_key(curr->key); 448 agp_free_key(curr->key);
446 if (curr->type == AGP_PHYS_MEMORY) { 449 if (curr->type == AGP_PHYS_MEMORY) {
447 if (curr->page_count == 4) 450 if (curr->page_count == 4)
448 i8xx_destroy_pages(gart_to_virt(curr->memory[0])); 451 i8xx_destroy_pages(curr->pages[0]);
449 else { 452 else {
450 void *va = gart_to_virt(curr->memory[0]); 453 agp_bridge->driver->agp_destroy_page(curr->pages[0],
451
452 agp_bridge->driver->agp_destroy_page(va,
453 AGP_PAGE_DESTROY_UNMAP); 454 AGP_PAGE_DESTROY_UNMAP);
454 agp_bridge->driver->agp_destroy_page(va, 455 agp_bridge->driver->agp_destroy_page(curr->pages[0],
455 AGP_PAGE_DESTROY_FREE); 456 AGP_PAGE_DESTROY_FREE);
456 } 457 }
457 agp_free_page_array(curr); 458 agp_free_page_array(curr);
@@ -460,8 +461,9 @@ static void intel_i810_free_by_type(struct agp_memory *curr)
460} 461}
461 462
462static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge, 463static unsigned long intel_i810_mask_memory(struct agp_bridge_data *bridge,
463 unsigned long addr, int type) 464 struct page *page, int type)
464{ 465{
466 unsigned long addr = phys_to_gart(page_to_phys(page));
465 /* Type checking must be done elsewhere */ 467 /* Type checking must be done elsewhere */
466 return addr | bridge->driver->masks[type].mask; 468 return addr | bridge->driver->masks[type].mask;
467} 469}
@@ -849,7 +851,7 @@ static int intel_i830_insert_entries(struct agp_memory *mem, off_t pg_start,
849 851
850 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 852 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
851 writel(agp_bridge->driver->mask_memory(agp_bridge, 853 writel(agp_bridge->driver->mask_memory(agp_bridge,
852 mem->memory[i], mask_type), 854 mem->pages[i], mask_type),
853 intel_private.registers+I810_PTE_BASE+(j*4)); 855 intel_private.registers+I810_PTE_BASE+(j*4));
854 } 856 }
855 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4)); 857 readl(intel_private.registers+I810_PTE_BASE+((j-1)*4));
@@ -1079,7 +1081,7 @@ static int intel_i915_insert_entries(struct agp_memory *mem, off_t pg_start,
1079 1081
1080 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 1082 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
1081 writel(agp_bridge->driver->mask_memory(agp_bridge, 1083 writel(agp_bridge->driver->mask_memory(agp_bridge,
1082 mem->memory[i], mask_type), intel_private.gtt+j); 1084 mem->pages[i], mask_type), intel_private.gtt+j);
1083 } 1085 }
1084 1086
1085 readl(intel_private.gtt+j-1); 1087 readl(intel_private.gtt+j-1);
@@ -1194,8 +1196,9 @@ static int intel_i915_create_gatt_table(struct agp_bridge_data *bridge)
1194 * this conditional. 1196 * this conditional.
1195 */ 1197 */
1196static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge, 1198static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge,
1197 unsigned long addr, int type) 1199 struct page *page, int type)
1198{ 1200{
1201 dma_addr_t addr = phys_to_gart(page_to_phys(page));
1199 /* Shift high bits down */ 1202 /* Shift high bits down */
1200 addr |= (addr >> 28) & 0xf0; 1203 addr |= (addr >> 28) & 0xf0;
1201 1204
@@ -1211,6 +1214,8 @@ static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size)
1211 case PCI_DEVICE_ID_INTEL_Q45_HB: 1214 case PCI_DEVICE_ID_INTEL_Q45_HB:
1212 case PCI_DEVICE_ID_INTEL_G45_HB: 1215 case PCI_DEVICE_ID_INTEL_G45_HB:
1213 case PCI_DEVICE_ID_INTEL_G41_HB: 1216 case PCI_DEVICE_ID_INTEL_G41_HB:
1217 case PCI_DEVICE_ID_INTEL_IGDNG_D_HB:
1218 case PCI_DEVICE_ID_INTEL_IGDNG_M_HB:
1214 *gtt_offset = *gtt_size = MB(2); 1219 *gtt_offset = *gtt_size = MB(2);
1215 break; 1220 break;
1216 default: 1221 default:
@@ -2186,6 +2191,10 @@ static const struct intel_driver_description {
2186 "G45/G43", NULL, &intel_i965_driver }, 2191 "G45/G43", NULL, &intel_i965_driver },
2187 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 0, 2192 { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 0,
2188 "G41", NULL, &intel_i965_driver }, 2193 "G41", NULL, &intel_i965_driver },
2194 { PCI_DEVICE_ID_INTEL_IGDNG_D_HB, PCI_DEVICE_ID_INTEL_IGDNG_D_IG, 0,
2195 "IGDNG/D", NULL, &intel_i965_driver },
2196 { PCI_DEVICE_ID_INTEL_IGDNG_M_HB, PCI_DEVICE_ID_INTEL_IGDNG_M_IG, 0,
2197 "IGDNG/M", NULL, &intel_i965_driver },
2189 { 0, 0, 0, NULL, NULL, NULL } 2198 { 0, 0, 0, NULL, NULL, NULL }
2190}; 2199};
2191 2200
@@ -2387,6 +2396,8 @@ static struct pci_device_id agp_intel_pci_table[] = {
2387 ID(PCI_DEVICE_ID_INTEL_Q45_HB), 2396 ID(PCI_DEVICE_ID_INTEL_Q45_HB),
2388 ID(PCI_DEVICE_ID_INTEL_G45_HB), 2397 ID(PCI_DEVICE_ID_INTEL_G45_HB),
2389 ID(PCI_DEVICE_ID_INTEL_G41_HB), 2398 ID(PCI_DEVICE_ID_INTEL_G41_HB),
2399 ID(PCI_DEVICE_ID_INTEL_IGDNG_D_HB),
2400 ID(PCI_DEVICE_ID_INTEL_IGDNG_M_HB),
2390 { } 2401 { }
2391}; 2402};
2392 2403
diff --git a/drivers/char/agp/nvidia-agp.c b/drivers/char/agp/nvidia-agp.c
index 16acee2de117..263d71dd441c 100644
--- a/drivers/char/agp/nvidia-agp.c
+++ b/drivers/char/agp/nvidia-agp.c
@@ -225,7 +225,7 @@ static int nvidia_insert_memory(struct agp_memory *mem, off_t pg_start, int type
225 } 225 }
226 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 226 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
227 writel(agp_bridge->driver->mask_memory(agp_bridge, 227 writel(agp_bridge->driver->mask_memory(agp_bridge,
228 mem->memory[i], mask_type), 228 mem->pages[i], mask_type),
229 agp_bridge->gatt_table+nvidia_private.pg_offset+j); 229 agp_bridge->gatt_table+nvidia_private.pg_offset+j);
230 } 230 }
231 231
diff --git a/drivers/char/agp/parisc-agp.c b/drivers/char/agp/parisc-agp.c
index 699e3422ad93..f4bb43fb8016 100644
--- a/drivers/char/agp/parisc-agp.c
+++ b/drivers/char/agp/parisc-agp.c
@@ -31,6 +31,10 @@
31#define AGP8X_MODE_BIT 3 31#define AGP8X_MODE_BIT 3
32#define AGP8X_MODE (1 << AGP8X_MODE_BIT) 32#define AGP8X_MODE (1 << AGP8X_MODE_BIT)
33 33
34static unsigned long
35parisc_agp_mask_memory(struct agp_bridge_data *bridge, unsigned long addr,
36 int type);
37
34static struct _parisc_agp_info { 38static struct _parisc_agp_info {
35 void __iomem *ioc_regs; 39 void __iomem *ioc_regs;
36 void __iomem *lba_regs; 40 void __iomem *lba_regs;
@@ -149,12 +153,12 @@ parisc_agp_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
149 for (i = 0, j = io_pg_start; i < mem->page_count; i++) { 153 for (i = 0, j = io_pg_start; i < mem->page_count; i++) {
150 unsigned long paddr; 154 unsigned long paddr;
151 155
152 paddr = mem->memory[i]; 156 paddr = page_to_phys(mem->pages[i]);
153 for (k = 0; 157 for (k = 0;
154 k < info->io_pages_per_kpage; 158 k < info->io_pages_per_kpage;
155 k++, j++, paddr += info->io_page_size) { 159 k++, j++, paddr += info->io_page_size) {
156 info->gatt[j] = 160 info->gatt[j] =
157 agp_bridge->driver->mask_memory(agp_bridge, 161 parisc_agp_mask_memory(agp_bridge,
158 paddr, type); 162 paddr, type);
159 } 163 }
160 } 164 }
@@ -185,9 +189,17 @@ parisc_agp_remove_memory(struct agp_memory *mem, off_t pg_start, int type)
185} 189}
186 190
187static unsigned long 191static unsigned long
188parisc_agp_mask_memory(struct agp_bridge_data *bridge, 192parisc_agp_mask_memory(struct agp_bridge_data *bridge, unsigned long addr,
189 unsigned long addr, int type) 193 int type)
194{
195 return SBA_PDIR_VALID_BIT | addr;
196}
197
198static unsigned long
199parisc_agp_page_mask_memory(struct agp_bridge_data *bridge, struct page *page,
200 int type)
190{ 201{
202 unsigned long addr = phys_to_gart(page_to_phys(page));
191 return SBA_PDIR_VALID_BIT | addr; 203 return SBA_PDIR_VALID_BIT | addr;
192} 204}
193 205
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index b972d83bb1b2..d3ea2e4226b5 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -38,7 +38,7 @@ static struct aper_size_info_fixed sgi_tioca_sizes[] = {
38 {0, 0, 0}, 38 {0, 0, 0},
39}; 39};
40 40
41static void *sgi_tioca_alloc_page(struct agp_bridge_data *bridge) 41static struct page *sgi_tioca_alloc_page(struct agp_bridge_data *bridge)
42{ 42{
43 struct page *page; 43 struct page *page;
44 int nid; 44 int nid;
@@ -52,7 +52,7 @@ static void *sgi_tioca_alloc_page(struct agp_bridge_data *bridge)
52 52
53 get_page(page); 53 get_page(page);
54 atomic_inc(&agp_bridge->current_memory_agp); 54 atomic_inc(&agp_bridge->current_memory_agp);
55 return page_address(page); 55 return page;
56} 56}
57 57
58/* 58/*
@@ -71,8 +71,9 @@ static void sgi_tioca_tlbflush(struct agp_memory *mem)
71 */ 71 */
72static unsigned long 72static unsigned long
73sgi_tioca_mask_memory(struct agp_bridge_data *bridge, 73sgi_tioca_mask_memory(struct agp_bridge_data *bridge,
74 unsigned long addr, int type) 74 struct page *page, int type)
75{ 75{
76 unsigned long addr = phys_to_gart(page_to_phys(page));
76 return tioca_physpage_to_gart(addr); 77 return tioca_physpage_to_gart(addr);
77} 78}
78 79
@@ -189,7 +190,7 @@ static int sgi_tioca_insert_memory(struct agp_memory *mem, off_t pg_start,
189 190
190 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 191 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
191 table[j] = 192 table[j] =
192 bridge->driver->mask_memory(bridge, mem->memory[i], 193 bridge->driver->mask_memory(bridge, mem->pages[i],
193 mem->type); 194 mem->type);
194 } 195 }
195 196
diff --git a/drivers/char/agp/sworks-agp.c b/drivers/char/agp/sworks-agp.c
index 6224df8b7f0a..b964a2199329 100644
--- a/drivers/char/agp/sworks-agp.c
+++ b/drivers/char/agp/sworks-agp.c
@@ -349,7 +349,7 @@ static int serverworks_insert_memory(struct agp_memory *mem,
349 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 349 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
350 addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr; 350 addr = (j * PAGE_SIZE) + agp_bridge->gart_bus_addr;
351 cur_gatt = SVRWRKS_GET_GATT(addr); 351 cur_gatt = SVRWRKS_GET_GATT(addr);
352 writel(agp_bridge->driver->mask_memory(agp_bridge, mem->memory[i], mem->type), cur_gatt+GET_GATT_OFF(addr)); 352 writel(agp_bridge->driver->mask_memory(agp_bridge, mem->pages[i], mem->type), cur_gatt+GET_GATT_OFF(addr));
353 } 353 }
354 serverworks_tlbflush(mem); 354 serverworks_tlbflush(mem);
355 return 0; 355 return 0;
diff --git a/drivers/char/agp/uninorth-agp.c b/drivers/char/agp/uninorth-agp.c
index 03f95ec08f59..f192c3b9ad41 100644
--- a/drivers/char/agp/uninorth-agp.c
+++ b/drivers/char/agp/uninorth-agp.c
@@ -146,13 +146,20 @@ static int uninorth_insert_memory(struct agp_memory *mem, off_t pg_start,
146{ 146{
147 int i, j, num_entries; 147 int i, j, num_entries;
148 void *temp; 148 void *temp;
149 int mask_type;
149 150
150 temp = agp_bridge->current_size; 151 temp = agp_bridge->current_size;
151 num_entries = A_SIZE_32(temp)->num_entries; 152 num_entries = A_SIZE_32(temp)->num_entries;
152 153
153 if (type != 0 || mem->type != 0) 154 if (type != mem->type)
155 return -EINVAL;
156
157 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
158 if (mask_type != 0) {
154 /* We know nothing of memory types */ 159 /* We know nothing of memory types */
155 return -EINVAL; 160 return -EINVAL;
161 }
162
156 if ((pg_start + mem->page_count) > num_entries) 163 if ((pg_start + mem->page_count) > num_entries)
157 return -EINVAL; 164 return -EINVAL;
158 165
@@ -166,9 +173,9 @@ static int uninorth_insert_memory(struct agp_memory *mem, off_t pg_start,
166 173
167 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 174 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
168 agp_bridge->gatt_table[j] = 175 agp_bridge->gatt_table[j] =
169 cpu_to_le32((mem->memory[i] & 0xFFFFF000UL) | 0x1UL); 176 cpu_to_le32((page_to_phys(mem->pages[i]) & 0xFFFFF000UL) | 0x1UL);
170 flush_dcache_range((unsigned long)__va(mem->memory[i]), 177 flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])),
171 (unsigned long)__va(mem->memory[i])+0x1000); 178 (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000);
172 } 179 }
173 (void)in_le32((volatile u32*)&agp_bridge->gatt_table[pg_start]); 180 (void)in_le32((volatile u32*)&agp_bridge->gatt_table[pg_start]);
174 mb(); 181 mb();
@@ -184,13 +191,20 @@ static int u3_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
184 int i, num_entries; 191 int i, num_entries;
185 void *temp; 192 void *temp;
186 u32 *gp; 193 u32 *gp;
194 int mask_type;
187 195
188 temp = agp_bridge->current_size; 196 temp = agp_bridge->current_size;
189 num_entries = A_SIZE_32(temp)->num_entries; 197 num_entries = A_SIZE_32(temp)->num_entries;
190 198
191 if (type != 0 || mem->type != 0) 199 if (type != mem->type)
200 return -EINVAL;
201
202 mask_type = agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type);
203 if (mask_type != 0) {
192 /* We know nothing of memory types */ 204 /* We know nothing of memory types */
193 return -EINVAL; 205 return -EINVAL;
206 }
207
194 if ((pg_start + mem->page_count) > num_entries) 208 if ((pg_start + mem->page_count) > num_entries)
195 return -EINVAL; 209 return -EINVAL;
196 210
@@ -205,9 +219,9 @@ static int u3_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
205 } 219 }
206 220
207 for (i = 0; i < mem->page_count; i++) { 221 for (i = 0; i < mem->page_count; i++) {
208 gp[i] = (mem->memory[i] >> PAGE_SHIFT) | 0x80000000UL; 222 gp[i] = (page_to_phys(mem->pages[i]) >> PAGE_SHIFT) | 0x80000000UL;
209 flush_dcache_range((unsigned long)__va(mem->memory[i]), 223 flush_dcache_range((unsigned long)__va(page_to_phys(mem->pages[i])),
210 (unsigned long)__va(mem->memory[i])+0x1000); 224 (unsigned long)__va(page_to_phys(mem->pages[i]))+0x1000);
211 } 225 }
212 mb(); 226 mb();
213 flush_dcache_range((unsigned long)gp, (unsigned long) &gp[i]); 227 flush_dcache_range((unsigned long)gp, (unsigned long) &gp[i]);
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index fd3ebd1be570..72429b6b2fa8 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -779,7 +779,7 @@ static void change_speed(struct async_struct *info,
779 info->IER |= UART_IER_MSI; 779 info->IER |= UART_IER_MSI;
780 } 780 }
781 /* TBD: 781 /* TBD:
782 * Does clearing IER_MSI imply that we should disbale the VBL interrupt ? 782 * Does clearing IER_MSI imply that we should disable the VBL interrupt ?
783 */ 783 */
784 784
785 /* 785 /*
diff --git a/drivers/char/bfin_jtag_comm.c b/drivers/char/bfin_jtag_comm.c
new file mode 100644
index 000000000000..1d7c34c73b20
--- /dev/null
+++ b/drivers/char/bfin_jtag_comm.c
@@ -0,0 +1,365 @@
1/*
2 * TTY over Blackfin JTAG Communication
3 *
4 * Copyright 2008-2009 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 */
10
11#define DRV_NAME "bfin-jtag-comm"
12#define DEV_NAME "ttyBFJC"
13#define pr_fmt(fmt) DRV_NAME ": " fmt
14
15#include <linux/circ_buf.h>
16#include <linux/console.h>
17#include <linux/delay.h>
18#include <linux/err.h>
19#include <linux/kernel.h>
20#include <linux/kthread.h>
21#include <linux/module.h>
22#include <linux/mutex.h>
23#include <linux/sched.h>
24#include <linux/tty.h>
25#include <linux/tty_driver.h>
26#include <linux/tty_flip.h>
27#include <asm/atomic.h>
28
29#define pr_init(fmt, args...) ({ static const __initconst char __fmt[] = fmt; printk(__fmt, ## args); })
30
31/* See the Debug/Emulation chapter in the HRM */
32#define EMUDOF 0x00000001 /* EMUDAT_OUT full & valid */
33#define EMUDIF 0x00000002 /* EMUDAT_IN full & valid */
34#define EMUDOOVF 0x00000004 /* EMUDAT_OUT overflow */
35#define EMUDIOVF 0x00000008 /* EMUDAT_IN overflow */
36
37static inline uint32_t bfin_write_emudat(uint32_t emudat)
38{
39 __asm__ __volatile__("emudat = %0;" : : "d"(emudat));
40 return emudat;
41}
42
43static inline uint32_t bfin_read_emudat(void)
44{
45 uint32_t emudat;
46 __asm__ __volatile__("%0 = emudat;" : "=d"(emudat));
47 return emudat;
48}
49
50static inline uint32_t bfin_write_emudat_chars(char a, char b, char c, char d)
51{
52 return bfin_write_emudat((a << 0) | (b << 8) | (c << 16) | (d << 24));
53}
54
55#define CIRC_SIZE 2048 /* see comment in tty_io.c:do_tty_write() */
56#define CIRC_MASK (CIRC_SIZE - 1)
57#define circ_empty(circ) ((circ)->head == (circ)->tail)
58#define circ_free(circ) CIRC_SPACE((circ)->head, (circ)->tail, CIRC_SIZE)
59#define circ_cnt(circ) CIRC_CNT((circ)->head, (circ)->tail, CIRC_SIZE)
60#define circ_byte(circ, idx) ((circ)->buf[(idx) & CIRC_MASK])
61
62static struct tty_driver *bfin_jc_driver;
63static struct task_struct *bfin_jc_kthread;
64static struct tty_struct * volatile bfin_jc_tty;
65static unsigned long bfin_jc_count;
66static DEFINE_MUTEX(bfin_jc_tty_mutex);
67static volatile struct circ_buf bfin_jc_write_buf;
68
69static int
70bfin_jc_emudat_manager(void *arg)
71{
72 uint32_t inbound_len = 0, outbound_len = 0;
73
74 while (!kthread_should_stop()) {
75 /* no one left to give data to, so sleep */
76 if (bfin_jc_tty == NULL && circ_empty(&bfin_jc_write_buf)) {
77 pr_debug("waiting for readers\n");
78 __set_current_state(TASK_UNINTERRUPTIBLE);
79 schedule();
80 __set_current_state(TASK_RUNNING);
81 }
82
83 /* no data available, so just chill */
84 if (!(bfin_read_DBGSTAT() & EMUDIF) && circ_empty(&bfin_jc_write_buf)) {
85 pr_debug("waiting for data (in_len = %i) (circ: %i %i)\n",
86 inbound_len, bfin_jc_write_buf.tail, bfin_jc_write_buf.head);
87 if (inbound_len)
88 schedule();
89 else
90 schedule_timeout_interruptible(HZ);
91 continue;
92 }
93
94 /* if incoming data is ready, eat it */
95 if (bfin_read_DBGSTAT() & EMUDIF) {
96 struct tty_struct *tty;
97 mutex_lock(&bfin_jc_tty_mutex);
98 tty = (struct tty_struct *)bfin_jc_tty;
99 if (tty != NULL) {
100 uint32_t emudat = bfin_read_emudat();
101 if (inbound_len == 0) {
102 pr_debug("incoming length: 0x%08x\n", emudat);
103 inbound_len = emudat;
104 } else {
105 size_t num_chars = (4 <= inbound_len ? 4 : inbound_len);
106 pr_debug(" incoming data: 0x%08x (pushing %zu)\n", emudat, num_chars);
107 inbound_len -= num_chars;
108 tty_insert_flip_string(tty, (unsigned char *)&emudat, num_chars);
109 tty_flip_buffer_push(tty);
110 }
111 }
112 mutex_unlock(&bfin_jc_tty_mutex);
113 }
114
115 /* if outgoing data is ready, post it */
116 if (!(bfin_read_DBGSTAT() & EMUDOF) && !circ_empty(&bfin_jc_write_buf)) {
117 if (outbound_len == 0) {
118 outbound_len = circ_cnt(&bfin_jc_write_buf);
119 bfin_write_emudat(outbound_len);
120 pr_debug("outgoing length: 0x%08x\n", outbound_len);
121 } else {
122 struct tty_struct *tty;
123 int tail = bfin_jc_write_buf.tail;
124 size_t ate = (4 <= outbound_len ? 4 : outbound_len);
125 uint32_t emudat =
126 bfin_write_emudat_chars(
127 circ_byte(&bfin_jc_write_buf, tail + 0),
128 circ_byte(&bfin_jc_write_buf, tail + 1),
129 circ_byte(&bfin_jc_write_buf, tail + 2),
130 circ_byte(&bfin_jc_write_buf, tail + 3)
131 );
132 bfin_jc_write_buf.tail += ate;
133 outbound_len -= ate;
134 mutex_lock(&bfin_jc_tty_mutex);
135 tty = (struct tty_struct *)bfin_jc_tty;
136 if (tty)
137 tty_wakeup(tty);
138 mutex_unlock(&bfin_jc_tty_mutex);
139 pr_debug(" outgoing data: 0x%08x (pushing %zu)\n", emudat, ate);
140 }
141 }
142 }
143
144 __set_current_state(TASK_RUNNING);
145 return 0;
146}
147
148static int
149bfin_jc_open(struct tty_struct *tty, struct file *filp)
150{
151 mutex_lock(&bfin_jc_tty_mutex);
152 pr_debug("open %lu\n", bfin_jc_count);
153 ++bfin_jc_count;
154 bfin_jc_tty = tty;
155 wake_up_process(bfin_jc_kthread);
156 mutex_unlock(&bfin_jc_tty_mutex);
157 return 0;
158}
159
160static void
161bfin_jc_close(struct tty_struct *tty, struct file *filp)
162{
163 mutex_lock(&bfin_jc_tty_mutex);
164 pr_debug("close %lu\n", bfin_jc_count);
165 if (--bfin_jc_count == 0)
166 bfin_jc_tty = NULL;
167 wake_up_process(bfin_jc_kthread);
168 mutex_unlock(&bfin_jc_tty_mutex);
169}
170
171/* XXX: we dont handle the put_char() case where we must handle count = 1 */
172static int
173bfin_jc_circ_write(const unsigned char *buf, int count)
174{
175 int i;
176 count = min(count, circ_free(&bfin_jc_write_buf));
177 pr_debug("going to write chunk of %i bytes\n", count);
178 for (i = 0; i < count; ++i)
179 circ_byte(&bfin_jc_write_buf, bfin_jc_write_buf.head + i) = buf[i];
180 bfin_jc_write_buf.head += i;
181 return i;
182}
183
184#ifndef CONFIG_BFIN_JTAG_COMM_CONSOLE
185# define acquire_console_sem()
186# define release_console_sem()
187#endif
188static int
189bfin_jc_write(struct tty_struct *tty, const unsigned char *buf, int count)
190{
191 int i;
192 acquire_console_sem();
193 i = bfin_jc_circ_write(buf, count);
194 release_console_sem();
195 wake_up_process(bfin_jc_kthread);
196 return i;
197}
198
199static void
200bfin_jc_flush_chars(struct tty_struct *tty)
201{
202 wake_up_process(bfin_jc_kthread);
203}
204
205static int
206bfin_jc_write_room(struct tty_struct *tty)
207{
208 return circ_free(&bfin_jc_write_buf);
209}
210
211static int
212bfin_jc_chars_in_buffer(struct tty_struct *tty)
213{
214 return circ_cnt(&bfin_jc_write_buf);
215}
216
217static void
218bfin_jc_wait_until_sent(struct tty_struct *tty, int timeout)
219{
220 unsigned long expire = jiffies + timeout;
221 while (!circ_empty(&bfin_jc_write_buf)) {
222 if (signal_pending(current))
223 break;
224 if (time_after(jiffies, expire))
225 break;
226 }
227}
228
229static struct tty_operations bfin_jc_ops = {
230 .open = bfin_jc_open,
231 .close = bfin_jc_close,
232 .write = bfin_jc_write,
233 /*.put_char = bfin_jc_put_char,*/
234 .flush_chars = bfin_jc_flush_chars,
235 .write_room = bfin_jc_write_room,
236 .chars_in_buffer = bfin_jc_chars_in_buffer,
237 .wait_until_sent = bfin_jc_wait_until_sent,
238};
239
240static int __init bfin_jc_init(void)
241{
242 int ret;
243
244 bfin_jc_kthread = kthread_create(bfin_jc_emudat_manager, NULL, DRV_NAME);
245 if (IS_ERR(bfin_jc_kthread))
246 return PTR_ERR(bfin_jc_kthread);
247
248 ret = -ENOMEM;
249
250 bfin_jc_write_buf.head = bfin_jc_write_buf.tail = 0;
251 bfin_jc_write_buf.buf = kmalloc(CIRC_SIZE, GFP_KERNEL);
252 if (!bfin_jc_write_buf.buf)
253 goto err;
254
255 bfin_jc_driver = alloc_tty_driver(1);
256 if (!bfin_jc_driver)
257 goto err;
258
259 bfin_jc_driver->owner = THIS_MODULE;
260 bfin_jc_driver->driver_name = DRV_NAME;
261 bfin_jc_driver->name = DEV_NAME;
262 bfin_jc_driver->type = TTY_DRIVER_TYPE_SERIAL;
263 bfin_jc_driver->subtype = SERIAL_TYPE_NORMAL;
264 bfin_jc_driver->init_termios = tty_std_termios;
265 tty_set_operations(bfin_jc_driver, &bfin_jc_ops);
266
267 ret = tty_register_driver(bfin_jc_driver);
268 if (ret)
269 goto err;
270
271 pr_init(KERN_INFO DRV_NAME ": initialized\n");
272
273 return 0;
274
275 err:
276 put_tty_driver(bfin_jc_driver);
277 kfree(bfin_jc_write_buf.buf);
278 kthread_stop(bfin_jc_kthread);
279 return ret;
280}
281module_init(bfin_jc_init);
282
283static void __exit bfin_jc_exit(void)
284{
285 kthread_stop(bfin_jc_kthread);
286 kfree(bfin_jc_write_buf.buf);
287 tty_unregister_driver(bfin_jc_driver);
288 put_tty_driver(bfin_jc_driver);
289}
290module_exit(bfin_jc_exit);
291
292#if defined(CONFIG_BFIN_JTAG_COMM_CONSOLE) || defined(CONFIG_EARLY_PRINTK)
293static void
294bfin_jc_straight_buffer_write(const char *buf, unsigned count)
295{
296 unsigned ate = 0;
297 while (bfin_read_DBGSTAT() & EMUDOF)
298 continue;
299 bfin_write_emudat(count);
300 while (ate < count) {
301 while (bfin_read_DBGSTAT() & EMUDOF)
302 continue;
303 bfin_write_emudat_chars(buf[ate], buf[ate+1], buf[ate+2], buf[ate+3]);
304 ate += 4;
305 }
306}
307#endif
308
309#ifdef CONFIG_BFIN_JTAG_COMM_CONSOLE
310static void
311bfin_jc_console_write(struct console *co, const char *buf, unsigned count)
312{
313 if (bfin_jc_kthread == NULL)
314 bfin_jc_straight_buffer_write(buf, count);
315 else
316 bfin_jc_circ_write(buf, count);
317}
318
319static struct tty_driver *
320bfin_jc_console_device(struct console *co, int *index)
321{
322 *index = co->index;
323 return bfin_jc_driver;
324}
325
326static struct console bfin_jc_console = {
327 .name = DEV_NAME,
328 .write = bfin_jc_console_write,
329 .device = bfin_jc_console_device,
330 .flags = CON_ANYTIME | CON_PRINTBUFFER,
331 .index = -1,
332};
333
334static int __init bfin_jc_console_init(void)
335{
336 register_console(&bfin_jc_console);
337 return 0;
338}
339console_initcall(bfin_jc_console_init);
340#endif
341
342#ifdef CONFIG_EARLY_PRINTK
343static void __init
344bfin_jc_early_write(struct console *co, const char *buf, unsigned int count)
345{
346 bfin_jc_straight_buffer_write(buf, count);
347}
348
349static struct __initdata console bfin_jc_early_console = {
350 .name = "early_BFJC",
351 .write = bfin_jc_early_write,
352 .flags = CON_ANYTIME | CON_PRINTBUFFER,
353 .index = -1,
354};
355
356struct console * __init
357bfin_jc_early_init(unsigned int port, unsigned int cflag)
358{
359 return &bfin_jc_early_console;
360}
361#endif
362
363MODULE_AUTHOR("Mike Frysinger <vapier@gentoo.org>");
364MODULE_DESCRIPTION("TTY over Blackfin JTAG Communication");
365MODULE_LICENSE("GPL");
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 1fdb9f657d8f..f3366d3f06cf 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -604,7 +604,6 @@
604 604
605#define NR_PORTS 256 605#define NR_PORTS 256
606 606
607#define ZE_V1_NPORTS 64
608#define ZO_V1 0 607#define ZO_V1 0
609#define ZO_V2 1 608#define ZO_V2 1
610#define ZE_V1 2 609#define ZE_V1 2
@@ -663,18 +662,6 @@
663static void cy_throttle(struct tty_struct *tty); 662static void cy_throttle(struct tty_struct *tty);
664static void cy_send_xchar(struct tty_struct *tty, char ch); 663static void cy_send_xchar(struct tty_struct *tty, char ch);
665 664
666#define IS_CYC_Z(card) ((card).num_chips == (unsigned int)-1)
667
668#define Z_FPGA_CHECK(card) \
669 ((readl(&((struct RUNTIME_9060 __iomem *) \
670 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
671
672#define ISZLOADED(card) (((ZO_V1 == readl(&((struct RUNTIME_9060 __iomem *) \
673 ((card).ctl_addr))->mail_box_0)) || \
674 Z_FPGA_CHECK(card)) && \
675 (ZFIRM_ID == readl(&((struct FIRM_ID __iomem *) \
676 ((card).base_addr+ID_ADDRESS))->signature)))
677
678#ifndef SERIAL_XMIT_SIZE 665#ifndef SERIAL_XMIT_SIZE
679#define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096)) 666#define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096))
680#endif 667#endif
@@ -687,8 +674,6 @@ static void cy_send_xchar(struct tty_struct *tty, char ch);
687#define DRIVER_VERSION 0x02010203 674#define DRIVER_VERSION 0x02010203
688#define RAM_SIZE 0x80000 675#define RAM_SIZE 0x80000
689 676
690#define Z_FPGA_LOADED(X) ((readl(&(X)->init_ctrl) & (1<<17)) != 0)
691
692enum zblock_type { 677enum zblock_type {
693 ZBLOCK_PRG = 0, 678 ZBLOCK_PRG = 0,
694 ZBLOCK_FPGA = 1 679 ZBLOCK_FPGA = 1
@@ -883,6 +868,29 @@ static void cyz_rx_restart(unsigned long);
883static struct timer_list cyz_rx_full_timer[NR_PORTS]; 868static struct timer_list cyz_rx_full_timer[NR_PORTS];
884#endif /* CONFIG_CYZ_INTR */ 869#endif /* CONFIG_CYZ_INTR */
885 870
871static inline bool cy_is_Z(struct cyclades_card *card)
872{
873 return card->num_chips == (unsigned int)-1;
874}
875
876static inline bool __cyz_fpga_loaded(struct RUNTIME_9060 __iomem *ctl_addr)
877{
878 return readl(&ctl_addr->init_ctrl) & (1 << 17);
879}
880
881static inline bool cyz_fpga_loaded(struct cyclades_card *card)
882{
883 return __cyz_fpga_loaded(card->ctl_addr.p9060);
884}
885
886static inline bool cyz_is_loaded(struct cyclades_card *card)
887{
888 struct FIRM_ID __iomem *fw_id = card->base_addr + ID_ADDRESS;
889
890 return (card->hw_ver == ZO_V1 || cyz_fpga_loaded(card)) &&
891 readl(&fw_id->signature) == ZFIRM_ID;
892}
893
886static inline int serial_paranoia_check(struct cyclades_port *info, 894static inline int serial_paranoia_check(struct cyclades_port *info,
887 char *name, const char *routine) 895 char *name, const char *routine)
888{ 896{
@@ -1395,19 +1403,15 @@ cyz_fetch_msg(struct cyclades_card *cinfo,
1395 unsigned long loc_doorbell; 1403 unsigned long loc_doorbell;
1396 1404
1397 firm_id = cinfo->base_addr + ID_ADDRESS; 1405 firm_id = cinfo->base_addr + ID_ADDRESS;
1398 if (!ISZLOADED(*cinfo))
1399 return -1;
1400 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1406 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1401 board_ctrl = &zfw_ctrl->board_ctrl; 1407 board_ctrl = &zfw_ctrl->board_ctrl;
1402 1408
1403 loc_doorbell = readl(&((struct RUNTIME_9060 __iomem *) 1409 loc_doorbell = readl(&cinfo->ctl_addr.p9060->loc_doorbell);
1404 (cinfo->ctl_addr))->loc_doorbell);
1405 if (loc_doorbell) { 1410 if (loc_doorbell) {
1406 *cmd = (char)(0xff & loc_doorbell); 1411 *cmd = (char)(0xff & loc_doorbell);
1407 *channel = readl(&board_ctrl->fwcmd_channel); 1412 *channel = readl(&board_ctrl->fwcmd_channel);
1408 *param = (__u32) readl(&board_ctrl->fwcmd_param); 1413 *param = (__u32) readl(&board_ctrl->fwcmd_param);
1409 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))-> 1414 cy_writel(&cinfo->ctl_addr.p9060->loc_doorbell, 0xffffffff);
1410 loc_doorbell, 0xffffffff);
1411 return 1; 1415 return 1;
1412 } 1416 }
1413 return 0; 1417 return 0;
@@ -1424,15 +1428,14 @@ cyz_issue_cmd(struct cyclades_card *cinfo,
1424 unsigned int index; 1428 unsigned int index;
1425 1429
1426 firm_id = cinfo->base_addr + ID_ADDRESS; 1430 firm_id = cinfo->base_addr + ID_ADDRESS;
1427 if (!ISZLOADED(*cinfo)) 1431 if (!cyz_is_loaded(cinfo))
1428 return -1; 1432 return -1;
1429 1433
1430 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1434 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1431 board_ctrl = &zfw_ctrl->board_ctrl; 1435 board_ctrl = &zfw_ctrl->board_ctrl;
1432 1436
1433 index = 0; 1437 index = 0;
1434 pci_doorbell = 1438 pci_doorbell = &cinfo->ctl_addr.p9060->pci_doorbell;
1435 &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell;
1436 while ((readl(pci_doorbell) & 0xff) != 0) { 1439 while ((readl(pci_doorbell) & 0xff) != 0) {
1437 if (index++ == 1000) 1440 if (index++ == 1000)
1438 return (int)(readl(pci_doorbell) & 0xff); 1441 return (int)(readl(pci_doorbell) & 0xff);
@@ -1624,10 +1627,8 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1624 static struct BOARD_CTRL __iomem *board_ctrl; 1627 static struct BOARD_CTRL __iomem *board_ctrl;
1625 static struct CH_CTRL __iomem *ch_ctrl; 1628 static struct CH_CTRL __iomem *ch_ctrl;
1626 static struct BUF_CTRL __iomem *buf_ctrl; 1629 static struct BUF_CTRL __iomem *buf_ctrl;
1627 __u32 channel; 1630 __u32 channel, param, fw_ver;
1628 __u8 cmd; 1631 __u8 cmd;
1629 __u32 param;
1630 __u32 hw_ver, fw_ver;
1631 int special_count; 1632 int special_count;
1632 int delta_count; 1633 int delta_count;
1633 1634
@@ -1635,8 +1636,6 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1635 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1636 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1636 board_ctrl = &zfw_ctrl->board_ctrl; 1637 board_ctrl = &zfw_ctrl->board_ctrl;
1637 fw_ver = readl(&board_ctrl->fw_version); 1638 fw_ver = readl(&board_ctrl->fw_version);
1638 hw_ver = readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1639 mail_box_0);
1640 1639
1641 while (cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) { 1640 while (cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) {
1642 special_count = 0; 1641 special_count = 0;
@@ -1737,15 +1736,7 @@ static irqreturn_t cyz_interrupt(int irq, void *dev_id)
1737{ 1736{
1738 struct cyclades_card *cinfo = dev_id; 1737 struct cyclades_card *cinfo = dev_id;
1739 1738
1740 if (unlikely(cinfo == NULL)) { 1739 if (unlikely(!cyz_is_loaded(cinfo))) {
1741#ifdef CY_DEBUG_INTERRUPTS
1742 printk(KERN_DEBUG "cyz_interrupt: spurious interrupt %d\n",
1743 irq);
1744#endif
1745 return IRQ_NONE; /* spurious interrupt */
1746 }
1747
1748 if (unlikely(!ISZLOADED(*cinfo))) {
1749#ifdef CY_DEBUG_INTERRUPTS 1740#ifdef CY_DEBUG_INTERRUPTS
1750 printk(KERN_DEBUG "cyz_interrupt: board not yet loaded " 1741 printk(KERN_DEBUG "cyz_interrupt: board not yet loaded "
1751 "(IRQ%d).\n", irq); 1742 "(IRQ%d).\n", irq);
@@ -1785,7 +1776,6 @@ static void cyz_poll(unsigned long arg)
1785 struct tty_struct *tty; 1776 struct tty_struct *tty;
1786 struct FIRM_ID __iomem *firm_id; 1777 struct FIRM_ID __iomem *firm_id;
1787 struct ZFW_CTRL __iomem *zfw_ctrl; 1778 struct ZFW_CTRL __iomem *zfw_ctrl;
1788 struct BOARD_CTRL __iomem *board_ctrl;
1789 struct BUF_CTRL __iomem *buf_ctrl; 1779 struct BUF_CTRL __iomem *buf_ctrl;
1790 unsigned long expires = jiffies + HZ; 1780 unsigned long expires = jiffies + HZ;
1791 unsigned int port, card; 1781 unsigned int port, card;
@@ -1793,19 +1783,17 @@ static void cyz_poll(unsigned long arg)
1793 for (card = 0; card < NR_CARDS; card++) { 1783 for (card = 0; card < NR_CARDS; card++) {
1794 cinfo = &cy_card[card]; 1784 cinfo = &cy_card[card];
1795 1785
1796 if (!IS_CYC_Z(*cinfo)) 1786 if (!cy_is_Z(cinfo))
1797 continue; 1787 continue;
1798 if (!ISZLOADED(*cinfo)) 1788 if (!cyz_is_loaded(cinfo))
1799 continue; 1789 continue;
1800 1790
1801 firm_id = cinfo->base_addr + ID_ADDRESS; 1791 firm_id = cinfo->base_addr + ID_ADDRESS;
1802 zfw_ctrl = cinfo->base_addr + 1792 zfw_ctrl = cinfo->base_addr +
1803 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 1793 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1804 board_ctrl = &(zfw_ctrl->board_ctrl);
1805 1794
1806 /* Skip first polling cycle to avoid racing conditions with the FW */ 1795 /* Skip first polling cycle to avoid racing conditions with the FW */
1807 if (!cinfo->intr_enabled) { 1796 if (!cinfo->intr_enabled) {
1808 cinfo->nports = (int)readl(&board_ctrl->n_channel);
1809 cinfo->intr_enabled = 1; 1797 cinfo->intr_enabled = 1;
1810 continue; 1798 continue;
1811 } 1799 }
@@ -1874,7 +1862,7 @@ static int startup(struct cyclades_port *info)
1874 1862
1875 set_line_char(info); 1863 set_line_char(info);
1876 1864
1877 if (!IS_CYC_Z(*card)) { 1865 if (!cy_is_Z(card)) {
1878 chip = channel >> 2; 1866 chip = channel >> 2;
1879 channel &= 0x03; 1867 channel &= 0x03;
1880 index = card->bus_index; 1868 index = card->bus_index;
@@ -1931,7 +1919,7 @@ static int startup(struct cyclades_port *info)
1931 base_addr = card->base_addr; 1919 base_addr = card->base_addr;
1932 1920
1933 firm_id = base_addr + ID_ADDRESS; 1921 firm_id = base_addr + ID_ADDRESS;
1934 if (!ISZLOADED(*card)) 1922 if (!cyz_is_loaded(card))
1935 return -ENODEV; 1923 return -ENODEV;
1936 1924
1937 zfw_ctrl = card->base_addr + 1925 zfw_ctrl = card->base_addr +
@@ -2026,7 +2014,7 @@ static void start_xmit(struct cyclades_port *info)
2026 2014
2027 card = info->card; 2015 card = info->card;
2028 channel = info->line - card->first_line; 2016 channel = info->line - card->first_line;
2029 if (!IS_CYC_Z(*card)) { 2017 if (!cy_is_Z(card)) {
2030 chip = channel >> 2; 2018 chip = channel >> 2;
2031 channel &= 0x03; 2019 channel &= 0x03;
2032 index = card->bus_index; 2020 index = card->bus_index;
@@ -2070,7 +2058,7 @@ static void shutdown(struct cyclades_port *info)
2070 2058
2071 card = info->card; 2059 card = info->card;
2072 channel = info->line - card->first_line; 2060 channel = info->line - card->first_line;
2073 if (!IS_CYC_Z(*card)) { 2061 if (!cy_is_Z(card)) {
2074 chip = channel >> 2; 2062 chip = channel >> 2;
2075 channel &= 0x03; 2063 channel &= 0x03;
2076 index = card->bus_index; 2064 index = card->bus_index;
@@ -2126,7 +2114,7 @@ static void shutdown(struct cyclades_port *info)
2126#endif 2114#endif
2127 2115
2128 firm_id = base_addr + ID_ADDRESS; 2116 firm_id = base_addr + ID_ADDRESS;
2129 if (!ISZLOADED(*card)) 2117 if (!cyz_is_loaded(card))
2130 return; 2118 return;
2131 2119
2132 zfw_ctrl = card->base_addr + 2120 zfw_ctrl = card->base_addr +
@@ -2233,7 +2221,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2233#endif 2221#endif
2234 info->port.blocked_open++; 2222 info->port.blocked_open++;
2235 2223
2236 if (!IS_CYC_Z(*cinfo)) { 2224 if (!cy_is_Z(cinfo)) {
2237 chip = channel >> 2; 2225 chip = channel >> 2;
2238 channel &= 0x03; 2226 channel &= 0x03;
2239 index = cinfo->bus_index; 2227 index = cinfo->bus_index;
@@ -2296,7 +2284,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2296 2284
2297 base_addr = cinfo->base_addr; 2285 base_addr = cinfo->base_addr;
2298 firm_id = base_addr + ID_ADDRESS; 2286 firm_id = base_addr + ID_ADDRESS;
2299 if (!ISZLOADED(*cinfo)) { 2287 if (!cyz_is_loaded(cinfo)) {
2300 __set_current_state(TASK_RUNNING); 2288 __set_current_state(TASK_RUNNING);
2301 remove_wait_queue(&info->port.open_wait, &wait); 2289 remove_wait_queue(&info->port.open_wait, &wait);
2302 return -EINVAL; 2290 return -EINVAL;
@@ -2397,16 +2385,14 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2397 treat it as absent from the system. This 2385 treat it as absent from the system. This
2398 will make the user pay attention. 2386 will make the user pay attention.
2399 */ 2387 */
2400 if (IS_CYC_Z(*info->card)) { 2388 if (cy_is_Z(info->card)) {
2401 struct cyclades_card *cinfo = info->card; 2389 struct cyclades_card *cinfo = info->card;
2402 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS; 2390 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
2403 2391
2404 if (!ISZLOADED(*cinfo)) { 2392 if (!cyz_is_loaded(cinfo)) {
2405 if (((ZE_V1 == readl(&((struct RUNTIME_9060 __iomem *) 2393 if (cinfo->hw_ver == ZE_V1 && cyz_fpga_loaded(cinfo) &&
2406 (cinfo->ctl_addr))->mail_box_0)) && 2394 readl(&firm_id->signature) ==
2407 Z_FPGA_CHECK(*cinfo)) && 2395 ZFIRM_HLT) {
2408 (ZFIRM_HLT == readl(
2409 &firm_id->signature))) {
2410 printk(KERN_ERR "cyc:Cyclades-Z Error: you " 2396 printk(KERN_ERR "cyc:Cyclades-Z Error: you "
2411 "need an external power supply for " 2397 "need an external power supply for "
2412 "this number of ports.\nFirmware " 2398 "this number of ports.\nFirmware "
@@ -2423,18 +2409,13 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2423 interrupts should be enabled as soon as the first open 2409 interrupts should be enabled as soon as the first open
2424 happens to one of its ports. */ 2410 happens to one of its ports. */
2425 if (!cinfo->intr_enabled) { 2411 if (!cinfo->intr_enabled) {
2426 struct ZFW_CTRL __iomem *zfw_ctrl; 2412 u16 intr;
2427 struct BOARD_CTRL __iomem *board_ctrl;
2428
2429 zfw_ctrl = cinfo->base_addr +
2430 (readl(&firm_id->zfwctrl_addr) &
2431 0xfffff);
2432
2433 board_ctrl = &zfw_ctrl->board_ctrl;
2434 2413
2435 /* Enable interrupts on the PLX chip */ 2414 /* Enable interrupts on the PLX chip */
2436 cy_writew(cinfo->ctl_addr + 0x68, 2415 intr = readw(&cinfo->ctl_addr.p9060->
2437 readw(cinfo->ctl_addr + 0x68) | 0x0900); 2416 intr_ctrl_stat) | 0x0900;
2417 cy_writew(&cinfo->ctl_addr.p9060->
2418 intr_ctrl_stat, intr);
2438 /* Enable interrupts on the FW */ 2419 /* Enable interrupts on the FW */
2439 retval = cyz_issue_cmd(cinfo, 0, 2420 retval = cyz_issue_cmd(cinfo, 0,
2440 C_CM_IRQ_ENBL, 0L); 2421 C_CM_IRQ_ENBL, 0L);
@@ -2442,8 +2423,6 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2442 printk(KERN_ERR "cyc:IRQ enable retval " 2423 printk(KERN_ERR "cyc:IRQ enable retval "
2443 "was %x\n", retval); 2424 "was %x\n", retval);
2444 } 2425 }
2445 cinfo->nports =
2446 (int)readl(&board_ctrl->n_channel);
2447 cinfo->intr_enabled = 1; 2426 cinfo->intr_enabled = 1;
2448 } 2427 }
2449 } 2428 }
@@ -2556,7 +2535,7 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2556#endif 2535#endif
2557 card = info->card; 2536 card = info->card;
2558 channel = (info->line) - (card->first_line); 2537 channel = (info->line) - (card->first_line);
2559 if (!IS_CYC_Z(*card)) { 2538 if (!cy_is_Z(card)) {
2560 chip = channel >> 2; 2539 chip = channel >> 2;
2561 channel &= 0x03; 2540 channel &= 0x03;
2562 index = card->bus_index; 2541 index = card->bus_index;
@@ -2601,7 +2580,7 @@ static void cy_flush_buffer(struct tty_struct *tty)
2601 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 2580 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2602 spin_unlock_irqrestore(&card->card_lock, flags); 2581 spin_unlock_irqrestore(&card->card_lock, flags);
2603 2582
2604 if (IS_CYC_Z(*card)) { /* If it is a Z card, flush the on-board 2583 if (cy_is_Z(card)) { /* If it is a Z card, flush the on-board
2605 buffers as well */ 2584 buffers as well */
2606 spin_lock_irqsave(&card->card_lock, flags); 2585 spin_lock_irqsave(&card->card_lock, flags);
2607 retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L); 2586 retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L);
@@ -2682,7 +2661,7 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
2682 2661
2683 spin_lock_irqsave(&card->card_lock, flags); 2662 spin_lock_irqsave(&card->card_lock, flags);
2684 2663
2685 if (!IS_CYC_Z(*card)) { 2664 if (!cy_is_Z(card)) {
2686 int channel = info->line - card->first_line; 2665 int channel = info->line - card->first_line;
2687 int index = card->bus_index; 2666 int index = card->bus_index;
2688 void __iomem *base_addr = card->base_addr + 2667 void __iomem *base_addr = card->base_addr +
@@ -2902,7 +2881,7 @@ static int cy_chars_in_buffer(struct tty_struct *tty)
2902 channel = (info->line) - (card->first_line); 2881 channel = (info->line) - (card->first_line);
2903 2882
2904#ifdef Z_EXT_CHARS_IN_BUFFER 2883#ifdef Z_EXT_CHARS_IN_BUFFER
2905 if (!IS_CYC_Z(cy_card[card])) { 2884 if (!cy_is_Z(card)) {
2906#endif /* Z_EXT_CHARS_IN_BUFFER */ 2885#endif /* Z_EXT_CHARS_IN_BUFFER */
2907#ifdef CY_DEBUG_IO 2886#ifdef CY_DEBUG_IO
2908 printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n", 2887 printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n",
@@ -2984,7 +2963,6 @@ static void set_line_char(struct cyclades_port *info)
2984 void __iomem *base_addr; 2963 void __iomem *base_addr;
2985 int chip, channel, index; 2964 int chip, channel, index;
2986 unsigned cflag, iflag; 2965 unsigned cflag, iflag;
2987 unsigned short chip_number;
2988 int baud, baud_rate = 0; 2966 int baud, baud_rate = 0;
2989 int i; 2967 int i;
2990 2968
@@ -3013,9 +2991,8 @@ static void set_line_char(struct cyclades_port *info)
3013 2991
3014 card = info->card; 2992 card = info->card;
3015 channel = info->line - card->first_line; 2993 channel = info->line - card->first_line;
3016 chip_number = channel / 4;
3017 2994
3018 if (!IS_CYC_Z(*card)) { 2995 if (!cy_is_Z(card)) {
3019 2996
3020 index = card->bus_index; 2997 index = card->bus_index;
3021 2998
@@ -3233,21 +3210,17 @@ static void set_line_char(struct cyclades_port *info)
3233 } else { 3210 } else {
3234 struct FIRM_ID __iomem *firm_id; 3211 struct FIRM_ID __iomem *firm_id;
3235 struct ZFW_CTRL __iomem *zfw_ctrl; 3212 struct ZFW_CTRL __iomem *zfw_ctrl;
3236 struct BOARD_CTRL __iomem *board_ctrl;
3237 struct CH_CTRL __iomem *ch_ctrl; 3213 struct CH_CTRL __iomem *ch_ctrl;
3238 struct BUF_CTRL __iomem *buf_ctrl;
3239 __u32 sw_flow; 3214 __u32 sw_flow;
3240 int retval; 3215 int retval;
3241 3216
3242 firm_id = card->base_addr + ID_ADDRESS; 3217 firm_id = card->base_addr + ID_ADDRESS;
3243 if (!ISZLOADED(*card)) 3218 if (!cyz_is_loaded(card))
3244 return; 3219 return;
3245 3220
3246 zfw_ctrl = card->base_addr + 3221 zfw_ctrl = card->base_addr +
3247 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 3222 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3248 board_ctrl = &zfw_ctrl->board_ctrl;
3249 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); 3223 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3250 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
3251 3224
3252 /* baud rate */ 3225 /* baud rate */
3253 baud = tty_get_baud_rate(info->port.tty); 3226 baud = tty_get_baud_rate(info->port.tty);
@@ -3457,7 +3430,7 @@ static int get_lsr_info(struct cyclades_port *info, unsigned int __user *value)
3457 3430
3458 card = info->card; 3431 card = info->card;
3459 channel = (info->line) - (card->first_line); 3432 channel = (info->line) - (card->first_line);
3460 if (!IS_CYC_Z(*card)) { 3433 if (!cy_is_Z(card)) {
3461 chip = channel >> 2; 3434 chip = channel >> 2;
3462 channel &= 0x03; 3435 channel &= 0x03;
3463 index = card->bus_index; 3436 index = card->bus_index;
@@ -3497,7 +3470,7 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3497 3470
3498 card = info->card; 3471 card = info->card;
3499 channel = info->line - card->first_line; 3472 channel = info->line - card->first_line;
3500 if (!IS_CYC_Z(*card)) { 3473 if (!cy_is_Z(card)) {
3501 chip = channel >> 2; 3474 chip = channel >> 2;
3502 channel &= 0x03; 3475 channel &= 0x03;
3503 index = card->bus_index; 3476 index = card->bus_index;
@@ -3523,7 +3496,7 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3523 } else { 3496 } else {
3524 base_addr = card->base_addr; 3497 base_addr = card->base_addr;
3525 firm_id = card->base_addr + ID_ADDRESS; 3498 firm_id = card->base_addr + ID_ADDRESS;
3526 if (ISZLOADED(*card)) { 3499 if (cyz_is_loaded(card)) {
3527 zfw_ctrl = card->base_addr + 3500 zfw_ctrl = card->base_addr +
3528 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 3501 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3529 board_ctrl = &zfw_ctrl->board_ctrl; 3502 board_ctrl = &zfw_ctrl->board_ctrl;
@@ -3566,7 +3539,7 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3566 3539
3567 card = info->card; 3540 card = info->card;
3568 channel = (info->line) - (card->first_line); 3541 channel = (info->line) - (card->first_line);
3569 if (!IS_CYC_Z(*card)) { 3542 if (!cy_is_Z(card)) {
3570 chip = channel >> 2; 3543 chip = channel >> 2;
3571 channel &= 0x03; 3544 channel &= 0x03;
3572 index = card->bus_index; 3545 index = card->bus_index;
@@ -3641,7 +3614,7 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3641 base_addr = card->base_addr; 3614 base_addr = card->base_addr;
3642 3615
3643 firm_id = card->base_addr + ID_ADDRESS; 3616 firm_id = card->base_addr + ID_ADDRESS;
3644 if (ISZLOADED(*card)) { 3617 if (cyz_is_loaded(card)) {
3645 zfw_ctrl = card->base_addr + 3618 zfw_ctrl = card->base_addr +
3646 (readl(&firm_id->zfwctrl_addr) & 0xfffff); 3619 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3647 board_ctrl = &zfw_ctrl->board_ctrl; 3620 board_ctrl = &zfw_ctrl->board_ctrl;
@@ -3713,7 +3686,7 @@ static int cy_break(struct tty_struct *tty, int break_state)
3713 card = info->card; 3686 card = info->card;
3714 3687
3715 spin_lock_irqsave(&card->card_lock, flags); 3688 spin_lock_irqsave(&card->card_lock, flags);
3716 if (!IS_CYC_Z(*card)) { 3689 if (!cy_is_Z(card)) {
3717 /* Let the transmit ISR take care of this (since it 3690 /* Let the transmit ISR take care of this (since it
3718 requires stuffing characters into the output stream). 3691 requires stuffing characters into the output stream).
3719 */ 3692 */
@@ -3782,7 +3755,7 @@ static int set_threshold(struct cyclades_port *info, unsigned long value)
3782 3755
3783 card = info->card; 3756 card = info->card;
3784 channel = info->line - card->first_line; 3757 channel = info->line - card->first_line;
3785 if (!IS_CYC_Z(*card)) { 3758 if (!cy_is_Z(card)) {
3786 chip = channel >> 2; 3759 chip = channel >> 2;
3787 channel &= 0x03; 3760 channel &= 0x03;
3788 index = card->bus_index; 3761 index = card->bus_index;
@@ -3810,7 +3783,7 @@ static int get_threshold(struct cyclades_port *info,
3810 3783
3811 card = info->card; 3784 card = info->card;
3812 channel = info->line - card->first_line; 3785 channel = info->line - card->first_line;
3813 if (!IS_CYC_Z(*card)) { 3786 if (!cy_is_Z(card)) {
3814 chip = channel >> 2; 3787 chip = channel >> 2;
3815 channel &= 0x03; 3788 channel &= 0x03;
3816 index = card->bus_index; 3789 index = card->bus_index;
@@ -3844,7 +3817,7 @@ static int set_timeout(struct cyclades_port *info, unsigned long value)
3844 3817
3845 card = info->card; 3818 card = info->card;
3846 channel = info->line - card->first_line; 3819 channel = info->line - card->first_line;
3847 if (!IS_CYC_Z(*card)) { 3820 if (!cy_is_Z(card)) {
3848 chip = channel >> 2; 3821 chip = channel >> 2;
3849 channel &= 0x03; 3822 channel &= 0x03;
3850 index = card->bus_index; 3823 index = card->bus_index;
@@ -3867,7 +3840,7 @@ static int get_timeout(struct cyclades_port *info,
3867 3840
3868 card = info->card; 3841 card = info->card;
3869 channel = info->line - card->first_line; 3842 channel = info->line - card->first_line;
3870 if (!IS_CYC_Z(*card)) { 3843 if (!cy_is_Z(card)) {
3871 chip = channel >> 2; 3844 chip = channel >> 2;
3872 channel &= 0x03; 3845 channel &= 0x03;
3873 index = card->bus_index; 3846 index = card->bus_index;
@@ -4121,7 +4094,7 @@ static void cy_send_xchar(struct tty_struct *tty, char ch)
4121 card = info->card; 4094 card = info->card;
4122 channel = info->line - card->first_line; 4095 channel = info->line - card->first_line;
4123 4096
4124 if (IS_CYC_Z(*card)) { 4097 if (cy_is_Z(card)) {
4125 if (ch == STOP_CHAR(tty)) 4098 if (ch == STOP_CHAR(tty))
4126 cyz_issue_cmd(card, channel, C_CM_SENDXOFF, 0L); 4099 cyz_issue_cmd(card, channel, C_CM_SENDXOFF, 0L);
4127 else if (ch == START_CHAR(tty)) 4100 else if (ch == START_CHAR(tty))
@@ -4154,7 +4127,7 @@ static void cy_throttle(struct tty_struct *tty)
4154 card = info->card; 4127 card = info->card;
4155 4128
4156 if (I_IXOFF(tty)) { 4129 if (I_IXOFF(tty)) {
4157 if (!IS_CYC_Z(*card)) 4130 if (!cy_is_Z(card))
4158 cy_send_xchar(tty, STOP_CHAR(tty)); 4131 cy_send_xchar(tty, STOP_CHAR(tty));
4159 else 4132 else
4160 info->throttle = 1; 4133 info->throttle = 1;
@@ -4162,7 +4135,7 @@ static void cy_throttle(struct tty_struct *tty)
4162 4135
4163 if (tty->termios->c_cflag & CRTSCTS) { 4136 if (tty->termios->c_cflag & CRTSCTS) {
4164 channel = info->line - card->first_line; 4137 channel = info->line - card->first_line;
4165 if (!IS_CYC_Z(*card)) { 4138 if (!cy_is_Z(card)) {
4166 chip = channel >> 2; 4139 chip = channel >> 2;
4167 channel &= 0x03; 4140 channel &= 0x03;
4168 index = card->bus_index; 4141 index = card->bus_index;
@@ -4219,7 +4192,7 @@ static void cy_unthrottle(struct tty_struct *tty)
4219 if (tty->termios->c_cflag & CRTSCTS) { 4192 if (tty->termios->c_cflag & CRTSCTS) {
4220 card = info->card; 4193 card = info->card;
4221 channel = info->line - card->first_line; 4194 channel = info->line - card->first_line;
4222 if (!IS_CYC_Z(*card)) { 4195 if (!cy_is_Z(card)) {
4223 chip = channel >> 2; 4196 chip = channel >> 2;
4224 channel &= 0x03; 4197 channel &= 0x03;
4225 index = card->bus_index; 4198 index = card->bus_index;
@@ -4263,7 +4236,7 @@ static void cy_stop(struct tty_struct *tty)
4263 4236
4264 cinfo = info->card; 4237 cinfo = info->card;
4265 channel = info->line - cinfo->first_line; 4238 channel = info->line - cinfo->first_line;
4266 if (!IS_CYC_Z(*cinfo)) { 4239 if (!cy_is_Z(cinfo)) {
4267 index = cinfo->bus_index; 4240 index = cinfo->bus_index;
4268 chip = channel >> 2; 4241 chip = channel >> 2;
4269 channel &= 0x03; 4242 channel &= 0x03;
@@ -4296,7 +4269,7 @@ static void cy_start(struct tty_struct *tty)
4296 cinfo = info->card; 4269 cinfo = info->card;
4297 channel = info->line - cinfo->first_line; 4270 channel = info->line - cinfo->first_line;
4298 index = cinfo->bus_index; 4271 index = cinfo->bus_index;
4299 if (!IS_CYC_Z(*cinfo)) { 4272 if (!cy_is_Z(cinfo)) {
4300 chip = channel >> 2; 4273 chip = channel >> 2;
4301 channel &= 0x03; 4274 channel &= 0x03;
4302 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index); 4275 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
@@ -4347,33 +4320,20 @@ static void cy_hangup(struct tty_struct *tty)
4347static int __devinit cy_init_card(struct cyclades_card *cinfo) 4320static int __devinit cy_init_card(struct cyclades_card *cinfo)
4348{ 4321{
4349 struct cyclades_port *info; 4322 struct cyclades_port *info;
4350 u32 uninitialized_var(mailbox); 4323 unsigned int port;
4351 unsigned int nports, port;
4352 unsigned short chip_number; 4324 unsigned short chip_number;
4353 int uninitialized_var(index);
4354 4325
4355 spin_lock_init(&cinfo->card_lock); 4326 spin_lock_init(&cinfo->card_lock);
4327 cinfo->intr_enabled = 0;
4356 4328
4357 if (IS_CYC_Z(*cinfo)) { /* Cyclades-Z */ 4329 cinfo->ports = kcalloc(cinfo->nports, sizeof(*cinfo->ports),
4358 mailbox = readl(&((struct RUNTIME_9060 __iomem *) 4330 GFP_KERNEL);
4359 cinfo->ctl_addr)->mail_box_0);
4360 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
4361 cinfo->intr_enabled = 0;
4362 cinfo->nports = 0; /* Will be correctly set later, after
4363 Z FW is loaded */
4364 } else {
4365 index = cinfo->bus_index;
4366 nports = cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips;
4367 }
4368
4369 cinfo->ports = kzalloc(sizeof(*cinfo->ports) * nports, GFP_KERNEL);
4370 if (cinfo->ports == NULL) { 4331 if (cinfo->ports == NULL) {
4371 printk(KERN_ERR "Cyclades: cannot allocate ports\n"); 4332 printk(KERN_ERR "Cyclades: cannot allocate ports\n");
4372 cinfo->nports = 0;
4373 return -ENOMEM; 4333 return -ENOMEM;
4374 } 4334 }
4375 4335
4376 for (port = cinfo->first_line; port < cinfo->first_line + nports; 4336 for (port = cinfo->first_line; port < cinfo->first_line + cinfo->nports;
4377 port++) { 4337 port++) {
4378 info = &cinfo->ports[port - cinfo->first_line]; 4338 info = &cinfo->ports[port - cinfo->first_line];
4379 tty_port_init(&info->port); 4339 tty_port_init(&info->port);
@@ -4387,9 +4347,9 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo)
4387 init_completion(&info->shutdown_wait); 4347 init_completion(&info->shutdown_wait);
4388 init_waitqueue_head(&info->delta_msr_wait); 4348 init_waitqueue_head(&info->delta_msr_wait);
4389 4349
4390 if (IS_CYC_Z(*cinfo)) { 4350 if (cy_is_Z(cinfo)) {
4391 info->type = PORT_STARTECH; 4351 info->type = PORT_STARTECH;
4392 if (mailbox == ZO_V1) 4352 if (cinfo->hw_ver == ZO_V1)
4393 info->xmit_fifo_size = CYZ_FIFO_SIZE; 4353 info->xmit_fifo_size = CYZ_FIFO_SIZE;
4394 else 4354 else
4395 info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE; 4355 info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE;
@@ -4398,6 +4358,7 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo)
4398 cyz_rx_restart, (unsigned long)info); 4358 cyz_rx_restart, (unsigned long)info);
4399#endif 4359#endif
4400 } else { 4360 } else {
4361 int index = cinfo->bus_index;
4401 info->type = PORT_CIRRUS; 4362 info->type = PORT_CIRRUS;
4402 info->xmit_fifo_size = CyMAX_CHAR_FIFO; 4363 info->xmit_fifo_size = CyMAX_CHAR_FIFO;
4403 info->cor1 = CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS; 4364 info->cor1 = CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS;
@@ -4430,7 +4391,7 @@ static int __devinit cy_init_card(struct cyclades_card *cinfo)
4430 } 4391 }
4431 4392
4432#ifndef CONFIG_CYZ_INTR 4393#ifndef CONFIG_CYZ_INTR
4433 if (IS_CYC_Z(*cinfo) && !timer_pending(&cyz_timerlist)) { 4394 if (cy_is_Z(cinfo) && !timer_pending(&cyz_timerlist)) {
4434 mod_timer(&cyz_timerlist, jiffies + 1); 4395 mod_timer(&cyz_timerlist, jiffies + 1);
4435#ifdef CY_PCI_DEBUG 4396#ifdef CY_PCI_DEBUG
4436 printk(KERN_DEBUG "Cyclades-Z polling initialized\n"); 4397 printk(KERN_DEBUG "Cyclades-Z polling initialized\n");
@@ -4621,11 +4582,12 @@ static int __init cy_detect_isa(void)
4621 4582
4622 /* set cy_card */ 4583 /* set cy_card */
4623 cy_card[j].base_addr = cy_isa_address; 4584 cy_card[j].base_addr = cy_isa_address;
4624 cy_card[j].ctl_addr = NULL; 4585 cy_card[j].ctl_addr.p9050 = NULL;
4625 cy_card[j].irq = (int)cy_isa_irq; 4586 cy_card[j].irq = (int)cy_isa_irq;
4626 cy_card[j].bus_index = 0; 4587 cy_card[j].bus_index = 0;
4627 cy_card[j].first_line = cy_next_channel; 4588 cy_card[j].first_line = cy_next_channel;
4628 cy_card[j].num_chips = cy_isa_nchan / 4; 4589 cy_card[j].num_chips = cy_isa_nchan / CyPORTS_PER_CHIP;
4590 cy_card[j].nports = cy_isa_nchan;
4629 if (cy_init_card(&cy_card[j])) { 4591 if (cy_init_card(&cy_card[j])) {
4630 cy_card[j].base_addr = NULL; 4592 cy_card[j].base_addr = NULL;
4631 free_irq(cy_isa_irq, &cy_card[j]); 4593 free_irq(cy_isa_irq, &cy_card[j]);
@@ -4781,7 +4743,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4781 struct CUSTOM_REG __iomem *cust = base_addr; 4743 struct CUSTOM_REG __iomem *cust = base_addr;
4782 struct ZFW_CTRL __iomem *pt_zfwctrl; 4744 struct ZFW_CTRL __iomem *pt_zfwctrl;
4783 void __iomem *tmp; 4745 void __iomem *tmp;
4784 u32 mailbox, status; 4746 u32 mailbox, status, nchan;
4785 unsigned int i; 4747 unsigned int i;
4786 int retval; 4748 int retval;
4787 4749
@@ -4793,7 +4755,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4793 4755
4794 /* Check whether the firmware is already loaded and running. If 4756 /* Check whether the firmware is already loaded and running. If
4795 positive, skip this board */ 4757 positive, skip this board */
4796 if (Z_FPGA_LOADED(ctl_addr) && readl(&fid->signature) == ZFIRM_ID) { 4758 if (__cyz_fpga_loaded(ctl_addr) && readl(&fid->signature) == ZFIRM_ID) {
4797 u32 cntval = readl(base_addr + 0x190); 4759 u32 cntval = readl(base_addr + 0x190);
4798 4760
4799 udelay(100); 4761 udelay(100);
@@ -4812,7 +4774,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4812 4774
4813 mailbox = readl(&ctl_addr->mail_box_0); 4775 mailbox = readl(&ctl_addr->mail_box_0);
4814 4776
4815 if (mailbox == 0 || Z_FPGA_LOADED(ctl_addr)) { 4777 if (mailbox == 0 || __cyz_fpga_loaded(ctl_addr)) {
4816 /* stops CPU and set window to beginning of RAM */ 4778 /* stops CPU and set window to beginning of RAM */
4817 cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); 4779 cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
4818 cy_writel(&cust->cpu_stop, 0); 4780 cy_writel(&cust->cpu_stop, 0);
@@ -4828,7 +4790,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4828 base_addr); 4790 base_addr);
4829 if (retval) 4791 if (retval)
4830 goto err_rel; 4792 goto err_rel;
4831 if (!Z_FPGA_LOADED(ctl_addr)) { 4793 if (!__cyz_fpga_loaded(ctl_addr)) {
4832 dev_err(&pdev->dev, "fw upload successful, but fw is " 4794 dev_err(&pdev->dev, "fw upload successful, but fw is "
4833 "not loaded\n"); 4795 "not loaded\n");
4834 goto err_rel; 4796 goto err_rel;
@@ -4887,7 +4849,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4887 "system before loading the new FW to the " 4849 "system before loading the new FW to the "
4888 "Cyclades-Z.\n"); 4850 "Cyclades-Z.\n");
4889 4851
4890 if (Z_FPGA_LOADED(ctl_addr)) 4852 if (__cyz_fpga_loaded(ctl_addr))
4891 plx_init(pdev, irq, ctl_addr); 4853 plx_init(pdev, irq, ctl_addr);
4892 4854
4893 retval = -EIO; 4855 retval = -EIO;
@@ -4902,16 +4864,16 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4902 base_addr + ID_ADDRESS, readl(&fid->zfwctrl_addr), 4864 base_addr + ID_ADDRESS, readl(&fid->zfwctrl_addr),
4903 base_addr + readl(&fid->zfwctrl_addr)); 4865 base_addr + readl(&fid->zfwctrl_addr));
4904 4866
4867 nchan = readl(&pt_zfwctrl->board_ctrl.n_channel);
4905 dev_info(&pdev->dev, "Cyclades-Z FW loaded: version = %x, ports = %u\n", 4868 dev_info(&pdev->dev, "Cyclades-Z FW loaded: version = %x, ports = %u\n",
4906 readl(&pt_zfwctrl->board_ctrl.fw_version), 4869 readl(&pt_zfwctrl->board_ctrl.fw_version), nchan);
4907 readl(&pt_zfwctrl->board_ctrl.n_channel));
4908 4870
4909 if (readl(&pt_zfwctrl->board_ctrl.n_channel) == 0) { 4871 if (nchan == 0) {
4910 dev_warn(&pdev->dev, "no Cyclades-Z ports were found. Please " 4872 dev_warn(&pdev->dev, "no Cyclades-Z ports were found. Please "
4911 "check the connection between the Z host card and the " 4873 "check the connection between the Z host card and the "
4912 "serial expanders.\n"); 4874 "serial expanders.\n");
4913 4875
4914 if (Z_FPGA_LOADED(ctl_addr)) 4876 if (__cyz_fpga_loaded(ctl_addr))
4915 plx_init(pdev, irq, ctl_addr); 4877 plx_init(pdev, irq, ctl_addr);
4916 4878
4917 dev_info(&pdev->dev, "Null number of ports detected. Board " 4879 dev_info(&pdev->dev, "Null number of ports detected. Board "
@@ -4932,9 +4894,7 @@ static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
4932 cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) | 4894 cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) |
4933 0x00030800UL); 4895 0x00030800UL);
4934 4896
4935 plx_init(pdev, irq, ctl_addr); 4897 return nchan;
4936
4937 return 0;
4938err_rel: 4898err_rel:
4939 release_firmware(fw); 4899 release_firmware(fw);
4940err: 4900err:
@@ -4946,7 +4906,7 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
4946{ 4906{
4947 void __iomem *addr0 = NULL, *addr2 = NULL; 4907 void __iomem *addr0 = NULL, *addr2 = NULL;
4948 char *card_name = NULL; 4908 char *card_name = NULL;
4949 u32 mailbox; 4909 u32 uninitialized_var(mailbox);
4950 unsigned int device_id, nchan = 0, card_no, i; 4910 unsigned int device_id, nchan = 0, card_no, i;
4951 unsigned char plx_ver; 4911 unsigned char plx_ver;
4952 int retval, irq; 4912 int retval, irq;
@@ -5023,11 +4983,12 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5023 } 4983 }
5024 4984
5025 /* Disable interrupts on the PLX before resetting it */ 4985 /* Disable interrupts on the PLX before resetting it */
5026 cy_writew(addr0 + 0x68, readw(addr0 + 0x68) & ~0x0900); 4986 cy_writew(&ctl_addr->intr_ctrl_stat,
4987 readw(&ctl_addr->intr_ctrl_stat) & ~0x0900);
5027 4988
5028 plx_init(pdev, irq, addr0); 4989 plx_init(pdev, irq, addr0);
5029 4990
5030 mailbox = (u32)readl(&ctl_addr->mail_box_0); 4991 mailbox = readl(&ctl_addr->mail_box_0);
5031 4992
5032 addr2 = ioremap_nocache(pci_resource_start(pdev, 2), 4993 addr2 = ioremap_nocache(pci_resource_start(pdev, 2),
5033 mailbox == ZE_V1 ? CyPCI_Ze_win : CyPCI_Zwin); 4994 mailbox == ZE_V1 ? CyPCI_Ze_win : CyPCI_Zwin);
@@ -5038,12 +4999,8 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5038 4999
5039 if (mailbox == ZE_V1) { 5000 if (mailbox == ZE_V1) {
5040 card_name = "Cyclades-Ze"; 5001 card_name = "Cyclades-Ze";
5041
5042 readl(&ctl_addr->mail_box_0);
5043 nchan = ZE_V1_NPORTS;
5044 } else { 5002 } else {
5045 card_name = "Cyclades-8Zo"; 5003 card_name = "Cyclades-8Zo";
5046
5047#ifdef CY_PCI_DEBUG 5004#ifdef CY_PCI_DEBUG
5048 if (mailbox == ZO_V1) { 5005 if (mailbox == ZO_V1) {
5049 cy_writel(&ctl_addr->loc_addr_base, WIN_CREG); 5006 cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
@@ -5065,15 +5022,12 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5065 */ 5022 */
5066 if ((mailbox == ZO_V1) || (mailbox == ZO_V2)) 5023 if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
5067 cy_writel(addr2 + ID_ADDRESS, 0L); 5024 cy_writel(addr2 + ID_ADDRESS, 0L);
5068
5069 retval = cyz_load_fw(pdev, addr2, addr0, irq);
5070 if (retval)
5071 goto err_unmap;
5072 /* This must be a Cyclades-8Zo/PCI. The extendable
5073 version will have a different device_id and will
5074 be allocated its maximum number of ports. */
5075 nchan = 8;
5076 } 5025 }
5026
5027 retval = cyz_load_fw(pdev, addr2, addr0, irq);
5028 if (retval <= 0)
5029 goto err_unmap;
5030 nchan = retval;
5077 } 5031 }
5078 5032
5079 if ((cy_next_channel + nchan) > NR_PORTS) { 5033 if ((cy_next_channel + nchan) > NR_PORTS) {
@@ -5103,8 +5057,10 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5103 dev_err(&pdev->dev, "could not allocate IRQ\n"); 5057 dev_err(&pdev->dev, "could not allocate IRQ\n");
5104 goto err_unmap; 5058 goto err_unmap;
5105 } 5059 }
5106 cy_card[card_no].num_chips = nchan / 4; 5060 cy_card[card_no].num_chips = nchan / CyPORTS_PER_CHIP;
5107 } else { 5061 } else {
5062 cy_card[card_no].hw_ver = mailbox;
5063 cy_card[card_no].num_chips = (unsigned int)-1;
5108#ifdef CONFIG_CYZ_INTR 5064#ifdef CONFIG_CYZ_INTR
5109 /* allocate IRQ only if board has an IRQ */ 5065 /* allocate IRQ only if board has an IRQ */
5110 if (irq != 0 && irq != 255) { 5066 if (irq != 0 && irq != 255) {
@@ -5117,15 +5073,15 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5117 } 5073 }
5118 } 5074 }
5119#endif /* CONFIG_CYZ_INTR */ 5075#endif /* CONFIG_CYZ_INTR */
5120 cy_card[card_no].num_chips = (unsigned int)-1;
5121 } 5076 }
5122 5077
5123 /* set cy_card */ 5078 /* set cy_card */
5124 cy_card[card_no].base_addr = addr2; 5079 cy_card[card_no].base_addr = addr2;
5125 cy_card[card_no].ctl_addr = addr0; 5080 cy_card[card_no].ctl_addr.p9050 = addr0;
5126 cy_card[card_no].irq = irq; 5081 cy_card[card_no].irq = irq;
5127 cy_card[card_no].bus_index = 1; 5082 cy_card[card_no].bus_index = 1;
5128 cy_card[card_no].first_line = cy_next_channel; 5083 cy_card[card_no].first_line = cy_next_channel;
5084 cy_card[card_no].nports = nchan;
5129 retval = cy_init_card(&cy_card[card_no]); 5085 retval = cy_init_card(&cy_card[card_no]);
5130 if (retval) 5086 if (retval)
5131 goto err_null; 5087 goto err_null;
@@ -5138,17 +5094,20 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5138 plx_ver = readb(addr2 + CyPLX_VER) & 0x0f; 5094 plx_ver = readb(addr2 + CyPLX_VER) & 0x0f;
5139 switch (plx_ver) { 5095 switch (plx_ver) {
5140 case PLX_9050: 5096 case PLX_9050:
5141
5142 cy_writeb(addr0 + 0x4c, 0x43); 5097 cy_writeb(addr0 + 0x4c, 0x43);
5143 break; 5098 break;
5144 5099
5145 case PLX_9060: 5100 case PLX_9060:
5146 case PLX_9080: 5101 case PLX_9080:
5147 default: /* Old boards, use PLX_9060 */ 5102 default: /* Old boards, use PLX_9060 */
5148 plx_init(pdev, irq, addr0); 5103 {
5149 cy_writew(addr0 + 0x68, readw(addr0 + 0x68) | 0x0900); 5104 struct RUNTIME_9060 __iomem *ctl_addr = addr0;
5105 plx_init(pdev, irq, ctl_addr);
5106 cy_writew(&ctl_addr->intr_ctrl_stat,
5107 readw(&ctl_addr->intr_ctrl_stat) | 0x0900);
5150 break; 5108 break;
5151 } 5109 }
5110 }
5152 } 5111 }
5153 5112
5154 dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from " 5113 dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from "
@@ -5179,22 +5138,23 @@ static void __devexit cy_pci_remove(struct pci_dev *pdev)
5179 unsigned int i; 5138 unsigned int i;
5180 5139
5181 /* non-Z with old PLX */ 5140 /* non-Z with old PLX */
5182 if (!IS_CYC_Z(*cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) == 5141 if (!cy_is_Z(cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) ==
5183 PLX_9050) 5142 PLX_9050)
5184 cy_writeb(cinfo->ctl_addr + 0x4c, 0); 5143 cy_writeb(cinfo->ctl_addr.p9050 + 0x4c, 0);
5185 else 5144 else
5186#ifndef CONFIG_CYZ_INTR 5145#ifndef CONFIG_CYZ_INTR
5187 if (!IS_CYC_Z(*cinfo)) 5146 if (!cy_is_Z(cinfo))
5188#endif 5147#endif
5189 cy_writew(cinfo->ctl_addr + 0x68, 5148 cy_writew(&cinfo->ctl_addr.p9060->intr_ctrl_stat,
5190 readw(cinfo->ctl_addr + 0x68) & ~0x0900); 5149 readw(&cinfo->ctl_addr.p9060->intr_ctrl_stat) &
5150 ~0x0900);
5191 5151
5192 iounmap(cinfo->base_addr); 5152 iounmap(cinfo->base_addr);
5193 if (cinfo->ctl_addr) 5153 if (cinfo->ctl_addr.p9050)
5194 iounmap(cinfo->ctl_addr); 5154 iounmap(cinfo->ctl_addr.p9050);
5195 if (cinfo->irq 5155 if (cinfo->irq
5196#ifndef CONFIG_CYZ_INTR 5156#ifndef CONFIG_CYZ_INTR
5197 && !IS_CYC_Z(*cinfo) 5157 && !cy_is_Z(cinfo)
5198#endif /* CONFIG_CYZ_INTR */ 5158#endif /* CONFIG_CYZ_INTR */
5199 ) 5159 )
5200 free_irq(cinfo->irq, cinfo); 5160 free_irq(cinfo->irq, cinfo);
@@ -5240,7 +5200,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
5240 (cur_jifs - info->idle_stats.recv_idle)/ 5200 (cur_jifs - info->idle_stats.recv_idle)/
5241 HZ, info->idle_stats.overruns, 5201 HZ, info->idle_stats.overruns,
5242 /* FIXME: double check locking */ 5202 /* FIXME: double check locking */
5243 (long)info->port.tty->ldisc.ops->num); 5203 (long)info->port.tty->ldisc->ops->num);
5244 else 5204 else
5245 seq_printf(m, "%3d %8lu %10lu %8lu " 5205 seq_printf(m, "%3d %8lu %10lu %8lu "
5246 "%10lu %8lu %9lu %6ld\n", 5206 "%10lu %8lu %9lu %6ld\n",
@@ -5386,11 +5346,11 @@ static void __exit cy_cleanup_module(void)
5386 /* clear interrupt */ 5346 /* clear interrupt */
5387 cy_writeb(card->base_addr + Cy_ClrIntr, 0); 5347 cy_writeb(card->base_addr + Cy_ClrIntr, 0);
5388 iounmap(card->base_addr); 5348 iounmap(card->base_addr);
5389 if (card->ctl_addr) 5349 if (card->ctl_addr.p9050)
5390 iounmap(card->ctl_addr); 5350 iounmap(card->ctl_addr.p9050);
5391 if (card->irq 5351 if (card->irq
5392#ifndef CONFIG_CYZ_INTR 5352#ifndef CONFIG_CYZ_INTR
5393 && !IS_CYC_Z(*card) 5353 && !cy_is_Z(card)
5394#endif /* CONFIG_CYZ_INTR */ 5354#endif /* CONFIG_CYZ_INTR */
5395 ) 5355 )
5396 free_irq(card->irq, card); 5356 free_irq(card->irq, card);
diff --git a/drivers/char/dtlk.c b/drivers/char/dtlk.c
index 6b900b297cc6..52e06589821d 100644
--- a/drivers/char/dtlk.c
+++ b/drivers/char/dtlk.c
@@ -571,7 +571,7 @@ static char dtlk_read_tts(void)
571 portval = inb_p(dtlk_port_tts); 571 portval = inb_p(dtlk_port_tts);
572 } while ((portval & TTS_READABLE) == 0 && 572 } while ((portval & TTS_READABLE) == 0 &&
573 retries++ < DTLK_MAX_RETRIES); 573 retries++ < DTLK_MAX_RETRIES);
574 if (retries == DTLK_MAX_RETRIES) 574 if (retries > DTLK_MAX_RETRIES)
575 printk(KERN_ERR "dtlk_read_tts() timeout\n"); 575 printk(KERN_ERR "dtlk_read_tts() timeout\n");
576 576
577 ch = inb_p(dtlk_port_tts); /* input from TTS port */ 577 ch = inb_p(dtlk_port_tts); /* input from TTS port */
@@ -583,7 +583,7 @@ static char dtlk_read_tts(void)
583 portval = inb_p(dtlk_port_tts); 583 portval = inb_p(dtlk_port_tts);
584 } while ((portval & TTS_READABLE) != 0 && 584 } while ((portval & TTS_READABLE) != 0 &&
585 retries++ < DTLK_MAX_RETRIES); 585 retries++ < DTLK_MAX_RETRIES);
586 if (retries == DTLK_MAX_RETRIES) 586 if (retries > DTLK_MAX_RETRIES)
587 printk(KERN_ERR "dtlk_read_tts() timeout\n"); 587 printk(KERN_ERR "dtlk_read_tts() timeout\n");
588 588
589 TRACE_RET; 589 TRACE_RET;
@@ -640,7 +640,7 @@ static char dtlk_write_tts(char ch)
640 while ((inb_p(dtlk_port_tts) & TTS_WRITABLE) == 0 && 640 while ((inb_p(dtlk_port_tts) & TTS_WRITABLE) == 0 &&
641 retries++ < DTLK_MAX_RETRIES) /* DT ready? */ 641 retries++ < DTLK_MAX_RETRIES) /* DT ready? */
642 ; 642 ;
643 if (retries == DTLK_MAX_RETRIES) 643 if (retries > DTLK_MAX_RETRIES)
644 printk(KERN_ERR "dtlk_write_tts() timeout\n"); 644 printk(KERN_ERR "dtlk_write_tts() timeout\n");
645 645
646 outb_p(ch, dtlk_port_tts); /* output to TTS port */ 646 outb_p(ch, dtlk_port_tts); /* output to TTS port */
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index af7c13ca9493..abef1f7d84fe 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -745,7 +745,7 @@ static int epca_carrier_raised(struct tty_port *port)
745 return 0; 745 return 0;
746} 746}
747 747
748static void epca_raise_dtr_rts(struct tty_port *port) 748static void epca_dtr_rts(struct tty_port *port, int onoff)
749{ 749{
750} 750}
751 751
@@ -925,7 +925,7 @@ static const struct tty_operations pc_ops = {
925 925
926static const struct tty_port_operations epca_port_ops = { 926static const struct tty_port_operations epca_port_ops = {
927 .carrier_raised = epca_carrier_raised, 927 .carrier_raised = epca_carrier_raised,
928 .raise_dtr_rts = epca_raise_dtr_rts, 928 .dtr_rts = epca_dtr_rts,
929}; 929};
930 930
931static int info_open(struct tty_struct *tty, struct file *filp) 931static int info_open(struct tty_struct *tty, struct file *filp)
@@ -1518,7 +1518,7 @@ static void doevent(int crd)
1518 if (event & MODEMCHG_IND) { 1518 if (event & MODEMCHG_IND) {
1519 /* A modem signal change has been indicated */ 1519 /* A modem signal change has been indicated */
1520 ch->imodem = mstat; 1520 ch->imodem = mstat;
1521 if (test_bit(ASYNC_CHECK_CD, &ch->port.flags)) { 1521 if (test_bit(ASYNCB_CHECK_CD, &ch->port.flags)) {
1522 /* We are now receiving dcd */ 1522 /* We are now receiving dcd */
1523 if (mstat & ch->dcd) 1523 if (mstat & ch->dcd)
1524 wake_up_interruptible(&ch->port.open_wait); 1524 wake_up_interruptible(&ch->port.open_wait);
@@ -1765,9 +1765,9 @@ static void epcaparam(struct tty_struct *tty, struct channel *ch)
1765 * that the driver will wait on carrier detect. 1765 * that the driver will wait on carrier detect.
1766 */ 1766 */
1767 if (ts->c_cflag & CLOCAL) 1767 if (ts->c_cflag & CLOCAL)
1768 clear_bit(ASYNC_CHECK_CD, &ch->port.flags); 1768 clear_bit(ASYNCB_CHECK_CD, &ch->port.flags);
1769 else 1769 else
1770 set_bit(ASYNC_CHECK_CD, &ch->port.flags); 1770 set_bit(ASYNCB_CHECK_CD, &ch->port.flags);
1771 mval = ch->m_dtr | ch->m_rts; 1771 mval = ch->m_dtr | ch->m_rts;
1772 } /* End CBAUD not detected */ 1772 } /* End CBAUD not detected */
1773 iflag = termios2digi_i(ch, ts->c_iflag); 1773 iflag = termios2digi_i(ch, ts->c_iflag);
@@ -2114,8 +2114,8 @@ static int pc_ioctl(struct tty_struct *tty, struct file *file,
2114 tty_wait_until_sent(tty, 0); 2114 tty_wait_until_sent(tty, 0);
2115 } else { 2115 } else {
2116 /* ldisc lock already held in ioctl */ 2116 /* ldisc lock already held in ioctl */
2117 if (tty->ldisc.ops->flush_buffer) 2117 if (tty->ldisc->ops->flush_buffer)
2118 tty->ldisc.ops->flush_buffer(tty); 2118 tty->ldisc->ops->flush_buffer(tty);
2119 } 2119 }
2120 unlock_kernel(); 2120 unlock_kernel();
2121 /* Fall Thru */ 2121 /* Fall Thru */
@@ -2244,7 +2244,8 @@ static void do_softint(struct work_struct *work)
2244 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { 2244 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2245 tty_hangup(tty); 2245 tty_hangup(tty);
2246 wake_up_interruptible(&ch->port.open_wait); 2246 wake_up_interruptible(&ch->port.open_wait);
2247 clear_bit(ASYNC_NORMAL_ACTIVE, &ch->port.flags); 2247 clear_bit(ASYNCB_NORMAL_ACTIVE,
2248 &ch->port.flags);
2248 } 2249 }
2249 } 2250 }
2250 tty_kref_put(tty); 2251 tty_kref_put(tty);
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index 340ba4f9dc54..4a9f3492b921 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -224,7 +224,7 @@ static void hpet_timer_set_irq(struct hpet_dev *devp)
224 break; 224 break;
225 } 225 }
226 226
227 gsi = acpi_register_gsi(irq, ACPI_LEVEL_SENSITIVE, 227 gsi = acpi_register_gsi(NULL, irq, ACPI_LEVEL_SENSITIVE,
228 ACPI_ACTIVE_LOW); 228 ACPI_ACTIVE_LOW);
229 if (gsi > 0) 229 if (gsi > 0)
230 break; 230 break;
@@ -939,7 +939,7 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
939 irqp = &res->data.extended_irq; 939 irqp = &res->data.extended_irq;
940 940
941 for (i = 0; i < irqp->interrupt_count; i++) { 941 for (i = 0; i < irqp->interrupt_count; i++) {
942 irq = acpi_register_gsi(irqp->interrupts[i], 942 irq = acpi_register_gsi(NULL, irqp->interrupts[i],
943 irqp->triggering, irqp->polarity); 943 irqp->triggering, irqp->polarity);
944 if (irq < 0) 944 if (irq < 0)
945 return AE_ERROR; 945 return AE_ERROR;
diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
index 449727b6166d..936d05bf37fa 100644
--- a/drivers/char/hvc_iseries.c
+++ b/drivers/char/hvc_iseries.c
@@ -241,7 +241,7 @@ static int __devexit hvc_vio_remove(struct vio_dev *vdev)
241static struct vio_driver hvc_vio_driver = { 241static struct vio_driver hvc_vio_driver = {
242 .id_table = hvc_driver_table, 242 .id_table = hvc_driver_table,
243 .probe = hvc_vio_probe, 243 .probe = hvc_vio_probe,
244 .remove = hvc_vio_remove, 244 .remove = __devexit_p(hvc_vio_remove),
245 .driver = { 245 .driver = {
246 .name = hvc_driver_name, 246 .name = hvc_driver_name,
247 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
index 54481a887769..86105efb4eb6 100644
--- a/drivers/char/hvc_iucv.c
+++ b/drivers/char/hvc_iucv.c
@@ -4,7 +4,7 @@
4 * This HVC device driver provides terminal access using 4 * This HVC device driver provides terminal access using
5 * z/VM IUCV communication paths. 5 * z/VM IUCV communication paths.
6 * 6 *
7 * Copyright IBM Corp. 2008 7 * Copyright IBM Corp. 2008, 2009
8 * 8 *
9 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com> 9 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
10 */ 10 */
@@ -15,6 +15,7 @@
15#include <asm/ebcdic.h> 15#include <asm/ebcdic.h>
16#include <linux/ctype.h> 16#include <linux/ctype.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/device.h>
18#include <linux/init.h> 19#include <linux/init.h>
19#include <linux/mempool.h> 20#include <linux/mempool.h>
20#include <linux/moduleparam.h> 21#include <linux/moduleparam.h>
@@ -74,6 +75,7 @@ struct hvc_iucv_private {
74 wait_queue_head_t sndbuf_waitq; /* wait for send completion */ 75 wait_queue_head_t sndbuf_waitq; /* wait for send completion */
75 struct list_head tty_outqueue; /* outgoing IUCV messages */ 76 struct list_head tty_outqueue; /* outgoing IUCV messages */
76 struct list_head tty_inqueue; /* incoming IUCV messages */ 77 struct list_head tty_inqueue; /* incoming IUCV messages */
78 struct device *dev; /* device structure */
77}; 79};
78 80
79struct iucv_tty_buffer { 81struct iucv_tty_buffer {
@@ -542,7 +544,68 @@ static void flush_sndbuf_sync(struct hvc_iucv_private *priv)
542 544
543 if (sync_wait) 545 if (sync_wait)
544 wait_event_timeout(priv->sndbuf_waitq, 546 wait_event_timeout(priv->sndbuf_waitq,
545 tty_outqueue_empty(priv), HZ); 547 tty_outqueue_empty(priv), HZ/10);
548}
549
550/**
551 * hvc_iucv_hangup() - Sever IUCV path and schedule hvc tty hang up
552 * @priv: Pointer to hvc_iucv_private structure
553 *
554 * This routine severs an existing IUCV communication path and hangs
555 * up the underlying HVC terminal device.
556 * The hang-up occurs only if an IUCV communication path is established;
557 * otherwise there is no need to hang up the terminal device.
558 *
559 * The IUCV HVC hang-up is separated into two steps:
560 * 1. After the IUCV path has been severed, the iucv_state is set to
561 * IUCV_SEVERED.
562 * 2. Later, when the HVC thread calls hvc_iucv_get_chars(), the
563 * IUCV_SEVERED state causes the tty hang-up in the HVC layer.
564 *
565 * If the tty has not yet been opened, clean up the hvc_iucv_private
566 * structure to allow re-connects.
567 * If the tty has been opened, let get_chars() return -EPIPE to signal
568 * the HVC layer to hang up the tty and, if so, wake up the HVC thread
569 * to call get_chars()...
570 *
571 * Special notes on hanging up a HVC terminal instantiated as console:
572 * Hang-up: 1. do_tty_hangup() replaces file ops (= hung_up_tty_fops)
573 * 2. do_tty_hangup() calls tty->ops->close() for console_filp
574 * => no hangup notifier is called by HVC (default)
575 * 2. hvc_close() returns because of tty_hung_up_p(filp)
576 * => no delete notifier is called!
577 * Finally, the back-end is not being notified, thus, the tty session is
578 * kept active (TTY_OPEN) to be ready for re-connects.
579 *
580 * Locking: spin_lock(&priv->lock) w/o disabling bh
581 */
582static void hvc_iucv_hangup(struct hvc_iucv_private *priv)
583{
584 struct iucv_path *path;
585
586 path = NULL;
587 spin_lock(&priv->lock);
588 if (priv->iucv_state == IUCV_CONNECTED) {
589 path = priv->path;
590 priv->path = NULL;
591 priv->iucv_state = IUCV_SEVERED;
592 if (priv->tty_state == TTY_CLOSED)
593 hvc_iucv_cleanup(priv);
594 else
595 /* console is special (see above) */
596 if (priv->is_console) {
597 hvc_iucv_cleanup(priv);
598 priv->tty_state = TTY_OPENED;
599 } else
600 hvc_kick();
601 }
602 spin_unlock(&priv->lock);
603
604 /* finally sever path (outside of priv->lock due to lock ordering) */
605 if (path) {
606 iucv_path_sever(path, NULL);
607 iucv_path_free(path);
608 }
546} 609}
547 610
548/** 611/**
@@ -735,11 +798,8 @@ out_path_handled:
735 * @ipuser: User specified data for this path 798 * @ipuser: User specified data for this path
736 * (AF_IUCV: port/service name and originator port) 799 * (AF_IUCV: port/service name and originator port)
737 * 800 *
738 * The function also severs the path (as required by the IUCV protocol) and 801 * This function calls the hvc_iucv_hangup() function for the
739 * sets the iucv state to IUCV_SEVERED for the associated struct 802 * respective IUCV HVC terminal.
740 * hvc_iucv_private instance. Later, the IUCV_SEVERED state triggers a tty
741 * hangup (hvc_iucv_get_chars() / hvc_iucv_write()).
742 * If tty portion of the HVC is closed, clean up the outqueue.
743 * 803 *
744 * Locking: struct hvc_iucv_private->lock 804 * Locking: struct hvc_iucv_private->lock
745 */ 805 */
@@ -747,33 +807,7 @@ static void hvc_iucv_path_severed(struct iucv_path *path, u8 ipuser[16])
747{ 807{
748 struct hvc_iucv_private *priv = path->private; 808 struct hvc_iucv_private *priv = path->private;
749 809
750 spin_lock(&priv->lock); 810 hvc_iucv_hangup(priv);
751 priv->iucv_state = IUCV_SEVERED;
752
753 /* If the tty has not yet been opened, clean up the hvc_iucv_private
754 * structure to allow re-connects.
755 * This is also done for our console device because console hangups
756 * are handled specially and no notifier is called by HVC.
757 * The tty session is active (TTY_OPEN) and ready for re-connects...
758 *
759 * If it has been opened, let get_chars() return -EPIPE to signal the
760 * HVC layer to hang up the tty.
761 * If so, we need to wake up the HVC thread to call get_chars()...
762 */
763 priv->path = NULL;
764 if (priv->tty_state == TTY_CLOSED)
765 hvc_iucv_cleanup(priv);
766 else
767 if (priv->is_console) {
768 hvc_iucv_cleanup(priv);
769 priv->tty_state = TTY_OPENED;
770 } else
771 hvc_kick();
772 spin_unlock(&priv->lock);
773
774 /* finally sever path (outside of priv->lock due to lock ordering) */
775 iucv_path_sever(path, ipuser);
776 iucv_path_free(path);
777} 811}
778 812
779/** 813/**
@@ -853,6 +887,37 @@ static void hvc_iucv_msg_complete(struct iucv_path *path,
853 destroy_tty_buffer_list(&list_remove); 887 destroy_tty_buffer_list(&list_remove);
854} 888}
855 889
890/**
891 * hvc_iucv_pm_freeze() - Freeze PM callback
892 * @dev: IUVC HVC terminal device
893 *
894 * Sever an established IUCV communication path and
895 * trigger a hang-up of the underlying HVC terminal.
896 */
897static int hvc_iucv_pm_freeze(struct device *dev)
898{
899 struct hvc_iucv_private *priv = dev_get_drvdata(dev);
900
901 local_bh_disable();
902 hvc_iucv_hangup(priv);
903 local_bh_enable();
904
905 return 0;
906}
907
908/**
909 * hvc_iucv_pm_restore_thaw() - Thaw and restore PM callback
910 * @dev: IUVC HVC terminal device
911 *
912 * Wake up the HVC thread to trigger hang-up and respective
913 * HVC back-end notifier invocations.
914 */
915static int hvc_iucv_pm_restore_thaw(struct device *dev)
916{
917 hvc_kick();
918 return 0;
919}
920
856 921
857/* HVC operations */ 922/* HVC operations */
858static struct hv_ops hvc_iucv_ops = { 923static struct hv_ops hvc_iucv_ops = {
@@ -863,6 +928,20 @@ static struct hv_ops hvc_iucv_ops = {
863 .notifier_hangup = hvc_iucv_notifier_hangup, 928 .notifier_hangup = hvc_iucv_notifier_hangup,
864}; 929};
865 930
931/* Suspend / resume device operations */
932static struct dev_pm_ops hvc_iucv_pm_ops = {
933 .freeze = hvc_iucv_pm_freeze,
934 .thaw = hvc_iucv_pm_restore_thaw,
935 .restore = hvc_iucv_pm_restore_thaw,
936};
937
938/* IUCV HVC device driver */
939static struct device_driver hvc_iucv_driver = {
940 .name = KMSG_COMPONENT,
941 .bus = &iucv_bus,
942 .pm = &hvc_iucv_pm_ops,
943};
944
866/** 945/**
867 * hvc_iucv_alloc() - Allocates a new struct hvc_iucv_private instance 946 * hvc_iucv_alloc() - Allocates a new struct hvc_iucv_private instance
868 * @id: hvc_iucv_table index 947 * @id: hvc_iucv_table index
@@ -897,14 +976,12 @@ static int __init hvc_iucv_alloc(int id, unsigned int is_console)
897 /* set console flag */ 976 /* set console flag */
898 priv->is_console = is_console; 977 priv->is_console = is_console;
899 978
900 /* finally allocate hvc */ 979 /* allocate hvc device */
901 priv->hvc = hvc_alloc(HVC_IUCV_MAGIC + id, /* PAGE_SIZE */ 980 priv->hvc = hvc_alloc(HVC_IUCV_MAGIC + id, /* PAGE_SIZE */
902 HVC_IUCV_MAGIC + id, &hvc_iucv_ops, 256); 981 HVC_IUCV_MAGIC + id, &hvc_iucv_ops, 256);
903 if (IS_ERR(priv->hvc)) { 982 if (IS_ERR(priv->hvc)) {
904 rc = PTR_ERR(priv->hvc); 983 rc = PTR_ERR(priv->hvc);
905 free_page((unsigned long) priv->sndbuf); 984 goto out_error_hvc;
906 kfree(priv);
907 return rc;
908 } 985 }
909 986
910 /* notify HVC thread instead of using polling */ 987 /* notify HVC thread instead of using polling */
@@ -915,8 +992,45 @@ static int __init hvc_iucv_alloc(int id, unsigned int is_console)
915 memcpy(priv->srv_name, name, 8); 992 memcpy(priv->srv_name, name, 8);
916 ASCEBC(priv->srv_name, 8); 993 ASCEBC(priv->srv_name, 8);
917 994
995 /* create and setup device */
996 priv->dev = kzalloc(sizeof(*priv->dev), GFP_KERNEL);
997 if (!priv->dev) {
998 rc = -ENOMEM;
999 goto out_error_dev;
1000 }
1001 dev_set_name(priv->dev, "hvc_iucv%d", id);
1002 dev_set_drvdata(priv->dev, priv);
1003 priv->dev->bus = &iucv_bus;
1004 priv->dev->parent = iucv_root;
1005 priv->dev->driver = &hvc_iucv_driver;
1006 priv->dev->release = (void (*)(struct device *)) kfree;
1007 rc = device_register(priv->dev);
1008 if (rc) {
1009 kfree(priv->dev);
1010 goto out_error_dev;
1011 }
1012
918 hvc_iucv_table[id] = priv; 1013 hvc_iucv_table[id] = priv;
919 return 0; 1014 return 0;
1015
1016out_error_dev:
1017 hvc_remove(priv->hvc);
1018out_error_hvc:
1019 free_page((unsigned long) priv->sndbuf);
1020 kfree(priv);
1021
1022 return rc;
1023}
1024
1025/**
1026 * hvc_iucv_destroy() - Destroy and free hvc_iucv_private instances
1027 */
1028static void __init hvc_iucv_destroy(struct hvc_iucv_private *priv)
1029{
1030 hvc_remove(priv->hvc);
1031 device_unregister(priv->dev);
1032 free_page((unsigned long) priv->sndbuf);
1033 kfree(priv);
920} 1034}
921 1035
922/** 1036/**
@@ -1109,6 +1223,11 @@ static int __init hvc_iucv_init(void)
1109 goto out_error; 1223 goto out_error;
1110 } 1224 }
1111 1225
1226 /* register IUCV HVC device driver */
1227 rc = driver_register(&hvc_iucv_driver);
1228 if (rc)
1229 goto out_error;
1230
1112 /* parse hvc_iucv_allow string and create z/VM user ID filter list */ 1231 /* parse hvc_iucv_allow string and create z/VM user ID filter list */
1113 if (hvc_iucv_filter_string) { 1232 if (hvc_iucv_filter_string) {
1114 rc = hvc_iucv_setup_filter(hvc_iucv_filter_string); 1233 rc = hvc_iucv_setup_filter(hvc_iucv_filter_string);
@@ -1183,15 +1302,14 @@ out_error_iucv:
1183 iucv_unregister(&hvc_iucv_handler, 0); 1302 iucv_unregister(&hvc_iucv_handler, 0);
1184out_error_hvc: 1303out_error_hvc:
1185 for (i = 0; i < hvc_iucv_devices; i++) 1304 for (i = 0; i < hvc_iucv_devices; i++)
1186 if (hvc_iucv_table[i]) { 1305 if (hvc_iucv_table[i])
1187 if (hvc_iucv_table[i]->hvc) 1306 hvc_iucv_destroy(hvc_iucv_table[i]);
1188 hvc_remove(hvc_iucv_table[i]->hvc);
1189 kfree(hvc_iucv_table[i]);
1190 }
1191out_error_memory: 1307out_error_memory:
1192 mempool_destroy(hvc_iucv_mempool); 1308 mempool_destroy(hvc_iucv_mempool);
1193 kmem_cache_destroy(hvc_iucv_buffer_cache); 1309 kmem_cache_destroy(hvc_iucv_buffer_cache);
1194out_error: 1310out_error:
1311 if (hvc_iucv_filter)
1312 kfree(hvc_iucv_filter);
1195 hvc_iucv_devices = 0; /* ensure that we do not provide any device */ 1313 hvc_iucv_devices = 0; /* ensure that we do not provide any device */
1196 return rc; 1314 return rc;
1197} 1315}
diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
index bd62dc86b47d..c72b994652ac 100644
--- a/drivers/char/hvc_vio.c
+++ b/drivers/char/hvc_vio.c
@@ -113,7 +113,7 @@ static int __devexit hvc_vio_remove(struct vio_dev *vdev)
113static struct vio_driver hvc_vio_driver = { 113static struct vio_driver hvc_vio_driver = {
114 .id_table = hvc_driver_table, 114 .id_table = hvc_driver_table,
115 .probe = hvc_vio_probe, 115 .probe = hvc_vio_probe,
116 .remove = hvc_vio_remove, 116 .remove = __devexit_p(hvc_vio_remove),
117 .driver = { 117 .driver = {
118 .name = hvc_driver_name, 118 .name = hvc_driver_name,
119 .owner = THIS_MODULE, 119 .owner = THIS_MODULE,
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index c76bccf5354d..266b858b8f85 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -347,7 +347,7 @@ static void __exit hvcs_module_exit(void);
347 347
348static inline struct hvcs_struct *from_vio_dev(struct vio_dev *viod) 348static inline struct hvcs_struct *from_vio_dev(struct vio_dev *viod)
349{ 349{
350 return viod->dev.driver_data; 350 return dev_get_drvdata(&viod->dev);
351} 351}
352/* The sysfs interface for the driver and devices */ 352/* The sysfs interface for the driver and devices */
353 353
@@ -785,7 +785,7 @@ static int __devinit hvcs_probe(
785 kref_init(&hvcsd->kref); 785 kref_init(&hvcsd->kref);
786 786
787 hvcsd->vdev = dev; 787 hvcsd->vdev = dev;
788 dev->dev.driver_data = hvcsd; 788 dev_set_drvdata(&dev->dev, hvcsd);
789 789
790 hvcsd->index = index; 790 hvcsd->index = index;
791 791
@@ -831,7 +831,7 @@ static int __devinit hvcs_probe(
831 831
832static int __devexit hvcs_remove(struct vio_dev *dev) 832static int __devexit hvcs_remove(struct vio_dev *dev)
833{ 833{
834 struct hvcs_struct *hvcsd = dev->dev.driver_data; 834 struct hvcs_struct *hvcsd = dev_get_drvdata(&dev->dev);
835 unsigned long flags; 835 unsigned long flags;
836 struct tty_struct *tty; 836 struct tty_struct *tty;
837 837
@@ -868,7 +868,7 @@ static int __devexit hvcs_remove(struct vio_dev *dev)
868static struct vio_driver hvcs_vio_driver = { 868static struct vio_driver hvcs_vio_driver = {
869 .id_table = hvcs_driver_table, 869 .id_table = hvcs_driver_table,
870 .probe = hvcs_probe, 870 .probe = hvcs_probe,
871 .remove = hvcs_remove, 871 .remove = __devexit_p(hvcs_remove),
872 .driver = { 872 .driver = {
873 .name = hvcs_driver_name, 873 .name = hvcs_driver_name,
874 .owner = THIS_MODULE, 874 .owner = THIS_MODULE,
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 5fab6470f4b2..ce66a70184f7 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -88,7 +88,7 @@ config HW_RANDOM_N2RNG
88 88
89config HW_RANDOM_VIA 89config HW_RANDOM_VIA
90 tristate "VIA HW Random Number Generator support" 90 tristate "VIA HW Random Number Generator support"
91 depends on HW_RANDOM && X86_32 91 depends on HW_RANDOM && X86
92 default HW_RANDOM 92 default HW_RANDOM
93 ---help--- 93 ---help---
94 This driver provides kernel-side support for the Random Number 94 This driver provides kernel-side support for the Random Number
@@ -148,3 +148,28 @@ config HW_RANDOM_VIRTIO
148 148
149 To compile this driver as a module, choose M here: the 149 To compile this driver as a module, choose M here: the
150 module will be called virtio-rng. If unsure, say N. 150 module will be called virtio-rng. If unsure, say N.
151
152config HW_RANDOM_TX4939
153 tristate "TX4939 Random Number Generator support"
154 depends on HW_RANDOM && SOC_TX4939
155 default HW_RANDOM
156 ---help---
157 This driver provides kernel-side support for the Random Number
158 Generator hardware found on TX4939 SoC.
159
160 To compile this driver as a module, choose M here: the
161 module will be called tx4939-rng.
162
163 If unsure, say Y.
164
165config HW_RANDOM_MXC_RNGA
166 tristate "Freescale i.MX RNGA Random Number Generator"
167 depends on HW_RANDOM && ARCH_HAS_RNGA
168 ---help---
169 This driver provides kernel-side support for the Random Number
170 Generator hardware found on Freescale i.MX processors.
171
172 To compile this driver as a module, choose M here: the
173 module will be called mxc-rnga.
174
175 If unsure, say Y.
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index e81d21a5f28f..676828ba8123 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -15,3 +15,5 @@ obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
15obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o 15obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
16obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o 16obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
17obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o 17obj-$(CONFIG_HW_RANDOM_VIRTIO) += virtio-rng.o
18obj-$(CONFIG_HW_RANDOM_TX4939) += tx4939-rng.o
19obj-$(CONFIG_HW_RANDOM_MXC_RNGA) += mxc-rnga.o
diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
index e5d583c84e4f..fc93e2fc7c71 100644
--- a/drivers/char/hw_random/core.c
+++ b/drivers/char/hw_random/core.c
@@ -153,6 +153,7 @@ static const struct file_operations rng_chrdev_ops = {
153static struct miscdevice rng_miscdev = { 153static struct miscdevice rng_miscdev = {
154 .minor = RNG_MISCDEV_MINOR, 154 .minor = RNG_MISCDEV_MINOR,
155 .name = RNG_MODULE_NAME, 155 .name = RNG_MODULE_NAME,
156 .devnode = "hwrng",
156 .fops = &rng_chrdev_ops, 157 .fops = &rng_chrdev_ops,
157}; 158};
158 159
diff --git a/drivers/char/hw_random/mxc-rnga.c b/drivers/char/hw_random/mxc-rnga.c
new file mode 100644
index 000000000000..187c6be80f43
--- /dev/null
+++ b/drivers/char/hw_random/mxc-rnga.c
@@ -0,0 +1,247 @@
1/*
2 * RNG driver for Freescale RNGA
3 *
4 * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
5 * Author: Alan Carvalho de Assis <acassis@gmail.com>
6 */
7
8/*
9 * The code contained herein is licensed under the GNU General Public
10 * License. You may obtain a copy of the GNU General Public License
11 * Version 2 or later at the following locations:
12 *
13 * http://www.opensource.org/licenses/gpl-license.html
14 * http://www.gnu.org/copyleft/gpl.html
15 *
16 * This driver is based on other RNG drivers.
17 */
18
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/clk.h>
23#include <linux/err.h>
24#include <linux/ioport.h>
25#include <linux/platform_device.h>
26#include <linux/hw_random.h>
27#include <linux/io.h>
28
29/* RNGA Registers */
30#define RNGA_CONTROL 0x00
31#define RNGA_STATUS 0x04
32#define RNGA_ENTROPY 0x08
33#define RNGA_OUTPUT_FIFO 0x0c
34#define RNGA_MODE 0x10
35#define RNGA_VERIFICATION_CONTROL 0x14
36#define RNGA_OSC_CONTROL_COUNTER 0x18
37#define RNGA_OSC1_COUNTER 0x1c
38#define RNGA_OSC2_COUNTER 0x20
39#define RNGA_OSC_COUNTER_STATUS 0x24
40
41/* RNGA Registers Range */
42#define RNG_ADDR_RANGE 0x28
43
44/* RNGA Control Register */
45#define RNGA_CONTROL_SLEEP 0x00000010
46#define RNGA_CONTROL_CLEAR_INT 0x00000008
47#define RNGA_CONTROL_MASK_INTS 0x00000004
48#define RNGA_CONTROL_HIGH_ASSURANCE 0x00000002
49#define RNGA_CONTROL_GO 0x00000001
50
51#define RNGA_STATUS_LEVEL_MASK 0x0000ff00
52
53/* RNGA Status Register */
54#define RNGA_STATUS_OSC_DEAD 0x80000000
55#define RNGA_STATUS_SLEEP 0x00000010
56#define RNGA_STATUS_ERROR_INT 0x00000008
57#define RNGA_STATUS_FIFO_UNDERFLOW 0x00000004
58#define RNGA_STATUS_LAST_READ_STATUS 0x00000002
59#define RNGA_STATUS_SECURITY_VIOLATION 0x00000001
60
61static struct platform_device *rng_dev;
62
63static int mxc_rnga_data_present(struct hwrng *rng)
64{
65 int level;
66 void __iomem *rng_base = (void __iomem *)rng->priv;
67
68 /* how many random numbers is in FIFO? [0-16] */
69 level = ((__raw_readl(rng_base + RNGA_STATUS) &
70 RNGA_STATUS_LEVEL_MASK) >> 8);
71
72 return level > 0 ? 1 : 0;
73}
74
75static int mxc_rnga_data_read(struct hwrng *rng, u32 * data)
76{
77 int err;
78 u32 ctrl;
79 void __iomem *rng_base = (void __iomem *)rng->priv;
80
81 /* retrieve a random number from FIFO */
82 *data = __raw_readl(rng_base + RNGA_OUTPUT_FIFO);
83
84 /* some error while reading this random number? */
85 err = __raw_readl(rng_base + RNGA_STATUS) & RNGA_STATUS_ERROR_INT;
86
87 /* if error: clear error interrupt, but doesn't return random number */
88 if (err) {
89 dev_dbg(&rng_dev->dev, "Error while reading random number!\n");
90 ctrl = __raw_readl(rng_base + RNGA_CONTROL);
91 __raw_writel(ctrl | RNGA_CONTROL_CLEAR_INT,
92 rng_base + RNGA_CONTROL);
93 return 0;
94 } else
95 return 4;
96}
97
98static int mxc_rnga_init(struct hwrng *rng)
99{
100 u32 ctrl, osc;
101 void __iomem *rng_base = (void __iomem *)rng->priv;
102
103 /* wake up */
104 ctrl = __raw_readl(rng_base + RNGA_CONTROL);
105 __raw_writel(ctrl & ~RNGA_CONTROL_SLEEP, rng_base + RNGA_CONTROL);
106
107 /* verify if oscillator is working */
108 osc = __raw_readl(rng_base + RNGA_STATUS);
109 if (osc & RNGA_STATUS_OSC_DEAD) {
110 dev_err(&rng_dev->dev, "RNGA Oscillator is dead!\n");
111 return -ENODEV;
112 }
113
114 /* go running */
115 ctrl = __raw_readl(rng_base + RNGA_CONTROL);
116 __raw_writel(ctrl | RNGA_CONTROL_GO, rng_base + RNGA_CONTROL);
117
118 return 0;
119}
120
121static void mxc_rnga_cleanup(struct hwrng *rng)
122{
123 u32 ctrl;
124 void __iomem *rng_base = (void __iomem *)rng->priv;
125
126 ctrl = __raw_readl(rng_base + RNGA_CONTROL);
127
128 /* stop rnga */
129 __raw_writel(ctrl & ~RNGA_CONTROL_GO, rng_base + RNGA_CONTROL);
130}
131
132static struct hwrng mxc_rnga = {
133 .name = "mxc-rnga",
134 .init = mxc_rnga_init,
135 .cleanup = mxc_rnga_cleanup,
136 .data_present = mxc_rnga_data_present,
137 .data_read = mxc_rnga_data_read
138};
139
140static int __init mxc_rnga_probe(struct platform_device *pdev)
141{
142 int err = -ENODEV;
143 struct clk *clk;
144 struct resource *res, *mem;
145 void __iomem *rng_base = NULL;
146
147 if (rng_dev)
148 return -EBUSY;
149
150 clk = clk_get(&pdev->dev, "rng");
151 if (IS_ERR(clk)) {
152 dev_err(&pdev->dev, "Could not get rng_clk!\n");
153 err = PTR_ERR(clk);
154 goto out;
155 }
156
157 clk_enable(clk);
158
159 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
160 if (!res) {
161 err = -ENOENT;
162 goto err_region;
163 }
164
165 mem = request_mem_region(res->start, resource_size(res), pdev->name);
166 if (mem == NULL) {
167 err = -EBUSY;
168 goto err_region;
169 }
170
171 rng_base = ioremap(res->start, resource_size(res));
172 if (!rng_base) {
173 err = -ENOMEM;
174 goto err_ioremap;
175 }
176
177 mxc_rnga.priv = (unsigned long)rng_base;
178
179 err = hwrng_register(&mxc_rnga);
180 if (err) {
181 dev_err(&pdev->dev, "MXC RNGA registering failed (%d)\n", err);
182 goto err_register;
183 }
184
185 rng_dev = pdev;
186
187 dev_info(&pdev->dev, "MXC RNGA Registered.\n");
188
189 return 0;
190
191err_register:
192 iounmap(rng_base);
193 rng_base = NULL;
194
195err_ioremap:
196 release_mem_region(res->start, resource_size(res));
197
198err_region:
199 clk_disable(clk);
200 clk_put(clk);
201
202out:
203 return err;
204}
205
206static int __exit mxc_rnga_remove(struct platform_device *pdev)
207{
208 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
209 void __iomem *rng_base = (void __iomem *)mxc_rnga.priv;
210 struct clk *clk = clk_get(&pdev->dev, "rng");
211
212 hwrng_unregister(&mxc_rnga);
213
214 iounmap(rng_base);
215
216 release_mem_region(res->start, resource_size(res));
217
218 clk_disable(clk);
219 clk_put(clk);
220
221 return 0;
222}
223
224static struct platform_driver mxc_rnga_driver = {
225 .driver = {
226 .name = "mxc_rnga",
227 .owner = THIS_MODULE,
228 },
229 .remove = __exit_p(mxc_rnga_remove),
230};
231
232static int __init mod_init(void)
233{
234 return platform_driver_probe(&mxc_rnga_driver, mxc_rnga_probe);
235}
236
237static void __exit mod_exit(void)
238{
239 platform_driver_unregister(&mxc_rnga_driver);
240}
241
242module_init(mod_init);
243module_exit(mod_exit);
244
245MODULE_AUTHOR("Freescale Semiconductor, Inc.");
246MODULE_DESCRIPTION("H/W RNGA driver for i.MX");
247MODULE_LICENSE("GPL");
diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index 538313f9e7ac..00dd3de1be51 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -89,7 +89,7 @@ static struct hwrng omap_rng_ops = {
89 .data_read = omap_rng_data_read, 89 .data_read = omap_rng_data_read,
90}; 90};
91 91
92static int __init omap_rng_probe(struct platform_device *pdev) 92static int __devinit omap_rng_probe(struct platform_device *pdev)
93{ 93{
94 struct resource *res, *mem; 94 struct resource *res, *mem;
95 int ret; 95 int ret;
diff --git a/drivers/char/hw_random/timeriomem-rng.c b/drivers/char/hw_random/timeriomem-rng.c
index dcd352ad0e7f..a94e930575f2 100644
--- a/drivers/char/hw_random/timeriomem-rng.c
+++ b/drivers/char/hw_random/timeriomem-rng.c
@@ -88,9 +88,9 @@ static struct hwrng timeriomem_rng_ops = {
88 .priv = 0, 88 .priv = 0,
89}; 89};
90 90
91static int __init timeriomem_rng_probe(struct platform_device *pdev) 91static int __devinit timeriomem_rng_probe(struct platform_device *pdev)
92{ 92{
93 struct resource *res, *mem; 93 struct resource *res;
94 int ret; 94 int ret;
95 95
96 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 96 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -98,21 +98,12 @@ static int __init timeriomem_rng_probe(struct platform_device *pdev)
98 if (!res) 98 if (!res)
99 return -ENOENT; 99 return -ENOENT;
100 100
101 mem = request_mem_region(res->start, res->end - res->start + 1,
102 pdev->name);
103 if (mem == NULL)
104 return -EBUSY;
105
106 dev_set_drvdata(&pdev->dev, mem);
107
108 timeriomem_rng_data = pdev->dev.platform_data; 101 timeriomem_rng_data = pdev->dev.platform_data;
109 102
110 timeriomem_rng_data->address = ioremap(res->start, 103 timeriomem_rng_data->address = ioremap(res->start,
111 res->end - res->start + 1); 104 res->end - res->start + 1);
112 if (!timeriomem_rng_data->address) { 105 if (!timeriomem_rng_data->address)
113 ret = -ENOMEM; 106 return -EIO;
114 goto err_ioremap;
115 }
116 107
117 if (timeriomem_rng_data->period != 0 108 if (timeriomem_rng_data->period != 0
118 && usecs_to_jiffies(timeriomem_rng_data->period) > 0) { 109 && usecs_to_jiffies(timeriomem_rng_data->period) > 0) {
@@ -125,7 +116,7 @@ static int __init timeriomem_rng_probe(struct platform_device *pdev)
125 116
126 ret = hwrng_register(&timeriomem_rng_ops); 117 ret = hwrng_register(&timeriomem_rng_ops);
127 if (ret) 118 if (ret)
128 goto err_register; 119 goto failed;
129 120
130 dev_info(&pdev->dev, "32bits from 0x%p @ %dus\n", 121 dev_info(&pdev->dev, "32bits from 0x%p @ %dus\n",
131 timeriomem_rng_data->address, 122 timeriomem_rng_data->address,
@@ -133,24 +124,19 @@ static int __init timeriomem_rng_probe(struct platform_device *pdev)
133 124
134 return 0; 125 return 0;
135 126
136err_register: 127failed:
137 dev_err(&pdev->dev, "problem registering\n"); 128 dev_err(&pdev->dev, "problem registering\n");
138 iounmap(timeriomem_rng_data->address); 129 iounmap(timeriomem_rng_data->address);
139err_ioremap:
140 release_resource(mem);
141 130
142 return ret; 131 return ret;
143} 132}
144 133
145static int __devexit timeriomem_rng_remove(struct platform_device *pdev) 134static int __devexit timeriomem_rng_remove(struct platform_device *pdev)
146{ 135{
147 struct resource *mem = dev_get_drvdata(&pdev->dev);
148
149 del_timer_sync(&timeriomem_rng_timer); 136 del_timer_sync(&timeriomem_rng_timer);
150 hwrng_unregister(&timeriomem_rng_ops); 137 hwrng_unregister(&timeriomem_rng_ops);
151 138
152 iounmap(timeriomem_rng_data->address); 139 iounmap(timeriomem_rng_data->address);
153 release_resource(mem);
154 140
155 return 0; 141 return 0;
156} 142}
diff --git a/drivers/char/hw_random/tx4939-rng.c b/drivers/char/hw_random/tx4939-rng.c
new file mode 100644
index 000000000000..544d9085a8e8
--- /dev/null
+++ b/drivers/char/hw_random/tx4939-rng.c
@@ -0,0 +1,184 @@
1/*
2 * RNG driver for TX4939 Random Number Generators (RNG)
3 *
4 * Copyright (C) 2009 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10#include <linux/module.h>
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/delay.h>
14#include <linux/io.h>
15#include <linux/platform_device.h>
16#include <linux/hw_random.h>
17
18#define TX4939_RNG_RCSR 0x00000000
19#define TX4939_RNG_ROR(n) (0x00000018 + (n) * 8)
20
21#define TX4939_RNG_RCSR_INTE 0x00000008
22#define TX4939_RNG_RCSR_RST 0x00000004
23#define TX4939_RNG_RCSR_FIN 0x00000002
24#define TX4939_RNG_RCSR_ST 0x00000001
25
26struct tx4939_rng {
27 struct hwrng rng;
28 void __iomem *base;
29 u64 databuf[3];
30 unsigned int data_avail;
31};
32
33static void rng_io_start(void)
34{
35#ifndef CONFIG_64BIT
36 /*
37 * readq is reading a 64-bit register using a 64-bit load. On
38 * a 32-bit kernel however interrupts or any other processor
39 * exception would clobber the upper 32-bit of the processor
40 * register so interrupts need to be disabled.
41 */
42 local_irq_disable();
43#endif
44}
45
46static void rng_io_end(void)
47{
48#ifndef CONFIG_64BIT
49 local_irq_enable();
50#endif
51}
52
53static u64 read_rng(void __iomem *base, unsigned int offset)
54{
55 return ____raw_readq(base + offset);
56}
57
58static void write_rng(u64 val, void __iomem *base, unsigned int offset)
59{
60 return ____raw_writeq(val, base + offset);
61}
62
63static int tx4939_rng_data_present(struct hwrng *rng, int wait)
64{
65 struct tx4939_rng *rngdev = container_of(rng, struct tx4939_rng, rng);
66 int i;
67
68 if (rngdev->data_avail)
69 return rngdev->data_avail;
70 for (i = 0; i < 20; i++) {
71 rng_io_start();
72 if (!(read_rng(rngdev->base, TX4939_RNG_RCSR)
73 & TX4939_RNG_RCSR_ST)) {
74 rngdev->databuf[0] =
75 read_rng(rngdev->base, TX4939_RNG_ROR(0));
76 rngdev->databuf[1] =
77 read_rng(rngdev->base, TX4939_RNG_ROR(1));
78 rngdev->databuf[2] =
79 read_rng(rngdev->base, TX4939_RNG_ROR(2));
80 rngdev->data_avail =
81 sizeof(rngdev->databuf) / sizeof(u32);
82 /* Start RNG */
83 write_rng(TX4939_RNG_RCSR_ST,
84 rngdev->base, TX4939_RNG_RCSR);
85 wait = 0;
86 }
87 rng_io_end();
88 if (!wait)
89 break;
90 /* 90 bus clock cycles by default for generation */
91 ndelay(90 * 5);
92 }
93 return rngdev->data_avail;
94}
95
96static int tx4939_rng_data_read(struct hwrng *rng, u32 *buffer)
97{
98 struct tx4939_rng *rngdev = container_of(rng, struct tx4939_rng, rng);
99
100 rngdev->data_avail--;
101 *buffer = *((u32 *)&rngdev->databuf + rngdev->data_avail);
102 return sizeof(u32);
103}
104
105static int __init tx4939_rng_probe(struct platform_device *dev)
106{
107 struct tx4939_rng *rngdev;
108 struct resource *r;
109 int i;
110
111 r = platform_get_resource(dev, IORESOURCE_MEM, 0);
112 if (!r)
113 return -EBUSY;
114 rngdev = devm_kzalloc(&dev->dev, sizeof(*rngdev), GFP_KERNEL);
115 if (!rngdev)
116 return -ENOMEM;
117 if (!devm_request_mem_region(&dev->dev, r->start, resource_size(r),
118 dev_name(&dev->dev)))
119 return -EBUSY;
120 rngdev->base = devm_ioremap(&dev->dev, r->start, resource_size(r));
121 if (!rngdev->base)
122 return -EBUSY;
123
124 rngdev->rng.name = dev_name(&dev->dev);
125 rngdev->rng.data_present = tx4939_rng_data_present;
126 rngdev->rng.data_read = tx4939_rng_data_read;
127
128 rng_io_start();
129 /* Reset RNG */
130 write_rng(TX4939_RNG_RCSR_RST, rngdev->base, TX4939_RNG_RCSR);
131 write_rng(0, rngdev->base, TX4939_RNG_RCSR);
132 /* Start RNG */
133 write_rng(TX4939_RNG_RCSR_ST, rngdev->base, TX4939_RNG_RCSR);
134 rng_io_end();
135 /*
136 * Drop first two results. From the datasheet:
137 * The quality of the random numbers generated immediately
138 * after reset can be insufficient. Therefore, do not use
139 * random numbers obtained from the first and second
140 * generations; use the ones from the third or subsequent
141 * generation.
142 */
143 for (i = 0; i < 2; i++) {
144 rngdev->data_avail = 0;
145 if (!tx4939_rng_data_present(&rngdev->rng, 1))
146 return -EIO;
147 }
148
149 platform_set_drvdata(dev, rngdev);
150 return hwrng_register(&rngdev->rng);
151}
152
153static int __exit tx4939_rng_remove(struct platform_device *dev)
154{
155 struct tx4939_rng *rngdev = platform_get_drvdata(dev);
156
157 hwrng_unregister(&rngdev->rng);
158 platform_set_drvdata(dev, NULL);
159 return 0;
160}
161
162static struct platform_driver tx4939_rng_driver = {
163 .driver = {
164 .name = "tx4939-rng",
165 .owner = THIS_MODULE,
166 },
167 .remove = tx4939_rng_remove,
168};
169
170static int __init tx4939rng_init(void)
171{
172 return platform_driver_probe(&tx4939_rng_driver, tx4939_rng_probe);
173}
174
175static void __exit tx4939rng_exit(void)
176{
177 platform_driver_unregister(&tx4939_rng_driver);
178}
179
180module_init(tx4939rng_init);
181module_exit(tx4939rng_exit);
182
183MODULE_DESCRIPTION("H/W Random Number Generator (RNG) driver for TX4939");
184MODULE_LICENSE("GPL");
diff --git a/drivers/char/hw_random/via-rng.c b/drivers/char/hw_random/via-rng.c
index 4e9573c1d39e..794aacb715c1 100644
--- a/drivers/char/hw_random/via-rng.c
+++ b/drivers/char/hw_random/via-rng.c
@@ -132,6 +132,19 @@ static int via_rng_init(struct hwrng *rng)
132 struct cpuinfo_x86 *c = &cpu_data(0); 132 struct cpuinfo_x86 *c = &cpu_data(0);
133 u32 lo, hi, old_lo; 133 u32 lo, hi, old_lo;
134 134
135 /* VIA Nano CPUs don't have the MSR_VIA_RNG anymore. The RNG
136 * is always enabled if CPUID rng_en is set. There is no
137 * RNG configuration like it used to be the case in this
138 * register */
139 if ((c->x86 == 6) && (c->x86_model >= 0x0f)) {
140 if (!cpu_has_xstore_enabled) {
141 printk(KERN_ERR PFX "can't enable hardware RNG "
142 "if XSTORE is not enabled\n");
143 return -ENODEV;
144 }
145 return 0;
146 }
147
135 /* Control the RNG via MSR. Tread lightly and pay very close 148 /* Control the RNG via MSR. Tread lightly and pay very close
136 * close attention to values written, as the reserved fields 149 * close attention to values written, as the reserved fields
137 * are documented to be "undefined and unpredictable"; but it 150 * are documented to be "undefined and unpredictable"; but it
@@ -205,5 +218,5 @@ static void __exit mod_exit(void)
205module_init(mod_init); 218module_init(mod_init);
206module_exit(mod_exit); 219module_exit(mod_exit);
207 220
208MODULE_DESCRIPTION("H/W RNG driver for VIA chipsets"); 221MODULE_DESCRIPTION("H/W RNG driver for VIA CPU with PadLock");
209MODULE_LICENSE("GPL"); 222MODULE_LICENSE("GPL");
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 86e83f883139..32216b623248 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -35,13 +35,13 @@ static DECLARE_COMPLETION(have_data);
35 35
36static void random_recv_done(struct virtqueue *vq) 36static void random_recv_done(struct virtqueue *vq)
37{ 37{
38 int len; 38 unsigned int len;
39 39
40 /* We can get spurious callbacks, e.g. shared IRQs + virtio_pci. */ 40 /* We can get spurious callbacks, e.g. shared IRQs + virtio_pci. */
41 if (!vq->vq_ops->get_buf(vq, &len)) 41 if (!vq->vq_ops->get_buf(vq, &len))
42 return; 42 return;
43 43
44 data_left = len / sizeof(random_data[0]); 44 data_left += len;
45 complete(&have_data); 45 complete(&have_data);
46} 46}
47 47
@@ -49,7 +49,7 @@ static void register_buffer(void)
49{ 49{
50 struct scatterlist sg; 50 struct scatterlist sg;
51 51
52 sg_init_one(&sg, random_data, RANDOM_DATA_SIZE); 52 sg_init_one(&sg, random_data+data_left, RANDOM_DATA_SIZE-data_left);
53 /* There should always be room for one buffer. */ 53 /* There should always be room for one buffer. */
54 if (vq->vq_ops->add_buf(vq, &sg, 0, 1, random_data) != 0) 54 if (vq->vq_ops->add_buf(vq, &sg, 0, 1, random_data) != 0)
55 BUG(); 55 BUG();
@@ -59,24 +59,32 @@ static void register_buffer(void)
59/* At least we don't udelay() in a loop like some other drivers. */ 59/* At least we don't udelay() in a loop like some other drivers. */
60static int virtio_data_present(struct hwrng *rng, int wait) 60static int virtio_data_present(struct hwrng *rng, int wait)
61{ 61{
62 if (data_left) 62 if (data_left >= sizeof(u32))
63 return 1; 63 return 1;
64 64
65again:
65 if (!wait) 66 if (!wait)
66 return 0; 67 return 0;
67 68
68 wait_for_completion(&have_data); 69 wait_for_completion(&have_data);
70
71 /* Not enough? Re-register. */
72 if (unlikely(data_left < sizeof(u32))) {
73 register_buffer();
74 goto again;
75 }
76
69 return 1; 77 return 1;
70} 78}
71 79
72/* virtio_data_present() must have succeeded before this is called. */ 80/* virtio_data_present() must have succeeded before this is called. */
73static int virtio_data_read(struct hwrng *rng, u32 *data) 81static int virtio_data_read(struct hwrng *rng, u32 *data)
74{ 82{
75 BUG_ON(!data_left); 83 BUG_ON(data_left < sizeof(u32));
76 84 data_left -= sizeof(u32);
77 *data = random_data[--data_left]; 85 *data = random_data[data_left / 4];
78 86
79 if (!data_left) { 87 if (data_left < sizeof(u32)) {
80 init_completion(&have_data); 88 init_completion(&have_data);
81 register_buffer(); 89 register_buffer();
82 } 90 }
@@ -94,13 +102,13 @@ static int virtrng_probe(struct virtio_device *vdev)
94 int err; 102 int err;
95 103
96 /* We expect a single virtqueue. */ 104 /* We expect a single virtqueue. */
97 vq = vdev->config->find_vq(vdev, 0, random_recv_done); 105 vq = virtio_find_single_vq(vdev, random_recv_done, "input");
98 if (IS_ERR(vq)) 106 if (IS_ERR(vq))
99 return PTR_ERR(vq); 107 return PTR_ERR(vq);
100 108
101 err = hwrng_register(&virtio_hwrng); 109 err = hwrng_register(&virtio_hwrng);
102 if (err) { 110 if (err) {
103 vdev->config->del_vq(vq); 111 vdev->config->del_vqs(vdev);
104 return err; 112 return err;
105 } 113 }
106 114
@@ -112,7 +120,7 @@ static void virtrng_remove(struct virtio_device *vdev)
112{ 120{
113 vdev->config->reset(vdev); 121 vdev->config->reset(vdev);
114 hwrng_unregister(&virtio_hwrng); 122 hwrng_unregister(&virtio_hwrng);
115 vdev->config->del_vq(vq); 123 vdev->config->del_vqs(vdev);
116} 124}
117 125
118static struct virtio_device_id id_table[] = { 126static struct virtio_device_id id_table[] = {
diff --git a/drivers/char/ip2/i2lib.c b/drivers/char/ip2/i2lib.c
index 0061e18aff60..0d10b89218ed 100644
--- a/drivers/char/ip2/i2lib.c
+++ b/drivers/char/ip2/i2lib.c
@@ -868,11 +868,11 @@ i2Input(i2ChanStrPtr pCh)
868 amountToMove = count; 868 amountToMove = count;
869 } 869 }
870 // Move the first block 870 // Move the first block
871 pCh->pTTY->ldisc.ops->receive_buf( pCh->pTTY, 871 pCh->pTTY->ldisc->ops->receive_buf( pCh->pTTY,
872 &(pCh->Ibuf[stripIndex]), NULL, amountToMove ); 872 &(pCh->Ibuf[stripIndex]), NULL, amountToMove );
873 // If we needed to wrap, do the second data move 873 // If we needed to wrap, do the second data move
874 if (count > amountToMove) { 874 if (count > amountToMove) {
875 pCh->pTTY->ldisc.ops->receive_buf( pCh->pTTY, 875 pCh->pTTY->ldisc->ops->receive_buf( pCh->pTTY,
876 pCh->Ibuf, NULL, count - amountToMove ); 876 pCh->Ibuf, NULL, count - amountToMove );
877 } 877 }
878 // Bump and wrap the stripIndex all at once by the amount of data read. This 878 // Bump and wrap the stripIndex all at once by the amount of data read. This
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index afd9247cf082..517271c762e6 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -1315,8 +1315,8 @@ static inline void isig(int sig, struct tty_struct *tty, int flush)
1315 if (tty->pgrp) 1315 if (tty->pgrp)
1316 kill_pgrp(tty->pgrp, sig, 1); 1316 kill_pgrp(tty->pgrp, sig, 1);
1317 if (flush || !L_NOFLSH(tty)) { 1317 if (flush || !L_NOFLSH(tty)) {
1318 if ( tty->ldisc.ops->flush_buffer ) 1318 if ( tty->ldisc->ops->flush_buffer )
1319 tty->ldisc.ops->flush_buffer(tty); 1319 tty->ldisc->ops->flush_buffer(tty);
1320 i2InputFlush( tty->driver_data ); 1320 i2InputFlush( tty->driver_data );
1321 } 1321 }
1322} 1322}
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 259644646b82..d2e698096ace 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -2375,14 +2375,14 @@ static int __devinit ipmi_of_probe(struct of_device *dev,
2375 info->io.addr_data, info->io.regsize, info->io.regspacing, 2375 info->io.addr_data, info->io.regsize, info->io.regspacing,
2376 info->irq); 2376 info->irq);
2377 2377
2378 dev->dev.driver_data = (void *) info; 2378 dev_set_drvdata(&dev->dev, info);
2379 2379
2380 return try_smi_init(info); 2380 return try_smi_init(info);
2381} 2381}
2382 2382
2383static int __devexit ipmi_of_remove(struct of_device *dev) 2383static int __devexit ipmi_of_remove(struct of_device *dev)
2384{ 2384{
2385 cleanup_one_si(dev->dev.driver_data); 2385 cleanup_one_si(dev_get_drvdata(&dev->dev));
2386 return 0; 2386 return 0;
2387} 2387}
2388 2388
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index a59eac584d16..4159292e35cf 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -329,7 +329,7 @@ static inline void drop_rts(struct isi_port *port)
329 329
330/* card->lock MUST NOT be held */ 330/* card->lock MUST NOT be held */
331 331
332static void isicom_raise_dtr_rts(struct tty_port *port) 332static void isicom_dtr_rts(struct tty_port *port, int on)
333{ 333{
334 struct isi_port *ip = container_of(port, struct isi_port, port); 334 struct isi_port *ip = container_of(port, struct isi_port, port);
335 struct isi_board *card = ip->card; 335 struct isi_board *card = ip->card;
@@ -339,10 +339,17 @@ static void isicom_raise_dtr_rts(struct tty_port *port)
339 if (!lock_card(card)) 339 if (!lock_card(card))
340 return; 340 return;
341 341
342 outw(0x8000 | (channel << card->shift_count) | 0x02, base); 342 if (on) {
343 outw(0x0f04, base); 343 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
344 InterruptTheCard(base); 344 outw(0x0f04, base);
345 ip->status |= (ISI_DTR | ISI_RTS); 345 InterruptTheCard(base);
346 ip->status |= (ISI_DTR | ISI_RTS);
347 } else {
348 outw(0x8000 | (channel << card->shift_count) | 0x02, base);
349 outw(0x0C04, base);
350 InterruptTheCard(base);
351 ip->status &= ~(ISI_DTR | ISI_RTS);
352 }
346 unlock_card(card); 353 unlock_card(card);
347} 354}
348 355
@@ -1339,7 +1346,7 @@ static const struct tty_operations isicom_ops = {
1339 1346
1340static const struct tty_port_operations isicom_port_ops = { 1347static const struct tty_port_operations isicom_port_ops = {
1341 .carrier_raised = isicom_carrier_raised, 1348 .carrier_raised = isicom_carrier_raised,
1342 .raise_dtr_rts = isicom_raise_dtr_rts, 1349 .dtr_rts = isicom_dtr_rts,
1343}; 1350};
1344 1351
1345static int __devinit reset_card(struct pci_dev *pdev, 1352static int __devinit reset_card(struct pci_dev *pdev,
@@ -1586,7 +1593,7 @@ static unsigned int card_count;
1586static int __devinit isicom_probe(struct pci_dev *pdev, 1593static int __devinit isicom_probe(struct pci_dev *pdev,
1587 const struct pci_device_id *ent) 1594 const struct pci_device_id *ent)
1588{ 1595{
1589 unsigned int signature, index; 1596 unsigned int uninitialized_var(signature), index;
1590 int retval = -EPERM; 1597 int retval = -EPERM;
1591 struct isi_board *board = NULL; 1598 struct isi_board *board = NULL;
1592 1599
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index fff19f7e29d2..0c999f5bb3db 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -1140,14 +1140,14 @@ static int stli_carrier_raised(struct tty_port *port)
1140 return (portp->sigs & TIOCM_CD) ? 1 : 0; 1140 return (portp->sigs & TIOCM_CD) ? 1 : 0;
1141} 1141}
1142 1142
1143static void stli_raise_dtr_rts(struct tty_port *port) 1143static void stli_dtr_rts(struct tty_port *port, int on)
1144{ 1144{
1145 struct stliport *portp = container_of(port, struct stliport, port); 1145 struct stliport *portp = container_of(port, struct stliport, port);
1146 struct stlibrd *brdp = stli_brds[portp->brdnr]; 1146 struct stlibrd *brdp = stli_brds[portp->brdnr];
1147 stli_mkasysigs(&portp->asig, 1, 1); 1147 stli_mkasysigs(&portp->asig, on, on);
1148 if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, 1148 if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1149 sizeof(asysigs_t), 0) < 0) 1149 sizeof(asysigs_t), 0) < 0)
1150 printk(KERN_WARNING "istallion: dtr raise failed.\n"); 1150 printk(KERN_WARNING "istallion: dtr set failed.\n");
1151} 1151}
1152 1152
1153 1153
@@ -3785,7 +3785,7 @@ err:
3785 return retval; 3785 return retval;
3786} 3786}
3787 3787
3788static void stli_pciremove(struct pci_dev *pdev) 3788static void __devexit stli_pciremove(struct pci_dev *pdev)
3789{ 3789{
3790 struct stlibrd *brdp = pci_get_drvdata(pdev); 3790 struct stlibrd *brdp = pci_get_drvdata(pdev);
3791 3791
@@ -4417,7 +4417,7 @@ static const struct tty_operations stli_ops = {
4417 4417
4418static const struct tty_port_operations stli_port_ops = { 4418static const struct tty_port_operations stli_port_ops = {
4419 .carrier_raised = stli_carrier_raised, 4419 .carrier_raised = stli_carrier_raised,
4420 .raise_dtr_rts = stli_raise_dtr_rts, 4420 .dtr_rts = stli_dtr_rts,
4421}; 4421};
4422 4422
4423/*****************************************************************************/ 4423/*****************************************************************************/
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index de26a978fbdd..737be953cc58 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -1123,8 +1123,6 @@ static int emulate_raw(struct vc_data *vc, unsigned int keycode,
1123 1123
1124#define HW_RAW(dev) 0 1124#define HW_RAW(dev) 0
1125 1125
1126#warning "Cannot generate rawmode keyboard for your architecture yet."
1127
1128static int emulate_raw(struct vc_data *vc, unsigned int keycode, unsigned char up_flag) 1126static int emulate_raw(struct vc_data *vc, unsigned int keycode, unsigned char up_flag)
1129{ 1127{
1130 if (keycode > 127) 1128 if (keycode > 127)
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 65e12bca657c..afa8813e737a 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -694,9 +694,8 @@ static ssize_t read_zero(struct file * file, char __user * buf,
694 written += chunk - unwritten; 694 written += chunk - unwritten;
695 if (unwritten) 695 if (unwritten)
696 break; 696 break;
697 /* Consider changing this to just 'signal_pending()' with lots of testing */ 697 if (signal_pending(current))
698 if (fatal_signal_pending(current)) 698 return written ? written : -ERESTARTSYS;
699 return written ? written : -EINTR;
700 buf += chunk; 699 buf += chunk;
701 count -= chunk; 700 count -= chunk;
702 cond_resched(); 701 cond_resched();
@@ -864,59 +863,58 @@ static const struct file_operations kmsg_fops = {
864 .write = kmsg_write, 863 .write = kmsg_write,
865}; 864};
866 865
867static int memory_open(struct inode * inode, struct file * filp) 866static const struct {
868{ 867 unsigned int minor;
869 int ret = 0; 868 char *name;
870 869 umode_t mode;
871 lock_kernel(); 870 const struct file_operations *fops;
872 switch (iminor(inode)) { 871 struct backing_dev_info *dev_info;
873 case 1: 872} devlist[] = { /* list of minor devices */
874 filp->f_op = &mem_fops; 873 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops,
875 filp->f_mapping->backing_dev_info = 874 &directly_mappable_cdev_bdi},
876 &directly_mappable_cdev_bdi;
877 break;
878#ifdef CONFIG_DEVKMEM 875#ifdef CONFIG_DEVKMEM
879 case 2: 876 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops,
880 filp->f_op = &kmem_fops; 877 &directly_mappable_cdev_bdi},
881 filp->f_mapping->backing_dev_info =
882 &directly_mappable_cdev_bdi;
883 break;
884#endif 878#endif
885 case 3: 879 {3, "null", S_IRUGO | S_IWUGO, &null_fops, NULL},
886 filp->f_op = &null_fops;
887 break;
888#ifdef CONFIG_DEVPORT 880#ifdef CONFIG_DEVPORT
889 case 4: 881 {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops, NULL},
890 filp->f_op = &port_fops;
891 break;
892#endif 882#endif
893 case 5: 883 {5, "zero", S_IRUGO | S_IWUGO, &zero_fops, &zero_bdi},
894 filp->f_mapping->backing_dev_info = &zero_bdi; 884 {7, "full", S_IRUGO | S_IWUGO, &full_fops, NULL},
895 filp->f_op = &zero_fops; 885 {8, "random", S_IRUGO | S_IWUSR, &random_fops, NULL},
896 break; 886 {9, "urandom", S_IRUGO | S_IWUSR, &urandom_fops, NULL},
897 case 7: 887 {11,"kmsg", S_IRUGO | S_IWUSR, &kmsg_fops, NULL},
898 filp->f_op = &full_fops;
899 break;
900 case 8:
901 filp->f_op = &random_fops;
902 break;
903 case 9:
904 filp->f_op = &urandom_fops;
905 break;
906 case 11:
907 filp->f_op = &kmsg_fops;
908 break;
909#ifdef CONFIG_CRASH_DUMP 888#ifdef CONFIG_CRASH_DUMP
910 case 12: 889 {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops, NULL},
911 filp->f_op = &oldmem_fops;
912 break;
913#endif 890#endif
914 default: 891};
915 unlock_kernel(); 892
916 return -ENXIO; 893static int memory_open(struct inode *inode, struct file *filp)
894{
895 int ret = 0;
896 int i;
897
898 lock_kernel();
899
900 for (i = 0; i < ARRAY_SIZE(devlist); i++) {
901 if (devlist[i].minor == iminor(inode)) {
902 filp->f_op = devlist[i].fops;
903 if (devlist[i].dev_info) {
904 filp->f_mapping->backing_dev_info =
905 devlist[i].dev_info;
906 }
907
908 break;
909 }
917 } 910 }
918 if (filp->f_op && filp->f_op->open) 911
919 ret = filp->f_op->open(inode,filp); 912 if (i == ARRAY_SIZE(devlist))
913 ret = -ENXIO;
914 else
915 if (filp->f_op && filp->f_op->open)
916 ret = filp->f_op->open(inode, filp);
917
920 unlock_kernel(); 918 unlock_kernel();
921 return ret; 919 return ret;
922} 920}
@@ -925,30 +923,6 @@ static const struct file_operations memory_fops = {
925 .open = memory_open, /* just a selector for the real open */ 923 .open = memory_open, /* just a selector for the real open */
926}; 924};
927 925
928static const struct {
929 unsigned int minor;
930 char *name;
931 umode_t mode;
932 const struct file_operations *fops;
933} devlist[] = { /* list of minor devices */
934 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops},
935#ifdef CONFIG_DEVKMEM
936 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops},
937#endif
938 {3, "null", S_IRUGO | S_IWUGO, &null_fops},
939#ifdef CONFIG_DEVPORT
940 {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops},
941#endif
942 {5, "zero", S_IRUGO | S_IWUGO, &zero_fops},
943 {7, "full", S_IRUGO | S_IWUGO, &full_fops},
944 {8, "random", S_IRUGO | S_IWUSR, &random_fops},
945 {9, "urandom", S_IRUGO | S_IWUSR, &urandom_fops},
946 {11,"kmsg", S_IRUGO | S_IWUSR, &kmsg_fops},
947#ifdef CONFIG_CRASH_DUMP
948 {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops},
949#endif
950};
951
952static struct class *mem_class; 926static struct class *mem_class;
953 927
954static int __init chr_dev_init(void) 928static int __init chr_dev_init(void)
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index a5e0db9d7662..62c99fa59e2b 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -168,7 +168,6 @@ static const struct file_operations misc_fops = {
168 .open = misc_open, 168 .open = misc_open,
169}; 169};
170 170
171
172/** 171/**
173 * misc_register - register a miscellaneous device 172 * misc_register - register a miscellaneous device
174 * @misc: device structure 173 * @misc: device structure
@@ -217,8 +216,8 @@ int misc_register(struct miscdevice * misc)
217 misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7); 216 misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
218 dev = MKDEV(MISC_MAJOR, misc->minor); 217 dev = MKDEV(MISC_MAJOR, misc->minor);
219 218
220 misc->this_device = device_create(misc_class, misc->parent, dev, NULL, 219 misc->this_device = device_create(misc_class, misc->parent, dev,
221 "%s", misc->name); 220 misc, "%s", misc->name);
222 if (IS_ERR(misc->this_device)) { 221 if (IS_ERR(misc->this_device)) {
223 err = PTR_ERR(misc->this_device); 222 err = PTR_ERR(misc->this_device);
224 goto out; 223 goto out;
@@ -264,6 +263,15 @@ int misc_deregister(struct miscdevice *misc)
264EXPORT_SYMBOL(misc_register); 263EXPORT_SYMBOL(misc_register);
265EXPORT_SYMBOL(misc_deregister); 264EXPORT_SYMBOL(misc_deregister);
266 265
266static char *misc_nodename(struct device *dev)
267{
268 struct miscdevice *c = dev_get_drvdata(dev);
269
270 if (c->devnode)
271 return kstrdup(c->devnode, GFP_KERNEL);
272 return NULL;
273}
274
267static int __init misc_init(void) 275static int __init misc_init(void)
268{ 276{
269 int err; 277 int err;
@@ -279,6 +287,7 @@ static int __init misc_init(void)
279 err = -EIO; 287 err = -EIO;
280 if (register_chrdev(MISC_MAJOR,"misc",&misc_fops)) 288 if (register_chrdev(MISC_MAJOR,"misc",&misc_fops))
281 goto fail_printk; 289 goto fail_printk;
290 misc_class->nodename = misc_nodename;
282 return 0; 291 return 0;
283 292
284fail_printk: 293fail_printk:
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 4a4cab73d0be..65b6ff2442c6 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -1184,6 +1184,11 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1184 return -ENODEV; 1184 return -ENODEV;
1185 } 1185 }
1186 1186
1187 if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) {
1188 mutex_unlock(&moxa_openlock);
1189 return -ENODEV;
1190 }
1191
1187 ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; 1192 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
1188 ch->port.count++; 1193 ch->port.count++;
1189 tty->driver_data = ch; 1194 tty->driver_data = ch;
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 13f8871e5b21..52d953eb30c3 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -547,14 +547,18 @@ static int mxser_carrier_raised(struct tty_port *port)
547 return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0; 547 return (inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD)?1:0;
548} 548}
549 549
550static void mxser_raise_dtr_rts(struct tty_port *port) 550static void mxser_dtr_rts(struct tty_port *port, int on)
551{ 551{
552 struct mxser_port *mp = container_of(port, struct mxser_port, port); 552 struct mxser_port *mp = container_of(port, struct mxser_port, port);
553 unsigned long flags; 553 unsigned long flags;
554 554
555 spin_lock_irqsave(&mp->slock, flags); 555 spin_lock_irqsave(&mp->slock, flags);
556 outb(inb(mp->ioaddr + UART_MCR) | 556 if (on)
557 UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR); 557 outb(inb(mp->ioaddr + UART_MCR) |
558 UART_MCR_DTR | UART_MCR_RTS, mp->ioaddr + UART_MCR);
559 else
560 outb(inb(mp->ioaddr + UART_MCR)&~(UART_MCR_DTR | UART_MCR_RTS),
561 mp->ioaddr + UART_MCR);
558 spin_unlock_irqrestore(&mp->slock, flags); 562 spin_unlock_irqrestore(&mp->slock, flags);
559} 563}
560 564
@@ -1044,8 +1048,6 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
1044 if (retval) 1048 if (retval)
1045 return retval; 1049 return retval;
1046 1050
1047 /* unmark here for very high baud rate (ex. 921600 bps) used */
1048 tty->low_latency = 1;
1049 return 0; 1051 return 0;
1050} 1052}
1051 1053
@@ -2356,7 +2358,7 @@ static const struct tty_operations mxser_ops = {
2356 2358
2357struct tty_port_operations mxser_port_ops = { 2359struct tty_port_operations mxser_port_ops = {
2358 .carrier_raised = mxser_carrier_raised, 2360 .carrier_raised = mxser_carrier_raised,
2359 .raise_dtr_rts = mxser_raise_dtr_rts, 2361 .dtr_rts = mxser_dtr_rts,
2360}; 2362};
2361 2363
2362/* 2364/*
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c
index bacb3e2872ae..1c43c8cdee25 100644
--- a/drivers/char/n_hdlc.c
+++ b/drivers/char/n_hdlc.c
@@ -10,7 +10,6 @@
10 * Paul Mackerras <Paul.Mackerras@cs.anu.edu.au> 10 * Paul Mackerras <Paul.Mackerras@cs.anu.edu.au>
11 * 11 *
12 * Original release 01/11/99 12 * Original release 01/11/99
13 * $Id: n_hdlc.c,v 4.8 2003/05/06 21:18:51 paulkf Exp $
14 * 13 *
15 * This code is released under the GNU General Public License (GPL) 14 * This code is released under the GNU General Public License (GPL)
16 * 15 *
@@ -79,7 +78,6 @@
79 */ 78 */
80 79
81#define HDLC_MAGIC 0x239e 80#define HDLC_MAGIC 0x239e
82#define HDLC_VERSION "$Revision: 4.8 $"
83 81
84#include <linux/module.h> 82#include <linux/module.h>
85#include <linux/init.h> 83#include <linux/init.h>
@@ -114,7 +112,7 @@
114#define MAX_HDLC_FRAME_SIZE 65535 112#define MAX_HDLC_FRAME_SIZE 65535
115#define DEFAULT_RX_BUF_COUNT 10 113#define DEFAULT_RX_BUF_COUNT 10
116#define MAX_RX_BUF_COUNT 60 114#define MAX_RX_BUF_COUNT 60
117#define DEFAULT_TX_BUF_COUNT 1 115#define DEFAULT_TX_BUF_COUNT 3
118 116
119struct n_hdlc_buf { 117struct n_hdlc_buf {
120 struct n_hdlc_buf *link; 118 struct n_hdlc_buf *link;
@@ -199,6 +197,31 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty);
199#define tty2n_hdlc(tty) ((struct n_hdlc *) ((tty)->disc_data)) 197#define tty2n_hdlc(tty) ((struct n_hdlc *) ((tty)->disc_data))
200#define n_hdlc2tty(n_hdlc) ((n_hdlc)->tty) 198#define n_hdlc2tty(n_hdlc) ((n_hdlc)->tty)
201 199
200static void flush_rx_queue(struct tty_struct *tty)
201{
202 struct n_hdlc *n_hdlc = tty2n_hdlc(tty);
203 struct n_hdlc_buf *buf;
204
205 while ((buf = n_hdlc_buf_get(&n_hdlc->rx_buf_list)))
206 n_hdlc_buf_put(&n_hdlc->rx_free_buf_list, buf);
207}
208
209static void flush_tx_queue(struct tty_struct *tty)
210{
211 struct n_hdlc *n_hdlc = tty2n_hdlc(tty);
212 struct n_hdlc_buf *buf;
213 unsigned long flags;
214
215 while ((buf = n_hdlc_buf_get(&n_hdlc->tx_buf_list)))
216 n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, buf);
217 spin_lock_irqsave(&n_hdlc->tx_buf_list.spinlock, flags);
218 if (n_hdlc->tbuf) {
219 n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, n_hdlc->tbuf);
220 n_hdlc->tbuf = NULL;
221 }
222 spin_unlock_irqrestore(&n_hdlc->tx_buf_list.spinlock, flags);
223}
224
202static struct tty_ldisc_ops n_hdlc_ldisc = { 225static struct tty_ldisc_ops n_hdlc_ldisc = {
203 .owner = THIS_MODULE, 226 .owner = THIS_MODULE,
204 .magic = TTY_LDISC_MAGIC, 227 .magic = TTY_LDISC_MAGIC,
@@ -211,6 +234,7 @@ static struct tty_ldisc_ops n_hdlc_ldisc = {
211 .poll = n_hdlc_tty_poll, 234 .poll = n_hdlc_tty_poll,
212 .receive_buf = n_hdlc_tty_receive, 235 .receive_buf = n_hdlc_tty_receive,
213 .write_wakeup = n_hdlc_tty_wakeup, 236 .write_wakeup = n_hdlc_tty_wakeup,
237 .flush_buffer = flush_rx_queue,
214}; 238};
215 239
216/** 240/**
@@ -341,10 +365,7 @@ static int n_hdlc_tty_open (struct tty_struct *tty)
341 set_bit(TTY_NO_WRITE_SPLIT,&tty->flags); 365 set_bit(TTY_NO_WRITE_SPLIT,&tty->flags);
342#endif 366#endif
343 367
344 /* Flush any pending characters in the driver and discipline. */ 368 /* flush receive data from driver */
345 if (tty->ldisc.ops->flush_buffer)
346 tty->ldisc.ops->flush_buffer(tty);
347
348 tty_driver_flush_buffer(tty); 369 tty_driver_flush_buffer(tty);
349 370
350 if (debuglevel >= DEBUG_LEVEL_INFO) 371 if (debuglevel >= DEBUG_LEVEL_INFO)
@@ -763,6 +784,14 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, struct file *file,
763 error = put_user(count, (int __user *)arg); 784 error = put_user(count, (int __user *)arg);
764 break; 785 break;
765 786
787 case TCFLSH:
788 switch (arg) {
789 case TCIOFLUSH:
790 case TCOFLUSH:
791 flush_tx_queue(tty);
792 }
793 /* fall through to default */
794
766 default: 795 default:
767 error = n_tty_ioctl_helper(tty, file, cmd, arg); 796 error = n_tty_ioctl_helper(tty, file, cmd, arg);
768 break; 797 break;
@@ -919,8 +948,7 @@ static struct n_hdlc_buf* n_hdlc_buf_get(struct n_hdlc_buf_list *list)
919} /* end of n_hdlc_buf_get() */ 948} /* end of n_hdlc_buf_get() */
920 949
921static char hdlc_banner[] __initdata = 950static char hdlc_banner[] __initdata =
922 KERN_INFO "HDLC line discipline: version " HDLC_VERSION 951 KERN_INFO "HDLC line discipline maxframe=%u\n";
923 ", maxframe=%u\n";
924static char hdlc_register_ok[] __initdata = 952static char hdlc_register_ok[] __initdata =
925 KERN_INFO "N_HDLC line discipline registered.\n"; 953 KERN_INFO "N_HDLC line discipline registered.\n";
926static char hdlc_register_fail[] __initdata = 954static char hdlc_register_fail[] __initdata =
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index d2e93e343226..2e99158ebb8a 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -1062,7 +1062,7 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1062 struct r3964_client_info *pClient; 1062 struct r3964_client_info *pClient;
1063 struct r3964_message *pMsg; 1063 struct r3964_message *pMsg;
1064 struct r3964_client_message theMsg; 1064 struct r3964_client_message theMsg;
1065 int count; 1065 int ret;
1066 1066
1067 TRACE_L("read()"); 1067 TRACE_L("read()");
1068 1068
@@ -1074,8 +1074,8 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1074 if (pMsg == NULL) { 1074 if (pMsg == NULL) {
1075 /* no messages available. */ 1075 /* no messages available. */
1076 if (file->f_flags & O_NONBLOCK) { 1076 if (file->f_flags & O_NONBLOCK) {
1077 unlock_kernel(); 1077 ret = -EAGAIN;
1078 return -EAGAIN; 1078 goto unlock;
1079 } 1079 }
1080 /* block until there is a message: */ 1080 /* block until there is a message: */
1081 wait_event_interruptible(pInfo->read_wait, 1081 wait_event_interruptible(pInfo->read_wait,
@@ -1085,29 +1085,31 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1085 /* If we still haven't got a message, we must have been signalled */ 1085 /* If we still haven't got a message, we must have been signalled */
1086 1086
1087 if (!pMsg) { 1087 if (!pMsg) {
1088 unlock_kernel(); 1088 ret = -EINTR;
1089 return -EINTR; 1089 goto unlock;
1090 } 1090 }
1091 1091
1092 /* deliver msg to client process: */ 1092 /* deliver msg to client process: */
1093 theMsg.msg_id = pMsg->msg_id; 1093 theMsg.msg_id = pMsg->msg_id;
1094 theMsg.arg = pMsg->arg; 1094 theMsg.arg = pMsg->arg;
1095 theMsg.error_code = pMsg->error_code; 1095 theMsg.error_code = pMsg->error_code;
1096 count = sizeof(struct r3964_client_message); 1096 ret = sizeof(struct r3964_client_message);
1097 1097
1098 kfree(pMsg); 1098 kfree(pMsg);
1099 TRACE_M("r3964_read - msg kfree %p", pMsg); 1099 TRACE_M("r3964_read - msg kfree %p", pMsg);
1100 1100
1101 if (copy_to_user(buf, &theMsg, count)) { 1101 if (copy_to_user(buf, &theMsg, ret)) {
1102 unlock_kernel(); 1102 ret = -EFAULT;
1103 return -EFAULT; 1103 goto unlock;
1104 } 1104 }
1105 1105
1106 TRACE_PS("read - return %d", count); 1106 TRACE_PS("read - return %d", ret);
1107 return count; 1107 goto unlock;
1108 } 1108 }
1109 ret = -EPERM;
1110unlock:
1109 unlock_kernel(); 1111 unlock_kernel();
1110 return -EPERM; 1112 return ret;
1111} 1113}
1112 1114
1113static ssize_t r3964_write(struct tty_struct *tty, struct file *file, 1115static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index f6f0e4ec2b51..94a5d5020abc 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -73,24 +73,6 @@
73#define ECHO_OP_SET_CANON_COL 0x81 73#define ECHO_OP_SET_CANON_COL 0x81
74#define ECHO_OP_ERASE_TAB 0x82 74#define ECHO_OP_ERASE_TAB 0x82
75 75
76static inline unsigned char *alloc_buf(void)
77{
78 gfp_t prio = in_interrupt() ? GFP_ATOMIC : GFP_KERNEL;
79
80 if (PAGE_SIZE != N_TTY_BUF_SIZE)
81 return kmalloc(N_TTY_BUF_SIZE, prio);
82 else
83 return (unsigned char *)__get_free_page(prio);
84}
85
86static inline void free_buf(unsigned char *buf)
87{
88 if (PAGE_SIZE != N_TTY_BUF_SIZE)
89 kfree(buf);
90 else
91 free_page((unsigned long) buf);
92}
93
94static inline int tty_put_user(struct tty_struct *tty, unsigned char x, 76static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
95 unsigned char __user *ptr) 77 unsigned char __user *ptr)
96{ 78{
@@ -1558,11 +1540,11 @@ static void n_tty_close(struct tty_struct *tty)
1558{ 1540{
1559 n_tty_flush_buffer(tty); 1541 n_tty_flush_buffer(tty);
1560 if (tty->read_buf) { 1542 if (tty->read_buf) {
1561 free_buf(tty->read_buf); 1543 kfree(tty->read_buf);
1562 tty->read_buf = NULL; 1544 tty->read_buf = NULL;
1563 } 1545 }
1564 if (tty->echo_buf) { 1546 if (tty->echo_buf) {
1565 free_buf(tty->echo_buf); 1547 kfree(tty->echo_buf);
1566 tty->echo_buf = NULL; 1548 tty->echo_buf = NULL;
1567 } 1549 }
1568} 1550}
@@ -1584,17 +1566,16 @@ static int n_tty_open(struct tty_struct *tty)
1584 1566
1585 /* These are ugly. Currently a malloc failure here can panic */ 1567 /* These are ugly. Currently a malloc failure here can panic */
1586 if (!tty->read_buf) { 1568 if (!tty->read_buf) {
1587 tty->read_buf = alloc_buf(); 1569 tty->read_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1588 if (!tty->read_buf) 1570 if (!tty->read_buf)
1589 return -ENOMEM; 1571 return -ENOMEM;
1590 } 1572 }
1591 if (!tty->echo_buf) { 1573 if (!tty->echo_buf) {
1592 tty->echo_buf = alloc_buf(); 1574 tty->echo_buf = kzalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
1575
1593 if (!tty->echo_buf) 1576 if (!tty->echo_buf)
1594 return -ENOMEM; 1577 return -ENOMEM;
1595 } 1578 }
1596 memset(tty->read_buf, 0, N_TTY_BUF_SIZE);
1597 memset(tty->echo_buf, 0, N_TTY_BUF_SIZE);
1598 reset_buffer_flags(tty); 1579 reset_buffer_flags(tty);
1599 tty->column = 0; 1580 tty->column = 0;
1600 n_tty_set_termios(tty, NULL); 1581 n_tty_set_termios(tty, NULL);
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index d6102b644b55..574f1c79b6e6 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -1591,8 +1591,6 @@ static int ntty_open(struct tty_struct *tty, struct file *file)
1591 1591
1592 /* Enable interrupt downlink for channel */ 1592 /* Enable interrupt downlink for channel */
1593 if (port->port.count == 1) { 1593 if (port->port.count == 1) {
1594 /* FIXME: is this needed now ? */
1595 tty->low_latency = 1;
1596 tty->driver_data = port; 1594 tty->driver_data = port;
1597 tty_port_tty_set(&port->port, tty); 1595 tty_port_tty_set(&port->port, tty);
1598 DBG1("open: %d", port->token_dl); 1596 DBG1("open: %d", port->token_dl);
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index dbb912574569..881934c068c8 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -1575,7 +1575,8 @@ static long cmm_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1575 clear_bit(LOCK_IO, &dev->flags); 1575 clear_bit(LOCK_IO, &dev->flags);
1576 wake_up_interruptible(&dev->ioq); 1576 wake_up_interruptible(&dev->ioq);
1577 1577
1578 return 0; 1578 rc = 0;
1579 break;
1579 case CM_IOCSPTS: 1580 case CM_IOCSPTS:
1580 { 1581 {
1581 struct ptsreq krnptsreq; 1582 struct ptsreq krnptsreq;
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index 19d79fc54461..77b364889224 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -383,7 +383,7 @@ static void async_mode(MGSLPC_INFO *info);
383static void tx_timeout(unsigned long context); 383static void tx_timeout(unsigned long context);
384 384
385static int carrier_raised(struct tty_port *port); 385static int carrier_raised(struct tty_port *port);
386static void raise_dtr_rts(struct tty_port *port); 386static void dtr_rts(struct tty_port *port, int onoff);
387 387
388#if SYNCLINK_GENERIC_HDLC 388#if SYNCLINK_GENERIC_HDLC
389#define dev_to_port(D) (dev_to_hdlc(D)->priv) 389#define dev_to_port(D) (dev_to_hdlc(D)->priv)
@@ -513,7 +513,7 @@ static void ldisc_receive_buf(struct tty_struct *tty,
513 513
514static const struct tty_port_operations mgslpc_port_ops = { 514static const struct tty_port_operations mgslpc_port_ops = {
515 .carrier_raised = carrier_raised, 515 .carrier_raised = carrier_raised,
516 .raise_dtr_rts = raise_dtr_rts 516 .dtr_rts = dtr_rts
517}; 517};
518 518
519static int mgslpc_probe(struct pcmcia_device *link) 519static int mgslpc_probe(struct pcmcia_device *link)
@@ -2528,13 +2528,16 @@ static int carrier_raised(struct tty_port *port)
2528 return 0; 2528 return 0;
2529} 2529}
2530 2530
2531static void raise_dtr_rts(struct tty_port *port) 2531static void dtr_rts(struct tty_port *port, int onoff)
2532{ 2532{
2533 MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port); 2533 MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port);
2534 unsigned long flags; 2534 unsigned long flags;
2535 2535
2536 spin_lock_irqsave(&info->lock,flags); 2536 spin_lock_irqsave(&info->lock,flags);
2537 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; 2537 if (onoff)
2538 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
2539 else
2540 info->serial_signals &= ~SerialSignal_RTS + SerialSignal_DTR;
2538 set_signals(info); 2541 set_signals(info);
2539 spin_unlock_irqrestore(&info->lock,flags); 2542 spin_unlock_irqrestore(&info->lock,flags);
2540} 2543}
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index c84c34fb1231..432655bcb04c 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -114,8 +114,7 @@ static ssize_t pp_read (struct file * file, char __user * buf, size_t count,
114 114
115 if (!(pp->flags & PP_CLAIMED)) { 115 if (!(pp->flags & PP_CLAIMED)) {
116 /* Don't have the port claimed */ 116 /* Don't have the port claimed */
117 printk (KERN_DEBUG CHRDEV "%x: claim the port first\n", 117 pr_debug(CHRDEV "%x: claim the port first\n", minor);
118 minor);
119 return -EINVAL; 118 return -EINVAL;
120 } 119 }
121 120
@@ -198,8 +197,7 @@ static ssize_t pp_write (struct file * file, const char __user * buf,
198 197
199 if (!(pp->flags & PP_CLAIMED)) { 198 if (!(pp->flags & PP_CLAIMED)) {
200 /* Don't have the port claimed */ 199 /* Don't have the port claimed */
201 printk (KERN_DEBUG CHRDEV "%x: claim the port first\n", 200 pr_debug(CHRDEV "%x: claim the port first\n", minor);
202 minor);
203 return -EINVAL; 201 return -EINVAL;
204 } 202 }
205 203
@@ -313,7 +311,7 @@ static int register_device (int minor, struct pp_struct *pp)
313 } 311 }
314 312
315 pp->pdev = pdev; 313 pp->pdev = pdev;
316 printk (KERN_DEBUG "%s: registered pardevice\n", name); 314 pr_debug("%s: registered pardevice\n", name);
317 return 0; 315 return 0;
318} 316}
319 317
@@ -343,8 +341,7 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
343 int ret; 341 int ret;
344 342
345 if (pp->flags & PP_CLAIMED) { 343 if (pp->flags & PP_CLAIMED) {
346 printk (KERN_DEBUG CHRDEV 344 pr_debug(CHRDEV "%x: you've already got it!\n", minor);
347 "%x: you've already got it!\n", minor);
348 return -EINVAL; 345 return -EINVAL;
349 } 346 }
350 347
@@ -379,7 +376,7 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
379 } 376 }
380 case PPEXCL: 377 case PPEXCL:
381 if (pp->pdev) { 378 if (pp->pdev) {
382 printk (KERN_DEBUG CHRDEV "%x: too late for PPEXCL; " 379 pr_debug(CHRDEV "%x: too late for PPEXCL; "
383 "already registered\n", minor); 380 "already registered\n", minor);
384 if (pp->flags & PP_EXCL) 381 if (pp->flags & PP_EXCL)
385 /* But it's not really an error. */ 382 /* But it's not really an error. */
@@ -491,8 +488,7 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
491 /* Everything else requires the port to be claimed, so check 488 /* Everything else requires the port to be claimed, so check
492 * that now. */ 489 * that now. */
493 if ((pp->flags & PP_CLAIMED) == 0) { 490 if ((pp->flags & PP_CLAIMED) == 0) {
494 printk (KERN_DEBUG CHRDEV "%x: claim the port first\n", 491 pr_debug(CHRDEV "%x: claim the port first\n", minor);
495 minor);
496 return -EINVAL; 492 return -EINVAL;
497 } 493 }
498 494
@@ -624,8 +620,7 @@ static int pp_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
624 return 0; 620 return 0;
625 621
626 default: 622 default:
627 printk (KERN_DEBUG CHRDEV "%x: What? (cmd=0x%x)\n", minor, 623 pr_debug(CHRDEV "%x: What? (cmd=0x%x)\n", minor, cmd);
628 cmd);
629 return -EINVAL; 624 return -EINVAL;
630 } 625 }
631 626
@@ -698,9 +693,8 @@ static int pp_release (struct inode * inode, struct file * file)
698 } 693 }
699 if (compat_negot) { 694 if (compat_negot) {
700 parport_negotiate (pp->pdev->port, IEEE1284_MODE_COMPAT); 695 parport_negotiate (pp->pdev->port, IEEE1284_MODE_COMPAT);
701 printk (KERN_DEBUG CHRDEV 696 pr_debug(CHRDEV "%x: negotiated back to compatibility "
702 "%x: negotiated back to compatibility mode because " 697 "mode because user-space forgot\n", minor);
703 "user-space forgot\n", minor);
704 } 698 }
705 699
706 if (pp->flags & PP_CLAIMED) { 700 if (pp->flags & PP_CLAIMED) {
@@ -713,7 +707,7 @@ static int pp_release (struct inode * inode, struct file * file)
713 info->phase = pp->saved_state.phase; 707 info->phase = pp->saved_state.phase;
714 parport_release (pp->pdev); 708 parport_release (pp->pdev);
715 if (compat_negot != 1) { 709 if (compat_negot != 1) {
716 printk (KERN_DEBUG CHRDEV "%x: released pardevice " 710 pr_debug(CHRDEV "%x: released pardevice "
717 "because user-space forgot\n", minor); 711 "because user-space forgot\n", minor);
718 } 712 }
719 } 713 }
@@ -723,8 +717,7 @@ static int pp_release (struct inode * inode, struct file * file)
723 parport_unregister_device (pp->pdev); 717 parport_unregister_device (pp->pdev);
724 kfree (name); 718 kfree (name);
725 pp->pdev = NULL; 719 pp->pdev = NULL;
726 printk (KERN_DEBUG CHRDEV "%x: unregistered pardevice\n", 720 pr_debug(CHRDEV "%x: unregistered pardevice\n", minor);
727 minor);
728 } 721 }
729 722
730 kfree (pp); 723 kfree (pp);
diff --git a/drivers/char/ps3flash.c b/drivers/char/ps3flash.c
index afbe45676d71..f424d394a286 100644
--- a/drivers/char/ps3flash.c
+++ b/drivers/char/ps3flash.c
@@ -33,48 +33,64 @@
33 33
34struct ps3flash_private { 34struct ps3flash_private {
35 struct mutex mutex; /* Bounce buffer mutex */ 35 struct mutex mutex; /* Bounce buffer mutex */
36 u64 chunk_sectors;
37 int tag; /* Start sector of buffer, -1 if invalid */
38 bool dirty;
36}; 39};
37 40
38static struct ps3_storage_device *ps3flash_dev; 41static struct ps3_storage_device *ps3flash_dev;
39 42
40static ssize_t ps3flash_read_write_sectors(struct ps3_storage_device *dev, 43static int ps3flash_read_write_sectors(struct ps3_storage_device *dev,
41 u64 lpar, u64 start_sector, 44 u64 start_sector, int write)
42 u64 sectors, int write)
43{ 45{
44 u64 res = ps3stor_read_write_sectors(dev, lpar, start_sector, sectors, 46 struct ps3flash_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
47 u64 res = ps3stor_read_write_sectors(dev, dev->bounce_lpar,
48 start_sector, priv->chunk_sectors,
45 write); 49 write);
46 if (res) { 50 if (res) {
47 dev_err(&dev->sbd.core, "%s:%u: %s failed 0x%llx\n", __func__, 51 dev_err(&dev->sbd.core, "%s:%u: %s failed 0x%llx\n", __func__,
48 __LINE__, write ? "write" : "read", res); 52 __LINE__, write ? "write" : "read", res);
49 return -EIO; 53 return -EIO;
50 } 54 }
51 return sectors; 55 return 0;
52} 56}
53 57
54static ssize_t ps3flash_read_sectors(struct ps3_storage_device *dev, 58static int ps3flash_writeback(struct ps3_storage_device *dev)
55 u64 start_sector, u64 sectors,
56 unsigned int sector_offset)
57{ 59{
58 u64 max_sectors, lpar; 60 struct ps3flash_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
61 int res;
59 62
60 max_sectors = dev->bounce_size / dev->blk_size; 63 if (!priv->dirty || priv->tag < 0)
61 if (sectors > max_sectors) { 64 return 0;
62 dev_dbg(&dev->sbd.core, "%s:%u Limiting sectors to %llu\n",
63 __func__, __LINE__, max_sectors);
64 sectors = max_sectors;
65 }
66 65
67 lpar = dev->bounce_lpar + sector_offset * dev->blk_size; 66 res = ps3flash_read_write_sectors(dev, priv->tag, 1);
68 return ps3flash_read_write_sectors(dev, lpar, start_sector, sectors, 67 if (res)
69 0); 68 return res;
69
70 priv->dirty = false;
71 return 0;
70} 72}
71 73
72static ssize_t ps3flash_write_chunk(struct ps3_storage_device *dev, 74static int ps3flash_fetch(struct ps3_storage_device *dev, u64 start_sector)
73 u64 start_sector)
74{ 75{
75 u64 sectors = dev->bounce_size / dev->blk_size; 76 struct ps3flash_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
76 return ps3flash_read_write_sectors(dev, dev->bounce_lpar, start_sector, 77 int res;
77 sectors, 1); 78
79 if (start_sector == priv->tag)
80 return 0;
81
82 res = ps3flash_writeback(dev);
83 if (res)
84 return res;
85
86 priv->tag = -1;
87
88 res = ps3flash_read_write_sectors(dev, start_sector, 0);
89 if (res)
90 return res;
91
92 priv->tag = start_sector;
93 return 0;
78} 94}
79 95
80static loff_t ps3flash_llseek(struct file *file, loff_t offset, int origin) 96static loff_t ps3flash_llseek(struct file *file, loff_t offset, int origin)
@@ -104,18 +120,19 @@ out:
104 return res; 120 return res;
105} 121}
106 122
107static ssize_t ps3flash_read(struct file *file, char __user *buf, size_t count, 123static ssize_t ps3flash_read(char __user *userbuf, void *kernelbuf,
108 loff_t *pos) 124 size_t count, loff_t *pos)
109{ 125{
110 struct ps3_storage_device *dev = ps3flash_dev; 126 struct ps3_storage_device *dev = ps3flash_dev;
111 struct ps3flash_private *priv = dev->sbd.core.driver_data; 127 struct ps3flash_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
112 u64 size, start_sector, end_sector, offset; 128 u64 size, sector, offset;
113 ssize_t sectors_read; 129 int res;
114 size_t remaining, n; 130 size_t remaining, n;
131 const void *src;
115 132
116 dev_dbg(&dev->sbd.core, 133 dev_dbg(&dev->sbd.core,
117 "%s:%u: Reading %zu bytes at position %lld to user 0x%p\n", 134 "%s:%u: Reading %zu bytes at position %lld to U0x%p/K0x%p\n",
118 __func__, __LINE__, count, *pos, buf); 135 __func__, __LINE__, count, *pos, userbuf, kernelbuf);
119 136
120 size = dev->regions[dev->region_idx].size*dev->blk_size; 137 size = dev->regions[dev->region_idx].size*dev->blk_size;
121 if (*pos >= size || !count) 138 if (*pos >= size || !count)
@@ -128,61 +145,63 @@ static ssize_t ps3flash_read(struct file *file, char __user *buf, size_t count,
128 count = size - *pos; 145 count = size - *pos;
129 } 146 }
130 147
131 start_sector = *pos / dev->blk_size; 148 sector = *pos / dev->bounce_size * priv->chunk_sectors;
132 offset = *pos % dev->blk_size; 149 offset = *pos % dev->bounce_size;
133 end_sector = DIV_ROUND_UP(*pos + count, dev->blk_size);
134 150
135 remaining = count; 151 remaining = count;
136 do { 152 do {
153 n = min_t(u64, remaining, dev->bounce_size - offset);
154 src = dev->bounce_buf + offset;
155
137 mutex_lock(&priv->mutex); 156 mutex_lock(&priv->mutex);
138 157
139 sectors_read = ps3flash_read_sectors(dev, start_sector, 158 res = ps3flash_fetch(dev, sector);
140 end_sector-start_sector, 159 if (res)
141 0);
142 if (sectors_read < 0) {
143 mutex_unlock(&priv->mutex);
144 goto fail; 160 goto fail;
145 }
146 161
147 n = min_t(u64, remaining, sectors_read*dev->blk_size-offset);
148 dev_dbg(&dev->sbd.core, 162 dev_dbg(&dev->sbd.core,
149 "%s:%u: copy %lu bytes from 0x%p to user 0x%p\n", 163 "%s:%u: copy %lu bytes from 0x%p to U0x%p/K0x%p\n",
150 __func__, __LINE__, n, dev->bounce_buf+offset, buf); 164 __func__, __LINE__, n, src, userbuf, kernelbuf);
151 if (copy_to_user(buf, dev->bounce_buf+offset, n)) { 165 if (userbuf) {
152 mutex_unlock(&priv->mutex); 166 if (copy_to_user(userbuf, src, n)) {
153 sectors_read = -EFAULT; 167 res = -EFAULT;
154 goto fail; 168 goto fail;
169 }
170 userbuf += n;
171 }
172 if (kernelbuf) {
173 memcpy(kernelbuf, src, n);
174 kernelbuf += n;
155 } 175 }
156 176
157 mutex_unlock(&priv->mutex); 177 mutex_unlock(&priv->mutex);
158 178
159 *pos += n; 179 *pos += n;
160 buf += n;
161 remaining -= n; 180 remaining -= n;
162 start_sector += sectors_read; 181 sector += priv->chunk_sectors;
163 offset = 0; 182 offset = 0;
164 } while (remaining > 0); 183 } while (remaining > 0);
165 184
166 return count; 185 return count;
167 186
168fail: 187fail:
169 return sectors_read; 188 mutex_unlock(&priv->mutex);
189 return res;
170} 190}
171 191
172static ssize_t ps3flash_write(struct file *file, const char __user *buf, 192static ssize_t ps3flash_write(const char __user *userbuf,
173 size_t count, loff_t *pos) 193 const void *kernelbuf, size_t count, loff_t *pos)
174{ 194{
175 struct ps3_storage_device *dev = ps3flash_dev; 195 struct ps3_storage_device *dev = ps3flash_dev;
176 struct ps3flash_private *priv = dev->sbd.core.driver_data; 196 struct ps3flash_private *priv = ps3_system_bus_get_drvdata(&dev->sbd);
177 u64 size, chunk_sectors, start_write_sector, end_write_sector, 197 u64 size, sector, offset;
178 end_read_sector, start_read_sector, head, tail, offset; 198 int res = 0;
179 ssize_t res;
180 size_t remaining, n; 199 size_t remaining, n;
181 unsigned int sec_off; 200 void *dst;
182 201
183 dev_dbg(&dev->sbd.core, 202 dev_dbg(&dev->sbd.core,
184 "%s:%u: Writing %zu bytes at position %lld from user 0x%p\n", 203 "%s:%u: Writing %zu bytes at position %lld from U0x%p/K0x%p\n",
185 __func__, __LINE__, count, *pos, buf); 204 __func__, __LINE__, count, *pos, userbuf, kernelbuf);
186 205
187 size = dev->regions[dev->region_idx].size*dev->blk_size; 206 size = dev->regions[dev->region_idx].size*dev->blk_size;
188 if (*pos >= size || !count) 207 if (*pos >= size || !count)
@@ -195,89 +214,46 @@ static ssize_t ps3flash_write(struct file *file, const char __user *buf,
195 count = size - *pos; 214 count = size - *pos;
196 } 215 }
197 216
198 chunk_sectors = dev->bounce_size / dev->blk_size; 217 sector = *pos / dev->bounce_size * priv->chunk_sectors;
199
200 start_write_sector = *pos / dev->bounce_size * chunk_sectors;
201 offset = *pos % dev->bounce_size; 218 offset = *pos % dev->bounce_size;
202 end_write_sector = DIV_ROUND_UP(*pos + count, dev->bounce_size) *
203 chunk_sectors;
204
205 end_read_sector = DIV_ROUND_UP(*pos, dev->blk_size);
206 start_read_sector = (*pos + count) / dev->blk_size;
207
208 /*
209 * As we have to write in 256 KiB chunks, while we can read in blk_size
210 * (usually 512 bytes) chunks, we perform the following steps:
211 * 1. Read from start_write_sector to end_read_sector ("head")
212 * 2. Read from start_read_sector to end_write_sector ("tail")
213 * 3. Copy data to buffer
214 * 4. Write from start_write_sector to end_write_sector
215 * All of this is complicated by using only one 256 KiB bounce buffer.
216 */
217
218 head = end_read_sector - start_write_sector;
219 tail = end_write_sector - start_read_sector;
220 219
221 remaining = count; 220 remaining = count;
222 do { 221 do {
222 n = min_t(u64, remaining, dev->bounce_size - offset);
223 dst = dev->bounce_buf + offset;
224
223 mutex_lock(&priv->mutex); 225 mutex_lock(&priv->mutex);
224 226
225 if (end_read_sector >= start_read_sector) { 227 if (n != dev->bounce_size)
226 /* Merge head and tail */ 228 res = ps3flash_fetch(dev, sector);
227 dev_dbg(&dev->sbd.core, 229 else if (sector != priv->tag)
228 "Merged head and tail: %llu sectors at %llu\n", 230 res = ps3flash_writeback(dev);
229 chunk_sectors, start_write_sector); 231 if (res)
230 res = ps3flash_read_sectors(dev, start_write_sector, 232 goto fail;
231 chunk_sectors, 0); 233
232 if (res < 0) 234 dev_dbg(&dev->sbd.core,
235 "%s:%u: copy %lu bytes from U0x%p/K0x%p to 0x%p\n",
236 __func__, __LINE__, n, userbuf, kernelbuf, dst);
237 if (userbuf) {
238 if (copy_from_user(dst, userbuf, n)) {
239 res = -EFAULT;
233 goto fail; 240 goto fail;
234 } else {
235 if (head) {
236 /* Read head */
237 dev_dbg(&dev->sbd.core,
238 "head: %llu sectors at %llu\n", head,
239 start_write_sector);
240 res = ps3flash_read_sectors(dev,
241 start_write_sector,
242 head, 0);
243 if (res < 0)
244 goto fail;
245 }
246 if (start_read_sector <
247 start_write_sector+chunk_sectors) {
248 /* Read tail */
249 dev_dbg(&dev->sbd.core,
250 "tail: %llu sectors at %llu\n", tail,
251 start_read_sector);
252 sec_off = start_read_sector-start_write_sector;
253 res = ps3flash_read_sectors(dev,
254 start_read_sector,
255 tail, sec_off);
256 if (res < 0)
257 goto fail;
258 } 241 }
242 userbuf += n;
259 } 243 }
260 244 if (kernelbuf) {
261 n = min_t(u64, remaining, dev->bounce_size-offset); 245 memcpy(dst, kernelbuf, n);
262 dev_dbg(&dev->sbd.core, 246 kernelbuf += n;
263 "%s:%u: copy %lu bytes from user 0x%p to 0x%p\n",
264 __func__, __LINE__, n, buf, dev->bounce_buf+offset);
265 if (copy_from_user(dev->bounce_buf+offset, buf, n)) {
266 res = -EFAULT;
267 goto fail;
268 } 247 }
269 248
270 res = ps3flash_write_chunk(dev, start_write_sector); 249 priv->tag = sector;
271 if (res < 0) 250 priv->dirty = true;
272 goto fail;
273 251
274 mutex_unlock(&priv->mutex); 252 mutex_unlock(&priv->mutex);
275 253
276 *pos += n; 254 *pos += n;
277 buf += n;
278 remaining -= n; 255 remaining -= n;
279 start_write_sector += chunk_sectors; 256 sector += priv->chunk_sectors;
280 head = 0;
281 offset = 0; 257 offset = 0;
282 } while (remaining > 0); 258 } while (remaining > 0);
283 259
@@ -288,6 +264,51 @@ fail:
288 return res; 264 return res;
289} 265}
290 266
267static ssize_t ps3flash_user_read(struct file *file, char __user *buf,
268 size_t count, loff_t *pos)
269{
270 return ps3flash_read(buf, NULL, count, pos);
271}
272
273static ssize_t ps3flash_user_write(struct file *file, const char __user *buf,
274 size_t count, loff_t *pos)
275{
276 return ps3flash_write(buf, NULL, count, pos);
277}
278
279static ssize_t ps3flash_kernel_read(void *buf, size_t count, loff_t pos)
280{
281 return ps3flash_read(NULL, buf, count, &pos);
282}
283
284static ssize_t ps3flash_kernel_write(const void *buf, size_t count,
285 loff_t pos)
286{
287 ssize_t res;
288 int wb;
289
290 res = ps3flash_write(NULL, buf, count, &pos);
291 if (res < 0)
292 return res;
293
294 /* Make kernel writes synchronous */
295 wb = ps3flash_writeback(ps3flash_dev);
296 if (wb)
297 return wb;
298
299 return res;
300}
301
302static int ps3flash_flush(struct file *file, fl_owner_t id)
303{
304 return ps3flash_writeback(ps3flash_dev);
305}
306
307static int ps3flash_fsync(struct file *file, struct dentry *dentry,
308 int datasync)
309{
310 return ps3flash_writeback(ps3flash_dev);
311}
291 312
292static irqreturn_t ps3flash_interrupt(int irq, void *data) 313static irqreturn_t ps3flash_interrupt(int irq, void *data)
293{ 314{
@@ -312,12 +333,18 @@ static irqreturn_t ps3flash_interrupt(int irq, void *data)
312 return IRQ_HANDLED; 333 return IRQ_HANDLED;
313} 334}
314 335
315
316static const struct file_operations ps3flash_fops = { 336static const struct file_operations ps3flash_fops = {
317 .owner = THIS_MODULE, 337 .owner = THIS_MODULE,
318 .llseek = ps3flash_llseek, 338 .llseek = ps3flash_llseek,
319 .read = ps3flash_read, 339 .read = ps3flash_user_read,
320 .write = ps3flash_write, 340 .write = ps3flash_user_write,
341 .flush = ps3flash_flush,
342 .fsync = ps3flash_fsync,
343};
344
345static const struct ps3_os_area_flash_ops ps3flash_kernel_ops = {
346 .read = ps3flash_kernel_read,
347 .write = ps3flash_kernel_write,
321}; 348};
322 349
323static struct miscdevice ps3flash_misc = { 350static struct miscdevice ps3flash_misc = {
@@ -366,11 +393,13 @@ static int __devinit ps3flash_probe(struct ps3_system_bus_device *_dev)
366 goto fail; 393 goto fail;
367 } 394 }
368 395
369 dev->sbd.core.driver_data = priv; 396 ps3_system_bus_set_drvdata(&dev->sbd, priv);
370 mutex_init(&priv->mutex); 397 mutex_init(&priv->mutex);
398 priv->tag = -1;
371 399
372 dev->bounce_size = ps3flash_bounce_buffer.size; 400 dev->bounce_size = ps3flash_bounce_buffer.size;
373 dev->bounce_buf = ps3flash_bounce_buffer.address; 401 dev->bounce_buf = ps3flash_bounce_buffer.address;
402 priv->chunk_sectors = dev->bounce_size / dev->blk_size;
374 403
375 error = ps3stor_setup(dev, ps3flash_interrupt); 404 error = ps3stor_setup(dev, ps3flash_interrupt);
376 if (error) 405 if (error)
@@ -386,13 +415,15 @@ static int __devinit ps3flash_probe(struct ps3_system_bus_device *_dev)
386 415
387 dev_info(&dev->sbd.core, "%s:%u: registered misc device %d\n", 416 dev_info(&dev->sbd.core, "%s:%u: registered misc device %d\n",
388 __func__, __LINE__, ps3flash_misc.minor); 417 __func__, __LINE__, ps3flash_misc.minor);
418
419 ps3_os_area_flash_register(&ps3flash_kernel_ops);
389 return 0; 420 return 0;
390 421
391fail_teardown: 422fail_teardown:
392 ps3stor_teardown(dev); 423 ps3stor_teardown(dev);
393fail_free_priv: 424fail_free_priv:
394 kfree(priv); 425 kfree(priv);
395 dev->sbd.core.driver_data = NULL; 426 ps3_system_bus_set_drvdata(&dev->sbd, NULL);
396fail: 427fail:
397 ps3flash_dev = NULL; 428 ps3flash_dev = NULL;
398 return error; 429 return error;
@@ -402,10 +433,11 @@ static int ps3flash_remove(struct ps3_system_bus_device *_dev)
402{ 433{
403 struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core); 434 struct ps3_storage_device *dev = to_ps3_storage_device(&_dev->core);
404 435
436 ps3_os_area_flash_register(NULL);
405 misc_deregister(&ps3flash_misc); 437 misc_deregister(&ps3flash_misc);
406 ps3stor_teardown(dev); 438 ps3stor_teardown(dev);
407 kfree(dev->sbd.core.driver_data); 439 kfree(ps3_system_bus_get_drvdata(&dev->sbd));
408 dev->sbd.core.driver_data = NULL; 440 ps3_system_bus_set_drvdata(&dev->sbd, NULL);
409 ps3flash_dev = NULL; 441 ps3flash_dev = NULL;
410 return 0; 442 return 0;
411} 443}
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 31038a0052a2..daebe1ba43d4 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -30,7 +30,6 @@
30 30
31#include <asm/system.h> 31#include <asm/system.h>
32 32
33/* These are global because they are accessed in tty_io.c */
34#ifdef CONFIG_UNIX98_PTYS 33#ifdef CONFIG_UNIX98_PTYS
35static struct tty_driver *ptm_driver; 34static struct tty_driver *ptm_driver;
36static struct tty_driver *pts_driver; 35static struct tty_driver *pts_driver;
@@ -96,23 +95,34 @@ static void pty_unthrottle(struct tty_struct *tty)
96 * a count. 95 * a count.
97 * 96 *
98 * FIXME: Our pty_write method is called with our ldisc lock held but 97 * FIXME: Our pty_write method is called with our ldisc lock held but
99 * not our partners. We can't just take the other one blindly without 98 * not our partners. We can't just wait on the other one blindly without
100 * risking deadlocks. 99 * risking deadlocks. At some point when everything has settled down we need
100 * to look into making pty_write at least able to sleep over an ldisc change.
101 *
102 * The return on no ldisc is a bit counter intuitive but the logic works
103 * like this. During an ldisc change the other end will flush its buffers. We
104 * thus return the full length which is identical to the case where we had
105 * proper locking and happened to queue the bytes just before the flush during
106 * the ldisc change.
101 */ 107 */
102static int pty_write(struct tty_struct *tty, const unsigned char *buf, 108static int pty_write(struct tty_struct *tty, const unsigned char *buf,
103 int count) 109 int count)
104{ 110{
105 struct tty_struct *to = tty->link; 111 struct tty_struct *to = tty->link;
106 int c; 112 struct tty_ldisc *ld;
113 int c = count;
107 114
108 if (!to || tty->stopped) 115 if (!to || tty->stopped)
109 return 0; 116 return 0;
110 117 ld = tty_ldisc_ref(to);
111 c = to->receive_room; 118
112 if (c > count) 119 if (ld) {
113 c = count; 120 c = to->receive_room;
114 to->ldisc.ops->receive_buf(to, buf, NULL, c); 121 if (c > count)
115 122 c = count;
123 ld->ops->receive_buf(to, buf, NULL, c);
124 tty_ldisc_deref(ld);
125 }
116 return c; 126 return c;
117} 127}
118 128
@@ -146,14 +156,23 @@ static int pty_write_room(struct tty_struct *tty)
146static int pty_chars_in_buffer(struct tty_struct *tty) 156static int pty_chars_in_buffer(struct tty_struct *tty)
147{ 157{
148 struct tty_struct *to = tty->link; 158 struct tty_struct *to = tty->link;
149 int count; 159 struct tty_ldisc *ld;
160 int count = 0;
150 161
151 /* We should get the line discipline lock for "tty->link" */ 162 /* We should get the line discipline lock for "tty->link" */
152 if (!to || !to->ldisc.ops->chars_in_buffer) 163 if (!to)
164 return 0;
165 /* We cannot take a sleeping reference here without deadlocking with
166 an ldisc change - but it doesn't really matter */
167 ld = tty_ldisc_ref(to);
168 if (ld == NULL)
153 return 0; 169 return 0;
154 170
155 /* The ldisc must report 0 if no characters available to be read */ 171 /* The ldisc must report 0 if no characters available to be read */
156 count = to->ldisc.ops->chars_in_buffer(to); 172 if (ld->ops->chars_in_buffer)
173 count = ld->ops->chars_in_buffer(to);
174
175 tty_ldisc_deref(ld);
157 176
158 if (tty->driver->subtype == PTY_TYPE_SLAVE) 177 if (tty->driver->subtype == PTY_TYPE_SLAVE)
159 return count; 178 return count;
@@ -183,12 +202,19 @@ static void pty_flush_buffer(struct tty_struct *tty)
183{ 202{
184 struct tty_struct *to = tty->link; 203 struct tty_struct *to = tty->link;
185 unsigned long flags; 204 unsigned long flags;
205 struct tty_ldisc *ld;
186 206
187 if (!to) 207 if (!to)
188 return; 208 return;
209 ld = tty_ldisc_ref(to);
210
211 /* The other end is changing discipline */
212 if (!ld)
213 return;
189 214
190 if (to->ldisc.ops->flush_buffer) 215 if (ld->ops->flush_buffer)
191 to->ldisc.ops->flush_buffer(to); 216 to->ldisc->ops->flush_buffer(to);
217 tty_ldisc_deref(ld);
192 218
193 if (to->packet) { 219 if (to->packet) {
194 spin_lock_irqsave(&tty->ctrl_lock, flags); 220 spin_lock_irqsave(&tty->ctrl_lock, flags);
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 20d90e6a6e50..05f9d18b9361 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -71,7 +71,7 @@ static int raw_open(struct inode *inode, struct file *filp)
71 err = bd_claim(bdev, raw_open); 71 err = bd_claim(bdev, raw_open);
72 if (err) 72 if (err)
73 goto out1; 73 goto out1;
74 err = set_blocksize(bdev, bdev_hardsect_size(bdev)); 74 err = set_blocksize(bdev, bdev_logical_block_size(bdev));
75 if (err) 75 if (err)
76 goto out2; 76 goto out2;
77 filp->f_flags |= O_DIRECT; 77 filp->f_flags |= O_DIRECT;
@@ -261,6 +261,11 @@ static const struct file_operations raw_ctl_fops = {
261 261
262static struct cdev raw_cdev; 262static struct cdev raw_cdev;
263 263
264static char *raw_nodename(struct device *dev)
265{
266 return kasprintf(GFP_KERNEL, "raw/%s", dev_name(dev));
267}
268
264static int __init raw_init(void) 269static int __init raw_init(void)
265{ 270{
266 dev_t dev = MKDEV(RAW_MAJOR, 0); 271 dev_t dev = MKDEV(RAW_MAJOR, 0);
@@ -284,6 +289,7 @@ static int __init raw_init(void)
284 ret = PTR_ERR(raw_class); 289 ret = PTR_ERR(raw_class);
285 goto error_region; 290 goto error_region;
286 } 291 }
292 raw_class->nodename = raw_nodename;
287 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl"); 293 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
288 294
289 return 0; 295 return 0;
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index f59fc5cea067..63d5b628477a 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -872,11 +872,16 @@ static int carrier_raised(struct tty_port *port)
872 return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0; 872 return (sGetChanStatusLo(&info->channel) & CD_ACT) ? 1 : 0;
873} 873}
874 874
875static void raise_dtr_rts(struct tty_port *port) 875static void dtr_rts(struct tty_port *port, int on)
876{ 876{
877 struct r_port *info = container_of(port, struct r_port, port); 877 struct r_port *info = container_of(port, struct r_port, port);
878 sSetDTR(&info->channel); 878 if (on) {
879 sSetRTS(&info->channel); 879 sSetDTR(&info->channel);
880 sSetRTS(&info->channel);
881 } else {
882 sClrDTR(&info->channel);
883 sClrRTS(&info->channel);
884 }
880} 885}
881 886
882/* 887/*
@@ -934,7 +939,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
934 /* 939 /*
935 * Info->count is now 1; so it's safe to sleep now. 940 * Info->count is now 1; so it's safe to sleep now.
936 */ 941 */
937 if (!test_bit(ASYNC_INITIALIZED, &port->flags)) { 942 if (!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
938 cp = &info->channel; 943 cp = &info->channel;
939 sSetRxTrigger(cp, TRIG_1); 944 sSetRxTrigger(cp, TRIG_1);
940 if (sGetChanStatus(cp) & CD_ACT) 945 if (sGetChanStatus(cp) & CD_ACT)
@@ -958,7 +963,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
958 sEnRxFIFO(cp); 963 sEnRxFIFO(cp);
959 sEnTransmit(cp); 964 sEnTransmit(cp);
960 965
961 set_bit(ASYNC_INITIALIZED, &info->port.flags); 966 set_bit(ASYNCB_INITIALIZED, &info->port.flags);
962 967
963 /* 968 /*
964 * Set up the tty->alt_speed kludge 969 * Set up the tty->alt_speed kludge
@@ -1641,7 +1646,7 @@ static int rp_write(struct tty_struct *tty,
1641 /* Write remaining data into the port's xmit_buf */ 1646 /* Write remaining data into the port's xmit_buf */
1642 while (1) { 1647 while (1) {
1643 /* Hung up ? */ 1648 /* Hung up ? */
1644 if (!test_bit(ASYNC_NORMAL_ACTIVE, &info->port.flags)) 1649 if (!test_bit(ASYNCB_NORMAL_ACTIVE, &info->port.flags))
1645 goto end; 1650 goto end;
1646 c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1); 1651 c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1);
1647 c = min(c, XMIT_BUF_SIZE - info->xmit_head); 1652 c = min(c, XMIT_BUF_SIZE - info->xmit_head);
@@ -2250,7 +2255,7 @@ static const struct tty_operations rocket_ops = {
2250 2255
2251static const struct tty_port_operations rocket_port_ops = { 2256static const struct tty_port_operations rocket_port_ops = {
2252 .carrier_raised = carrier_raised, 2257 .carrier_raised = carrier_raised,
2253 .raise_dtr_rts = raise_dtr_rts, 2258 .dtr_rts = dtr_rts,
2254}; 2259};
2255 2260
2256/* 2261/*
diff --git a/drivers/char/selection.c b/drivers/char/selection.c
index cb8ca5698963..f97b9e848064 100644
--- a/drivers/char/selection.c
+++ b/drivers/char/selection.c
@@ -327,7 +327,7 @@ int paste_selection(struct tty_struct *tty)
327 } 327 }
328 count = sel_buffer_lth - pasted; 328 count = sel_buffer_lth - pasted;
329 count = min(count, tty->receive_room); 329 count = min(count, tty->receive_room);
330 tty->ldisc.ops->receive_buf(tty, sel_buffer + pasted, 330 tty->ldisc->ops->receive_buf(tty, sel_buffer + pasted,
331 NULL, count); 331 NULL, count);
332 pasted += count; 332 pasted += count;
333 } 333 }
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 2ad813a801dc..53e504f41b20 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -772,11 +772,11 @@ static int stl_carrier_raised(struct tty_port *port)
772 return (portp->sigs & TIOCM_CD) ? 1 : 0; 772 return (portp->sigs & TIOCM_CD) ? 1 : 0;
773} 773}
774 774
775static void stl_raise_dtr_rts(struct tty_port *port) 775static void stl_dtr_rts(struct tty_port *port, int on)
776{ 776{
777 struct stlport *portp = container_of(port, struct stlport, port); 777 struct stlport *portp = container_of(port, struct stlport, port);
778 /* Takes brd_lock internally */ 778 /* Takes brd_lock internally */
779 stl_setsignals(portp, 1, 1); 779 stl_setsignals(portp, on, on);
780} 780}
781 781
782/*****************************************************************************/ 782/*****************************************************************************/
@@ -2547,7 +2547,7 @@ static const struct tty_operations stl_ops = {
2547 2547
2548static const struct tty_port_operations stl_port_ops = { 2548static const struct tty_port_operations stl_port_ops = {
2549 .carrier_raised = stl_carrier_raised, 2549 .carrier_raised = stl_carrier_raised,
2550 .raise_dtr_rts = stl_raise_dtr_rts, 2550 .dtr_rts = stl_dtr_rts,
2551}; 2551};
2552 2552
2553/*****************************************************************************/ 2553/*****************************************************************************/
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index afd0b26ca056..afded3a2379c 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -3247,13 +3247,16 @@ static int carrier_raised(struct tty_port *port)
3247 return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; 3247 return (info->serial_signals & SerialSignal_DCD) ? 1 : 0;
3248} 3248}
3249 3249
3250static void raise_dtr_rts(struct tty_port *port) 3250static void dtr_rts(struct tty_port *port, int on)
3251{ 3251{
3252 struct mgsl_struct *info = container_of(port, struct mgsl_struct, port); 3252 struct mgsl_struct *info = container_of(port, struct mgsl_struct, port);
3253 unsigned long flags; 3253 unsigned long flags;
3254 3254
3255 spin_lock_irqsave(&info->irq_spinlock,flags); 3255 spin_lock_irqsave(&info->irq_spinlock,flags);
3256 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; 3256 if (on)
3257 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3258 else
3259 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
3257 usc_set_serial_signals(info); 3260 usc_set_serial_signals(info);
3258 spin_unlock_irqrestore(&info->irq_spinlock,flags); 3261 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3259} 3262}
@@ -4258,7 +4261,7 @@ static void mgsl_add_device( struct mgsl_struct *info )
4258 4261
4259static const struct tty_port_operations mgsl_port_ops = { 4262static const struct tty_port_operations mgsl_port_ops = {
4260 .carrier_raised = carrier_raised, 4263 .carrier_raised = carrier_raised,
4261 .raise_dtr_rts = raise_dtr_rts, 4264 .dtr_rts = dtr_rts,
4262}; 4265};
4263 4266
4264 4267
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 5e256494686a..a2e67e6df3a1 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -214,6 +214,7 @@ struct slgt_desc
214#define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b)) 214#define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b))
215#define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b)) 215#define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b))
216#define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0)) 216#define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0))
217#define set_desc_status(a, b) (a).status = cpu_to_le16((unsigned short)(b))
217#define desc_count(a) (le16_to_cpu((a).count)) 218#define desc_count(a) (le16_to_cpu((a).count))
218#define desc_status(a) (le16_to_cpu((a).status)) 219#define desc_status(a) (le16_to_cpu((a).status))
219#define desc_complete(a) (le16_to_cpu((a).status) & BIT15) 220#define desc_complete(a) (le16_to_cpu((a).status) & BIT15)
@@ -297,6 +298,7 @@ struct slgt_info {
297 u32 max_frame_size; /* as set by device config */ 298 u32 max_frame_size; /* as set by device config */
298 299
299 unsigned int rbuf_fill_level; 300 unsigned int rbuf_fill_level;
301 unsigned int rx_pio;
300 unsigned int if_mode; 302 unsigned int if_mode;
301 unsigned int base_clock; 303 unsigned int base_clock;
302 304
@@ -331,6 +333,8 @@ struct slgt_info {
331 struct slgt_desc *rbufs; 333 struct slgt_desc *rbufs;
332 unsigned int rbuf_current; 334 unsigned int rbuf_current;
333 unsigned int rbuf_index; 335 unsigned int rbuf_index;
336 unsigned int rbuf_fill_index;
337 unsigned short rbuf_fill_count;
334 338
335 unsigned int tbuf_count; 339 unsigned int tbuf_count;
336 struct slgt_desc *tbufs; 340 struct slgt_desc *tbufs;
@@ -463,7 +467,6 @@ static unsigned int free_tbuf_count(struct slgt_info *info);
463static unsigned int tbuf_bytes(struct slgt_info *info); 467static unsigned int tbuf_bytes(struct slgt_info *info);
464static void reset_tbufs(struct slgt_info *info); 468static void reset_tbufs(struct slgt_info *info);
465static void tdma_reset(struct slgt_info *info); 469static void tdma_reset(struct slgt_info *info);
466static void tdma_start(struct slgt_info *info);
467static void tx_load(struct slgt_info *info, const char *buf, unsigned int count); 470static void tx_load(struct slgt_info *info, const char *buf, unsigned int count);
468 471
469static void get_signals(struct slgt_info *info); 472static void get_signals(struct slgt_info *info);
@@ -791,6 +794,18 @@ static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
791 } 794 }
792} 795}
793 796
797static void update_tx_timer(struct slgt_info *info)
798{
799 /*
800 * use worst case speed of 1200bps to calculate transmit timeout
801 * based on data in buffers (tbuf_bytes) and FIFO (128 bytes)
802 */
803 if (info->params.mode == MGSL_MODE_HDLC) {
804 int timeout = (tbuf_bytes(info) * 7) + 1000;
805 mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(timeout));
806 }
807}
808
794static int write(struct tty_struct *tty, 809static int write(struct tty_struct *tty,
795 const unsigned char *buf, int count) 810 const unsigned char *buf, int count)
796{ 811{
@@ -834,8 +849,18 @@ start:
834 spin_lock_irqsave(&info->lock,flags); 849 spin_lock_irqsave(&info->lock,flags);
835 if (!info->tx_active) 850 if (!info->tx_active)
836 tx_start(info); 851 tx_start(info);
837 else 852 else if (!(rd_reg32(info, TDCSR) & BIT0)) {
838 tdma_start(info); 853 /* transmit still active but transmit DMA stopped */
854 unsigned int i = info->tbuf_current;
855 if (!i)
856 i = info->tbuf_count;
857 i--;
858 /* if DMA buf unsent must try later after tx idle */
859 if (desc_count(info->tbufs[i]))
860 ret = 0;
861 }
862 if (ret > 0)
863 update_tx_timer(info);
839 spin_unlock_irqrestore(&info->lock,flags); 864 spin_unlock_irqrestore(&info->lock,flags);
840 } 865 }
841 866
@@ -1498,10 +1523,9 @@ static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
1498 /* save start time for transmit timeout detection */ 1523 /* save start time for transmit timeout detection */
1499 dev->trans_start = jiffies; 1524 dev->trans_start = jiffies;
1500 1525
1501 /* start hardware transmitter if necessary */
1502 spin_lock_irqsave(&info->lock,flags); 1526 spin_lock_irqsave(&info->lock,flags);
1503 if (!info->tx_active) 1527 tx_start(info);
1504 tx_start(info); 1528 update_tx_timer(info);
1505 spin_unlock_irqrestore(&info->lock,flags); 1529 spin_unlock_irqrestore(&info->lock,flags);
1506 1530
1507 return 0; 1531 return 0;
@@ -2110,6 +2134,40 @@ static void ri_change(struct slgt_info *info, unsigned short status)
2110 info->pending_bh |= BH_STATUS; 2134 info->pending_bh |= BH_STATUS;
2111} 2135}
2112 2136
2137static void isr_rxdata(struct slgt_info *info)
2138{
2139 unsigned int count = info->rbuf_fill_count;
2140 unsigned int i = info->rbuf_fill_index;
2141 unsigned short reg;
2142
2143 while (rd_reg16(info, SSR) & IRQ_RXDATA) {
2144 reg = rd_reg16(info, RDR);
2145 DBGISR(("isr_rxdata %s RDR=%04X\n", info->device_name, reg));
2146 if (desc_complete(info->rbufs[i])) {
2147 /* all buffers full */
2148 rx_stop(info);
2149 info->rx_restart = 1;
2150 continue;
2151 }
2152 info->rbufs[i].buf[count++] = (unsigned char)reg;
2153 /* async mode saves status byte to buffer for each data byte */
2154 if (info->params.mode == MGSL_MODE_ASYNC)
2155 info->rbufs[i].buf[count++] = (unsigned char)(reg >> 8);
2156 if (count == info->rbuf_fill_level || (reg & BIT10)) {
2157 /* buffer full or end of frame */
2158 set_desc_count(info->rbufs[i], count);
2159 set_desc_status(info->rbufs[i], BIT15 | (reg >> 8));
2160 info->rbuf_fill_count = count = 0;
2161 if (++i == info->rbuf_count)
2162 i = 0;
2163 info->pending_bh |= BH_RECEIVE;
2164 }
2165 }
2166
2167 info->rbuf_fill_index = i;
2168 info->rbuf_fill_count = count;
2169}
2170
2113static void isr_serial(struct slgt_info *info) 2171static void isr_serial(struct slgt_info *info)
2114{ 2172{
2115 unsigned short status = rd_reg16(info, SSR); 2173 unsigned short status = rd_reg16(info, SSR);
@@ -2125,6 +2183,8 @@ static void isr_serial(struct slgt_info *info)
2125 if (info->tx_count) 2183 if (info->tx_count)
2126 isr_txeom(info, status); 2184 isr_txeom(info, status);
2127 } 2185 }
2186 if (info->rx_pio && (status & IRQ_RXDATA))
2187 isr_rxdata(info);
2128 if ((status & IRQ_RXBREAK) && (status & RXBREAK)) { 2188 if ((status & IRQ_RXBREAK) && (status & RXBREAK)) {
2129 info->icount.brk++; 2189 info->icount.brk++;
2130 /* process break detection if tty control allows */ 2190 /* process break detection if tty control allows */
@@ -2141,7 +2201,8 @@ static void isr_serial(struct slgt_info *info)
2141 } else { 2201 } else {
2142 if (status & (IRQ_TXIDLE + IRQ_TXUNDER)) 2202 if (status & (IRQ_TXIDLE + IRQ_TXUNDER))
2143 isr_txeom(info, status); 2203 isr_txeom(info, status);
2144 2204 if (info->rx_pio && (status & IRQ_RXDATA))
2205 isr_rxdata(info);
2145 if (status & IRQ_RXIDLE) { 2206 if (status & IRQ_RXIDLE) {
2146 if (status & RXIDLE) 2207 if (status & RXIDLE)
2147 info->icount.rxidle++; 2208 info->icount.rxidle++;
@@ -2642,6 +2703,10 @@ static int rx_enable(struct slgt_info *info, int enable)
2642 return -EINVAL; 2703 return -EINVAL;
2643 } 2704 }
2644 info->rbuf_fill_level = rbuf_fill_level; 2705 info->rbuf_fill_level = rbuf_fill_level;
2706 if (rbuf_fill_level < 128)
2707 info->rx_pio = 1; /* PIO mode */
2708 else
2709 info->rx_pio = 0; /* DMA mode */
2645 rx_stop(info); /* restart receiver to use new fill level */ 2710 rx_stop(info); /* restart receiver to use new fill level */
2646 } 2711 }
2647 2712
@@ -3099,13 +3164,16 @@ static int carrier_raised(struct tty_port *port)
3099 return (info->signals & SerialSignal_DCD) ? 1 : 0; 3164 return (info->signals & SerialSignal_DCD) ? 1 : 0;
3100} 3165}
3101 3166
3102static void raise_dtr_rts(struct tty_port *port) 3167static void dtr_rts(struct tty_port *port, int on)
3103{ 3168{
3104 unsigned long flags; 3169 unsigned long flags;
3105 struct slgt_info *info = container_of(port, struct slgt_info, port); 3170 struct slgt_info *info = container_of(port, struct slgt_info, port);
3106 3171
3107 spin_lock_irqsave(&info->lock,flags); 3172 spin_lock_irqsave(&info->lock,flags);
3108 info->signals |= SerialSignal_RTS + SerialSignal_DTR; 3173 if (on)
3174 info->signals |= SerialSignal_RTS + SerialSignal_DTR;
3175 else
3176 info->signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
3109 set_signals(info); 3177 set_signals(info);
3110 spin_unlock_irqrestore(&info->lock,flags); 3178 spin_unlock_irqrestore(&info->lock,flags);
3111} 3179}
@@ -3419,7 +3487,7 @@ static void add_device(struct slgt_info *info)
3419 3487
3420static const struct tty_port_operations slgt_port_ops = { 3488static const struct tty_port_operations slgt_port_ops = {
3421 .carrier_raised = carrier_raised, 3489 .carrier_raised = carrier_raised,
3422 .raise_dtr_rts = raise_dtr_rts, 3490 .dtr_rts = dtr_rts,
3423}; 3491};
3424 3492
3425/* 3493/*
@@ -3841,15 +3909,27 @@ static void rx_start(struct slgt_info *info)
3841 rdma_reset(info); 3909 rdma_reset(info);
3842 reset_rbufs(info); 3910 reset_rbufs(info);
3843 3911
3844 /* set 1st descriptor address */ 3912 if (info->rx_pio) {
3845 wr_reg32(info, RDDAR, info->rbufs[0].pdesc); 3913 /* rx request when rx FIFO not empty */
3846 3914 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) & ~BIT14));
3847 if (info->params.mode != MGSL_MODE_ASYNC) { 3915 slgt_irq_on(info, IRQ_RXDATA);
3848 /* enable rx DMA and DMA interrupt */ 3916 if (info->params.mode == MGSL_MODE_ASYNC) {
3849 wr_reg32(info, RDCSR, (BIT2 + BIT0)); 3917 /* enable saving of rx status */
3918 wr_reg32(info, RDCSR, BIT6);
3919 }
3850 } else { 3920 } else {
3851 /* enable saving of rx status, rx DMA and DMA interrupt */ 3921 /* rx request when rx FIFO half full */
3852 wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0)); 3922 wr_reg16(info, SCR, (unsigned short)(rd_reg16(info, SCR) | BIT14));
3923 /* set 1st descriptor address */
3924 wr_reg32(info, RDDAR, info->rbufs[0].pdesc);
3925
3926 if (info->params.mode != MGSL_MODE_ASYNC) {
3927 /* enable rx DMA and DMA interrupt */
3928 wr_reg32(info, RDCSR, (BIT2 + BIT0));
3929 } else {
3930 /* enable saving of rx status, rx DMA and DMA interrupt */
3931 wr_reg32(info, RDCSR, (BIT6 + BIT2 + BIT0));
3932 }
3853 } 3933 }
3854 3934
3855 slgt_irq_on(info, IRQ_RXOVER); 3935 slgt_irq_on(info, IRQ_RXOVER);
@@ -3886,50 +3966,19 @@ static void tx_start(struct slgt_info *info)
3886 slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE); 3966 slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE);
3887 /* clear tx idle and underrun status bits */ 3967 /* clear tx idle and underrun status bits */
3888 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); 3968 wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER));
3889 if (info->params.mode == MGSL_MODE_HDLC)
3890 mod_timer(&info->tx_timer, jiffies +
3891 msecs_to_jiffies(5000));
3892 } else { 3969 } else {
3893 slgt_irq_off(info, IRQ_TXDATA); 3970 slgt_irq_off(info, IRQ_TXDATA);
3894 slgt_irq_on(info, IRQ_TXIDLE); 3971 slgt_irq_on(info, IRQ_TXIDLE);
3895 /* clear tx idle status bit */ 3972 /* clear tx idle status bit */
3896 wr_reg16(info, SSR, IRQ_TXIDLE); 3973 wr_reg16(info, SSR, IRQ_TXIDLE);
3897 } 3974 }
3898 tdma_start(info); 3975 /* set 1st descriptor address and start DMA */
3976 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
3977 wr_reg32(info, TDCSR, BIT2 + BIT0);
3899 info->tx_active = true; 3978 info->tx_active = true;
3900 } 3979 }
3901} 3980}
3902 3981
3903/*
3904 * start transmit DMA if inactive and there are unsent buffers
3905 */
3906static void tdma_start(struct slgt_info *info)
3907{
3908 unsigned int i;
3909
3910 if (rd_reg32(info, TDCSR) & BIT0)
3911 return;
3912
3913 /* transmit DMA inactive, check for unsent buffers */
3914 i = info->tbuf_start;
3915 while (!desc_count(info->tbufs[i])) {
3916 if (++i == info->tbuf_count)
3917 i = 0;
3918 if (i == info->tbuf_current)
3919 return;
3920 }
3921 info->tbuf_start = i;
3922
3923 /* there are unsent buffers, start transmit DMA */
3924
3925 /* reset needed if previous error condition */
3926 tdma_reset(info);
3927
3928 /* set 1st descriptor address */
3929 wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc);
3930 wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */
3931}
3932
3933static void tx_stop(struct slgt_info *info) 3982static void tx_stop(struct slgt_info *info)
3934{ 3983{
3935 unsigned short val; 3984 unsigned short val;
@@ -4467,6 +4516,8 @@ static void free_rbufs(struct slgt_info *info, unsigned int i, unsigned int last
4467static void reset_rbufs(struct slgt_info *info) 4516static void reset_rbufs(struct slgt_info *info)
4468{ 4517{
4469 free_rbufs(info, 0, info->rbuf_count - 1); 4518 free_rbufs(info, 0, info->rbuf_count - 1);
4519 info->rbuf_fill_index = 0;
4520 info->rbuf_fill_count = 0;
4470} 4521}
4471 4522
4472/* 4523/*
@@ -4942,8 +4993,7 @@ static void tx_timeout(unsigned long context)
4942 info->icount.txtimeout++; 4993 info->icount.txtimeout++;
4943 } 4994 }
4944 spin_lock_irqsave(&info->lock,flags); 4995 spin_lock_irqsave(&info->lock,flags);
4945 info->tx_active = false; 4996 tx_stop(info);
4946 info->tx_count = 0;
4947 spin_unlock_irqrestore(&info->lock,flags); 4997 spin_unlock_irqrestore(&info->lock,flags);
4948 4998
4949#if SYNCLINK_GENERIC_HDLC 4999#if SYNCLINK_GENERIC_HDLC
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 26de60efe4b2..6f727e3c53ad 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -3277,13 +3277,16 @@ static int carrier_raised(struct tty_port *port)
3277 return (info->serial_signals & SerialSignal_DCD) ? 1 : 0; 3277 return (info->serial_signals & SerialSignal_DCD) ? 1 : 0;
3278} 3278}
3279 3279
3280static void raise_dtr_rts(struct tty_port *port) 3280static void dtr_rts(struct tty_port *port, int on)
3281{ 3281{
3282 SLMP_INFO *info = container_of(port, SLMP_INFO, port); 3282 SLMP_INFO *info = container_of(port, SLMP_INFO, port);
3283 unsigned long flags; 3283 unsigned long flags;
3284 3284
3285 spin_lock_irqsave(&info->lock,flags); 3285 spin_lock_irqsave(&info->lock,flags);
3286 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR; 3286 if (on)
3287 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3288 else
3289 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
3287 set_signals(info); 3290 set_signals(info);
3288 spin_unlock_irqrestore(&info->lock,flags); 3291 spin_unlock_irqrestore(&info->lock,flags);
3289} 3292}
@@ -3746,7 +3749,7 @@ static void add_device(SLMP_INFO *info)
3746 3749
3747static const struct tty_port_operations port_ops = { 3750static const struct tty_port_operations port_ops = {
3748 .carrier_raised = carrier_raised, 3751 .carrier_raised = carrier_raised,
3749 .raise_dtr_rts = raise_dtr_rts, 3752 .dtr_rts = dtr_rts,
3750}; 3753};
3751 3754
3752/* Allocate and initialize a device instance structure 3755/* Allocate and initialize a device instance structure
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index d6a807f4077d..0db35857e4d8 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -25,6 +25,7 @@
25#include <linux/kbd_kern.h> 25#include <linux/kbd_kern.h>
26#include <linux/proc_fs.h> 26#include <linux/proc_fs.h>
27#include <linux/quotaops.h> 27#include <linux/quotaops.h>
28#include <linux/perf_counter.h>
28#include <linux/kernel.h> 29#include <linux/kernel.h>
29#include <linux/module.h> 30#include <linux/module.h>
30#include <linux/suspend.h> 31#include <linux/suspend.h>
@@ -120,20 +121,17 @@ static struct sysrq_key_op sysrq_unraw_op = {
120#define sysrq_unraw_op (*(struct sysrq_key_op *)0) 121#define sysrq_unraw_op (*(struct sysrq_key_op *)0)
121#endif /* CONFIG_VT */ 122#endif /* CONFIG_VT */
122 123
123#ifdef CONFIG_KEXEC 124static void sysrq_handle_crash(int key, struct tty_struct *tty)
124static void sysrq_handle_crashdump(int key, struct tty_struct *tty)
125{ 125{
126 crash_kexec(get_irq_regs()); 126 char *killer = NULL;
127 *killer = 1;
127} 128}
128static struct sysrq_key_op sysrq_crashdump_op = { 129static struct sysrq_key_op sysrq_crashdump_op = {
129 .handler = sysrq_handle_crashdump, 130 .handler = sysrq_handle_crash,
130 .help_msg = "Crashdump", 131 .help_msg = "Crash",
131 .action_msg = "Trigger a crashdump", 132 .action_msg = "Trigger a crash",
132 .enable_mask = SYSRQ_ENABLE_DUMP, 133 .enable_mask = SYSRQ_ENABLE_DUMP,
133}; 134};
134#else
135#define sysrq_crashdump_op (*(struct sysrq_key_op *)0)
136#endif
137 135
138static void sysrq_handle_reboot(int key, struct tty_struct *tty) 136static void sysrq_handle_reboot(int key, struct tty_struct *tty)
139{ 137{
@@ -243,6 +241,7 @@ static void sysrq_handle_showregs(int key, struct tty_struct *tty)
243 struct pt_regs *regs = get_irq_regs(); 241 struct pt_regs *regs = get_irq_regs();
244 if (regs) 242 if (regs)
245 show_regs(regs); 243 show_regs(regs);
244 perf_counter_print_debug();
246} 245}
247static struct sysrq_key_op sysrq_showregs_op = { 246static struct sysrq_key_op sysrq_showregs_op = {
248 .handler = sysrq_handle_showregs, 247 .handler = sysrq_handle_showregs,
diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c
index 55ba6f142883..ac16fbec72d0 100644
--- a/drivers/char/tty_audit.c
+++ b/drivers/char/tty_audit.c
@@ -29,10 +29,7 @@ static struct tty_audit_buf *tty_audit_buf_alloc(int major, int minor,
29 buf = kmalloc(sizeof(*buf), GFP_KERNEL); 29 buf = kmalloc(sizeof(*buf), GFP_KERNEL);
30 if (!buf) 30 if (!buf)
31 goto err; 31 goto err;
32 if (PAGE_SIZE != N_TTY_BUF_SIZE) 32 buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
33 buf->data = kmalloc(N_TTY_BUF_SIZE, GFP_KERNEL);
34 else
35 buf->data = (unsigned char *)__get_free_page(GFP_KERNEL);
36 if (!buf->data) 33 if (!buf->data)
37 goto err_buf; 34 goto err_buf;
38 atomic_set(&buf->count, 1); 35 atomic_set(&buf->count, 1);
@@ -52,10 +49,7 @@ err:
52static void tty_audit_buf_free(struct tty_audit_buf *buf) 49static void tty_audit_buf_free(struct tty_audit_buf *buf)
53{ 50{
54 WARN_ON(buf->valid != 0); 51 WARN_ON(buf->valid != 0);
55 if (PAGE_SIZE != N_TTY_BUF_SIZE) 52 kfree(buf->data);
56 kfree(buf->data);
57 else
58 free_page((unsigned long)buf->data);
59 kfree(buf); 53 kfree(buf);
60} 54}
61 55
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 66b99a2049e3..a3afa0c387cd 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -295,7 +295,7 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line)
295 struct tty_driver *p, *res = NULL; 295 struct tty_driver *p, *res = NULL;
296 int tty_line = 0; 296 int tty_line = 0;
297 int len; 297 int len;
298 char *str; 298 char *str, *stp;
299 299
300 for (str = name; *str; str++) 300 for (str = name; *str; str++)
301 if ((*str >= '0' && *str <= '9') || *str == ',') 301 if ((*str >= '0' && *str <= '9') || *str == ',')
@@ -311,13 +311,14 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line)
311 list_for_each_entry(p, &tty_drivers, tty_drivers) { 311 list_for_each_entry(p, &tty_drivers, tty_drivers) {
312 if (strncmp(name, p->name, len) != 0) 312 if (strncmp(name, p->name, len) != 0)
313 continue; 313 continue;
314 if (*str == ',') 314 stp = str;
315 str++; 315 if (*stp == ',')
316 if (*str == '\0') 316 stp++;
317 str = NULL; 317 if (*stp == '\0')
318 stp = NULL;
318 319
319 if (tty_line >= 0 && tty_line <= p->num && p->ops && 320 if (tty_line >= 0 && tty_line <= p->num && p->ops &&
320 p->ops->poll_init && !p->ops->poll_init(p, tty_line, str)) { 321 p->ops->poll_init && !p->ops->poll_init(p, tty_line, stp)) {
321 res = tty_driver_kref_get(p); 322 res = tty_driver_kref_get(p);
322 *line = tty_line; 323 *line = tty_line;
323 break; 324 break;
@@ -470,43 +471,6 @@ void tty_wakeup(struct tty_struct *tty)
470EXPORT_SYMBOL_GPL(tty_wakeup); 471EXPORT_SYMBOL_GPL(tty_wakeup);
471 472
472/** 473/**
473 * tty_ldisc_flush - flush line discipline queue
474 * @tty: tty
475 *
476 * Flush the line discipline queue (if any) for this tty. If there
477 * is no line discipline active this is a no-op.
478 */
479
480void tty_ldisc_flush(struct tty_struct *tty)
481{
482 struct tty_ldisc *ld = tty_ldisc_ref(tty);
483 if (ld) {
484 if (ld->ops->flush_buffer)
485 ld->ops->flush_buffer(tty);
486 tty_ldisc_deref(ld);
487 }
488 tty_buffer_flush(tty);
489}
490
491EXPORT_SYMBOL_GPL(tty_ldisc_flush);
492
493/**
494 * tty_reset_termios - reset terminal state
495 * @tty: tty to reset
496 *
497 * Restore a terminal to the driver default state
498 */
499
500static void tty_reset_termios(struct tty_struct *tty)
501{
502 mutex_lock(&tty->termios_mutex);
503 *tty->termios = tty->driver->init_termios;
504 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
505 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
506 mutex_unlock(&tty->termios_mutex);
507}
508
509/**
510 * do_tty_hangup - actual handler for hangup events 474 * do_tty_hangup - actual handler for hangup events
511 * @work: tty device 475 * @work: tty device
512 * 476 *
@@ -535,7 +499,6 @@ static void do_tty_hangup(struct work_struct *work)
535 struct file *cons_filp = NULL; 499 struct file *cons_filp = NULL;
536 struct file *filp, *f = NULL; 500 struct file *filp, *f = NULL;
537 struct task_struct *p; 501 struct task_struct *p;
538 struct tty_ldisc *ld;
539 int closecount = 0, n; 502 int closecount = 0, n;
540 unsigned long flags; 503 unsigned long flags;
541 int refs = 0; 504 int refs = 0;
@@ -566,40 +529,8 @@ static void do_tty_hangup(struct work_struct *work)
566 filp->f_op = &hung_up_tty_fops; 529 filp->f_op = &hung_up_tty_fops;
567 } 530 }
568 file_list_unlock(); 531 file_list_unlock();
569 /*
570 * FIXME! What are the locking issues here? This may me overdoing
571 * things... This question is especially important now that we've
572 * removed the irqlock.
573 */
574 ld = tty_ldisc_ref(tty);
575 if (ld != NULL) {
576 /* We may have no line discipline at this point */
577 if (ld->ops->flush_buffer)
578 ld->ops->flush_buffer(tty);
579 tty_driver_flush_buffer(tty);
580 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) &&
581 ld->ops->write_wakeup)
582 ld->ops->write_wakeup(tty);
583 if (ld->ops->hangup)
584 ld->ops->hangup(tty);
585 }
586 /*
587 * FIXME: Once we trust the LDISC code better we can wait here for
588 * ldisc completion and fix the driver call race
589 */
590 wake_up_interruptible_poll(&tty->write_wait, POLLOUT);
591 wake_up_interruptible_poll(&tty->read_wait, POLLIN);
592 /*
593 * Shutdown the current line discipline, and reset it to
594 * N_TTY.
595 */
596 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS)
597 tty_reset_termios(tty);
598 /* Defer ldisc switch */
599 /* tty_deferred_ldisc_switch(N_TTY);
600 532
601 This should get done automatically when the port closes and 533 tty_ldisc_hangup(tty);
602 tty_release is called */
603 534
604 read_lock(&tasklist_lock); 535 read_lock(&tasklist_lock);
605 if (tty->session) { 536 if (tty->session) {
@@ -628,12 +559,15 @@ static void do_tty_hangup(struct work_struct *work)
628 read_unlock(&tasklist_lock); 559 read_unlock(&tasklist_lock);
629 560
630 spin_lock_irqsave(&tty->ctrl_lock, flags); 561 spin_lock_irqsave(&tty->ctrl_lock, flags);
631 tty->flags = 0; 562 clear_bit(TTY_THROTTLED, &tty->flags);
563 clear_bit(TTY_PUSH, &tty->flags);
564 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
632 put_pid(tty->session); 565 put_pid(tty->session);
633 put_pid(tty->pgrp); 566 put_pid(tty->pgrp);
634 tty->session = NULL; 567 tty->session = NULL;
635 tty->pgrp = NULL; 568 tty->pgrp = NULL;
636 tty->ctrl_status = 0; 569 tty->ctrl_status = 0;
570 set_bit(TTY_HUPPED, &tty->flags);
637 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 571 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
638 572
639 /* Account for the p->signal references we killed */ 573 /* Account for the p->signal references we killed */
@@ -659,10 +593,7 @@ static void do_tty_hangup(struct work_struct *work)
659 * can't yet guarantee all that. 593 * can't yet guarantee all that.
660 */ 594 */
661 set_bit(TTY_HUPPED, &tty->flags); 595 set_bit(TTY_HUPPED, &tty->flags);
662 if (ld) { 596 tty_ldisc_enable(tty);
663 tty_ldisc_enable(tty);
664 tty_ldisc_deref(ld);
665 }
666 unlock_kernel(); 597 unlock_kernel();
667 if (f) 598 if (f)
668 fput(f); 599 fput(f);
@@ -1332,7 +1263,9 @@ static int tty_reopen(struct tty_struct *tty)
1332 tty->count++; 1263 tty->count++;
1333 tty->driver = driver; /* N.B. why do this every time?? */ 1264 tty->driver = driver; /* N.B. why do this every time?? */
1334 1265
1266 mutex_lock(&tty->ldisc_mutex);
1335 WARN_ON(!test_bit(TTY_LDISC, &tty->flags)); 1267 WARN_ON(!test_bit(TTY_LDISC, &tty->flags));
1268 mutex_unlock(&tty->ldisc_mutex);
1336 1269
1337 return 0; 1270 return 0;
1338} 1271}
@@ -2480,6 +2413,24 @@ static int tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int
2480 return tty->ops->tiocmset(tty, file, set, clear); 2413 return tty->ops->tiocmset(tty, file, set, clear);
2481} 2414}
2482 2415
2416struct tty_struct *tty_pair_get_tty(struct tty_struct *tty)
2417{
2418 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
2419 tty->driver->subtype == PTY_TYPE_MASTER)
2420 tty = tty->link;
2421 return tty;
2422}
2423EXPORT_SYMBOL(tty_pair_get_tty);
2424
2425struct tty_struct *tty_pair_get_pty(struct tty_struct *tty)
2426{
2427 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
2428 tty->driver->subtype == PTY_TYPE_MASTER)
2429 return tty;
2430 return tty->link;
2431}
2432EXPORT_SYMBOL(tty_pair_get_pty);
2433
2483/* 2434/*
2484 * Split this up, as gcc can choke on it otherwise.. 2435 * Split this up, as gcc can choke on it otherwise..
2485 */ 2436 */
@@ -2495,11 +2446,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2495 if (tty_paranoia_check(tty, inode, "tty_ioctl")) 2446 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
2496 return -EINVAL; 2447 return -EINVAL;
2497 2448
2498 real_tty = tty; 2449 real_tty = tty_pair_get_tty(tty);
2499 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
2500 tty->driver->subtype == PTY_TYPE_MASTER)
2501 real_tty = tty->link;
2502
2503 2450
2504 /* 2451 /*
2505 * Factor out some common prep work 2452 * Factor out some common prep work
@@ -2555,7 +2502,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2555 case TIOCGSID: 2502 case TIOCGSID:
2556 return tiocgsid(tty, real_tty, p); 2503 return tiocgsid(tty, real_tty, p);
2557 case TIOCGETD: 2504 case TIOCGETD:
2558 return put_user(tty->ldisc.ops->num, (int __user *)p); 2505 return put_user(tty->ldisc->ops->num, (int __user *)p);
2559 case TIOCSETD: 2506 case TIOCSETD:
2560 return tiocsetd(tty, p); 2507 return tiocsetd(tty, p);
2561 /* 2508 /*
@@ -2770,6 +2717,7 @@ void initialize_tty_struct(struct tty_struct *tty,
2770 tty->buf.head = tty->buf.tail = NULL; 2717 tty->buf.head = tty->buf.tail = NULL;
2771 tty_buffer_init(tty); 2718 tty_buffer_init(tty);
2772 mutex_init(&tty->termios_mutex); 2719 mutex_init(&tty->termios_mutex);
2720 mutex_init(&tty->ldisc_mutex);
2773 init_waitqueue_head(&tty->write_wait); 2721 init_waitqueue_head(&tty->write_wait);
2774 init_waitqueue_head(&tty->read_wait); 2722 init_waitqueue_head(&tty->read_wait);
2775 INIT_WORK(&tty->hangup_work, do_tty_hangup); 2723 INIT_WORK(&tty->hangup_work, do_tty_hangup);
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index 6f4c7d0a53bf..b24f6c6a1ea3 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -97,14 +97,19 @@ EXPORT_SYMBOL(tty_driver_flush_buffer);
97 * @tty: terminal 97 * @tty: terminal
98 * 98 *
99 * Indicate that a tty should stop transmitting data down the stack. 99 * Indicate that a tty should stop transmitting data down the stack.
100 * Takes the termios mutex to protect against parallel throttle/unthrottle
101 * and also to ensure the driver can consistently reference its own
102 * termios data at this point when implementing software flow control.
100 */ 103 */
101 104
102void tty_throttle(struct tty_struct *tty) 105void tty_throttle(struct tty_struct *tty)
103{ 106{
107 mutex_lock(&tty->termios_mutex);
104 /* check TTY_THROTTLED first so it indicates our state */ 108 /* check TTY_THROTTLED first so it indicates our state */
105 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) && 109 if (!test_and_set_bit(TTY_THROTTLED, &tty->flags) &&
106 tty->ops->throttle) 110 tty->ops->throttle)
107 tty->ops->throttle(tty); 111 tty->ops->throttle(tty);
112 mutex_unlock(&tty->termios_mutex);
108} 113}
109EXPORT_SYMBOL(tty_throttle); 114EXPORT_SYMBOL(tty_throttle);
110 115
@@ -113,13 +118,21 @@ EXPORT_SYMBOL(tty_throttle);
113 * @tty: terminal 118 * @tty: terminal
114 * 119 *
115 * Indicate that a tty may continue transmitting data down the stack. 120 * Indicate that a tty may continue transmitting data down the stack.
121 * Takes the termios mutex to protect against parallel throttle/unthrottle
122 * and also to ensure the driver can consistently reference its own
123 * termios data at this point when implementing software flow control.
124 *
125 * Drivers should however remember that the stack can issue a throttle,
126 * then change flow control method, then unthrottle.
116 */ 127 */
117 128
118void tty_unthrottle(struct tty_struct *tty) 129void tty_unthrottle(struct tty_struct *tty)
119{ 130{
131 mutex_lock(&tty->termios_mutex);
120 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 132 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) &&
121 tty->ops->unthrottle) 133 tty->ops->unthrottle)
122 tty->ops->unthrottle(tty); 134 tty->ops->unthrottle(tty);
135 mutex_unlock(&tty->termios_mutex);
123} 136}
124EXPORT_SYMBOL(tty_unthrottle); 137EXPORT_SYMBOL(tty_unthrottle);
125 138
@@ -613,9 +626,25 @@ static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
613 return 0; 626 return 0;
614} 627}
615 628
629static void copy_termios(struct tty_struct *tty, struct ktermios *kterm)
630{
631 mutex_lock(&tty->termios_mutex);
632 memcpy(kterm, tty->termios, sizeof(struct ktermios));
633 mutex_unlock(&tty->termios_mutex);
634}
635
636static void copy_termios_locked(struct tty_struct *tty, struct ktermios *kterm)
637{
638 mutex_lock(&tty->termios_mutex);
639 memcpy(kterm, tty->termios_locked, sizeof(struct ktermios));
640 mutex_unlock(&tty->termios_mutex);
641}
642
616static int get_termio(struct tty_struct *tty, struct termio __user *termio) 643static int get_termio(struct tty_struct *tty, struct termio __user *termio)
617{ 644{
618 if (kernel_termios_to_user_termio(termio, tty->termios)) 645 struct ktermios kterm;
646 copy_termios(tty, &kterm);
647 if (kernel_termios_to_user_termio(termio, &kterm))
619 return -EFAULT; 648 return -EFAULT;
620 return 0; 649 return 0;
621} 650}
@@ -917,6 +946,7 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
917 struct tty_struct *real_tty; 946 struct tty_struct *real_tty;
918 void __user *p = (void __user *)arg; 947 void __user *p = (void __user *)arg;
919 int ret = 0; 948 int ret = 0;
949 struct ktermios kterm;
920 950
921 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 951 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
922 tty->driver->subtype == PTY_TYPE_MASTER) 952 tty->driver->subtype == PTY_TYPE_MASTER)
@@ -952,23 +982,20 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
952 return set_termios(real_tty, p, TERMIOS_OLD); 982 return set_termios(real_tty, p, TERMIOS_OLD);
953#ifndef TCGETS2 983#ifndef TCGETS2
954 case TCGETS: 984 case TCGETS:
955 mutex_lock(&real_tty->termios_mutex); 985 copy_termios(real_tty, &kterm);
956 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios)) 986 if (kernel_termios_to_user_termios((struct termios __user *)arg, &kterm))
957 ret = -EFAULT; 987 ret = -EFAULT;
958 mutex_unlock(&real_tty->termios_mutex);
959 return ret; 988 return ret;
960#else 989#else
961 case TCGETS: 990 case TCGETS:
962 mutex_lock(&real_tty->termios_mutex); 991 copy_termios(real_tty, &kterm);
963 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios)) 992 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, &kterm))
964 ret = -EFAULT; 993 ret = -EFAULT;
965 mutex_unlock(&real_tty->termios_mutex);
966 return ret; 994 return ret;
967 case TCGETS2: 995 case TCGETS2:
968 mutex_lock(&real_tty->termios_mutex); 996 copy_termios(real_tty, &kterm);
969 if (kernel_termios_to_user_termios((struct termios2 __user *)arg, real_tty->termios)) 997 if (kernel_termios_to_user_termios((struct termios2 __user *)arg, &kterm))
970 ret = -EFAULT; 998 ret = -EFAULT;
971 mutex_unlock(&real_tty->termios_mutex);
972 return ret; 999 return ret;
973 case TCSETSF2: 1000 case TCSETSF2:
974 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT); 1001 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT);
@@ -987,46 +1014,51 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
987 return set_termios(real_tty, p, TERMIOS_TERMIO); 1014 return set_termios(real_tty, p, TERMIOS_TERMIO);
988#ifndef TCGETS2 1015#ifndef TCGETS2
989 case TIOCGLCKTRMIOS: 1016 case TIOCGLCKTRMIOS:
990 mutex_lock(&real_tty->termios_mutex); 1017 copy_termios_locked(real_tty, &kterm);
991 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios_locked)) 1018 if (kernel_termios_to_user_termios((struct termios __user *)arg, &kterm))
992 ret = -EFAULT; 1019 ret = -EFAULT;
993 mutex_unlock(&real_tty->termios_mutex);
994 return ret; 1020 return ret;
995 case TIOCSLCKTRMIOS: 1021 case TIOCSLCKTRMIOS:
996 if (!capable(CAP_SYS_ADMIN)) 1022 if (!capable(CAP_SYS_ADMIN))
997 return -EPERM; 1023 return -EPERM;
998 mutex_lock(&real_tty->termios_mutex); 1024 copy_termios_locked(real_tty, &kterm);
999 if (user_termios_to_kernel_termios(real_tty->termios_locked, 1025 if (user_termios_to_kernel_termios(&kterm,
1000 (struct termios __user *) arg)) 1026 (struct termios __user *) arg))
1001 ret = -EFAULT; 1027 return -EFAULT;
1028 mutex_lock(&real_tty->termios_mutex);
1029 memcpy(real_tty->termios_locked, &kterm, sizeof(struct ktermios));
1002 mutex_unlock(&real_tty->termios_mutex); 1030 mutex_unlock(&real_tty->termios_mutex);
1003 return ret; 1031 return 0;
1004#else 1032#else
1005 case TIOCGLCKTRMIOS: 1033 case TIOCGLCKTRMIOS:
1006 mutex_lock(&real_tty->termios_mutex); 1034 copy_termios_locked(real_tty, &kterm);
1007 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios_locked)) 1035 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, &kterm))
1008 ret = -EFAULT; 1036 ret = -EFAULT;
1009 mutex_unlock(&real_tty->termios_mutex);
1010 return ret; 1037 return ret;
1011 case TIOCSLCKTRMIOS: 1038 case TIOCSLCKTRMIOS:
1012 if (!capable(CAP_SYS_ADMIN)) 1039 if (!capable(CAP_SYS_ADMIN))
1013 ret = -EPERM; 1040 return -EPERM;
1014 mutex_lock(&real_tty->termios_mutex); 1041 copy_termios_locked(real_tty, &kterm);
1015 if (user_termios_to_kernel_termios_1(real_tty->termios_locked, 1042 if (user_termios_to_kernel_termios_1(&kterm,
1016 (struct termios __user *) arg)) 1043 (struct termios __user *) arg))
1017 ret = -EFAULT; 1044 return -EFAULT;
1045 mutex_lock(&real_tty->termios_mutex);
1046 memcpy(real_tty->termios_locked, &kterm, sizeof(struct ktermios));
1018 mutex_unlock(&real_tty->termios_mutex); 1047 mutex_unlock(&real_tty->termios_mutex);
1019 return ret; 1048 return ret;
1020#endif 1049#endif
1021#ifdef TCGETX 1050#ifdef TCGETX
1022 case TCGETX: 1051 case TCGETX: {
1052 struct termiox ktermx;
1023 if (real_tty->termiox == NULL) 1053 if (real_tty->termiox == NULL)
1024 return -EINVAL; 1054 return -EINVAL;
1025 mutex_lock(&real_tty->termios_mutex); 1055 mutex_lock(&real_tty->termios_mutex);
1026 if (copy_to_user(p, real_tty->termiox, sizeof(struct termiox))) 1056 memcpy(&ktermx, real_tty->termiox, sizeof(struct termiox));
1027 ret = -EFAULT;
1028 mutex_unlock(&real_tty->termios_mutex); 1057 mutex_unlock(&real_tty->termios_mutex);
1058 if (copy_to_user(p, &ktermx, sizeof(struct termiox)))
1059 ret = -EFAULT;
1029 return ret; 1060 return ret;
1061 }
1030 case TCSETX: 1062 case TCSETX:
1031 return set_termiox(real_tty, p, 0); 1063 return set_termiox(real_tty, p, 0);
1032 case TCSETXW: 1064 case TCSETXW:
@@ -1035,10 +1067,9 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
1035 return set_termiox(real_tty, p, TERMIOS_FLUSH); 1067 return set_termiox(real_tty, p, TERMIOS_FLUSH);
1036#endif 1068#endif
1037 case TIOCGSOFTCAR: 1069 case TIOCGSOFTCAR:
1038 mutex_lock(&real_tty->termios_mutex); 1070 copy_termios(real_tty, &kterm);
1039 ret = put_user(C_CLOCAL(real_tty) ? 1 : 0, 1071 ret = put_user((kterm.c_cflag & CLOCAL) ? 1 : 0,
1040 (int __user *)arg); 1072 (int __user *)arg);
1041 mutex_unlock(&real_tty->termios_mutex);
1042 return ret; 1073 return ret;
1043 case TIOCSSOFTCAR: 1074 case TIOCSSOFTCAR:
1044 if (get_user(arg, (unsigned int __user *) arg)) 1075 if (get_user(arg, (unsigned int __user *) arg))
diff --git a/drivers/char/tty_ldisc.c b/drivers/char/tty_ldisc.c
index f78f5b0127a8..a19e935847b0 100644
--- a/drivers/char/tty_ldisc.c
+++ b/drivers/char/tty_ldisc.c
@@ -115,19 +115,22 @@ EXPORT_SYMBOL(tty_unregister_ldisc);
115/** 115/**
116 * tty_ldisc_try_get - try and reference an ldisc 116 * tty_ldisc_try_get - try and reference an ldisc
117 * @disc: ldisc number 117 * @disc: ldisc number
118 * @ld: tty ldisc structure to complete
119 * 118 *
120 * Attempt to open and lock a line discipline into place. Return 119 * Attempt to open and lock a line discipline into place. Return
121 * the line discipline refcounted and assigned in ld. On an error 120 * the line discipline refcounted or an error.
122 * report the error code back
123 */ 121 */
124 122
125static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld) 123static struct tty_ldisc *tty_ldisc_try_get(int disc)
126{ 124{
127 unsigned long flags; 125 unsigned long flags;
126 struct tty_ldisc *ld;
128 struct tty_ldisc_ops *ldops; 127 struct tty_ldisc_ops *ldops;
129 int err = -EINVAL; 128 int err = -EINVAL;
130 129
130 ld = kmalloc(sizeof(struct tty_ldisc), GFP_KERNEL);
131 if (ld == NULL)
132 return ERR_PTR(-ENOMEM);
133
131 spin_lock_irqsave(&tty_ldisc_lock, flags); 134 spin_lock_irqsave(&tty_ldisc_lock, flags);
132 ld->ops = NULL; 135 ld->ops = NULL;
133 ldops = tty_ldiscs[disc]; 136 ldops = tty_ldiscs[disc];
@@ -140,17 +143,21 @@ static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld)
140 /* lock it */ 143 /* lock it */
141 ldops->refcount++; 144 ldops->refcount++;
142 ld->ops = ldops; 145 ld->ops = ldops;
146 ld->refcount = 0;
143 err = 0; 147 err = 0;
144 } 148 }
145 } 149 }
146 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 150 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
147 return err; 151 if (err) {
152 kfree(ld);
153 return ERR_PTR(err);
154 }
155 return ld;
148} 156}
149 157
150/** 158/**
151 * tty_ldisc_get - take a reference to an ldisc 159 * tty_ldisc_get - take a reference to an ldisc
152 * @disc: ldisc number 160 * @disc: ldisc number
153 * @ld: tty line discipline structure to use
154 * 161 *
155 * Takes a reference to a line discipline. Deals with refcounts and 162 * Takes a reference to a line discipline. Deals with refcounts and
156 * module locking counts. Returns NULL if the discipline is not available. 163 * module locking counts. Returns NULL if the discipline is not available.
@@ -161,52 +168,55 @@ static int tty_ldisc_try_get(int disc, struct tty_ldisc *ld)
161 * takes tty_ldisc_lock to guard against ldisc races 168 * takes tty_ldisc_lock to guard against ldisc races
162 */ 169 */
163 170
164static int tty_ldisc_get(int disc, struct tty_ldisc *ld) 171static struct tty_ldisc *tty_ldisc_get(int disc)
165{ 172{
166 int err; 173 struct tty_ldisc *ld;
167 174
168 if (disc < N_TTY || disc >= NR_LDISCS) 175 if (disc < N_TTY || disc >= NR_LDISCS)
169 return -EINVAL; 176 return ERR_PTR(-EINVAL);
170 err = tty_ldisc_try_get(disc, ld); 177 ld = tty_ldisc_try_get(disc);
171 if (err < 0) { 178 if (IS_ERR(ld)) {
172 request_module("tty-ldisc-%d", disc); 179 request_module("tty-ldisc-%d", disc);
173 err = tty_ldisc_try_get(disc, ld); 180 ld = tty_ldisc_try_get(disc);
174 } 181 }
175 return err; 182 return ld;
176} 183}
177 184
178/** 185/**
179 * tty_ldisc_put - drop ldisc reference 186 * tty_ldisc_put - drop ldisc reference
180 * @disc: ldisc number 187 * @ld: ldisc
181 * 188 *
182 * Drop a reference to a line discipline. Manage refcounts and 189 * Drop a reference to a line discipline. Manage refcounts and
183 * module usage counts 190 * module usage counts. Free the ldisc once the recount hits zero.
184 * 191 *
185 * Locking: 192 * Locking:
186 * takes tty_ldisc_lock to guard against ldisc races 193 * takes tty_ldisc_lock to guard against ldisc races
187 */ 194 */
188 195
189static void tty_ldisc_put(struct tty_ldisc_ops *ld) 196static void tty_ldisc_put(struct tty_ldisc *ld)
190{ 197{
191 unsigned long flags; 198 unsigned long flags;
192 int disc = ld->num; 199 int disc = ld->ops->num;
200 struct tty_ldisc_ops *ldo;
193 201
194 BUG_ON(disc < N_TTY || disc >= NR_LDISCS); 202 BUG_ON(disc < N_TTY || disc >= NR_LDISCS);
195 203
196 spin_lock_irqsave(&tty_ldisc_lock, flags); 204 spin_lock_irqsave(&tty_ldisc_lock, flags);
197 ld = tty_ldiscs[disc]; 205 ldo = tty_ldiscs[disc];
198 BUG_ON(ld->refcount == 0); 206 BUG_ON(ldo->refcount == 0);
199 ld->refcount--; 207 ldo->refcount--;
200 module_put(ld->owner); 208 module_put(ldo->owner);
201 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 209 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
210 WARN_ON(ld->refcount);
211 kfree(ld);
202} 212}
203 213
204static void * tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos) 214static void *tty_ldiscs_seq_start(struct seq_file *m, loff_t *pos)
205{ 215{
206 return (*pos < NR_LDISCS) ? pos : NULL; 216 return (*pos < NR_LDISCS) ? pos : NULL;
207} 217}
208 218
209static void * tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos) 219static void *tty_ldiscs_seq_next(struct seq_file *m, void *v, loff_t *pos)
210{ 220{
211 (*pos)++; 221 (*pos)++;
212 return (*pos < NR_LDISCS) ? pos : NULL; 222 return (*pos < NR_LDISCS) ? pos : NULL;
@@ -219,12 +229,13 @@ static void tty_ldiscs_seq_stop(struct seq_file *m, void *v)
219static int tty_ldiscs_seq_show(struct seq_file *m, void *v) 229static int tty_ldiscs_seq_show(struct seq_file *m, void *v)
220{ 230{
221 int i = *(loff_t *)v; 231 int i = *(loff_t *)v;
222 struct tty_ldisc ld; 232 struct tty_ldisc *ld;
223 233
224 if (tty_ldisc_get(i, &ld) < 0) 234 ld = tty_ldisc_try_get(i);
235 if (IS_ERR(ld))
225 return 0; 236 return 0;
226 seq_printf(m, "%-10s %2d\n", ld.ops->name ? ld.ops->name : "???", i); 237 seq_printf(m, "%-10s %2d\n", ld->ops->name ? ld->ops->name : "???", i);
227 tty_ldisc_put(ld.ops); 238 tty_ldisc_put(ld);
228 return 0; 239 return 0;
229} 240}
230 241
@@ -254,7 +265,7 @@ const struct file_operations tty_ldiscs_proc_fops = {
254 * @ld: line discipline 265 * @ld: line discipline
255 * 266 *
256 * Install an instance of a line discipline into a tty structure. The 267 * Install an instance of a line discipline into a tty structure. The
257 * ldisc must have a reference count above zero to ensure it remains/ 268 * ldisc must have a reference count above zero to ensure it remains.
258 * The tty instance refcount starts at zero. 269 * The tty instance refcount starts at zero.
259 * 270 *
260 * Locking: 271 * Locking:
@@ -263,8 +274,7 @@ const struct file_operations tty_ldiscs_proc_fops = {
263 274
264static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld) 275static void tty_ldisc_assign(struct tty_struct *tty, struct tty_ldisc *ld)
265{ 276{
266 ld->refcount = 0; 277 tty->ldisc = ld;
267 tty->ldisc = *ld;
268} 278}
269 279
270/** 280/**
@@ -286,7 +296,7 @@ static int tty_ldisc_try(struct tty_struct *tty)
286 int ret = 0; 296 int ret = 0;
287 297
288 spin_lock_irqsave(&tty_ldisc_lock, flags); 298 spin_lock_irqsave(&tty_ldisc_lock, flags);
289 ld = &tty->ldisc; 299 ld = tty->ldisc;
290 if (test_bit(TTY_LDISC, &tty->flags)) { 300 if (test_bit(TTY_LDISC, &tty->flags)) {
291 ld->refcount++; 301 ld->refcount++;
292 ret = 1; 302 ret = 1;
@@ -315,10 +325,9 @@ struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *tty)
315{ 325{
316 /* wait_event is a macro */ 326 /* wait_event is a macro */
317 wait_event(tty_ldisc_wait, tty_ldisc_try(tty)); 327 wait_event(tty_ldisc_wait, tty_ldisc_try(tty));
318 WARN_ON(tty->ldisc.refcount == 0); 328 WARN_ON(tty->ldisc->refcount == 0);
319 return &tty->ldisc; 329 return tty->ldisc;
320} 330}
321
322EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait); 331EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
323 332
324/** 333/**
@@ -335,10 +344,9 @@ EXPORT_SYMBOL_GPL(tty_ldisc_ref_wait);
335struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty) 344struct tty_ldisc *tty_ldisc_ref(struct tty_struct *tty)
336{ 345{
337 if (tty_ldisc_try(tty)) 346 if (tty_ldisc_try(tty))
338 return &tty->ldisc; 347 return tty->ldisc;
339 return NULL; 348 return NULL;
340} 349}
341
342EXPORT_SYMBOL_GPL(tty_ldisc_ref); 350EXPORT_SYMBOL_GPL(tty_ldisc_ref);
343 351
344/** 352/**
@@ -366,7 +374,6 @@ void tty_ldisc_deref(struct tty_ldisc *ld)
366 wake_up(&tty_ldisc_wait); 374 wake_up(&tty_ldisc_wait);
367 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 375 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
368} 376}
369
370EXPORT_SYMBOL_GPL(tty_ldisc_deref); 377EXPORT_SYMBOL_GPL(tty_ldisc_deref);
371 378
372/** 379/**
@@ -389,6 +396,26 @@ void tty_ldisc_enable(struct tty_struct *tty)
389} 396}
390 397
391/** 398/**
399 * tty_ldisc_flush - flush line discipline queue
400 * @tty: tty
401 *
402 * Flush the line discipline queue (if any) for this tty. If there
403 * is no line discipline active this is a no-op.
404 */
405
406void tty_ldisc_flush(struct tty_struct *tty)
407{
408 struct tty_ldisc *ld = tty_ldisc_ref(tty);
409 if (ld) {
410 if (ld->ops->flush_buffer)
411 ld->ops->flush_buffer(tty);
412 tty_ldisc_deref(ld);
413 }
414 tty_buffer_flush(tty);
415}
416EXPORT_SYMBOL_GPL(tty_ldisc_flush);
417
418/**
392 * tty_set_termios_ldisc - set ldisc field 419 * tty_set_termios_ldisc - set ldisc field
393 * @tty: tty structure 420 * @tty: tty structure
394 * @num: line discipline number 421 * @num: line discipline number
@@ -407,6 +434,39 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
407 mutex_unlock(&tty->termios_mutex); 434 mutex_unlock(&tty->termios_mutex);
408} 435}
409 436
437/**
438 * tty_ldisc_open - open a line discipline
439 * @tty: tty we are opening the ldisc on
440 * @ld: discipline to open
441 *
442 * A helper opening method. Also a convenient debugging and check
443 * point.
444 */
445
446static int tty_ldisc_open(struct tty_struct *tty, struct tty_ldisc *ld)
447{
448 WARN_ON(test_and_set_bit(TTY_LDISC_OPEN, &tty->flags));
449 if (ld->ops->open)
450 return ld->ops->open(tty);
451 return 0;
452}
453
454/**
455 * tty_ldisc_close - close a line discipline
456 * @tty: tty we are opening the ldisc on
457 * @ld: discipline to close
458 *
459 * A helper close method. Also a convenient debugging and check
460 * point.
461 */
462
463static void tty_ldisc_close(struct tty_struct *tty, struct tty_ldisc *ld)
464{
465 WARN_ON(!test_bit(TTY_LDISC_OPEN, &tty->flags));
466 clear_bit(TTY_LDISC_OPEN, &tty->flags);
467 if (ld->ops->close)
468 ld->ops->close(tty);
469}
410 470
411/** 471/**
412 * tty_ldisc_restore - helper for tty ldisc change 472 * tty_ldisc_restore - helper for tty ldisc change
@@ -420,66 +480,136 @@ static void tty_set_termios_ldisc(struct tty_struct *tty, int num)
420static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old) 480static void tty_ldisc_restore(struct tty_struct *tty, struct tty_ldisc *old)
421{ 481{
422 char buf[64]; 482 char buf[64];
423 struct tty_ldisc new_ldisc; 483 struct tty_ldisc *new_ldisc;
484 int r;
424 485
425 /* There is an outstanding reference here so this is safe */ 486 /* There is an outstanding reference here so this is safe */
426 tty_ldisc_get(old->ops->num, old); 487 old = tty_ldisc_get(old->ops->num);
488 WARN_ON(IS_ERR(old));
427 tty_ldisc_assign(tty, old); 489 tty_ldisc_assign(tty, old);
428 tty_set_termios_ldisc(tty, old->ops->num); 490 tty_set_termios_ldisc(tty, old->ops->num);
429 if (old->ops->open && (old->ops->open(tty) < 0)) { 491 if (tty_ldisc_open(tty, old) < 0) {
430 tty_ldisc_put(old->ops); 492 tty_ldisc_put(old);
431 /* This driver is always present */ 493 /* This driver is always present */
432 if (tty_ldisc_get(N_TTY, &new_ldisc) < 0) 494 new_ldisc = tty_ldisc_get(N_TTY);
495 if (IS_ERR(new_ldisc))
433 panic("n_tty: get"); 496 panic("n_tty: get");
434 tty_ldisc_assign(tty, &new_ldisc); 497 tty_ldisc_assign(tty, new_ldisc);
435 tty_set_termios_ldisc(tty, N_TTY); 498 tty_set_termios_ldisc(tty, N_TTY);
436 if (new_ldisc.ops->open) { 499 r = tty_ldisc_open(tty, new_ldisc);
437 int r = new_ldisc.ops->open(tty); 500 if (r < 0)
438 if (r < 0) 501 panic("Couldn't open N_TTY ldisc for "
439 panic("Couldn't open N_TTY ldisc for " 502 "%s --- error %d.",
440 "%s --- error %d.", 503 tty_name(tty, buf), r);
441 tty_name(tty, buf), r);
442 }
443 } 504 }
444} 505}
445 506
446/** 507/**
508 * tty_ldisc_halt - shut down the line discipline
509 * @tty: tty device
510 *
511 * Shut down the line discipline and work queue for this tty device.
512 * The TTY_LDISC flag being cleared ensures no further references can
513 * be obtained while the delayed work queue halt ensures that no more
514 * data is fed to the ldisc.
515 *
516 * In order to wait for any existing references to complete see
517 * tty_ldisc_wait_idle.
518 */
519
520static int tty_ldisc_halt(struct tty_struct *tty)
521{
522 clear_bit(TTY_LDISC, &tty->flags);
523 return cancel_delayed_work(&tty->buf.work);
524}
525
526/**
527 * tty_ldisc_wait_idle - wait for the ldisc to become idle
528 * @tty: tty to wait for
529 *
530 * Wait for the line discipline to become idle. The discipline must
531 * have been halted for this to guarantee it remains idle.
532 *
533 * tty_ldisc_lock protects the ref counts currently.
534 */
535
536static int tty_ldisc_wait_idle(struct tty_struct *tty)
537{
538 unsigned long flags;
539 spin_lock_irqsave(&tty_ldisc_lock, flags);
540 while (tty->ldisc->refcount) {
541 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
542 if (wait_event_timeout(tty_ldisc_wait,
543 tty->ldisc->refcount == 0, 5 * HZ) == 0)
544 return -EBUSY;
545 spin_lock_irqsave(&tty_ldisc_lock, flags);
546 }
547 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
548 return 0;
549}
550
551/**
447 * tty_set_ldisc - set line discipline 552 * tty_set_ldisc - set line discipline
448 * @tty: the terminal to set 553 * @tty: the terminal to set
449 * @ldisc: the line discipline 554 * @ldisc: the line discipline
450 * 555 *
451 * Set the discipline of a tty line. Must be called from a process 556 * Set the discipline of a tty line. Must be called from a process
452 * context. 557 * context. The ldisc change logic has to protect itself against any
558 * overlapping ldisc change (including on the other end of pty pairs),
559 * the close of one side of a tty/pty pair, and eventually hangup.
453 * 560 *
454 * Locking: takes tty_ldisc_lock. 561 * Locking: takes tty_ldisc_lock, termios_mutex
455 * called functions take termios_mutex
456 */ 562 */
457 563
458int tty_set_ldisc(struct tty_struct *tty, int ldisc) 564int tty_set_ldisc(struct tty_struct *tty, int ldisc)
459{ 565{
460 int retval; 566 int retval;
461 struct tty_ldisc o_ldisc, new_ldisc; 567 struct tty_ldisc *o_ldisc, *new_ldisc;
462 int work; 568 int work, o_work = 0;
463 unsigned long flags;
464 struct tty_struct *o_tty; 569 struct tty_struct *o_tty;
465 570
466restart: 571 new_ldisc = tty_ldisc_get(ldisc);
467 /* This is a bit ugly for now but means we can break the 'ldisc 572 if (IS_ERR(new_ldisc))
468 is part of the tty struct' assumption later */ 573 return PTR_ERR(new_ldisc);
469 retval = tty_ldisc_get(ldisc, &new_ldisc); 574
470 if (retval) 575 /*
471 return retval; 576 * We need to look at the tty locking here for pty/tty pairs
577 * when both sides try to change in parallel.
578 */
579
580 o_tty = tty->link; /* o_tty is the pty side or NULL */
581
582
583 /*
584 * Check the no-op case
585 */
586
587 if (tty->ldisc->ops->num == ldisc) {
588 tty_ldisc_put(new_ldisc);
589 return 0;
590 }
472 591
473 /* 592 /*
474 * Problem: What do we do if this blocks ? 593 * Problem: What do we do if this blocks ?
594 * We could deadlock here
475 */ 595 */
476 596
477 tty_wait_until_sent(tty, 0); 597 tty_wait_until_sent(tty, 0);
478 598
479 if (tty->ldisc.ops->num == ldisc) { 599 mutex_lock(&tty->ldisc_mutex);
480 tty_ldisc_put(new_ldisc.ops); 600
481 return 0; 601 /*
602 * We could be midstream of another ldisc change which has
603 * dropped the lock during processing. If so we need to wait.
604 */
605
606 while (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
607 mutex_unlock(&tty->ldisc_mutex);
608 wait_event(tty_ldisc_wait,
609 test_bit(TTY_LDISC_CHANGING, &tty->flags) == 0);
610 mutex_lock(&tty->ldisc_mutex);
482 } 611 }
612 set_bit(TTY_LDISC_CHANGING, &tty->flags);
483 613
484 /* 614 /*
485 * No more input please, we are switching. The new ldisc 615 * No more input please, we are switching. The new ldisc
@@ -489,8 +619,6 @@ restart:
489 tty->receive_room = 0; 619 tty->receive_room = 0;
490 620
491 o_ldisc = tty->ldisc; 621 o_ldisc = tty->ldisc;
492 o_tty = tty->link;
493
494 /* 622 /*
495 * Make sure we don't change while someone holds a 623 * Make sure we don't change while someone holds a
496 * reference to the line discipline. The TTY_LDISC bit 624 * reference to the line discipline. The TTY_LDISC bit
@@ -501,108 +629,183 @@ restart:
501 * with a userspace app continually trying to use the tty in 629 * with a userspace app continually trying to use the tty in
502 * parallel to the change and re-referencing the tty. 630 * parallel to the change and re-referencing the tty.
503 */ 631 */
504 clear_bit(TTY_LDISC, &tty->flags);
505 if (o_tty)
506 clear_bit(TTY_LDISC, &o_tty->flags);
507 632
508 spin_lock_irqsave(&tty_ldisc_lock, flags); 633 work = tty_ldisc_halt(tty);
509 if (tty->ldisc.refcount || (o_tty && o_tty->ldisc.refcount)) {
510 if (tty->ldisc.refcount) {
511 /* Free the new ldisc we grabbed. Must drop the lock
512 first. */
513 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
514 tty_ldisc_put(o_ldisc.ops);
515 /*
516 * There are several reasons we may be busy, including
517 * random momentary I/O traffic. We must therefore
518 * retry. We could distinguish between blocking ops
519 * and retries if we made tty_ldisc_wait() smarter.
520 * That is up for discussion.
521 */
522 if (wait_event_interruptible(tty_ldisc_wait, tty->ldisc.refcount == 0) < 0)
523 return -ERESTARTSYS;
524 goto restart;
525 }
526 if (o_tty && o_tty->ldisc.refcount) {
527 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
528 tty_ldisc_put(o_tty->ldisc.ops);
529 if (wait_event_interruptible(tty_ldisc_wait, o_tty->ldisc.refcount == 0) < 0)
530 return -ERESTARTSYS;
531 goto restart;
532 }
533 }
534 /*
535 * If the TTY_LDISC bit is set, then we are racing against
536 * another ldisc change
537 */
538 if (test_bit(TTY_LDISC_CHANGING, &tty->flags)) {
539 struct tty_ldisc *ld;
540 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
541 tty_ldisc_put(new_ldisc.ops);
542 ld = tty_ldisc_ref_wait(tty);
543 tty_ldisc_deref(ld);
544 goto restart;
545 }
546 /*
547 * This flag is used to avoid two parallel ldisc changes. Once
548 * open and close are fine grained locked this may work better
549 * as a mutex shared with the open/close/hup paths
550 */
551 set_bit(TTY_LDISC_CHANGING, &tty->flags);
552 if (o_tty) 634 if (o_tty)
553 set_bit(TTY_LDISC_CHANGING, &o_tty->flags); 635 o_work = tty_ldisc_halt(o_tty);
554 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
555
556 /*
557 * From this point on we know nobody has an ldisc
558 * usage reference, nor can they obtain one until
559 * we say so later on.
560 */
561 636
562 work = cancel_delayed_work(&tty->buf.work);
563 /* 637 /*
564 * Wait for ->hangup_work and ->buf.work handlers to terminate 638 * Wait for ->hangup_work and ->buf.work handlers to terminate.
565 * MUST NOT hold locks here. 639 * We must drop the mutex here in case a hangup is also in process.
566 */ 640 */
641
642 mutex_unlock(&tty->ldisc_mutex);
643
567 flush_scheduled_work(); 644 flush_scheduled_work();
645
646 /* Let any existing reference holders finish */
647 retval = tty_ldisc_wait_idle(tty);
648 if (retval < 0) {
649 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
650 tty_ldisc_put(new_ldisc);
651 return retval;
652 }
653
654 mutex_lock(&tty->ldisc_mutex);
655 if (test_bit(TTY_HUPPED, &tty->flags)) {
656 /* We were raced by the hangup method. It will have stomped
657 the ldisc data and closed the ldisc down */
658 clear_bit(TTY_LDISC_CHANGING, &tty->flags);
659 mutex_unlock(&tty->ldisc_mutex);
660 tty_ldisc_put(new_ldisc);
661 return -EIO;
662 }
663
568 /* Shutdown the current discipline. */ 664 /* Shutdown the current discipline. */
569 if (o_ldisc.ops->close) 665 tty_ldisc_close(tty, o_ldisc);
570 (o_ldisc.ops->close)(tty);
571 666
572 /* Now set up the new line discipline. */ 667 /* Now set up the new line discipline. */
573 tty_ldisc_assign(tty, &new_ldisc); 668 tty_ldisc_assign(tty, new_ldisc);
574 tty_set_termios_ldisc(tty, ldisc); 669 tty_set_termios_ldisc(tty, ldisc);
575 if (new_ldisc.ops->open) 670
576 retval = (new_ldisc.ops->open)(tty); 671 retval = tty_ldisc_open(tty, new_ldisc);
577 if (retval < 0) { 672 if (retval < 0) {
578 tty_ldisc_put(new_ldisc.ops); 673 /* Back to the old one or N_TTY if we can't */
579 tty_ldisc_restore(tty, &o_ldisc); 674 tty_ldisc_put(new_ldisc);
675 tty_ldisc_restore(tty, o_ldisc);
580 } 676 }
677
581 /* At this point we hold a reference to the new ldisc and a 678 /* At this point we hold a reference to the new ldisc and a
582 a reference to the old ldisc. If we ended up flipping back 679 a reference to the old ldisc. If we ended up flipping back
583 to the existing ldisc we have two references to it */ 680 to the existing ldisc we have two references to it */
584 681
585 if (tty->ldisc.ops->num != o_ldisc.ops->num && tty->ops->set_ldisc) 682 if (tty->ldisc->ops->num != o_ldisc->ops->num && tty->ops->set_ldisc)
586 tty->ops->set_ldisc(tty); 683 tty->ops->set_ldisc(tty);
587 684
588 tty_ldisc_put(o_ldisc.ops); 685 tty_ldisc_put(o_ldisc);
589 686
590 /* 687 /*
591 * Allow ldisc referencing to occur as soon as the driver 688 * Allow ldisc referencing to occur again
592 * ldisc callback completes.
593 */ 689 */
594 690
595 tty_ldisc_enable(tty); 691 tty_ldisc_enable(tty);
596 if (o_tty) 692 if (o_tty)
597 tty_ldisc_enable(o_tty); 693 tty_ldisc_enable(o_tty);
598 694
599 /* Restart it in case no characters kick it off. Safe if 695 /* Restart the work queue in case no characters kick it off. Safe if
600 already running */ 696 already running */
601 if (work) 697 if (work)
602 schedule_delayed_work(&tty->buf.work, 1); 698 schedule_delayed_work(&tty->buf.work, 1);
699 if (o_work)
700 schedule_delayed_work(&o_tty->buf.work, 1);
701 mutex_unlock(&tty->ldisc_mutex);
603 return retval; 702 return retval;
604} 703}
605 704
705/**
706 * tty_reset_termios - reset terminal state
707 * @tty: tty to reset
708 *
709 * Restore a terminal to the driver default state.
710 */
711
712static void tty_reset_termios(struct tty_struct *tty)
713{
714 mutex_lock(&tty->termios_mutex);
715 *tty->termios = tty->driver->init_termios;
716 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
717 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
718 mutex_unlock(&tty->termios_mutex);
719}
720
721
722/**
723 * tty_ldisc_reinit - reinitialise the tty ldisc
724 * @tty: tty to reinit
725 *
726 * Switch the tty back to N_TTY line discipline and leave the
727 * ldisc state closed
728 */
729
730static void tty_ldisc_reinit(struct tty_struct *tty)
731{
732 struct tty_ldisc *ld;
733
734 tty_ldisc_close(tty, tty->ldisc);
735 tty_ldisc_put(tty->ldisc);
736 tty->ldisc = NULL;
737 /*
738 * Switch the line discipline back
739 */
740 ld = tty_ldisc_get(N_TTY);
741 BUG_ON(IS_ERR(ld));
742 tty_ldisc_assign(tty, ld);
743 tty_set_termios_ldisc(tty, N_TTY);
744}
745
746/**
747 * tty_ldisc_hangup - hangup ldisc reset
748 * @tty: tty being hung up
749 *
750 * Some tty devices reset their termios when they receive a hangup
751 * event. In that situation we must also switch back to N_TTY properly
752 * before we reset the termios data.
753 *
754 * Locking: We can take the ldisc mutex as the rest of the code is
755 * careful to allow for this.
756 *
757 * In the pty pair case this occurs in the close() path of the
758 * tty itself so we must be careful about locking rules.
759 */
760
761void tty_ldisc_hangup(struct tty_struct *tty)
762{
763 struct tty_ldisc *ld;
764
765 /*
766 * FIXME! What are the locking issues here? This may me overdoing
767 * things... This question is especially important now that we've
768 * removed the irqlock.
769 */
770 ld = tty_ldisc_ref(tty);
771 if (ld != NULL) {
772 /* We may have no line discipline at this point */
773 if (ld->ops->flush_buffer)
774 ld->ops->flush_buffer(tty);
775 tty_driver_flush_buffer(tty);
776 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) &&
777 ld->ops->write_wakeup)
778 ld->ops->write_wakeup(tty);
779 if (ld->ops->hangup)
780 ld->ops->hangup(tty);
781 tty_ldisc_deref(ld);
782 }
783 /*
784 * FIXME: Once we trust the LDISC code better we can wait here for
785 * ldisc completion and fix the driver call race
786 */
787 wake_up_interruptible_poll(&tty->write_wait, POLLOUT);
788 wake_up_interruptible_poll(&tty->read_wait, POLLIN);
789 /*
790 * Shutdown the current line discipline, and reset it to
791 * N_TTY.
792 */
793 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) {
794 /* Avoid racing set_ldisc */
795 mutex_lock(&tty->ldisc_mutex);
796 /* Switch back to N_TTY */
797 tty_ldisc_halt(tty);
798 tty_ldisc_wait_idle(tty);
799 tty_ldisc_reinit(tty);
800 /* At this point we have a closed ldisc and we want to
801 reopen it. We could defer this to the next open but
802 it means auditing a lot of other paths so this is a FIXME */
803 WARN_ON(tty_ldisc_open(tty, tty->ldisc));
804 tty_ldisc_enable(tty);
805 mutex_unlock(&tty->ldisc_mutex);
806 tty_reset_termios(tty);
807 }
808}
606 809
607/** 810/**
608 * tty_ldisc_setup - open line discipline 811 * tty_ldisc_setup - open line discipline
@@ -610,24 +813,23 @@ restart:
610 * @o_tty: pair tty for pty/tty pairs 813 * @o_tty: pair tty for pty/tty pairs
611 * 814 *
612 * Called during the initial open of a tty/pty pair in order to set up the 815 * Called during the initial open of a tty/pty pair in order to set up the
613 * line discplines and bind them to the tty. 816 * line disciplines and bind them to the tty. This has no locking issues
817 * as the device isn't yet active.
614 */ 818 */
615 819
616int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty) 820int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
617{ 821{
618 struct tty_ldisc *ld = &tty->ldisc; 822 struct tty_ldisc *ld = tty->ldisc;
619 int retval; 823 int retval;
620 824
621 if (ld->ops->open) { 825 retval = tty_ldisc_open(tty, ld);
622 retval = (ld->ops->open)(tty); 826 if (retval)
623 if (retval) 827 return retval;
624 return retval; 828
625 } 829 if (o_tty) {
626 if (o_tty && o_tty->ldisc.ops->open) { 830 retval = tty_ldisc_open(o_tty, o_tty->ldisc);
627 retval = (o_tty->ldisc.ops->open)(o_tty);
628 if (retval) { 831 if (retval) {
629 if (ld->ops->close) 832 tty_ldisc_close(tty, ld);
630 (ld->ops->close)(tty);
631 return retval; 833 return retval;
632 } 834 }
633 tty_ldisc_enable(o_tty); 835 tty_ldisc_enable(o_tty);
@@ -635,32 +837,25 @@ int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty)
635 tty_ldisc_enable(tty); 837 tty_ldisc_enable(tty);
636 return 0; 838 return 0;
637} 839}
638
639/** 840/**
640 * tty_ldisc_release - release line discipline 841 * tty_ldisc_release - release line discipline
641 * @tty: tty being shut down 842 * @tty: tty being shut down
642 * @o_tty: pair tty for pty/tty pairs 843 * @o_tty: pair tty for pty/tty pairs
643 * 844 *
644 * Called during the final close of a tty/pty pair in order to shut down the 845 * Called during the final close of a tty/pty pair in order to shut down
645 * line discpline layer. 846 * the line discpline layer. On exit the ldisc assigned is N_TTY and the
847 * ldisc has not been opened.
646 */ 848 */
647 849
648void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty) 850void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
649{ 851{
650 unsigned long flags;
651 struct tty_ldisc ld;
652 /* 852 /*
653 * Prevent flush_to_ldisc() from rescheduling the work for later. Then 853 * Prevent flush_to_ldisc() from rescheduling the work for later. Then
654 * kill any delayed work. As this is the final close it does not 854 * kill any delayed work. As this is the final close it does not
655 * race with the set_ldisc code path. 855 * race with the set_ldisc code path.
656 */ 856 */
657 clear_bit(TTY_LDISC, &tty->flags);
658 cancel_delayed_work(&tty->buf.work);
659
660 /*
661 * Wait for ->hangup_work and ->buf.work handlers to terminate
662 */
663 857
858 tty_ldisc_halt(tty);
664 flush_scheduled_work(); 859 flush_scheduled_work();
665 860
666 /* 861 /*
@@ -668,38 +863,19 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
668 * side waiters as the file is closing so user count on the file 863 * side waiters as the file is closing so user count on the file
669 * side is zero. 864 * side is zero.
670 */ 865 */
671 spin_lock_irqsave(&tty_ldisc_lock, flags); 866
672 while (tty->ldisc.refcount) { 867 tty_ldisc_wait_idle(tty);
673 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 868
674 wait_event(tty_ldisc_wait, tty->ldisc.refcount == 0);
675 spin_lock_irqsave(&tty_ldisc_lock, flags);
676 }
677 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
678 /* 869 /*
679 * Shutdown the current line discipline, and reset it to N_TTY. 870 * Shutdown the current line discipline, and reset it to N_TTY.
680 * 871 *
681 * FIXME: this MUST get fixed for the new reflocking 872 * FIXME: this MUST get fixed for the new reflocking
682 */ 873 */
683 if (tty->ldisc.ops->close)
684 (tty->ldisc.ops->close)(tty);
685 tty_ldisc_put(tty->ldisc.ops);
686 874
687 /* 875 tty_ldisc_reinit(tty);
688 * Switch the line discipline back 876 /* This will need doing differently if we need to lock */
689 */ 877 if (o_tty)
690 WARN_ON(tty_ldisc_get(N_TTY, &ld)); 878 tty_ldisc_release(o_tty, NULL);
691 tty_ldisc_assign(tty, &ld);
692 tty_set_termios_ldisc(tty, N_TTY);
693 if (o_tty) {
694 /* FIXME: could o_tty be in setldisc here ? */
695 clear_bit(TTY_LDISC, &o_tty->flags);
696 if (o_tty->ldisc.ops->close)
697 (o_tty->ldisc.ops->close)(o_tty);
698 tty_ldisc_put(o_tty->ldisc.ops);
699 WARN_ON(tty_ldisc_get(N_TTY, &ld));
700 tty_ldisc_assign(o_tty, &ld);
701 tty_set_termios_ldisc(o_tty, N_TTY);
702 }
703} 879}
704 880
705/** 881/**
@@ -712,10 +888,10 @@ void tty_ldisc_release(struct tty_struct *tty, struct tty_struct *o_tty)
712 888
713void tty_ldisc_init(struct tty_struct *tty) 889void tty_ldisc_init(struct tty_struct *tty)
714{ 890{
715 struct tty_ldisc ld; 891 struct tty_ldisc *ld = tty_ldisc_get(N_TTY);
716 if (tty_ldisc_get(N_TTY, &ld) < 0) 892 if (IS_ERR(ld))
717 panic("n_tty: init_tty"); 893 panic("n_tty: init_tty");
718 tty_ldisc_assign(tty, &ld); 894 tty_ldisc_assign(tty, ld);
719} 895}
720 896
721void tty_ldisc_begin(void) 897void tty_ldisc_begin(void)
diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c
index 9b8004c72686..4e862a75f7ff 100644
--- a/drivers/char/tty_port.c
+++ b/drivers/char/tty_port.c
@@ -137,7 +137,7 @@ int tty_port_carrier_raised(struct tty_port *port)
137EXPORT_SYMBOL(tty_port_carrier_raised); 137EXPORT_SYMBOL(tty_port_carrier_raised);
138 138
139/** 139/**
140 * tty_port_raise_dtr_rts - Riase DTR/RTS 140 * tty_port_raise_dtr_rts - Raise DTR/RTS
141 * @port: tty port 141 * @port: tty port
142 * 142 *
143 * Wrapper for the DTR/RTS raise logic. For the moment this is used 143 * Wrapper for the DTR/RTS raise logic. For the moment this is used
@@ -147,12 +147,28 @@ EXPORT_SYMBOL(tty_port_carrier_raised);
147 147
148void tty_port_raise_dtr_rts(struct tty_port *port) 148void tty_port_raise_dtr_rts(struct tty_port *port)
149{ 149{
150 if (port->ops->raise_dtr_rts) 150 if (port->ops->dtr_rts)
151 port->ops->raise_dtr_rts(port); 151 port->ops->dtr_rts(port, 1);
152} 152}
153EXPORT_SYMBOL(tty_port_raise_dtr_rts); 153EXPORT_SYMBOL(tty_port_raise_dtr_rts);
154 154
155/** 155/**
156 * tty_port_lower_dtr_rts - Lower DTR/RTS
157 * @port: tty port
158 *
159 * Wrapper for the DTR/RTS raise logic. For the moment this is used
160 * to hide some internal details. This will eventually become entirely
161 * internal to the tty port.
162 */
163
164void tty_port_lower_dtr_rts(struct tty_port *port)
165{
166 if (port->ops->dtr_rts)
167 port->ops->dtr_rts(port, 0);
168}
169EXPORT_SYMBOL(tty_port_lower_dtr_rts);
170
171/**
156 * tty_port_block_til_ready - Waiting logic for tty open 172 * tty_port_block_til_ready - Waiting logic for tty open
157 * @port: the tty port being opened 173 * @port: the tty port being opened
158 * @tty: the tty device being bound 174 * @tty: the tty device being bound
@@ -167,7 +183,7 @@ EXPORT_SYMBOL(tty_port_raise_dtr_rts);
167 * - port flags and counts 183 * - port flags and counts
168 * 184 *
169 * The passed tty_port must implement the carrier_raised method if it can 185 * The passed tty_port must implement the carrier_raised method if it can
170 * do carrier detect and the raise_dtr_rts method if it supports software 186 * do carrier detect and the dtr_rts method if it supports software
171 * management of these lines. Note that the dtr/rts raise is done each 187 * management of these lines. Note that the dtr/rts raise is done each
172 * iteration as a hangup may have previously dropped them while we wait. 188 * iteration as a hangup may have previously dropped them while we wait.
173 */ 189 */
@@ -177,12 +193,13 @@ int tty_port_block_til_ready(struct tty_port *port,
177{ 193{
178 int do_clocal = 0, retval; 194 int do_clocal = 0, retval;
179 unsigned long flags; 195 unsigned long flags;
180 DECLARE_WAITQUEUE(wait, current); 196 DEFINE_WAIT(wait);
181 int cd; 197 int cd;
182 198
183 /* block if port is in the process of being closed */ 199 /* block if port is in the process of being closed */
184 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { 200 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
185 interruptible_sleep_on(&port->close_wait); 201 wait_event_interruptible(port->close_wait,
202 !(port->flags & ASYNC_CLOSING));
186 if (port->flags & ASYNC_HUP_NOTIFY) 203 if (port->flags & ASYNC_HUP_NOTIFY)
187 return -EAGAIN; 204 return -EAGAIN;
188 else 205 else
@@ -205,7 +222,6 @@ int tty_port_block_til_ready(struct tty_port *port,
205 before the next open may complete */ 222 before the next open may complete */
206 223
207 retval = 0; 224 retval = 0;
208 add_wait_queue(&port->open_wait, &wait);
209 225
210 /* The port lock protects the port counts */ 226 /* The port lock protects the port counts */
211 spin_lock_irqsave(&port->lock, flags); 227 spin_lock_irqsave(&port->lock, flags);
@@ -219,7 +235,7 @@ int tty_port_block_til_ready(struct tty_port *port,
219 if (tty->termios->c_cflag & CBAUD) 235 if (tty->termios->c_cflag & CBAUD)
220 tty_port_raise_dtr_rts(port); 236 tty_port_raise_dtr_rts(port);
221 237
222 set_current_state(TASK_INTERRUPTIBLE); 238 prepare_to_wait(&port->open_wait, &wait, TASK_INTERRUPTIBLE);
223 /* Check for a hangup or uninitialised port. Return accordingly */ 239 /* Check for a hangup or uninitialised port. Return accordingly */
224 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { 240 if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
225 if (port->flags & ASYNC_HUP_NOTIFY) 241 if (port->flags & ASYNC_HUP_NOTIFY)
@@ -240,8 +256,7 @@ int tty_port_block_til_ready(struct tty_port *port,
240 } 256 }
241 schedule(); 257 schedule();
242 } 258 }
243 set_current_state(TASK_RUNNING); 259 finish_wait(&port->open_wait, &wait);
244 remove_wait_queue(&port->open_wait, &wait);
245 260
246 /* Update counts. A parallel hangup will have set count to zero and 261 /* Update counts. A parallel hangup will have set count to zero and
247 we must not mess that up further */ 262 we must not mess that up further */
@@ -292,6 +307,17 @@ int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct f
292 if (port->flags & ASYNC_INITIALIZED && 307 if (port->flags & ASYNC_INITIALIZED &&
293 port->closing_wait != ASYNC_CLOSING_WAIT_NONE) 308 port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
294 tty_wait_until_sent(tty, port->closing_wait); 309 tty_wait_until_sent(tty, port->closing_wait);
310 if (port->drain_delay) {
311 unsigned int bps = tty_get_baud_rate(tty);
312 long timeout;
313
314 if (bps > 1200)
315 timeout = max_t(long, (HZ * 10 * port->drain_delay) / bps,
316 HZ / 10);
317 else
318 timeout = 2 * HZ;
319 schedule_timeout_interruptible(timeout);
320 }
295 return 1; 321 return 1;
296} 322}
297EXPORT_SYMBOL(tty_port_close_start); 323EXPORT_SYMBOL(tty_port_close_start);
@@ -302,6 +328,9 @@ void tty_port_close_end(struct tty_port *port, struct tty_struct *tty)
302 328
303 tty_ldisc_flush(tty); 329 tty_ldisc_flush(tty);
304 330
331 if (tty->termios->c_cflag & HUPCL)
332 tty_port_lower_dtr_rts(port);
333
305 spin_lock_irqsave(&port->lock, flags); 334 spin_lock_irqsave(&port->lock, flags);
306 tty->closing = 0; 335 tty->closing = 0;
307 336
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index ffc9254f7e02..042c8149a6d1 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -867,7 +867,7 @@ static int viotape_probe(struct vio_dev *vdev, const struct vio_device_id *id)
867 int j; 867 int j;
868 struct device_node *node = vdev->dev.archdata.of_node; 868 struct device_node *node = vdev->dev.archdata.of_node;
869 869
870 if (i > VIOTAPE_MAX_TAPE) 870 if (i >= VIOTAPE_MAX_TAPE)
871 return -ENODEV; 871 return -ENODEV;
872 if (!node) 872 if (!node)
873 return -ENODEV; 873 return -ENODEV;
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index ff6f5a4b58fb..c74dacfa6795 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -188,6 +188,9 @@ static void hvc_handle_input(struct virtqueue *vq)
188 * Finally we put our input buffer in the input queue, ready to receive. */ 188 * Finally we put our input buffer in the input queue, ready to receive. */
189static int __devinit virtcons_probe(struct virtio_device *dev) 189static int __devinit virtcons_probe(struct virtio_device *dev)
190{ 190{
191 vq_callback_t *callbacks[] = { hvc_handle_input, NULL};
192 const char *names[] = { "input", "output" };
193 struct virtqueue *vqs[2];
191 int err; 194 int err;
192 195
193 vdev = dev; 196 vdev = dev;
@@ -199,20 +202,15 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
199 goto fail; 202 goto fail;
200 } 203 }
201 204
202 /* Find the input queue. */ 205 /* Find the queues. */
203 /* FIXME: This is why we want to wean off hvc: we do nothing 206 /* FIXME: This is why we want to wean off hvc: we do nothing
204 * when input comes in. */ 207 * when input comes in. */
205 in_vq = vdev->config->find_vq(vdev, 0, hvc_handle_input); 208 err = vdev->config->find_vqs(vdev, 2, vqs, callbacks, names);
206 if (IS_ERR(in_vq)) { 209 if (err)
207 err = PTR_ERR(in_vq);
208 goto free; 210 goto free;
209 }
210 211
211 out_vq = vdev->config->find_vq(vdev, 1, NULL); 212 in_vq = vqs[0];
212 if (IS_ERR(out_vq)) { 213 out_vq = vqs[1];
213 err = PTR_ERR(out_vq);
214 goto free_in_vq;
215 }
216 214
217 /* Start using the new console output. */ 215 /* Start using the new console output. */
218 virtio_cons.get_chars = get_chars; 216 virtio_cons.get_chars = get_chars;
@@ -233,17 +231,15 @@ static int __devinit virtcons_probe(struct virtio_device *dev)
233 hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE); 231 hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE);
234 if (IS_ERR(hvc)) { 232 if (IS_ERR(hvc)) {
235 err = PTR_ERR(hvc); 233 err = PTR_ERR(hvc);
236 goto free_out_vq; 234 goto free_vqs;
237 } 235 }
238 236
239 /* Register the input buffer the first time. */ 237 /* Register the input buffer the first time. */
240 add_inbuf(); 238 add_inbuf();
241 return 0; 239 return 0;
242 240
243free_out_vq: 241free_vqs:
244 vdev->config->del_vq(out_vq); 242 vdev->config->del_vqs(vdev);
245free_in_vq:
246 vdev->config->del_vq(in_vq);
247free: 243free:
248 kfree(inbuf); 244 kfree(inbuf);
249fail: 245fail:
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 08151d4de489..d9113b4c76e3 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -95,7 +95,6 @@
95#include <linux/timer.h> 95#include <linux/timer.h>
96#include <linux/interrupt.h> 96#include <linux/interrupt.h>
97#include <linux/workqueue.h> 97#include <linux/workqueue.h>
98#include <linux/bootmem.h>
99#include <linux/pm.h> 98#include <linux/pm.h>
100#include <linux/font.h> 99#include <linux/font.h>
101#include <linux/bitops.h> 100#include <linux/bitops.h>
@@ -172,8 +171,9 @@ int do_poke_blanked_console;
172int console_blanked; 171int console_blanked;
173 172
174static int vesa_blank_mode; /* 0:none 1:suspendV 2:suspendH 3:powerdown */ 173static int vesa_blank_mode; /* 0:none 1:suspendV 2:suspendH 3:powerdown */
175static int blankinterval = 10*60*HZ;
176static int vesa_off_interval; 174static int vesa_off_interval;
175static int blankinterval = 10*60;
176core_param(consoleblank, blankinterval, int, 0444);
177 177
178static DECLARE_WORK(console_work, console_callback); 178static DECLARE_WORK(console_work, console_callback);
179 179
@@ -1486,7 +1486,7 @@ static void setterm_command(struct vc_data *vc)
1486 update_attr(vc); 1486 update_attr(vc);
1487 break; 1487 break;
1488 case 9: /* set blanking interval */ 1488 case 9: /* set blanking interval */
1489 blankinterval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60 * HZ; 1489 blankinterval = ((vc->vc_par[1] < 60) ? vc->vc_par[1] : 60) * 60;
1490 poke_blanked_console(); 1490 poke_blanked_console();
1491 break; 1491 break;
1492 case 10: /* set bell frequency in Hz */ 1492 case 10: /* set bell frequency in Hz */
@@ -2872,17 +2872,14 @@ static int __init con_init(void)
2872 2872
2873 if (blankinterval) { 2873 if (blankinterval) {
2874 blank_state = blank_normal_wait; 2874 blank_state = blank_normal_wait;
2875 mod_timer(&console_timer, jiffies + blankinterval); 2875 mod_timer(&console_timer, jiffies + (blankinterval * HZ));
2876 } 2876 }
2877 2877
2878 /*
2879 * kmalloc is not running yet - we use the bootmem allocator.
2880 */
2881 for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) { 2878 for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {
2882 vc_cons[currcons].d = vc = alloc_bootmem(sizeof(struct vc_data)); 2879 vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT);
2883 INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); 2880 INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK);
2884 visual_init(vc, currcons, 1); 2881 visual_init(vc, currcons, 1);
2885 vc->vc_screenbuf = (unsigned short *)alloc_bootmem(vc->vc_screenbuf_size); 2882 vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT);
2886 vc->vc_kmalloced = 0; 2883 vc->vc_kmalloced = 0;
2887 vc_init(vc, vc->vc_rows, vc->vc_cols, 2884 vc_init(vc, vc->vc_rows, vc->vc_cols,
2888 currcons || !vc->vc_sw->con_save_screen); 2885 currcons || !vc->vc_sw->con_save_screen);
@@ -3681,7 +3678,7 @@ void do_unblank_screen(int leaving_gfx)
3681 return; /* but leave console_blanked != 0 */ 3678 return; /* but leave console_blanked != 0 */
3682 3679
3683 if (blankinterval) { 3680 if (blankinterval) {
3684 mod_timer(&console_timer, jiffies + blankinterval); 3681 mod_timer(&console_timer, jiffies + (blankinterval * HZ));
3685 blank_state = blank_normal_wait; 3682 blank_state = blank_normal_wait;
3686 } 3683 }
3687 3684
@@ -3715,7 +3712,7 @@ void unblank_screen(void)
3715static void blank_screen_t(unsigned long dummy) 3712static void blank_screen_t(unsigned long dummy)
3716{ 3713{
3717 if (unlikely(!keventd_up())) { 3714 if (unlikely(!keventd_up())) {
3718 mod_timer(&console_timer, jiffies + blankinterval); 3715 mod_timer(&console_timer, jiffies + (blankinterval * HZ));
3719 return; 3716 return;
3720 } 3717 }
3721 blank_timer_expired = 1; 3718 blank_timer_expired = 1;
@@ -3745,7 +3742,7 @@ void poke_blanked_console(void)
3745 if (console_blanked) 3742 if (console_blanked)
3746 unblank_screen(); 3743 unblank_screen();
3747 else if (blankinterval) { 3744 else if (blankinterval) {
3748 mod_timer(&console_timer, jiffies + blankinterval); 3745 mod_timer(&console_timer, jiffies + (blankinterval * HZ));
3749 blank_state = blank_normal_wait; 3746 blank_state = blank_normal_wait;
3750 } 3747 }
3751} 3748}
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index e6ce632a393e..7539bed0f7e0 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -396,7 +396,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
396 kbd = kbd_table + console; 396 kbd = kbd_table + console;
397 switch (cmd) { 397 switch (cmd) {
398 case TIOCLINUX: 398 case TIOCLINUX:
399 return tioclinux(tty, arg); 399 ret = tioclinux(tty, arg);
400 break;
400 case KIOCSOUND: 401 case KIOCSOUND:
401 if (!perm) 402 if (!perm)
402 goto eperm; 403 goto eperm;