History

Merge branch 'akpm' (Andrew's incoming - part two)

Says Andrew: "60 patches. That's good enough for -rc1 I guess. I have quite a lot of detritus to be rechecked, work through maintainers, etc. - most of the remains of MM - rtc - various misc - cgroups - memcg - cpusets - procfs - ipc - rapidio - sysctl - pps - w1 - drivers/misc - aio" * akpm: (60 commits) memcg: replace ss->id_lock with a rwlock aio: allocate kiocbs in batches drivers/misc/vmw_balloon.c: fix typo in code comment drivers/misc/vmw_balloon.c: determine page allocation flag can_sleep outside loop w1: disable irqs in critical section drivers/w1/w1_int.c: multiple masters used same init_name drivers/power/ds2780_battery.c: fix deadlock upon insertion and removal drivers/power/ds2780_battery.c: add a nolock function to w1 interface drivers/power/ds2780_battery.c: create central point for calling w1 interface w1: ds2760 and ds2780, use ida for id and ida_simple_get() to get it pps gpio client: add missing dependency pps: new client driver using GPIO pps: default echo function include/linux/dma-mapping.h: add dma_zalloc_coherent() sysctl: make CONFIG_SYSCTL_SYSCALL default to n sysctl: add support for poll() RapidIO: documentation update drivers/net/rionet.c: fix ethernet address macros for LE platforms RapidIO: fix potential null deref in rio_setup_device() RapidIO: add mport driver for Tsi721 bridge ...

Linus Torvalds committed 15 years ago

Commit 092f4c52 parents 80c2861 c1e2ee270 files · +4909 −1035Browse files

Unified · Split

70 files
  1. Documentation/DMA-API.txt +7 −0
  2. Documentation/cgroups/memory.txt +0 −1
  3. Documentation/feature-removal-schedule.txt +0 −35
  4. Documentation/rapidio/rapidio.txt +1 −1
  5. Documentation/rapidio/tsi721.txt +49 −0
  6. arch/powerpc/mm/gup.c +0 −12
  7. arch/powerpc/mm/hugetlbpage.c +16 −5
  8. arch/powerpc/sysdev/fsl_rio.c +1 −0
  9. arch/s390/mm/gup.c +13 −1
  10. arch/sparc/mm/gup.c +2 −0
  11. arch/x86/mm/gup.c +0 −10
  12. drivers/misc/vmw_balloon.c +2 −2
  13. drivers/net/rionet.c +2 −2
  14. drivers/power/ds2780_battery.c +51 −35
  15. drivers/pps/clients/Kconfig +9 −0
  16. drivers/pps/clients/Makefile +1 −0
  17. drivers/pps/clients/pps-gpio.c +227 −0
  18. drivers/pps/clients/pps-ktimer.c +0 −12
  19. drivers/pps/clients/pps_parport.c +0 −9
  20. drivers/pps/kapi.c +13 −7
  21. drivers/rapidio/Kconfig +4 −2
  22. drivers/rapidio/Makefile +1 −0
  23. drivers/rapidio/devices/Kconfig +10 −0
  24. drivers/rapidio/devices/Makefile +5 −0
  25. drivers/rapidio/devices/tsi721.c +2360 −0
  26. drivers/rapidio/devices/tsi721.h +766 −0
  27. drivers/rapidio/rio-scan.c +3 −3
  28. drivers/rtc/class.c +9 −23
  29. drivers/rtc/rtc-ds1307.c +27 −0
  30. drivers/rtc/rtc-mc13xxx.c +3 −3
  31. drivers/w1/slaves/w1_ds2760.c +6 −42
  32. drivers/w1/slaves/w1_ds2780.c +41 −55
  33. drivers/w1/slaves/w1_ds2780.h +2 −0
  34. drivers/w1/w1_int.c +1 −0
  35. drivers/w1/w1_io.c +5 −0
  36. fs/aio.c +107 −29
  37. fs/binfmt_elf.c +10 −1
  38. fs/hfs/btree.c +15 −5
  39. fs/isofs/inode.c +9 −1
  40. fs/proc/base.c +103 −43
  41. fs/proc/proc_sysctl.c +46 −0
  42. fs/ramfs/inode.c +0 −10
  43. include/linux/aio.h +1 −0
  44. include/linux/cgroup.h +1 −1
  45. include/linux/dma-mapping.h +10 −0
  46. include/linux/magic.h +5 −5
  47. include/linux/memcontrol.h +24 −20
  48. include/linux/mm.h +33 −34
  49. include/linux/mm_types.h +17 −4
  50. include/linux/pps-gpio.h +32 −0
  51. include/linux/rio_ids.h +1 −0
  52. include/linux/sem.h +6 −43
  53. include/linux/sysctl.h +22 −0
  54. include/linux/utsname.h +16 −0
  55. init/Kconfig +2 −2
  56. init/do_mounts.c +43 −5
  57. init/do_mounts_rd.c +14 −0
  58. ipc/sem.c +55 −1
  59. kernel/cgroup.c +21 −18
  60. kernel/cpuset.c +6 −3
  61. kernel/sys.c +2 −0
  62. kernel/utsname_sysctl.c +23 −0
  63. lib/idr.c +7 −4
  64. mm/huge_memory.c +26 −11
  65. mm/internal.h +46 −0
  66. mm/memcontrol.c +507 −499
  67. mm/memory.c +1 −1
  68. mm/page_cgroup.c +6 −3
  69. mm/swap.c +53 −30
  70. mm/vmscan.c +2 −2
Documentation/DMA-API.txt+7−0
@@ -50,6 +50,13 @@ specify the GFP_ flags (see kmalloc) for the allocation (the · 49 unmodified lines
5050 implementation may choose to ignore flags that affect the location of
5151 the returned memory, like GFP_DMA).
5252
53+void *
54+dma_zalloc_coherent(struct device *dev, size_t size,
55+ dma_addr_t *dma_handle, gfp_t flag)
56+
57+Wraps dma_alloc_coherent() and also zeroes the returned memory if the
58+allocation attempt succeeded.
59+
5360 void
5461 dma_free_coherent(struct device *dev, size_t size, void *cpu_addr,
5562 dma_addr_t dma_handle)
Documentation/cgroups/memory.txt+0−1
@@ -418,7 +418,6 @@ total_unevictable - sum of all children's "unevictable" · 417 unmodified lines
418418
419419 # The following additional stats are dependent on CONFIG_DEBUG_VM.
420420
421−inactive_ratio - VM internal parameter. (see mm/page_alloc.c)
422421 recent_rotated_anon - VM internal parameter. (see mm/vmscan.c)
423422 recent_rotated_file - VM internal parameter. (see mm/vmscan.c)
424423 recent_scanned_anon - VM internal parameter. (see mm/vmscan.c)
Documentation/feature-removal-schedule.txt+0−35
@@ -133,41 +133,6 @@ Who: Pavel Machek <pavel@ucw.cz> · 132 unmodified lines
133133
134134 ---------------------------
135135
136−What: sys_sysctl
137−When: September 2010
138−Option: CONFIG_SYSCTL_SYSCALL
139−Why: The same information is available in a more convenient from
140− /proc/sys, and none of the sysctl variables appear to be
141− important performance wise.
142−
143− Binary sysctls are a long standing source of subtle kernel
144− bugs and security issues.
145−
146− When I looked several months ago all I could find after
147− searching several distributions were 5 user space programs and
148− glibc (which falls back to /proc/sys) using this syscall.
149−
150− The man page for sysctl(2) documents it as unusable for user
151− space programs.
152−
153− sysctl(2) is not generally ABI compatible to a 32bit user
154− space application on a 64bit and a 32bit kernel.
155−
156− For the last several months the policy has been no new binary
157− sysctls and no one has put forward an argument to use them.
158−
159− Binary sysctls issues seem to keep happening appearing so
160− properly deprecating them (with a warning to user space) and a
161− 2 year grace warning period will mean eventually we can kill
162− them and end the pain.
163−
164− In the mean time individual binary sysctls can be dealt with
165− in a piecewise fashion.
166−
167−Who: Eric Biederman <ebiederm@xmission.com>
168−
169−---------------------------
170−
171136 What: /proc/<pid>/oom_adj
172137 When: August 2012
173138 Why: /proc/<pid>/oom_adj allows userspace to influence the oom killer's
Documentation/rapidio/rapidio.txt+1−1
@@ -144,7 +144,7 @@ and the default device ID in order to access the device on the active port. · 143 unmodified lines
144144
145145 After the host has completed enumeration of the entire network it releases
146146 devices by clearing device ID locks (calls rio_clear_locks()). For each endpoint
147−in the system, it sets the Master Enable bit in the Port General Control CSR
147+in the system, it sets the Discovered bit in the Port General Control CSR
148148 to indicate that enumeration is completed and agents are allowed to execute
149149 passive discovery of the network.
150150
Documentation/rapidio/tsi721.txt+49−0
@@ -0,0 +1,49 @@
1+RapidIO subsystem mport driver for IDT Tsi721 PCI Express-to-SRIO bridge.
2+=========================================================================
3+
4+I. Overview
5+
6+This driver implements all currently defined RapidIO mport callback functions.
7+It supports maintenance read and write operations, inbound and outbound RapidIO
8+doorbells, inbound maintenance port-writes and RapidIO messaging.
9+
10+To generate SRIO maintenance transactions this driver uses one of Tsi721 DMA
11+channels. This mechanism provides access to larger range of hop counts and
12+destination IDs without need for changes in outbound window translation.
13+
14+RapidIO messaging support uses dedicated messaging channels for each mailbox.
15+For inbound messages this driver uses destination ID matching to forward messages
16+into the corresponding message queue. Messaging callbacks are implemented to be
17+fully compatible with RIONET driver (Ethernet over RapidIO messaging services).
18+
19+II. Known problems
20+
21+ None.
22+
23+III. To do
24+
25+ Add DMA data transfers (non-messaging).
26+ Add inbound region (SRIO-to-PCIe) mapping.
27+
28+IV. Version History
29+
30+ 1.0.0 - Initial driver release.
31+
32+V. License
33+-----------------------------------------------
34+
35+ Copyright(c) 2011 Integrated Device Technology, Inc. All rights reserved.
36+
37+ This program is free software; you can redistribute it and/or modify it
38+ under the terms of the GNU General Public License as published by the Free
39+ Software Foundation; either version 2 of the License, or (at your option)
40+ any later version.
41+
42+ This program is distributed in the hope that it will be useful, but WITHOUT
43+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
44+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
45+ more details.
46+
47+ You should have received a copy of the GNU General Public License along with
48+ this program; if not, write to the Free Software Foundation, Inc.,
49+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
arch/powerpc/mm/gup.c+0−12
@@ -16,16 +16,6 @@ · 15 unmodified lines
1616
1717 #ifdef __HAVE_ARCH_PTE_SPECIAL
1818
19−static inline void get_huge_page_tail(struct page *page)
20−{
21− /*
22− * __split_huge_page_refcount() cannot run
23− * from under us.
24− */
25− VM_BUG_ON(atomic_read(&page->_count) < 0);
26− atomic_inc(&page->_count);
27−}
28−
2919 /*
3020 * The performance critical leaf functions are made noinline otherwise gcc
3121 * inlines everything into a single function which results in too much
@@ -57,8 +47,6 @@ static noinline int gup_pte_range(pmd_t pmd, unsigned long addr, · 25 unmodified lines
5747 put_page(page);
5848 return 0;
5949 }
60− if (PageTail(page))
61− get_huge_page_tail(page);
6250 pages[*nr] = page;
6351 (*nr)++;
6452
arch/powerpc/mm/hugetlbpage.c+16−5
@@ -390,7 +390,7 @@ static noinline int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long add · 389 unmodified lines
390390 {
391391 unsigned long mask;
392392 unsigned long pte_end;
393− struct page *head, *page;
393+ struct page *head, *page, *tail;
394394 pte_t pte;
395395 int refs;
396396
@@ -413,6 +413,7 @@ static noinline int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long add · 16 unmodified lines
413413 head = pte_page(pte);
414414
415415 page = head + ((addr & (sz-1)) >> PAGE_SHIFT);
416+ tail = page;
416417 do {
417418 VM_BUG_ON(compound_head(page) != head);
418419 pages[*nr] = page;
@@ -428,10 +429,20 @@ static noinline int gup_hugepte(pte_t *ptep, unsigned long sz, unsigned long add · 9 unmodified lines
428429
429430 if (unlikely(pte_val(pte) != pte_val(*ptep))) {
430431 /* Could be optimized better */
431− while (*nr) {
432− put_page(page);
433− (*nr)--;
434− }
432+ *nr -= refs;
433+ while (refs--)
434+ put_page(head);
435+ return 0;
436+ }
437+
438+ /*
439+ * Any tail page need their mapcount reference taken before we
440+ * return.
441+ */
442+ while (refs--) {
443+ if (PageTail(tail))
444+ get_huge_page_tail(tail);
445+ tail++;
435446 }
436447
437448 return 1;
arch/powerpc/sysdev/fsl_rio.c+1−0
@@ -1608,6 +1608,7 @@ int fsl_rio_setup(struct platform_device *dev) · 1607 unmodified lines
16081608 return 0;
16091609 err:
16101610 iounmap(priv->regs_win);
1611+ release_resource(&port->iores);
16111612 err_res:
16121613 kfree(priv);
16131614 err_priv:
arch/s390/mm/gup.c+13−1
@@ -52,7 +52,7 @@ static inline int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr, · 51 unmodified lines
5252 unsigned long end, int write, struct page **pages, int *nr)
5353 {
5454 unsigned long mask, result;
55− struct page *head, *page;
55+ struct page *head, *page, *tail;
5656 int refs;
5757
5858 result = write ? 0 : _SEGMENT_ENTRY_RO;
@@ -64,6 +64,7 @@ static inline int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr, · 5 unmodified lines
6464 refs = 0;
6565 head = pmd_page(pmd);
6666 page = head + ((addr & ~PMD_MASK) >> PAGE_SHIFT);
67+ tail = page;
6768 do {
6869 VM_BUG_ON(compound_head(page) != head);
6970 pages[*nr] = page;
@@ -81,6 +82,17 @@ static inline int gup_huge_pmd(pmd_t *pmdp, pmd_t pmd, unsigned long addr, · 11 unmodified lines
8182 *nr -= refs;
8283 while (refs--)
8384 put_page(head);
85+ return 0;
86+ }
87+
88+ /*
89+ * Any tail page need their mapcount reference taken before we
90+ * return.
91+ */
92+ while (refs--) {
93+ if (PageTail(tail))
94+ get_huge_page_tail(tail);
95+ tail++;
8496 }
8597
8698 return 1;
arch/sparc/mm/gup.c+2−0
@@ -56,6 +56,8 @@ static noinline int gup_pte_range(pmd_t pmd, unsigned long addr, · 55 unmodified lines
5656 put_page(head);
5757 return 0;
5858 }
59+ if (head != page)
60+ get_huge_page_tail(page);
5961
6062 pages[*nr] = page;
6163 (*nr)++;
arch/x86/mm/gup.c+0−10
@@ -108,16 +108,6 @@ static inline void get_head_page_multiple(struct page *page, int nr) · 107 unmodified lines
108108 SetPageReferenced(page);
109109 }
110110
111−static inline void get_huge_page_tail(struct page *page)
112−{
113− /*
114− * __split_huge_page_refcount() cannot run
115− * from under us.
116− */
117− VM_BUG_ON(atomic_read(&page->_count) < 0);
118− atomic_inc(&page->_count);
119−}
120−
121111 static noinline int gup_huge_pmd(pmd_t pmd, unsigned long addr,
122112 unsigned long end, int write, struct page **pages, int *nr)
123113 {
drivers/misc/vmw_balloon.c+2−2
@@ -151,7 +151,7 @@ MODULE_LICENSE("GPL"); · 150 unmodified lines
151151 struct vmballoon_stats {
152152 unsigned int timer;
153153
154− /* allocation statustics */
154+ /* allocation statistics */
155155 unsigned int alloc;
156156 unsigned int alloc_fail;
157157 unsigned int sleep_alloc;
@@ -412,6 +412,7 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep) · 254 unmodified lines
412412 gfp_t flags;
413413 unsigned int hv_status;
414414 bool locked = false;
415+ flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
415416
416417 do {
417418 if (!can_sleep)
@@ -419,7 +420,6 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep) · 1 unmodified line
419420 else
420421 STATS_INC(b->stats.sleep_alloc);
421422
422− flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
423423 page = alloc_page(flags);
424424 if (!page) {
425425 if (!can_sleep)
drivers/net/rionet.c+2−2
@@ -88,8 +88,8 @@ static struct rio_dev **rionet_active; · 87 unmodified lines
8888 #define dev_rionet_capable(dev) \
8989 is_rionet_capable(dev->src_ops, dev->dst_ops)
9090
91−#define RIONET_MAC_MATCH(x) (*(u32 *)x == 0x00010001)
92−#define RIONET_GET_DESTID(x) (*(u16 *)(x + 4))
91+#define RIONET_MAC_MATCH(x) (!memcmp((x), "\00\01\00\01", 4))
92+#define RIONET_GET_DESTID(x) ((*((u8 *)x + 4) << 8) | *((u8 *)x + 5))
9393
9494 static int rionet_rx_clean(struct net_device *ndev)
9595 {
drivers/power/ds2780_battery.c+51−35
@@ -39,6 +39,7 @@ struct ds2780_device_info { · 38 unmodified lines
3939 struct device *dev;
4040 struct power_supply bat;
4141 struct device *w1_dev;
42+ struct task_struct *mutex_holder;
4243 };
4344
4445 enum current_types {
@@ -49,8 +50,8 @@ enum current_types { · 4 unmodified lines
4950 static const char model[] = "DS2780";
5051 static const char manufacturer[] = "Maxim/Dallas";
5152
52−static inline struct ds2780_device_info *to_ds2780_device_info(
53− struct power_supply *psy)
53+static inline struct ds2780_device_info *
54+to_ds2780_device_info(struct power_supply *psy)
5455 {
5556 return container_of(psy, struct ds2780_device_info, bat);
5657 }
@@ -60,17 +61,28 @@ static inline struct power_supply *to_power_supply(struct device *dev) · 3 unmodified lines
6061 return dev_get_drvdata(dev);
6162 }
6263
63−static inline int ds2780_read8(struct device *dev, u8 *val, int addr)
64+static inline int ds2780_battery_io(struct ds2780_device_info *dev_info,
65+ char *buf, int addr, size_t count, int io)
6466 {
65− return w1_ds2780_io(dev, val, addr, sizeof(u8), 0);
67+ if (dev_info->mutex_holder == current)
68+ return w1_ds2780_io_nolock(dev_info->w1_dev, buf, addr, count, io);
69+ else
70+ return w1_ds2780_io(dev_info->w1_dev, buf, addr, count, io);
71+}
72+
73+static inline int ds2780_read8(struct ds2780_device_info *dev_info, u8 *val,
74+ int addr)
75+{
76+ return ds2780_battery_io(dev_info, val, addr, sizeof(u8), 0);
6677 }
6778
68−static int ds2780_read16(struct device *dev, s16 *val, int addr)
79+static int ds2780_read16(struct ds2780_device_info *dev_info, s16 *val,
80+ int addr)
6981 {
7082 int ret;
7183 u8 raw[2];
7284
73− ret = w1_ds2780_io(dev, raw, addr, sizeof(u8) * 2, 0);
85+ ret = ds2780_battery_io(dev_info, raw, addr, sizeof(raw), 0);
7486 if (ret < 0)
7587 return ret;
7688
@@ -79,16 +91,16 @@ static int ds2780_read16(struct device *dev, s16 *val, int addr) · 2 unmodified lines
7991 return 0;
8092 }
8193
82−static inline int ds2780_read_block(struct device *dev, u8 *val, int addr,
83− size_t count)
94+static inline int ds2780_read_block(struct ds2780_device_info *dev_info,
95+ u8 *val, int addr, size_t count)
8496 {
85− return w1_ds2780_io(dev, val, addr, count, 0);
97+ return ds2780_battery_io(dev_info, val, addr, count, 0);
8698 }
8799
88−static inline int ds2780_write(struct device *dev, u8 *val, int addr,
89− size_t count)
100+static inline int ds2780_write(struct ds2780_device_info *dev_info, u8 *val,
101+ int addr, size_t count)
90102 {
91− return w1_ds2780_io(dev, val, addr, count, 1);
103+ return ds2780_battery_io(dev_info, val, addr, count, 1);
92104 }
93105
94106 static inline int ds2780_store_eeprom(struct device *dev, int addr)
@@ -122,7 +134,7 @@ static int ds2780_set_sense_register(struct ds2780_device_info *dev_info, · 27 unmodified lines
122134 {
123135 int ret;
124136
125− ret = ds2780_write(dev_info->w1_dev, &conductance,
137+ ret = ds2780_write(dev_info, &conductance,
126138 DS2780_RSNSP_REG, sizeof(u8));
127139 if (ret < 0)
128140 return ret;
@@ -134,7 +146,7 @@ static int ds2780_set_sense_register(struct ds2780_device_info *dev_info, · 5 unmodified lines
134146 static int ds2780_get_rsgain_register(struct ds2780_device_info *dev_info,
135147 u16 *rsgain)
136148 {
137− return ds2780_read16(dev_info->w1_dev, rsgain, DS2780_RSGAIN_MSB_REG);
149+ return ds2780_read16(dev_info, rsgain, DS2780_RSGAIN_MSB_REG);
138150 }
139151
140152 /* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */
@@ -144,8 +156,8 @@ static int ds2780_set_rsgain_register(struct ds2780_device_info *dev_info, · 3 unmodified lines
144156 int ret;
145157 u8 raw[] = {rsgain >> 8, rsgain & 0xFF};
146158
147− ret = ds2780_write(dev_info->w1_dev, raw,
148− DS2780_RSGAIN_MSB_REG, sizeof(u8) * 2);
159+ ret = ds2780_write(dev_info, raw,
160+ DS2780_RSGAIN_MSB_REG, sizeof(raw));
149161 if (ret < 0)
150162 return ret;
151163
@@ -167,7 +179,7 @@ static int ds2780_get_voltage(struct ds2780_device_info *dev_info, · 15 unmodified lines
167179 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the
168180 * voltage LSB register
169181 */
170− ret = ds2780_read16(dev_info->w1_dev, &voltage_raw,
182+ ret = ds2780_read16(dev_info, &voltage_raw,
171183 DS2780_VOLT_MSB_REG);
172184 if (ret < 0)
173185 return ret;
@@ -196,7 +208,7 @@ static int ds2780_get_temperature(struct ds2780_device_info *dev_info, · 22 unmodified lines
196208 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the
197209 * temperature LSB register
198210 */
199− ret = ds2780_read16(dev_info->w1_dev, &temperature_raw,
211+ ret = ds2780_read16(dev_info, &temperature_raw,
200212 DS2780_TEMP_MSB_REG);
201213 if (ret < 0)
202214 return ret;
@@ -222,13 +234,13 @@ static int ds2780_get_current(struct ds2780_device_info *dev_info, · 19 unmodified lines
222234 * The units of measurement for current are dependent on the value of
223235 * the sense resistor.
224236 */
225− ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG);
237+ ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
226238 if (ret < 0)
227239 return ret;
228240
229241 if (sense_res_raw == 0) {
230242 dev_err(dev_info->dev, "sense resistor value is 0\n");
231− return -ENXIO;
243+ return -EINVAL;
232244 }
233245 sense_res = 1000 / sense_res_raw;
234246
@@ -248,7 +260,7 @@ static int ds2780_get_current(struct ds2780_device_info *dev_info, · 13 unmodified lines
248260 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current
249261 * LSB register
250262 */
251− ret = ds2780_read16(dev_info->w1_dev, &current_raw, reg_msb);
263+ ret = ds2780_read16(dev_info, &current_raw, reg_msb);
252264 if (ret < 0)
253265 return ret;
254266
@@ -267,7 +279,7 @@ static int ds2780_get_accumulated_current(struct ds2780_device_info *dev_info, · 12 unmodified lines
267279 * The units of measurement for accumulated current are dependent on
268280 * the value of the sense resistor.
269281 */
270− ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG);
282+ ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
271283 if (ret < 0)
272284 return ret;
273285
@@ -285,7 +297,7 @@ static int ds2780_get_accumulated_current(struct ds2780_device_info *dev_info, · 11 unmodified lines
285297 * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR
286298 * LSB register
287299 */
288− ret = ds2780_read16(dev_info->w1_dev, &current_raw, DS2780_ACR_MSB_REG);
300+ ret = ds2780_read16(dev_info, &current_raw, DS2780_ACR_MSB_REG);
289301 if (ret < 0)
290302 return ret;
291303
@@ -299,7 +311,7 @@ static int ds2780_get_capacity(struct ds2780_device_info *dev_info, · 7 unmodified lines
299311 int ret;
300312 u8 raw;
301313
302− ret = ds2780_read8(dev_info->w1_dev, &raw, DS2780_RARC_REG);
314+ ret = ds2780_read8(dev_info, &raw, DS2780_RARC_REG);
303315 if (ret < 0)
304316 return ret;
305317
@@ -345,7 +357,7 @@ static int ds2780_get_charge_now(struct ds2780_device_info *dev_info, · 39 unmodified lines
345357 * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC
346358 * LSB register
347359 */
348− ret = ds2780_read16(dev_info->w1_dev, &charge_raw, DS2780_RAAC_MSB_REG);
360+ ret = ds2780_read16(dev_info, &charge_raw, DS2780_RAAC_MSB_REG);
349361 if (ret < 0)
350362 return ret;
351363
@@ -356,7 +368,7 @@ static int ds2780_get_charge_now(struct ds2780_device_info *dev_info, · 4 unmodified lines
356368 static int ds2780_get_control_register(struct ds2780_device_info *dev_info,
357369 u8 *control_reg)
358370 {
359− return ds2780_read8(dev_info->w1_dev, control_reg, DS2780_CONTROL_REG);
371+ return ds2780_read8(dev_info, control_reg, DS2780_CONTROL_REG);
360372 }
361373
362374 static int ds2780_set_control_register(struct ds2780_device_info *dev_info,
@@ -364,7 +376,7 @@ static int ds2780_set_control_register(struct ds2780_device_info *dev_info, · 1 unmodified line
364376 {
365377 int ret;
366378
367− ret = ds2780_write(dev_info->w1_dev, &control_reg,
379+ ret = ds2780_write(dev_info, &control_reg,
368380 DS2780_CONTROL_REG, sizeof(u8));
369381 if (ret < 0)
370382 return ret;
@@ -503,7 +515,7 @@ static ssize_t ds2780_get_sense_resistor_value(struct device *dev, · 132 unmodified lines
503515 struct power_supply *psy = to_power_supply(dev);
504516 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
505517
506− ret = ds2780_read8(dev_info->w1_dev, &sense_resistor, DS2780_RSNSP_REG);
518+ ret = ds2780_read8(dev_info, &sense_resistor, DS2780_RSNSP_REG);
507519 if (ret < 0)
508520 return ret;
509521
@@ -584,7 +596,7 @@ static ssize_t ds2780_get_pio_pin(struct device *dev, · 74 unmodified lines
584596 struct power_supply *psy = to_power_supply(dev);
585597 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
586598
587− ret = ds2780_read8(dev_info->w1_dev, &sfr, DS2780_SFR_REG);
599+ ret = ds2780_read8(dev_info, &sfr, DS2780_SFR_REG);
588600 if (ret < 0)
589601 return ret;
590602
@@ -611,7 +623,7 @@ static ssize_t ds2780_set_pio_pin(struct device *dev, · 20 unmodified lines
611623 return -EINVAL;
612624 }
613625
614− ret = ds2780_write(dev_info->w1_dev, &new_setting,
626+ ret = ds2780_write(dev_info, &new_setting,
615627 DS2780_SFR_REG, sizeof(u8));
616628 if (ret < 0)
617629 return ret;
@@ -632,7 +644,7 @@ static ssize_t ds2780_read_param_eeprom_bin(struct file *filp, · 14 unmodified lines
632644 DS2780_EEPROM_BLOCK1_END -
633645 DS2780_EEPROM_BLOCK1_START + 1 - off);
634646
635− return ds2780_read_block(dev_info->w1_dev, buf,
647+ return ds2780_read_block(dev_info, buf,
636648 DS2780_EEPROM_BLOCK1_START + off, count);
637649 }
638650
@@ -650,7 +662,7 @@ static ssize_t ds2780_write_param_eeprom_bin(struct file *filp, · 11 unmodified lines
650662 DS2780_EEPROM_BLOCK1_END -
651663 DS2780_EEPROM_BLOCK1_START + 1 - off);
652664
653− ret = ds2780_write(dev_info->w1_dev, buf,
665+ ret = ds2780_write(dev_info, buf,
654666 DS2780_EEPROM_BLOCK1_START + off, count);
655667 if (ret < 0)
656668 return ret;
@@ -685,9 +697,8 @@ static ssize_t ds2780_read_user_eeprom_bin(struct file *filp, · 28 unmodified lines
685697 DS2780_EEPROM_BLOCK0_END -
686698 DS2780_EEPROM_BLOCK0_START + 1 - off);
687699
688− return ds2780_read_block(dev_info->w1_dev, buf,
700+ return ds2780_read_block(dev_info, buf,
689701 DS2780_EEPROM_BLOCK0_START + off, count);
690−
691702 }
692703
693704 static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
@@ -704,7 +715,7 @@ static ssize_t ds2780_write_user_eeprom_bin(struct file *filp, · 10 unmodified lines
704715 DS2780_EEPROM_BLOCK0_END -
705716 DS2780_EEPROM_BLOCK0_START + 1 - off);
706717
707− ret = ds2780_write(dev_info->w1_dev, buf,
718+ ret = ds2780_write(dev_info, buf,
708719 DS2780_EEPROM_BLOCK0_START + off, count);
709720 if (ret < 0)
710721 return ret;
@@ -768,6 +779,7 @@ static int __devinit ds2780_battery_probe(struct platform_device *pdev) · 57 unmodified lines
768779 dev_info->bat.properties = ds2780_battery_props;
769780 dev_info->bat.num_properties = ARRAY_SIZE(ds2780_battery_props);
770781 dev_info->bat.get_property = ds2780_battery_get_property;
782+ dev_info->mutex_holder = current;
771783
772784 ret = power_supply_register(&pdev->dev, &dev_info->bat);
773785 if (ret) {
@@ -797,6 +809,8 @@ static int __devinit ds2780_battery_probe(struct platform_device *pdev) · 23 unmodified lines
797809 goto fail_remove_bin_file;
798810 }
799811
812+ dev_info->mutex_holder = NULL;
813+
800814 return 0;
801815
802816 fail_remove_bin_file:
@@ -816,6 +830,8 @@ static int __devexit ds2780_battery_remove(struct platform_device *pdev) · 13 unmodified lines
816830 {
817831 struct ds2780_device_info *dev_info = platform_get_drvdata(pdev);
818832
833+ dev_info->mutex_holder = current;
834+
819835 /* remove attributes */
820836 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
821837
drivers/pps/clients/Kconfig+9−0
@@ -29,4 +29,13 @@ config PPS_CLIENT_PARPORT · 28 unmodified lines
2929 If you say yes here you get support for a PPS source connected
3030 with the interrupt pin of your parallel port.
3131
32+config PPS_CLIENT_GPIO
33+ tristate "PPS client using GPIO"
34+ depends on PPS && GENERIC_HARDIRQS
35+ help
36+ If you say yes here you get support for a PPS source using
37+ GPIO. To be useful you must also register a platform device
38+ specifying the GPIO pin and other options, usually in your board
39+ setup.
40+
3241 endif
drivers/pps/clients/Makefile+1−0
@@ -5,5 +5,6 @@ · 4 unmodified lines
55 obj-$(CONFIG_PPS_CLIENT_KTIMER) += pps-ktimer.o
66 obj-$(CONFIG_PPS_CLIENT_LDISC) += pps-ldisc.o
77 obj-$(CONFIG_PPS_CLIENT_PARPORT) += pps_parport.o
8+obj-$(CONFIG_PPS_CLIENT_GPIO) += pps-gpio.o
89
910 ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
drivers/pps/clients/pps-gpio.c+227−0
@@ -0,0 +1,227 @@
1+/*
2+ * pps-gpio.c -- PPS client driver using GPIO
3+ *
4+ *
5+ * Copyright (C) 2010 Ricardo Martins <rasm@fe.up.pt>
6+ * Copyright (C) 2011 James Nuss <jamesnuss@nanometrics.ca>
7+ *
8+ * This program is free software; you can redistribute it and/or modify
9+ * it under the terms of the GNU General Public License as published by
10+ * the Free Software Foundation; either version 2 of the License, or
11+ * (at your option) any later version.
12+ *
13+ * This program is distributed in the hope that it will be useful,
14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+ * GNU General Public License for more details.
17+ *
18+ * You should have received a copy of the GNU General Public License
19+ * along with this program; if not, write to the Free Software
20+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21+ */
22+
23+#define PPS_GPIO_NAME "pps-gpio"
24+#define pr_fmt(fmt) PPS_GPIO_NAME ": " fmt
25+
26+#include <linux/init.h>
27+#include <linux/kernel.h>
28+#include <linux/interrupt.h>
29+#include <linux/module.h>
30+#include <linux/platform_device.h>
31+#include <linux/slab.h>
32+#include <linux/pps_kernel.h>
33+#include <linux/pps-gpio.h>
34+#include <linux/gpio.h>
35+#include <linux/list.h>
36+
37+/* Info for each registered platform device */
38+struct pps_gpio_device_data {
39+ int irq; /* IRQ used as PPS source */
40+ struct pps_device *pps; /* PPS source device */
41+ struct pps_source_info info; /* PPS source information */
42+ const struct pps_gpio_platform_data *pdata;
43+};
44+
45+/*
46+ * Report the PPS event
47+ */
48+
49+static irqreturn_t pps_gpio_irq_handler(int irq, void *data)
50+{
51+ const struct pps_gpio_device_data *info;
52+ struct pps_event_time ts;
53+ int rising_edge;
54+
55+ /* Get the time stamp first */
56+ pps_get_ts(&ts);
57+
58+ info = data;
59+
60+ rising_edge = gpio_get_value(info->pdata->gpio_pin);
61+ if ((rising_edge && !info->pdata->assert_falling_edge) ||
62+ (!rising_edge && info->pdata->assert_falling_edge))
63+ pps_event(info->pps, &ts, PPS_CAPTUREASSERT, NULL);
64+ else if (info->pdata->capture_clear &&
65+ ((rising_edge && info->pdata->assert_falling_edge) ||
66+ (!rising_edge && !info->pdata->assert_falling_edge)))
67+ pps_event(info->pps, &ts, PPS_CAPTURECLEAR, NULL);
68+
69+ return IRQ_HANDLED;
70+}
71+
72+static int pps_gpio_setup(struct platform_device *pdev)
73+{
74+ int ret;
75+ const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data;
76+
77+ ret = gpio_request(pdata->gpio_pin, pdata->gpio_label);
78+ if (ret) {
79+ pr_warning("failed to request GPIO %u\n", pdata->gpio_pin);
80+ return -EINVAL;
81+ }
82+
83+ ret = gpio_direction_input(pdata->gpio_pin);
84+ if (ret) {
85+ pr_warning("failed to set pin direction\n");
86+ gpio_free(pdata->gpio_pin);
87+ return -EINVAL;
88+ }
89+
90+ return 0;
91+}
92+
93+static unsigned long
94+get_irqf_trigger_flags(const struct pps_gpio_platform_data *pdata)
95+{
96+ unsigned long flags = pdata->assert_falling_edge ?
97+ IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
98+
99+ if (pdata->capture_clear) {
100+ flags |= ((flags & IRQF_TRIGGER_RISING) ?
101+ IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING);
102+ }
103+
104+ return flags;
105+}
106+
107+static int pps_gpio_probe(struct platform_device *pdev)
108+{
109+ struct pps_gpio_device_data *data;
110+ int irq;
111+ int ret;
112+ int err;
113+ int pps_default_params;
114+ const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data;
115+
116+
117+ /* GPIO setup */
118+ ret = pps_gpio_setup(pdev);
119+ if (ret)
120+ return -EINVAL;
121+
122+ /* IRQ setup */
123+ irq = gpio_to_irq(pdata->gpio_pin);
124+ if (irq < 0) {
125+ pr_err("failed to map GPIO to IRQ: %d\n", irq);
126+ err = -EINVAL;
127+ goto return_error;
128+ }
129+
130+ /* allocate space for device info */
131+ data = kzalloc(sizeof(struct pps_gpio_device_data), GFP_KERNEL);
132+ if (data == NULL) {
133+ err = -ENOMEM;
134+ goto return_error;
135+ }
136+
137+ /* initialize PPS specific parts of the bookkeeping data structure. */
138+ data->info.mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
139+ PPS_ECHOASSERT | PPS_CANWAIT | PPS_TSFMT_TSPEC;
140+ if (pdata->capture_clear)
141+ data->info.mode |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR |
142+ PPS_ECHOCLEAR;
143+ data->info.owner = THIS_MODULE;
144+ snprintf(data->info.name, PPS_MAX_NAME_LEN - 1, "%s.%d",
145+ pdev->name, pdev->id);
146+
147+ /* register PPS source */
148+ pps_default_params = PPS_CAPTUREASSERT | PPS_OFFSETASSERT;
149+ if (pdata->capture_clear)
150+ pps_default_params |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR;
151+ data->pps = pps_register_source(&data->info, pps_default_params);
152+ if (data->pps == NULL) {
153+ kfree(data);
154+ pr_err("failed to register IRQ %d as PPS source\n", irq);
155+ err = -EINVAL;
156+ goto return_error;
157+ }
158+
159+ data->irq = irq;
160+ data->pdata = pdata;
161+
162+ /* register IRQ interrupt handler */
163+ ret = request_irq(irq, pps_gpio_irq_handler,
164+ get_irqf_trigger_flags(pdata), data->info.name, data);
165+ if (ret) {
166+ pps_unregister_source(data->pps);
167+ kfree(data);
168+ pr_err("failed to acquire IRQ %d\n", irq);
169+ err = -EINVAL;
170+ goto return_error;
171+ }
172+
173+ platform_set_drvdata(pdev, data);
174+ dev_info(data->pps->dev, "Registered IRQ %d as PPS source\n", irq);
175+
176+ return 0;
177+
178+return_error:
179+ gpio_free(pdata->gpio_pin);
180+ return err;
181+}
182+
183+static int pps_gpio_remove(struct platform_device *pdev)
184+{
185+ struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
186+ const struct pps_gpio_platform_data *pdata = data->pdata;
187+
188+ platform_set_drvdata(pdev, NULL);
189+ free_irq(data->irq, data);
190+ gpio_free(pdata->gpio_pin);
191+ pps_unregister_source(data->pps);
192+ pr_info("removed IRQ %d as PPS source\n", data->irq);
193+ kfree(data);
194+ return 0;
195+}
196+
197+static struct platform_driver pps_gpio_driver = {
198+ .probe = pps_gpio_probe,
199+ .remove = __devexit_p(pps_gpio_remove),
200+ .driver = {
201+ .name = PPS_GPIO_NAME,
202+ .owner = THIS_MODULE
203+ },
204+};
205+
206+static int __init pps_gpio_init(void)
207+{
208+ int ret = platform_driver_register(&pps_gpio_driver);
209+ if (ret < 0)
210+ pr_err("failed to register platform driver\n");
211+ return ret;
212+}
213+
214+static void __exit pps_gpio_exit(void)
215+{
216+ platform_driver_unregister(&pps_gpio_driver);
217+ pr_debug("unregistered platform driver\n");
218+}
219+
220+module_init(pps_gpio_init);
221+module_exit(pps_gpio_exit);
222+
223+MODULE_AUTHOR("Ricardo Martins <rasm@fe.up.pt>");
224+MODULE_AUTHOR("James Nuss <jamesnuss@nanometrics.ca>");
225+MODULE_DESCRIPTION("Use GPIO pin as PPS source");
226+MODULE_LICENSE("GPL");
227+MODULE_VERSION("1.0.0");
drivers/pps/clients/pps-ktimer.c+0−12
@@ -51,17 +51,6 @@ static void pps_ktimer_event(unsigned long ptr) · 50 unmodified lines
5151 mod_timer(&ktimer, jiffies + HZ);
5252 }
5353
54−/*
55− * The echo function
56− */
57−
58−static void pps_ktimer_echo(struct pps_device *pps, int event, void *data)
59−{
60− dev_info(pps->dev, "echo %s %s\n",
61− event & PPS_CAPTUREASSERT ? "assert" : "",
62− event & PPS_CAPTURECLEAR ? "clear" : "");
63−}
64−
6554 /*
6655 * The PPS info struct
6756 */
@@ -72,7 +61,6 @@ static struct pps_source_info pps_ktimer_info = { · 4 unmodified lines
7261 .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
7362 PPS_ECHOASSERT |
7463 PPS_CANWAIT | PPS_TSFMT_TSPEC,
75− .echo = pps_ktimer_echo,
7664 .owner = THIS_MODULE,
7765 };
7866
drivers/pps/clients/pps_parport.c+0−9
@@ -133,14 +133,6 @@ out_both: · 132 unmodified lines
133133 return;
134134 }
135135
136−/* the PPS echo function */
137−static void pps_echo(struct pps_device *pps, int event, void *data)
138−{
139− dev_info(pps->dev, "echo %s %s\n",
140− event & PPS_CAPTUREASSERT ? "assert" : "",
141− event & PPS_CAPTURECLEAR ? "clear" : "");
142−}
143−
144136 static void parport_attach(struct parport *port)
145137 {
146138 struct pps_client_pp *device;
@@ -151,7 +143,6 @@ static void parport_attach(struct parport *port) · 4 unmodified lines
151143 PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \
152144 PPS_ECHOASSERT | PPS_ECHOCLEAR | \
153145 PPS_CANWAIT | PPS_TSFMT_TSPEC,
154− .echo = pps_echo,
155146 .owner = THIS_MODULE,
156147 .dev = NULL
157148 };
drivers/pps/kapi.c+13−7
@@ -52,6 +52,14 @@ static void pps_add_offset(struct pps_ktime *ts, struct pps_ktime *offset) · 51 unmodified lines
5252 ts->sec += offset->sec;
5353 }
5454
55+static void pps_echo_client_default(struct pps_device *pps, int event,
56+ void *data)
57+{
58+ dev_info(pps->dev, "echo %s %s\n",
59+ event & PPS_CAPTUREASSERT ? "assert" : "",
60+ event & PPS_CAPTURECLEAR ? "clear" : "");
61+}
62+
5563 /*
5664 * Exported functions
5765 */
@@ -80,13 +88,6 @@ struct pps_device *pps_register_source(struct pps_source_info *info, · 22 unmodified lines
8088 err = -EINVAL;
8189 goto pps_register_source_exit;
8290 }
83− if ((info->mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR)) != 0 &&
84− info->echo == NULL) {
85− pr_err("%s: echo function is not defined\n",
86− info->name);
87− err = -EINVAL;
88− goto pps_register_source_exit;
89− }
9091 if ((info->mode & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) == 0) {
9192 pr_err("%s: unspecified time format\n",
9293 info->name);
@@ -108,6 +109,11 @@ struct pps_device *pps_register_source(struct pps_source_info *info, · 15 unmodified lines
108109 pps->params.mode = default_params;
109110 pps->info = *info;
110111
112+ /* check for default echo function */
113+ if ((pps->info.mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR)) &&
114+ pps->info.echo == NULL)
115+ pps->info.echo = pps_echo_client_default;
116+
111117 init_waitqueue_head(&pps->queue);
112118 spin_lock_init(&pps->lock);
113119
drivers/rapidio/Kconfig+4−2
@@ -1,6 +1,8 @@
11 #
22 # RapidIO configuration
33 #
4+source "drivers/rapidio/devices/Kconfig"
5+
46 config RAPIDIO_DISC_TIMEOUT
57 int "Discovery timeout duration (seconds)"
68 depends on RAPIDIO
@@ -20,8 +22,6 @@ config RAPIDIO_ENABLE_RX_TX_PORTS · 13 unmodified lines
2022 ports for Input/Output direction to allow other traffic
2123 than Maintenance transfers.
2224
23−source "drivers/rapidio/switches/Kconfig"
24−
2525 config RAPIDIO_DEBUG
2626 bool "RapidIO subsystem debug messages"
2727 depends on RAPIDIO
@@ -32,3 +32,5 @@ config RAPIDIO_DEBUG · 4 unmodified lines
3232 going on.
3333
3434 If you are unsure about this, say N here.
35+
36+source "drivers/rapidio/switches/Kconfig"
drivers/rapidio/Makefile+1−0
@@ -4,5 +4,6 @@ · 3 unmodified lines
44 obj-y += rio.o rio-access.o rio-driver.o rio-scan.o rio-sysfs.o
55
66 obj-$(CONFIG_RAPIDIO) += switches/
7+obj-$(CONFIG_RAPIDIO) += devices/
78
89 subdir-ccflags-$(CONFIG_RAPIDIO_DEBUG) := -DDEBUG
drivers/rapidio/devices/Kconfig+10−0
@@ -0,0 +1,10 @@
1+#
2+# RapidIO master port configuration
3+#
4+
5+config RAPIDIO_TSI721
6+ bool "IDT Tsi721 PCI Express SRIO Controller support"
7+ depends on RAPIDIO && PCIEPORTBUS
8+ default "n"
9+ ---help---
10+ Include support for IDT Tsi721 PCI Express Serial RapidIO controller.
drivers/rapidio/devices/Makefile+5−0
@@ -0,0 +1,5 @@
1+#
2+# Makefile for RapidIO devices
3+#
4+
5+obj-$(CONFIG_RAPIDIO_TSI721) += tsi721.o
drivers/rapidio/devices/tsi721.c+2360−0
@@ -0,0 +1,2360 @@
1+/*
2+ * RapidIO mport driver for Tsi721 PCIExpress-to-SRIO bridge
3+ *
4+ * Copyright 2011 Integrated Device Technology, Inc.
5+ * Alexandre Bounine <alexandre.bounine@idt.com>
6+ * Chul Kim <chul.kim@idt.com>
7+ *
8+ * This program is free software; you can redistribute it and/or modify it
9+ * under the terms of the GNU General Public License as published by the Free
10+ * Software Foundation; either version 2 of the License, or (at your option)
11+ * any later version.
12+ *
13+ * This program is distributed in the hope that it will be useful, but WITHOUT
14+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16+ * more details.
17+ *
18+ * You should have received a copy of the GNU General Public License along with
19+ * this program; if not, write to the Free Software Foundation, Inc., 59
20+ * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21+ */
22+
23+#include <linux/io.h>
24+#include <linux/errno.h>
25+#include <linux/init.h>
26+#include <linux/ioport.h>
27+#include <linux/kernel.h>
28+#include <linux/module.h>
29+#include <linux/pci.h>
30+#include <linux/rio.h>
31+#include <linux/rio_drv.h>
32+#include <linux/dma-mapping.h>
33+#include <linux/interrupt.h>
34+#include <linux/kfifo.h>
35+#include <linux/delay.h>
36+
37+#include "tsi721.h"
38+
39+#define DEBUG_PW /* Inbound Port-Write debugging */
40+
41+static void tsi721_omsg_handler(struct tsi721_device *priv, int ch);
42+static void tsi721_imsg_handler(struct tsi721_device *priv, int ch);
43+
44+/**
45+ * tsi721_lcread - read from local SREP config space
46+ * @mport: RapidIO master port info
47+ * @index: ID of RapdiIO interface
48+ * @offset: Offset into configuration space
49+ * @len: Length (in bytes) of the maintenance transaction
50+ * @data: Value to be read into
51+ *
52+ * Generates a local SREP space read. Returns %0 on
53+ * success or %-EINVAL on failure.
54+ */
55+static int tsi721_lcread(struct rio_mport *mport, int index, u32 offset,
56+ int len, u32 *data)
57+{
58+ struct tsi721_device *priv = mport->priv;
59+
60+ if (len != sizeof(u32))
61+ return -EINVAL; /* only 32-bit access is supported */
62+
63+ *data = ioread32(priv->regs + offset);
64+
65+ return 0;
66+}
67+
68+/**
69+ * tsi721_lcwrite - write into local SREP config space
70+ * @mport: RapidIO master port info
71+ * @index: ID of RapdiIO interface
72+ * @offset: Offset into configuration space
73+ * @len: Length (in bytes) of the maintenance transaction
74+ * @data: Value to be written
75+ *
76+ * Generates a local write into SREP configuration space. Returns %0 on
77+ * success or %-EINVAL on failure.
78+ */
79+static int tsi721_lcwrite(struct rio_mport *mport, int index, u32 offset,
80+ int len, u32 data)
81+{
82+ struct tsi721_device *priv = mport->priv;
83+
84+ if (len != sizeof(u32))
85+ return -EINVAL; /* only 32-bit access is supported */
86+
87+ iowrite32(data, priv->regs + offset);
88+
89+ return 0;
90+}
91+
92+/**
93+ * tsi721_maint_dma - Helper function to generate RapidIO maintenance
94+ * transactions using designated Tsi721 DMA channel.
95+ * @priv: pointer to tsi721 private data
96+ * @sys_size: RapdiIO transport system size
97+ * @destid: Destination ID of transaction
98+ * @hopcount: Number of hops to target device
99+ * @offset: Offset into configuration space
100+ * @len: Length (in bytes) of the maintenance transaction
101+ * @data: Location to be read from or write into
102+ * @do_wr: Operation flag (1 == MAINT_WR)
103+ *
104+ * Generates a RapidIO maintenance transaction (Read or Write).
105+ * Returns %0 on success and %-EINVAL or %-EFAULT on failure.
106+ */
107+static int tsi721_maint_dma(struct tsi721_device *priv, u32 sys_size,
108+ u16 destid, u8 hopcount, u32 offset, int len,
109+ u32 *data, int do_wr)
110+{
111+ struct tsi721_dma_desc *bd_ptr;
112+ u32 rd_count, swr_ptr, ch_stat;
113+ int i, err = 0;
114+ u32 op = do_wr ? MAINT_WR : MAINT_RD;
115+
116+ if (offset > (RIO_MAINT_SPACE_SZ - len) || (len != sizeof(u32)))
117+ return -EINVAL;
118+
119+ bd_ptr = priv->bdma[TSI721_DMACH_MAINT].bd_base;
120+
121+ rd_count = ioread32(
122+ priv->regs + TSI721_DMAC_DRDCNT(TSI721_DMACH_MAINT));
123+
124+ /* Initialize DMA descriptor */
125+ bd_ptr[0].type_id = cpu_to_le32((DTYPE2 << 29) | (op << 19) | destid);
126+ bd_ptr[0].bcount = cpu_to_le32((sys_size << 26) | 0x04);
127+ bd_ptr[0].raddr_lo = cpu_to_le32((hopcount << 24) | offset);
128+ bd_ptr[0].raddr_hi = 0;
129+ if (do_wr)
130+ bd_ptr[0].data[0] = cpu_to_be32p(data);
131+ else
132+ bd_ptr[0].data[0] = 0xffffffff;
133+
134+ mb();
135+
136+ /* Start DMA operation */
137+ iowrite32(rd_count + 2,
138+ priv->regs + TSI721_DMAC_DWRCNT(TSI721_DMACH_MAINT));
139+ ioread32(priv->regs + TSI721_DMAC_DWRCNT(TSI721_DMACH_MAINT));
140+ i = 0;
141+
142+ /* Wait until DMA transfer is finished */
143+ while ((ch_stat = ioread32(priv->regs +
144+ TSI721_DMAC_STS(TSI721_DMACH_MAINT))) & TSI721_DMAC_STS_RUN) {
145+ udelay(1);
146+ if (++i >= 5000000) {
147+ dev_dbg(&priv->pdev->dev,
148+ "%s : DMA[%d] read timeout ch_status=%x\n",
149+ __func__, TSI721_DMACH_MAINT, ch_stat);
150+ if (!do_wr)
151+ *data = 0xffffffff;
152+ err = -EIO;
153+ goto err_out;
154+ }
155+ }
156+
157+ if (ch_stat & TSI721_DMAC_STS_ABORT) {
158+ /* If DMA operation aborted due to error,
159+ * reinitialize DMA channel
160+ */
161+ dev_dbg(&priv->pdev->dev, "%s : DMA ABORT ch_stat=%x\n",
162+ __func__, ch_stat);
163+ dev_dbg(&priv->pdev->dev, "OP=%d : destid=%x hc=%x off=%x\n",
164+ do_wr ? MAINT_WR : MAINT_RD, destid, hopcount, offset);
165+ iowrite32(TSI721_DMAC_INT_ALL,
166+ priv->regs + TSI721_DMAC_INT(TSI721_DMACH_MAINT));
167+ iowrite32(TSI721_DMAC_CTL_INIT,
168+ priv->regs + TSI721_DMAC_CTL(TSI721_DMACH_MAINT));
169+ udelay(10);
170+ iowrite32(0, priv->regs +
171+ TSI721_DMAC_DWRCNT(TSI721_DMACH_MAINT));
172+ udelay(1);
173+ if (!do_wr)
174+ *data = 0xffffffff;
175+ err = -EIO;
176+ goto err_out;
177+ }
178+
179+ if (!do_wr)
180+ *data = be32_to_cpu(bd_ptr[0].data[0]);
181+
182+ /*
183+ * Update descriptor status FIFO RD pointer.
184+ * NOTE: Skipping check and clear FIFO entries because we are waiting
185+ * for transfer to be completed.
186+ */
187+ swr_ptr = ioread32(priv->regs + TSI721_DMAC_DSWP(TSI721_DMACH_MAINT));
188+ iowrite32(swr_ptr, priv->regs + TSI721_DMAC_DSRP(TSI721_DMACH_MAINT));
189+err_out:
190+
191+ return err;
192+}
193+
194+/**
195+ * tsi721_cread_dma - Generate a RapidIO maintenance read transaction
196+ * using Tsi721 BDMA engine.
197+ * @mport: RapidIO master port control structure
198+ * @index: ID of RapdiIO interface
199+ * @destid: Destination ID of transaction
200+ * @hopcount: Number of hops to target device
201+ * @offset: Offset into configuration space
202+ * @len: Length (in bytes) of the maintenance transaction
203+ * @val: Location to be read into
204+ *
205+ * Generates a RapidIO maintenance read transaction.
206+ * Returns %0 on success and %-EINVAL or %-EFAULT on failure.
207+ */
208+static int tsi721_cread_dma(struct rio_mport *mport, int index, u16 destid,
209+ u8 hopcount, u32 offset, int len, u32 *data)
210+{
211+ struct tsi721_device *priv = mport->priv;
212+
213+ return tsi721_maint_dma(priv, mport->sys_size, destid, hopcount,
214+ offset, len, data, 0);
215+}
216+
217+/**
218+ * tsi721_cwrite_dma - Generate a RapidIO maintenance write transaction
219+ * using Tsi721 BDMA engine
220+ * @mport: RapidIO master port control structure
221+ * @index: ID of RapdiIO interface
222+ * @destid: Destination ID of transaction
223+ * @hopcount: Number of hops to target device
224+ * @offset: Offset into configuration space
225+ * @len: Length (in bytes) of the maintenance transaction
226+ * @val: Value to be written
227+ *
228+ * Generates a RapidIO maintenance write transaction.
229+ * Returns %0 on success and %-EINVAL or %-EFAULT on failure.
230+ */
231+static int tsi721_cwrite_dma(struct rio_mport *mport, int index, u16 destid,
232+ u8 hopcount, u32 offset, int len, u32 data)
233+{
234+ struct tsi721_device *priv = mport->priv;
235+ u32 temp = data;
236+
237+ return tsi721_maint_dma(priv, mport->sys_size, destid, hopcount,
238+ offset, len, &temp, 1);
239+}
240+
241+/**
242+ * tsi721_pw_handler - Tsi721 inbound port-write interrupt handler
243+ * @mport: RapidIO master port structure
244+ *
245+ * Handles inbound port-write interrupts. Copies PW message from an internal
246+ * buffer into PW message FIFO and schedules deferred routine to process
247+ * queued messages.
248+ */
249+static int
250+tsi721_pw_handler(struct rio_mport *mport)
251+{
252+ struct tsi721_device *priv = mport->priv;
253+ u32 pw_stat;
254+ u32 pw_buf[TSI721_RIO_PW_MSG_SIZE/sizeof(u32)];
255+
256+
257+ pw_stat = ioread32(priv->regs + TSI721_RIO_PW_RX_STAT);
258+
259+ if (pw_stat & TSI721_RIO_PW_RX_STAT_PW_VAL) {
260+ pw_buf[0] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(0));
261+ pw_buf[1] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(1));
262+ pw_buf[2] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(2));
263+ pw_buf[3] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(3));
264+
265+ /* Queue PW message (if there is room in FIFO),
266+ * otherwise discard it.
267+ */
268+ spin_lock(&priv->pw_fifo_lock);
269+ if (kfifo_avail(&priv->pw_fifo) >= TSI721_RIO_PW_MSG_SIZE)
270+ kfifo_in(&priv->pw_fifo, pw_buf,
271+ TSI721_RIO_PW_MSG_SIZE);
272+ else
273+ priv->pw_discard_count++;
274+ spin_unlock(&priv->pw_fifo_lock);
275+ }
276+
277+ /* Clear pending PW interrupts */
278+ iowrite32(TSI721_RIO_PW_RX_STAT_PW_DISC | TSI721_RIO_PW_RX_STAT_PW_VAL,
279+ priv->regs + TSI721_RIO_PW_RX_STAT);
280+
281+ schedule_work(&priv->pw_work);
282+
283+ return 0;
284+}
285+
286+static void tsi721_pw_dpc(struct work_struct *work)
287+{
288+ struct tsi721_device *priv = container_of(work, struct tsi721_device,
289+ pw_work);
290+ u32 msg_buffer[RIO_PW_MSG_SIZE/sizeof(u32)]; /* Use full size PW message
291+ buffer for RIO layer */
292+
293+ /*
294+ * Process port-write messages
295+ */
296+ while (kfifo_out_spinlocked(&priv->pw_fifo, (unsigned char *)msg_buffer,
297+ TSI721_RIO_PW_MSG_SIZE, &priv->pw_fifo_lock)) {
298+ /* Process one message */
299+#ifdef DEBUG_PW
300+ {
301+ u32 i;
302+ pr_debug("%s : Port-Write Message:", __func__);
303+ for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32); ) {
304+ pr_debug("0x%02x: %08x %08x %08x %08x", i*4,
305+ msg_buffer[i], msg_buffer[i + 1],
306+ msg_buffer[i + 2], msg_buffer[i + 3]);
307+ i += 4;
308+ }
309+ pr_debug("\n");
310+ }
311+#endif
312+ /* Pass the port-write message to RIO core for processing */
313+ rio_inb_pwrite_handler((union rio_pw_msg *)msg_buffer);
314+ }
315+}
316+
317+/**
318+ * tsi721_pw_enable - enable/disable port-write interface init
319+ * @mport: Master port implementing the port write unit
320+ * @enable: 1=enable; 0=disable port-write message handling
321+ */
322+static int tsi721_pw_enable(struct rio_mport *mport, int enable)
323+{
324+ struct tsi721_device *priv = mport->priv;
325+ u32 rval;
326+
327+ rval = ioread32(priv->regs + TSI721_RIO_EM_INT_ENABLE);
328+
329+ if (enable)
330+ rval |= TSI721_RIO_EM_INT_ENABLE_PW_RX;
331+ else
332+ rval &= ~TSI721_RIO_EM_INT_ENABLE_PW_RX;
333+
334+ /* Clear pending PW interrupts */
335+ iowrite32(TSI721_RIO_PW_RX_STAT_PW_DISC | TSI721_RIO_PW_RX_STAT_PW_VAL,
336+ priv->regs + TSI721_RIO_PW_RX_STAT);
337+ /* Update enable bits */
338+ iowrite32(rval, priv->regs + TSI721_RIO_EM_INT_ENABLE);
339+
340+ return 0;
341+}
342+
343+/**
344+ * tsi721_dsend - Send a RapidIO doorbell
345+ * @mport: RapidIO master port info
346+ * @index: ID of RapidIO interface
347+ * @destid: Destination ID of target device
348+ * @data: 16-bit info field of RapidIO doorbell
349+ *
350+ * Sends a RapidIO doorbell message. Always returns %0.
351+ */
352+static int tsi721_dsend(struct rio_mport *mport, int index,
353+ u16 destid, u16 data)
354+{
355+ struct tsi721_device *priv = mport->priv;
356+ u32 offset;
357+
358+ offset = (((mport->sys_size) ? RIO_TT_CODE_16 : RIO_TT_CODE_8) << 18) |
359+ (destid << 2);
360+
361+ dev_dbg(&priv->pdev->dev,
362+ "Send Doorbell 0x%04x to destID 0x%x\n", data, destid);
363+ iowrite16be(data, priv->odb_base + offset);
364+
365+ return 0;
366+}
367+
368+/**
369+ * tsi721_dbell_handler - Tsi721 doorbell interrupt handler
370+ * @mport: RapidIO master port structure
371+ *
372+ * Handles inbound doorbell interrupts. Copies doorbell entry from an internal
373+ * buffer into DB message FIFO and schedules deferred routine to process
374+ * queued DBs.
375+ */
376+static int
377+tsi721_dbell_handler(struct rio_mport *mport)
378+{
379+ struct tsi721_device *priv = mport->priv;
380+ u32 regval;
381+
382+ /* Disable IDB interrupts */
383+ regval = ioread32(priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
384+ regval &= ~TSI721_SR_CHINT_IDBQRCV;
385+ iowrite32(regval,
386+ priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
387+
388+ schedule_work(&priv->idb_work);
389+
390+ return 0;
391+}
392+
393+static void tsi721_db_dpc(struct work_struct *work)
394+{
395+ struct tsi721_device *priv = container_of(work, struct tsi721_device,
396+ idb_work);
397+ struct rio_mport *mport;
398+ struct rio_dbell *dbell;
399+ int found = 0;
400+ u32 wr_ptr, rd_ptr;
401+ u64 *idb_entry;
402+ u32 regval;
403+ union {
404+ u64 msg;
405+ u8 bytes[8];
406+ } idb;
407+
408+ /*
409+ * Process queued inbound doorbells
410+ */
411+ mport = priv->mport;
412+
413+ wr_ptr = ioread32(priv->regs + TSI721_IDQ_WP(IDB_QUEUE));
414+ rd_ptr = ioread32(priv->regs + TSI721_IDQ_RP(IDB_QUEUE));
415+
416+ while (wr_ptr != rd_ptr) {
417+ idb_entry = (u64 *)(priv->idb_base +
418+ (TSI721_IDB_ENTRY_SIZE * rd_ptr));
419+ rd_ptr++;
420+ idb.msg = *idb_entry;
421+ *idb_entry = 0;
422+
423+ /* Process one doorbell */
424+ list_for_each_entry(dbell, &mport->dbells, node) {
425+ if ((dbell->res->start <= DBELL_INF(idb.bytes)) &&
426+ (dbell->res->end >= DBELL_INF(idb.bytes))) {
427+ found = 1;
428+ break;
429+ }
430+ }
431+
432+ if (found) {
433+ dbell->dinb(mport, dbell->dev_id, DBELL_SID(idb.bytes),
434+ DBELL_TID(idb.bytes), DBELL_INF(idb.bytes));
435+ } else {
436+ dev_dbg(&priv->pdev->dev,
437+ "spurious inb doorbell, sid %2.2x tid %2.2x"
438+ " info %4.4x\n", DBELL_SID(idb.bytes),
439+ DBELL_TID(idb.bytes), DBELL_INF(idb.bytes));
440+ }
441+ }
442+
443+ iowrite32(rd_ptr & (IDB_QSIZE - 1),
444+ priv->regs + TSI721_IDQ_RP(IDB_QUEUE));
445+
446+ /* Re-enable IDB interrupts */
447+ regval = ioread32(priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
448+ regval |= TSI721_SR_CHINT_IDBQRCV;
449+ iowrite32(regval,
450+ priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
451+}
452+
453+/**
454+ * tsi721_irqhandler - Tsi721 interrupt handler
455+ * @irq: Linux interrupt number
456+ * @ptr: Pointer to interrupt-specific data (mport structure)
457+ *
458+ * Handles Tsi721 interrupts signaled using MSI and INTA. Checks reported
459+ * interrupt events and calls an event-specific handler(s).
460+ */
461+static irqreturn_t tsi721_irqhandler(int irq, void *ptr)
462+{
463+ struct rio_mport *mport = (struct rio_mport *)ptr;
464+ struct tsi721_device *priv = mport->priv;
465+ u32 dev_int;
466+ u32 dev_ch_int;
467+ u32 intval;
468+ u32 ch_inte;
469+
470+ dev_int = ioread32(priv->regs + TSI721_DEV_INT);
471+ if (!dev_int)
472+ return IRQ_NONE;
473+
474+ dev_ch_int = ioread32(priv->regs + TSI721_DEV_CHAN_INT);
475+
476+ if (dev_int & TSI721_DEV_INT_SR2PC_CH) {
477+ /* Service SR2PC Channel interrupts */
478+ if (dev_ch_int & TSI721_INT_SR2PC_CHAN(IDB_QUEUE)) {
479+ /* Service Inbound Doorbell interrupt */
480+ intval = ioread32(priv->regs +
481+ TSI721_SR_CHINT(IDB_QUEUE));
482+ if (intval & TSI721_SR_CHINT_IDBQRCV)
483+ tsi721_dbell_handler(mport);
484+ else
485+ dev_info(&priv->pdev->dev,
486+ "Unsupported SR_CH_INT %x\n", intval);
487+
488+ /* Clear interrupts */
489+ iowrite32(intval,
490+ priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
491+ ioread32(priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
492+ }
493+ }
494+
495+ if (dev_int & TSI721_DEV_INT_SMSG_CH) {
496+ int ch;
497+
498+ /*
499+ * Service channel interrupts from Messaging Engine
500+ */
501+
502+ if (dev_ch_int & TSI721_INT_IMSG_CHAN_M) { /* Inbound Msg */
503+ /* Disable signaled OB MSG Channel interrupts */
504+ ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
505+ ch_inte &= ~(dev_ch_int & TSI721_INT_IMSG_CHAN_M);
506+ iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
507+
508+ /*
509+ * Process Inbound Message interrupt for each MBOX
510+ */
511+ for (ch = 4; ch < RIO_MAX_MBOX + 4; ch++) {
512+ if (!(dev_ch_int & TSI721_INT_IMSG_CHAN(ch)))
513+ continue;
514+ tsi721_imsg_handler(priv, ch);
515+ }
516+ }
517+
518+ if (dev_ch_int & TSI721_INT_OMSG_CHAN_M) { /* Outbound Msg */
519+ /* Disable signaled OB MSG Channel interrupts */
520+ ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
521+ ch_inte &= ~(dev_ch_int & TSI721_INT_OMSG_CHAN_M);
522+ iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
523+
524+ /*
525+ * Process Outbound Message interrupts for each MBOX
526+ */
527+
528+ for (ch = 0; ch < RIO_MAX_MBOX; ch++) {
529+ if (!(dev_ch_int & TSI721_INT_OMSG_CHAN(ch)))
530+ continue;
531+ tsi721_omsg_handler(priv, ch);
532+ }
533+ }
534+ }
535+
536+ if (dev_int & TSI721_DEV_INT_SRIO) {
537+ /* Service SRIO MAC interrupts */
538+ intval = ioread32(priv->regs + TSI721_RIO_EM_INT_STAT);
539+ if (intval & TSI721_RIO_EM_INT_STAT_PW_RX)
540+ tsi721_pw_handler(mport);
541+ }
542+
543+ return IRQ_HANDLED;
544+}
545+
546+static void tsi721_interrupts_init(struct tsi721_device *priv)
547+{
548+ u32 intr;
549+
550+ /* Enable IDB interrupts */
551+ iowrite32(TSI721_SR_CHINT_ALL,
552+ priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
553+ iowrite32(TSI721_SR_CHINT_IDBQRCV,
554+ priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
555+ iowrite32(TSI721_INT_SR2PC_CHAN(IDB_QUEUE),
556+ priv->regs + TSI721_DEV_CHAN_INTE);
557+
558+ /* Enable SRIO MAC interrupts */
559+ iowrite32(TSI721_RIO_EM_DEV_INT_EN_INT,
560+ priv->regs + TSI721_RIO_EM_DEV_INT_EN);
561+
562+ if (priv->flags & TSI721_USING_MSIX)
563+ intr = TSI721_DEV_INT_SRIO;
564+ else
565+ intr = TSI721_DEV_INT_SR2PC_CH | TSI721_DEV_INT_SRIO |
566+ TSI721_DEV_INT_SMSG_CH;
567+
568+ iowrite32(intr, priv->regs + TSI721_DEV_INTE);
569+ ioread32(priv->regs + TSI721_DEV_INTE);
570+}
571+
572+#ifdef CONFIG_PCI_MSI
573+/**
574+ * tsi721_omsg_msix - MSI-X interrupt handler for outbound messaging
575+ * @irq: Linux interrupt number
576+ * @ptr: Pointer to interrupt-specific data (mport structure)
577+ *
578+ * Handles outbound messaging interrupts signaled using MSI-X.
579+ */
580+static irqreturn_t tsi721_omsg_msix(int irq, void *ptr)
581+{
582+ struct tsi721_device *priv = ((struct rio_mport *)ptr)->priv;
583+ int mbox;
584+
585+ mbox = (irq - priv->msix[TSI721_VECT_OMB0_DONE].vector) % RIO_MAX_MBOX;
586+ tsi721_omsg_handler(priv, mbox);
587+ return IRQ_HANDLED;
588+}
589+
590+/**
591+ * tsi721_imsg_msix - MSI-X interrupt handler for inbound messaging
592+ * @irq: Linux interrupt number
593+ * @ptr: Pointer to interrupt-specific data (mport structure)
594+ *
595+ * Handles inbound messaging interrupts signaled using MSI-X.
596+ */
597+static irqreturn_t tsi721_imsg_msix(int irq, void *ptr)
598+{
599+ struct tsi721_device *priv = ((struct rio_mport *)ptr)->priv;
600+ int mbox;
601+
602+ mbox = (irq - priv->msix[TSI721_VECT_IMB0_RCV].vector) % RIO_MAX_MBOX;
603+ tsi721_imsg_handler(priv, mbox + 4);
604+ return IRQ_HANDLED;
605+}
606+
607+/**
608+ * tsi721_srio_msix - Tsi721 MSI-X SRIO MAC interrupt handler
609+ * @irq: Linux interrupt number
610+ * @ptr: Pointer to interrupt-specific data (mport structure)
611+ *
612+ * Handles Tsi721 interrupts from SRIO MAC.
613+ */
614+static irqreturn_t tsi721_srio_msix(int irq, void *ptr)
615+{
616+ struct tsi721_device *priv = ((struct rio_mport *)ptr)->priv;
617+ u32 srio_int;
618+
619+ /* Service SRIO MAC interrupts */
620+ srio_int = ioread32(priv->regs + TSI721_RIO_EM_INT_STAT);
621+ if (srio_int & TSI721_RIO_EM_INT_STAT_PW_RX)
622+ tsi721_pw_handler((struct rio_mport *)ptr);
623+
624+ return IRQ_HANDLED;
625+}
626+
627+/**
628+ * tsi721_sr2pc_ch_msix - Tsi721 MSI-X SR2PC Channel interrupt handler
629+ * @irq: Linux interrupt number
630+ * @ptr: Pointer to interrupt-specific data (mport structure)
631+ *
632+ * Handles Tsi721 interrupts from SR2PC Channel.
633+ * NOTE: At this moment services only one SR2PC channel associated with inbound
634+ * doorbells.
635+ */
636+static irqreturn_t tsi721_sr2pc_ch_msix(int irq, void *ptr)
637+{
638+ struct tsi721_device *priv = ((struct rio_mport *)ptr)->priv;
639+ u32 sr_ch_int;
640+
641+ /* Service Inbound DB interrupt from SR2PC channel */
642+ sr_ch_int = ioread32(priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
643+ if (sr_ch_int & TSI721_SR_CHINT_IDBQRCV)
644+ tsi721_dbell_handler((struct rio_mport *)ptr);
645+
646+ /* Clear interrupts */
647+ iowrite32(sr_ch_int, priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
648+ /* Read back to ensure that interrupt was cleared */
649+ sr_ch_int = ioread32(priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
650+
651+ return IRQ_HANDLED;
652+}
653+
654+/**
655+ * tsi721_request_msix - register interrupt service for MSI-X mode.
656+ * @mport: RapidIO master port structure
657+ *
658+ * Registers MSI-X interrupt service routines for interrupts that are active
659+ * immediately after mport initialization. Messaging interrupt service routines
660+ * should be registered during corresponding open requests.
661+ */
662+static int tsi721_request_msix(struct rio_mport *mport)
663+{
664+ struct tsi721_device *priv = mport->priv;
665+ int err = 0;
666+
667+ err = request_irq(priv->msix[TSI721_VECT_IDB].vector,
668+ tsi721_sr2pc_ch_msix, 0,
669+ priv->msix[TSI721_VECT_IDB].irq_name, (void *)mport);
670+ if (err)
671+ goto out;
672+
673+ err = request_irq(priv->msix[TSI721_VECT_PWRX].vector,
674+ tsi721_srio_msix, 0,
675+ priv->msix[TSI721_VECT_PWRX].irq_name, (void *)mport);
676+ if (err)
677+ free_irq(
678+ priv->msix[TSI721_VECT_IDB].vector,
679+ (void *)mport);
680+out:
681+ return err;
682+}
683+
684+/**
685+ * tsi721_enable_msix - Attempts to enable MSI-X support for Tsi721.
686+ * @priv: pointer to tsi721 private data
687+ *
688+ * Configures MSI-X support for Tsi721. Supports only an exact number
689+ * of requested vectors.
690+ */
691+static int tsi721_enable_msix(struct tsi721_device *priv)
692+{
693+ struct msix_entry entries[TSI721_VECT_MAX];
694+ int err;
695+ int i;
696+
697+ entries[TSI721_VECT_IDB].entry = TSI721_MSIX_SR2PC_IDBQ_RCV(IDB_QUEUE);
698+ entries[TSI721_VECT_PWRX].entry = TSI721_MSIX_SRIO_MAC_INT;
699+
700+ /*
701+ * Initialize MSI-X entries for Messaging Engine:
702+ * this driver supports four RIO mailboxes (inbound and outbound)
703+ * NOTE: Inbound message MBOX 0...4 use IB channels 4...7. Therefore
704+ * offset +4 is added to IB MBOX number.
705+ */
706+ for (i = 0; i < RIO_MAX_MBOX; i++) {
707+ entries[TSI721_VECT_IMB0_RCV + i].entry =
708+ TSI721_MSIX_IMSG_DQ_RCV(i + 4);
709+ entries[TSI721_VECT_IMB0_INT + i].entry =
710+ TSI721_MSIX_IMSG_INT(i + 4);
711+ entries[TSI721_VECT_OMB0_DONE + i].entry =
712+ TSI721_MSIX_OMSG_DONE(i);
713+ entries[TSI721_VECT_OMB0_INT + i].entry =
714+ TSI721_MSIX_OMSG_INT(i);
715+ }
716+
717+ err = pci_enable_msix(priv->pdev, entries, ARRAY_SIZE(entries));
718+ if (err) {
719+ if (err > 0)
720+ dev_info(&priv->pdev->dev,
721+ "Only %d MSI-X vectors available, "
722+ "not using MSI-X\n", err);
723+ return err;
724+ }
725+
726+ /*
727+ * Copy MSI-X vector information into tsi721 private structure
728+ */
729+ priv->msix[TSI721_VECT_IDB].vector = entries[TSI721_VECT_IDB].vector;
730+ snprintf(priv->msix[TSI721_VECT_IDB].irq_name, IRQ_DEVICE_NAME_MAX,
731+ DRV_NAME "-idb@pci:%s", pci_name(priv->pdev));
732+ priv->msix[TSI721_VECT_PWRX].vector = entries[TSI721_VECT_PWRX].vector;
733+ snprintf(priv->msix[TSI721_VECT_PWRX].irq_name, IRQ_DEVICE_NAME_MAX,
734+ DRV_NAME "-pwrx@pci:%s", pci_name(priv->pdev));
735+
736+ for (i = 0; i < RIO_MAX_MBOX; i++) {
737+ priv->msix[TSI721_VECT_IMB0_RCV + i].vector =
738+ entries[TSI721_VECT_IMB0_RCV + i].vector;
739+ snprintf(priv->msix[TSI721_VECT_IMB0_RCV + i].irq_name,
740+ IRQ_DEVICE_NAME_MAX, DRV_NAME "-imbr%d@pci:%s",
741+ i, pci_name(priv->pdev));
742+
743+ priv->msix[TSI721_VECT_IMB0_INT + i].vector =
744+ entries[TSI721_VECT_IMB0_INT + i].vector;
745+ snprintf(priv->msix[TSI721_VECT_IMB0_INT + i].irq_name,
746+ IRQ_DEVICE_NAME_MAX, DRV_NAME "-imbi%d@pci:%s",
747+ i, pci_name(priv->pdev));
748+
749+ priv->msix[TSI721_VECT_OMB0_DONE + i].vector =
750+ entries[TSI721_VECT_OMB0_DONE + i].vector;
751+ snprintf(priv->msix[TSI721_VECT_OMB0_DONE + i].irq_name,
752+ IRQ_DEVICE_NAME_MAX, DRV_NAME "-ombd%d@pci:%s",
753+ i, pci_name(priv->pdev));
754+
755+ priv->msix[TSI721_VECT_OMB0_INT + i].vector =
756+ entries[TSI721_VECT_OMB0_INT + i].vector;
757+ snprintf(priv->msix[TSI721_VECT_OMB0_INT + i].irq_name,
758+ IRQ_DEVICE_NAME_MAX, DRV_NAME "-ombi%d@pci:%s",
759+ i, pci_name(priv->pdev));
760+ }
761+
762+ return 0;
763+}
764+#endif /* CONFIG_PCI_MSI */
765+
766+static int tsi721_request_irq(struct rio_mport *mport)
767+{
768+ struct tsi721_device *priv = mport->priv;
769+ int err;
770+
771+#ifdef CONFIG_PCI_MSI
772+ if (priv->flags & TSI721_USING_MSIX)
773+ err = tsi721_request_msix(mport);
774+ else
775+#endif
776+ err = request_irq(priv->pdev->irq, tsi721_irqhandler,
777+ (priv->flags & TSI721_USING_MSI) ? 0 : IRQF_SHARED,
778+ DRV_NAME, (void *)mport);
779+
780+ if (err)
781+ dev_err(&priv->pdev->dev,
782+ "Unable to allocate interrupt, Error: %d\n", err);
783+
784+ return err;
785+}
786+
787+/**
788+ * tsi721_init_pc2sr_mapping - initializes outbound (PCIe->SRIO)
789+ * translation regions.
790+ * @priv: pointer to tsi721 private data
791+ *
792+ * Disables SREP translation regions.
793+ */
794+static void tsi721_init_pc2sr_mapping(struct tsi721_device *priv)
795+{
796+ int i;
797+
798+ /* Disable all PC2SR translation windows */
799+ for (i = 0; i < TSI721_OBWIN_NUM; i++)
800+ iowrite32(0, priv->regs + TSI721_OBWINLB(i));
801+}
802+
803+/**
804+ * tsi721_init_sr2pc_mapping - initializes inbound (SRIO->PCIe)
805+ * translation regions.
806+ * @priv: pointer to tsi721 private data
807+ *
808+ * Disables inbound windows.
809+ */
810+static void tsi721_init_sr2pc_mapping(struct tsi721_device *priv)
811+{
812+ int i;
813+
814+ /* Disable all SR2PC inbound windows */
815+ for (i = 0; i < TSI721_IBWIN_NUM; i++)
816+ iowrite32(0, priv->regs + TSI721_IBWINLB(i));
817+}
818+
819+/**
820+ * tsi721_port_write_init - Inbound port write interface init
821+ * @priv: pointer to tsi721 private data
822+ *
823+ * Initializes inbound port write handler.
824+ * Returns %0 on success or %-ENOMEM on failure.
825+ */
826+static int tsi721_port_write_init(struct tsi721_device *priv)
827+{
828+ priv->pw_discard_count = 0;
829+ INIT_WORK(&priv->pw_work, tsi721_pw_dpc);
830+ spin_lock_init(&priv->pw_fifo_lock);
831+ if (kfifo_alloc(&priv->pw_fifo,
832+ TSI721_RIO_PW_MSG_SIZE * 32, GFP_KERNEL)) {
833+ dev_err(&priv->pdev->dev, "PW FIFO allocation failed\n");
834+ return -ENOMEM;
835+ }
836+
837+ /* Use reliable port-write capture mode */
838+ iowrite32(TSI721_RIO_PW_CTL_PWC_REL, priv->regs + TSI721_RIO_PW_CTL);
839+ return 0;
840+}
841+
842+static int tsi721_doorbell_init(struct tsi721_device *priv)
843+{
844+ /* Outbound Doorbells do not require any setup.
845+ * Tsi721 uses dedicated PCI BAR1 to generate doorbells.
846+ * That BAR1 was mapped during the probe routine.
847+ */
848+
849+ /* Initialize Inbound Doorbell processing DPC and queue */
850+ priv->db_discard_count = 0;
851+ INIT_WORK(&priv->idb_work, tsi721_db_dpc);
852+
853+ /* Allocate buffer for inbound doorbells queue */
854+ priv->idb_base = dma_alloc_coherent(&priv->pdev->dev,
855+ IDB_QSIZE * TSI721_IDB_ENTRY_SIZE,
856+ &priv->idb_dma, GFP_KERNEL);
857+ if (!priv->idb_base)
858+ return -ENOMEM;
859+
860+ memset(priv->idb_base, 0, IDB_QSIZE * TSI721_IDB_ENTRY_SIZE);
861+
862+ dev_dbg(&priv->pdev->dev, "Allocated IDB buffer @ %p (phys = %llx)\n",
863+ priv->idb_base, (unsigned long long)priv->idb_dma);
864+
865+ iowrite32(TSI721_IDQ_SIZE_VAL(IDB_QSIZE),
866+ priv->regs + TSI721_IDQ_SIZE(IDB_QUEUE));
867+ iowrite32(((u64)priv->idb_dma >> 32),
868+ priv->regs + TSI721_IDQ_BASEU(IDB_QUEUE));
869+ iowrite32(((u64)priv->idb_dma & TSI721_IDQ_BASEL_ADDR),
870+ priv->regs + TSI721_IDQ_BASEL(IDB_QUEUE));
871+ /* Enable accepting all inbound doorbells */
872+ iowrite32(0, priv->regs + TSI721_IDQ_MASK(IDB_QUEUE));
873+
874+ iowrite32(TSI721_IDQ_INIT, priv->regs + TSI721_IDQ_CTL(IDB_QUEUE));
875+
876+ iowrite32(0, priv->regs + TSI721_IDQ_RP(IDB_QUEUE));
877+
878+ return 0;
879+}
880+
881+static void tsi721_doorbell_free(struct tsi721_device *priv)
882+{
883+ if (priv->idb_base == NULL)
884+ return;
885+
886+ /* Free buffer allocated for inbound doorbell queue */
887+ dma_free_coherent(&priv->pdev->dev, IDB_QSIZE * TSI721_IDB_ENTRY_SIZE,
888+ priv->idb_base, priv->idb_dma);
889+ priv->idb_base = NULL;
890+}
891+
892+static int tsi721_bdma_ch_init(struct tsi721_device *priv, int chnum)
893+{
894+ struct tsi721_dma_desc *bd_ptr;
895+ u64 *sts_ptr;
896+ dma_addr_t bd_phys, sts_phys;
897+ int sts_size;
898+ int bd_num = priv->bdma[chnum].bd_num;
899+
900+ dev_dbg(&priv->pdev->dev, "Init Block DMA Engine, CH%d\n", chnum);
901+
902+ /*
903+ * Initialize DMA channel for maintenance requests
904+ */
905+
906+ /* Allocate space for DMA descriptors */
907+ bd_ptr = dma_alloc_coherent(&priv->pdev->dev,
908+ bd_num * sizeof(struct tsi721_dma_desc),
909+ &bd_phys, GFP_KERNEL);
910+ if (!bd_ptr)
911+ return -ENOMEM;
912+
913+ priv->bdma[chnum].bd_phys = bd_phys;
914+ priv->bdma[chnum].bd_base = bd_ptr;
915+
916+ memset(bd_ptr, 0, bd_num * sizeof(struct tsi721_dma_desc));
917+
918+ dev_dbg(&priv->pdev->dev, "DMA descriptors @ %p (phys = %llx)\n",
919+ bd_ptr, (unsigned long long)bd_phys);
920+
921+ /* Allocate space for descriptor status FIFO */
922+ sts_size = (bd_num >= TSI721_DMA_MINSTSSZ) ?
923+ bd_num : TSI721_DMA_MINSTSSZ;
924+ sts_size = roundup_pow_of_two(sts_size);
925+ sts_ptr = dma_alloc_coherent(&priv->pdev->dev,
926+ sts_size * sizeof(struct tsi721_dma_sts),
927+ &sts_phys, GFP_KERNEL);
928+ if (!sts_ptr) {
929+ /* Free space allocated for DMA descriptors */
930+ dma_free_coherent(&priv->pdev->dev,
931+ bd_num * sizeof(struct tsi721_dma_desc),
932+ bd_ptr, bd_phys);
933+ priv->bdma[chnum].bd_base = NULL;
934+ return -ENOMEM;
935+ }
936+
937+ priv->bdma[chnum].sts_phys = sts_phys;
938+ priv->bdma[chnum].sts_base = sts_ptr;
939+ priv->bdma[chnum].sts_size = sts_size;
940+
941+ memset(sts_ptr, 0, sts_size);
942+
943+ dev_dbg(&priv->pdev->dev,
944+ "desc status FIFO @ %p (phys = %llx) size=0x%x\n",
945+ sts_ptr, (unsigned long long)sts_phys, sts_size);
946+
947+ /* Initialize DMA descriptors ring */
948+ bd_ptr[bd_num - 1].type_id = cpu_to_le32(DTYPE3 << 29);
949+ bd_ptr[bd_num - 1].next_lo = cpu_to_le32((u64)bd_phys &
950+ TSI721_DMAC_DPTRL_MASK);
951+ bd_ptr[bd_num - 1].next_hi = cpu_to_le32((u64)bd_phys >> 32);
952+
953+ /* Setup DMA descriptor pointers */
954+ iowrite32(((u64)bd_phys >> 32),
955+ priv->regs + TSI721_DMAC_DPTRH(chnum));
956+ iowrite32(((u64)bd_phys & TSI721_DMAC_DPTRL_MASK),
957+ priv->regs + TSI721_DMAC_DPTRL(chnum));
958+
959+ /* Setup descriptor status FIFO */
960+ iowrite32(((u64)sts_phys >> 32),
961+ priv->regs + TSI721_DMAC_DSBH(chnum));
962+ iowrite32(((u64)sts_phys & TSI721_DMAC_DSBL_MASK),
963+ priv->regs + TSI721_DMAC_DSBL(chnum));
964+ iowrite32(TSI721_DMAC_DSSZ_SIZE(sts_size),
965+ priv->regs + TSI721_DMAC_DSSZ(chnum));
966+
967+ /* Clear interrupt bits */
968+ iowrite32(TSI721_DMAC_INT_ALL,
969+ priv->regs + TSI721_DMAC_INT(chnum));
970+
971+ ioread32(priv->regs + TSI721_DMAC_INT(chnum));
972+
973+ /* Toggle DMA channel initialization */
974+ iowrite32(TSI721_DMAC_CTL_INIT, priv->regs + TSI721_DMAC_CTL(chnum));
975+ ioread32(priv->regs + TSI721_DMAC_CTL(chnum));
976+ udelay(10);
977+
978+ return 0;
979+}
980+
981+static int tsi721_bdma_ch_free(struct tsi721_device *priv, int chnum)
982+{
983+ u32 ch_stat;
984+
985+ if (priv->bdma[chnum].bd_base == NULL)
986+ return 0;
987+
988+ /* Check if DMA channel still running */
989+ ch_stat = ioread32(priv->regs + TSI721_DMAC_STS(chnum));
990+ if (ch_stat & TSI721_DMAC_STS_RUN)
991+ return -EFAULT;
992+
993+ /* Put DMA channel into init state */
994+ iowrite32(TSI721_DMAC_CTL_INIT,
995+ priv->regs + TSI721_DMAC_CTL(chnum));
996+
997+ /* Free space allocated for DMA descriptors */
998+ dma_free_coherent(&priv->pdev->dev,
999+ priv->bdma[chnum].bd_num * sizeof(struct tsi721_dma_desc),
1000+ priv->bdma[chnum].bd_base, priv->bdma[chnum].bd_phys);
1001+ priv->bdma[chnum].bd_base = NULL;
1002+
1003+ /* Free space allocated for status FIFO */
1004+ dma_free_coherent(&priv->pdev->dev,
1005+ priv->bdma[chnum].sts_size * sizeof(struct tsi721_dma_sts),
1006+ priv->bdma[chnum].sts_base, priv->bdma[chnum].sts_phys);
1007+ priv->bdma[chnum].sts_base = NULL;
1008+ return 0;
1009+}
1010+
1011+static int tsi721_bdma_init(struct tsi721_device *priv)
1012+{
1013+ /* Initialize BDMA channel allocated for RapidIO maintenance read/write
1014+ * request generation
1015+ */
1016+ priv->bdma[TSI721_DMACH_MAINT].bd_num = 2;
1017+ if (tsi721_bdma_ch_init(priv, TSI721_DMACH_MAINT)) {
1018+ dev_err(&priv->pdev->dev, "Unable to initialize maintenance DMA"
1019+ " channel %d, aborting\n", TSI721_DMACH_MAINT);
1020+ return -ENOMEM;
1021+ }
1022+
1023+ return 0;
1024+}
1025+
1026+static void tsi721_bdma_free(struct tsi721_device *priv)
1027+{
1028+ tsi721_bdma_ch_free(priv, TSI721_DMACH_MAINT);
1029+}
1030+
1031+/* Enable Inbound Messaging Interrupts */
1032+static void
1033+tsi721_imsg_interrupt_enable(struct tsi721_device *priv, int ch,
1034+ u32 inte_mask)
1035+{
1036+ u32 rval;
1037+
1038+ if (!inte_mask)
1039+ return;
1040+
1041+ /* Clear pending Inbound Messaging interrupts */
1042+ iowrite32(inte_mask, priv->regs + TSI721_IBDMAC_INT(ch));
1043+
1044+ /* Enable Inbound Messaging interrupts */
1045+ rval = ioread32(priv->regs + TSI721_IBDMAC_INTE(ch));
1046+ iowrite32(rval | inte_mask, priv->regs + TSI721_IBDMAC_INTE(ch));
1047+
1048+ if (priv->flags & TSI721_USING_MSIX)
1049+ return; /* Finished if we are in MSI-X mode */
1050+
1051+ /*
1052+ * For MSI and INTA interrupt signalling we need to enable next levels
1053+ */
1054+
1055+ /* Enable Device Channel Interrupt */
1056+ rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1057+ iowrite32(rval | TSI721_INT_IMSG_CHAN(ch),
1058+ priv->regs + TSI721_DEV_CHAN_INTE);
1059+}
1060+
1061+/* Disable Inbound Messaging Interrupts */
1062+static void
1063+tsi721_imsg_interrupt_disable(struct tsi721_device *priv, int ch,
1064+ u32 inte_mask)
1065+{
1066+ u32 rval;
1067+
1068+ if (!inte_mask)
1069+ return;
1070+
1071+ /* Clear pending Inbound Messaging interrupts */
1072+ iowrite32(inte_mask, priv->regs + TSI721_IBDMAC_INT(ch));
1073+
1074+ /* Disable Inbound Messaging interrupts */
1075+ rval = ioread32(priv->regs + TSI721_IBDMAC_INTE(ch));
1076+ rval &= ~inte_mask;
1077+ iowrite32(rval, priv->regs + TSI721_IBDMAC_INTE(ch));
1078+
1079+ if (priv->flags & TSI721_USING_MSIX)
1080+ return; /* Finished if we are in MSI-X mode */
1081+
1082+ /*
1083+ * For MSI and INTA interrupt signalling we need to disable next levels
1084+ */
1085+
1086+ /* Disable Device Channel Interrupt */
1087+ rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1088+ rval &= ~TSI721_INT_IMSG_CHAN(ch);
1089+ iowrite32(rval, priv->regs + TSI721_DEV_CHAN_INTE);
1090+}
1091+
1092+/* Enable Outbound Messaging interrupts */
1093+static void
1094+tsi721_omsg_interrupt_enable(struct tsi721_device *priv, int ch,
1095+ u32 inte_mask)
1096+{
1097+ u32 rval;
1098+
1099+ if (!inte_mask)
1100+ return;
1101+
1102+ /* Clear pending Outbound Messaging interrupts */
1103+ iowrite32(inte_mask, priv->regs + TSI721_OBDMAC_INT(ch));
1104+
1105+ /* Enable Outbound Messaging channel interrupts */
1106+ rval = ioread32(priv->regs + TSI721_OBDMAC_INTE(ch));
1107+ iowrite32(rval | inte_mask, priv->regs + TSI721_OBDMAC_INTE(ch));
1108+
1109+ if (priv->flags & TSI721_USING_MSIX)
1110+ return; /* Finished if we are in MSI-X mode */
1111+
1112+ /*
1113+ * For MSI and INTA interrupt signalling we need to enable next levels
1114+ */
1115+
1116+ /* Enable Device Channel Interrupt */
1117+ rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1118+ iowrite32(rval | TSI721_INT_OMSG_CHAN(ch),
1119+ priv->regs + TSI721_DEV_CHAN_INTE);
1120+}
1121+
1122+/* Disable Outbound Messaging interrupts */
1123+static void
1124+tsi721_omsg_interrupt_disable(struct tsi721_device *priv, int ch,
1125+ u32 inte_mask)
1126+{
1127+ u32 rval;
1128+
1129+ if (!inte_mask)
1130+ return;
1131+
1132+ /* Clear pending Outbound Messaging interrupts */
1133+ iowrite32(inte_mask, priv->regs + TSI721_OBDMAC_INT(ch));
1134+
1135+ /* Disable Outbound Messaging interrupts */
1136+ rval = ioread32(priv->regs + TSI721_OBDMAC_INTE(ch));
1137+ rval &= ~inte_mask;
1138+ iowrite32(rval, priv->regs + TSI721_OBDMAC_INTE(ch));
1139+
1140+ if (priv->flags & TSI721_USING_MSIX)
1141+ return; /* Finished if we are in MSI-X mode */
1142+
1143+ /*
1144+ * For MSI and INTA interrupt signalling we need to disable next levels
1145+ */
1146+
1147+ /* Disable Device Channel Interrupt */
1148+ rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1149+ rval &= ~TSI721_INT_OMSG_CHAN(ch);
1150+ iowrite32(rval, priv->regs + TSI721_DEV_CHAN_INTE);
1151+}
1152+
1153+/**
1154+ * tsi721_add_outb_message - Add message to the Tsi721 outbound message queue
1155+ * @mport: Master port with outbound message queue
1156+ * @rdev: Target of outbound message
1157+ * @mbox: Outbound mailbox
1158+ * @buffer: Message to add to outbound queue
1159+ * @len: Length of message
1160+ */
1161+static int
1162+tsi721_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox,
1163+ void *buffer, size_t len)
1164+{
1165+ struct tsi721_device *priv = mport->priv;
1166+ struct tsi721_omsg_desc *desc;
1167+ u32 tx_slot;
1168+
1169+ if (!priv->omsg_init[mbox] ||
1170+ len > TSI721_MSG_MAX_SIZE || len < 8)
1171+ return -EINVAL;
1172+
1173+ tx_slot = priv->omsg_ring[mbox].tx_slot;
1174+
1175+ /* Copy copy message into transfer buffer */
1176+ memcpy(priv->omsg_ring[mbox].omq_base[tx_slot], buffer, len);
1177+
1178+ if (len & 0x7)
1179+ len += 8;
1180+
1181+ /* Build descriptor associated with buffer */
1182+ desc = priv->omsg_ring[mbox].omd_base;
1183+ desc[tx_slot].type_id = cpu_to_le32((DTYPE4 << 29) | rdev->destid);
1184+ if (tx_slot % 4 == 0)
1185+ desc[tx_slot].type_id |= cpu_to_le32(TSI721_OMD_IOF);
1186+
1187+ desc[tx_slot].msg_info =
1188+ cpu_to_le32((mport->sys_size << 26) | (mbox << 22) |
1189+ (0xe << 12) | (len & 0xff8));
1190+ desc[tx_slot].bufptr_lo =
1191+ cpu_to_le32((u64)priv->omsg_ring[mbox].omq_phys[tx_slot] &
1192+ 0xffffffff);
1193+ desc[tx_slot].bufptr_hi =
1194+ cpu_to_le32((u64)priv->omsg_ring[mbox].omq_phys[tx_slot] >> 32);
1195+
1196+ priv->omsg_ring[mbox].wr_count++;
1197+
1198+ /* Go to next descriptor */
1199+ if (++priv->omsg_ring[mbox].tx_slot == priv->omsg_ring[mbox].size) {
1200+ priv->omsg_ring[mbox].tx_slot = 0;
1201+ /* Move through the ring link descriptor at the end */
1202+ priv->omsg_ring[mbox].wr_count++;
1203+ }
1204+
1205+ mb();
1206+
1207+ /* Set new write count value */
1208+ iowrite32(priv->omsg_ring[mbox].wr_count,
1209+ priv->regs + TSI721_OBDMAC_DWRCNT(mbox));
1210+ ioread32(priv->regs + TSI721_OBDMAC_DWRCNT(mbox));
1211+
1212+ return 0;
1213+}
1214+
1215+/**
1216+ * tsi721_omsg_handler - Outbound Message Interrupt Handler
1217+ * @priv: pointer to tsi721 private data
1218+ * @ch: number of OB MSG channel to service
1219+ *
1220+ * Services channel interrupts from outbound messaging engine.
1221+ */
1222+static void tsi721_omsg_handler(struct tsi721_device *priv, int ch)
1223+{
1224+ u32 omsg_int;
1225+
1226+ spin_lock(&priv->omsg_ring[ch].lock);
1227+
1228+ omsg_int = ioread32(priv->regs + TSI721_OBDMAC_INT(ch));
1229+
1230+ if (omsg_int & TSI721_OBDMAC_INT_ST_FULL)
1231+ dev_info(&priv->pdev->dev,
1232+ "OB MBOX%d: Status FIFO is full\n", ch);
1233+
1234+ if (omsg_int & (TSI721_OBDMAC_INT_DONE | TSI721_OBDMAC_INT_IOF_DONE)) {
1235+ u32 srd_ptr;
1236+ u64 *sts_ptr, last_ptr = 0, prev_ptr = 0;
1237+ int i, j;
1238+ u32 tx_slot;
1239+
1240+ /*
1241+ * Find last successfully processed descriptor
1242+ */
1243+
1244+ /* Check and clear descriptor status FIFO entries */
1245+ srd_ptr = priv->omsg_ring[ch].sts_rdptr;
1246+ sts_ptr = priv->omsg_ring[ch].sts_base;
1247+ j = srd_ptr * 8;
1248+ while (sts_ptr[j]) {
1249+ for (i = 0; i < 8 && sts_ptr[j]; i++, j++) {
1250+ prev_ptr = last_ptr;
1251+ last_ptr = le64_to_cpu(sts_ptr[j]);
1252+ sts_ptr[j] = 0;
1253+ }
1254+
1255+ ++srd_ptr;
1256+ srd_ptr %= priv->omsg_ring[ch].sts_size;
1257+ j = srd_ptr * 8;
1258+ }
1259+
1260+ if (last_ptr == 0)
1261+ goto no_sts_update;
1262+
1263+ priv->omsg_ring[ch].sts_rdptr = srd_ptr;
1264+ iowrite32(srd_ptr, priv->regs + TSI721_OBDMAC_DSRP(ch));
1265+
1266+ if (!priv->mport->outb_msg[ch].mcback)
1267+ goto no_sts_update;
1268+
1269+ /* Inform upper layer about transfer completion */
1270+
1271+ tx_slot = (last_ptr - (u64)priv->omsg_ring[ch].omd_phys)/
1272+ sizeof(struct tsi721_omsg_desc);
1273+
1274+ /*
1275+ * Check if this is a Link Descriptor (LD).
1276+ * If yes, ignore LD and use descriptor processed
1277+ * before LD.
1278+ */
1279+ if (tx_slot == priv->omsg_ring[ch].size) {
1280+ if (prev_ptr)
1281+ tx_slot = (prev_ptr -
1282+ (u64)priv->omsg_ring[ch].omd_phys)/
1283+ sizeof(struct tsi721_omsg_desc);
1284+ else
1285+ goto no_sts_update;
1286+ }
1287+
1288+ /* Move slot index to the next message to be sent */
1289+ ++tx_slot;
1290+ if (tx_slot == priv->omsg_ring[ch].size)
1291+ tx_slot = 0;
1292+ BUG_ON(tx_slot >= priv->omsg_ring[ch].size);
1293+ priv->mport->outb_msg[ch].mcback(priv->mport,
1294+ priv->omsg_ring[ch].dev_id, ch,
1295+ tx_slot);
1296+ }
1297+
1298+no_sts_update:
1299+
1300+ if (omsg_int & TSI721_OBDMAC_INT_ERROR) {
1301+ /*
1302+ * Outbound message operation aborted due to error,
1303+ * reinitialize OB MSG channel
1304+ */
1305+
1306+ dev_dbg(&priv->pdev->dev, "OB MSG ABORT ch_stat=%x\n",
1307+ ioread32(priv->regs + TSI721_OBDMAC_STS(ch)));
1308+
1309+ iowrite32(TSI721_OBDMAC_INT_ERROR,
1310+ priv->regs + TSI721_OBDMAC_INT(ch));
1311+ iowrite32(TSI721_OBDMAC_CTL_INIT,
1312+ priv->regs + TSI721_OBDMAC_CTL(ch));
1313+ ioread32(priv->regs + TSI721_OBDMAC_CTL(ch));
1314+
1315+ /* Inform upper level to clear all pending tx slots */
1316+ if (priv->mport->outb_msg[ch].mcback)
1317+ priv->mport->outb_msg[ch].mcback(priv->mport,
1318+ priv->omsg_ring[ch].dev_id, ch,
1319+ priv->omsg_ring[ch].tx_slot);
1320+ /* Synch tx_slot tracking */
1321+ iowrite32(priv->omsg_ring[ch].tx_slot,
1322+ priv->regs + TSI721_OBDMAC_DRDCNT(ch));
1323+ ioread32(priv->regs + TSI721_OBDMAC_DRDCNT(ch));
1324+ priv->omsg_ring[ch].wr_count = priv->omsg_ring[ch].tx_slot;
1325+ priv->omsg_ring[ch].sts_rdptr = 0;
1326+ }
1327+
1328+ /* Clear channel interrupts */
1329+ iowrite32(omsg_int, priv->regs + TSI721_OBDMAC_INT(ch));
1330+
1331+ if (!(priv->flags & TSI721_USING_MSIX)) {
1332+ u32 ch_inte;
1333+
1334+ /* Re-enable channel interrupts */
1335+ ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1336+ ch_inte |= TSI721_INT_OMSG_CHAN(ch);
1337+ iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
1338+ }
1339+
1340+ spin_unlock(&priv->omsg_ring[ch].lock);
1341+}
1342+
1343+/**
1344+ * tsi721_open_outb_mbox - Initialize Tsi721 outbound mailbox
1345+ * @mport: Master port implementing Outbound Messaging Engine
1346+ * @dev_id: Device specific pointer to pass on event
1347+ * @mbox: Mailbox to open
1348+ * @entries: Number of entries in the outbound mailbox ring
1349+ */
1350+static int tsi721_open_outb_mbox(struct rio_mport *mport, void *dev_id,
1351+ int mbox, int entries)
1352+{
1353+ struct tsi721_device *priv = mport->priv;
1354+ struct tsi721_omsg_desc *bd_ptr;
1355+ int i, rc = 0;
1356+
1357+ if ((entries < TSI721_OMSGD_MIN_RING_SIZE) ||
1358+ (entries > (TSI721_OMSGD_RING_SIZE)) ||
1359+ (!is_power_of_2(entries)) || mbox >= RIO_MAX_MBOX) {
1360+ rc = -EINVAL;
1361+ goto out;
1362+ }
1363+
1364+ priv->omsg_ring[mbox].dev_id = dev_id;
1365+ priv->omsg_ring[mbox].size = entries;
1366+ priv->omsg_ring[mbox].sts_rdptr = 0;
1367+ spin_lock_init(&priv->omsg_ring[mbox].lock);
1368+
1369+ /* Outbound Msg Buffer allocation based on
1370+ the number of maximum descriptor entries */
1371+ for (i = 0; i < entries; i++) {
1372+ priv->omsg_ring[mbox].omq_base[i] =
1373+ dma_alloc_coherent(
1374+ &priv->pdev->dev, TSI721_MSG_BUFFER_SIZE,
1375+ &priv->omsg_ring[mbox].omq_phys[i],
1376+ GFP_KERNEL);
1377+ if (priv->omsg_ring[mbox].omq_base[i] == NULL) {
1378+ dev_dbg(&priv->pdev->dev,
1379+ "Unable to allocate OB MSG data buffer for"
1380+ " MBOX%d\n", mbox);
1381+ rc = -ENOMEM;
1382+ goto out_buf;
1383+ }
1384+ }
1385+
1386+ /* Outbound message descriptor allocation */
1387+ priv->omsg_ring[mbox].omd_base = dma_alloc_coherent(
1388+ &priv->pdev->dev,
1389+ (entries + 1) * sizeof(struct tsi721_omsg_desc),
1390+ &priv->omsg_ring[mbox].omd_phys, GFP_KERNEL);
1391+ if (priv->omsg_ring[mbox].omd_base == NULL) {
1392+ dev_dbg(&priv->pdev->dev,
1393+ "Unable to allocate OB MSG descriptor memory "
1394+ "for MBOX%d\n", mbox);
1395+ rc = -ENOMEM;
1396+ goto out_buf;
1397+ }
1398+
1399+ priv->omsg_ring[mbox].tx_slot = 0;
1400+
1401+ /* Outbound message descriptor status FIFO allocation */
1402+ priv->omsg_ring[mbox].sts_size = roundup_pow_of_two(entries + 1);
1403+ priv->omsg_ring[mbox].sts_base = dma_alloc_coherent(&priv->pdev->dev,
1404+ priv->omsg_ring[mbox].sts_size *
1405+ sizeof(struct tsi721_dma_sts),
1406+ &priv->omsg_ring[mbox].sts_phys, GFP_KERNEL);
1407+ if (priv->omsg_ring[mbox].sts_base == NULL) {
1408+ dev_dbg(&priv->pdev->dev,
1409+ "Unable to allocate OB MSG descriptor status FIFO "
1410+ "for MBOX%d\n", mbox);
1411+ rc = -ENOMEM;
1412+ goto out_desc;
1413+ }
1414+
1415+ memset(priv->omsg_ring[mbox].sts_base, 0,
1416+ entries * sizeof(struct tsi721_dma_sts));
1417+
1418+ /*
1419+ * Configure Outbound Messaging Engine
1420+ */
1421+
1422+ /* Setup Outbound Message descriptor pointer */
1423+ iowrite32(((u64)priv->omsg_ring[mbox].omd_phys >> 32),
1424+ priv->regs + TSI721_OBDMAC_DPTRH(mbox));
1425+ iowrite32(((u64)priv->omsg_ring[mbox].omd_phys &
1426+ TSI721_OBDMAC_DPTRL_MASK),
1427+ priv->regs + TSI721_OBDMAC_DPTRL(mbox));
1428+
1429+ /* Setup Outbound Message descriptor status FIFO */
1430+ iowrite32(((u64)priv->omsg_ring[mbox].sts_phys >> 32),
1431+ priv->regs + TSI721_OBDMAC_DSBH(mbox));
1432+ iowrite32(((u64)priv->omsg_ring[mbox].sts_phys &
1433+ TSI721_OBDMAC_DSBL_MASK),
1434+ priv->regs + TSI721_OBDMAC_DSBL(mbox));
1435+ iowrite32(TSI721_DMAC_DSSZ_SIZE(priv->omsg_ring[mbox].sts_size),
1436+ priv->regs + (u32)TSI721_OBDMAC_DSSZ(mbox));
1437+
1438+ /* Enable interrupts */
1439+
1440+#ifdef CONFIG_PCI_MSI
1441+ if (priv->flags & TSI721_USING_MSIX) {
1442+ /* Request interrupt service if we are in MSI-X mode */
1443+ rc = request_irq(
1444+ priv->msix[TSI721_VECT_OMB0_DONE + mbox].vector,
1445+ tsi721_omsg_msix, 0,
1446+ priv->msix[TSI721_VECT_OMB0_DONE + mbox].irq_name,
1447+ (void *)mport);
1448+
1449+ if (rc) {
1450+ dev_dbg(&priv->pdev->dev,
1451+ "Unable to allocate MSI-X interrupt for "
1452+ "OBOX%d-DONE\n", mbox);
1453+ goto out_stat;
1454+ }
1455+
1456+ rc = request_irq(priv->msix[TSI721_VECT_OMB0_INT + mbox].vector,
1457+ tsi721_omsg_msix, 0,
1458+ priv->msix[TSI721_VECT_OMB0_INT + mbox].irq_name,
1459+ (void *)mport);
1460+
1461+ if (rc) {
1462+ dev_dbg(&priv->pdev->dev,
1463+ "Unable to allocate MSI-X interrupt for "
1464+ "MBOX%d-INT\n", mbox);
1465+ free_irq(
1466+ priv->msix[TSI721_VECT_OMB0_DONE + mbox].vector,
1467+ (void *)mport);
1468+ goto out_stat;
1469+ }
1470+ }
1471+#endif /* CONFIG_PCI_MSI */
1472+
1473+ tsi721_omsg_interrupt_enable(priv, mbox, TSI721_OBDMAC_INT_ALL);
1474+
1475+ /* Initialize Outbound Message descriptors ring */
1476+ bd_ptr = priv->omsg_ring[mbox].omd_base;
1477+ bd_ptr[entries].type_id = cpu_to_le32(DTYPE5 << 29);
1478+ bd_ptr[entries].msg_info = 0;
1479+ bd_ptr[entries].next_lo =
1480+ cpu_to_le32((u64)priv->omsg_ring[mbox].omd_phys &
1481+ TSI721_OBDMAC_DPTRL_MASK);
1482+ bd_ptr[entries].next_hi =
1483+ cpu_to_le32((u64)priv->omsg_ring[mbox].omd_phys >> 32);
1484+ priv->omsg_ring[mbox].wr_count = 0;
1485+ mb();
1486+
1487+ /* Initialize Outbound Message engine */
1488+ iowrite32(TSI721_OBDMAC_CTL_INIT, priv->regs + TSI721_OBDMAC_CTL(mbox));
1489+ ioread32(priv->regs + TSI721_OBDMAC_DWRCNT(mbox));
1490+ udelay(10);
1491+
1492+ priv->omsg_init[mbox] = 1;
1493+
1494+ return 0;
1495+
1496+#ifdef CONFIG_PCI_MSI
1497+out_stat:
1498+ dma_free_coherent(&priv->pdev->dev,
1499+ priv->omsg_ring[mbox].sts_size * sizeof(struct tsi721_dma_sts),
1500+ priv->omsg_ring[mbox].sts_base,
1501+ priv->omsg_ring[mbox].sts_phys);
1502+
1503+ priv->omsg_ring[mbox].sts_base = NULL;
1504+#endif /* CONFIG_PCI_MSI */
1505+
1506+out_desc:
1507+ dma_free_coherent(&priv->pdev->dev,
1508+ (entries + 1) * sizeof(struct tsi721_omsg_desc),
1509+ priv->omsg_ring[mbox].omd_base,
1510+ priv->omsg_ring[mbox].omd_phys);
1511+
1512+ priv->omsg_ring[mbox].omd_base = NULL;
1513+
1514+out_buf:
1515+ for (i = 0; i < priv->omsg_ring[mbox].size; i++) {
1516+ if (priv->omsg_ring[mbox].omq_base[i]) {
1517+ dma_free_coherent(&priv->pdev->dev,
1518+ TSI721_MSG_BUFFER_SIZE,
1519+ priv->omsg_ring[mbox].omq_base[i],
1520+ priv->omsg_ring[mbox].omq_phys[i]);
1521+
1522+ priv->omsg_ring[mbox].omq_base[i] = NULL;
1523+ }
1524+ }
1525+
1526+out:
1527+ return rc;
1528+}
1529+
1530+/**
1531+ * tsi721_close_outb_mbox - Close Tsi721 outbound mailbox
1532+ * @mport: Master port implementing the outbound message unit
1533+ * @mbox: Mailbox to close
1534+ */
1535+static void tsi721_close_outb_mbox(struct rio_mport *mport, int mbox)
1536+{
1537+ struct tsi721_device *priv = mport->priv;
1538+ u32 i;
1539+
1540+ if (!priv->omsg_init[mbox])
1541+ return;
1542+ priv->omsg_init[mbox] = 0;
1543+
1544+ /* Disable Interrupts */
1545+
1546+ tsi721_omsg_interrupt_disable(priv, mbox, TSI721_OBDMAC_INT_ALL);
1547+
1548+#ifdef CONFIG_PCI_MSI
1549+ if (priv->flags & TSI721_USING_MSIX) {
1550+ free_irq(priv->msix[TSI721_VECT_OMB0_DONE + mbox].vector,
1551+ (void *)mport);
1552+ free_irq(priv->msix[TSI721_VECT_OMB0_INT + mbox].vector,
1553+ (void *)mport);
1554+ }
1555+#endif /* CONFIG_PCI_MSI */
1556+
1557+ /* Free OMSG Descriptor Status FIFO */
1558+ dma_free_coherent(&priv->pdev->dev,
1559+ priv->omsg_ring[mbox].sts_size * sizeof(struct tsi721_dma_sts),
1560+ priv->omsg_ring[mbox].sts_base,
1561+ priv->omsg_ring[mbox].sts_phys);
1562+
1563+ priv->omsg_ring[mbox].sts_base = NULL;
1564+
1565+ /* Free OMSG descriptors */
1566+ dma_free_coherent(&priv->pdev->dev,
1567+ (priv->omsg_ring[mbox].size + 1) *
1568+ sizeof(struct tsi721_omsg_desc),
1569+ priv->omsg_ring[mbox].omd_base,
1570+ priv->omsg_ring[mbox].omd_phys);
1571+
1572+ priv->omsg_ring[mbox].omd_base = NULL;
1573+
1574+ /* Free message buffers */
1575+ for (i = 0; i < priv->omsg_ring[mbox].size; i++) {
1576+ if (priv->omsg_ring[mbox].omq_base[i]) {
1577+ dma_free_coherent(&priv->pdev->dev,
1578+ TSI721_MSG_BUFFER_SIZE,
1579+ priv->omsg_ring[mbox].omq_base[i],
1580+ priv->omsg_ring[mbox].omq_phys[i]);
1581+
1582+ priv->omsg_ring[mbox].omq_base[i] = NULL;
1583+ }
1584+ }
1585+}
1586+
1587+/**
1588+ * tsi721_imsg_handler - Inbound Message Interrupt Handler
1589+ * @priv: pointer to tsi721 private data
1590+ * @ch: inbound message channel number to service
1591+ *
1592+ * Services channel interrupts from inbound messaging engine.
1593+ */
1594+static void tsi721_imsg_handler(struct tsi721_device *priv, int ch)
1595+{
1596+ u32 mbox = ch - 4;
1597+ u32 imsg_int;
1598+
1599+ spin_lock(&priv->imsg_ring[mbox].lock);
1600+
1601+ imsg_int = ioread32(priv->regs + TSI721_IBDMAC_INT(ch));
1602+
1603+ if (imsg_int & TSI721_IBDMAC_INT_SRTO)
1604+ dev_info(&priv->pdev->dev, "IB MBOX%d SRIO timeout\n",
1605+ mbox);
1606+
1607+ if (imsg_int & TSI721_IBDMAC_INT_PC_ERROR)
1608+ dev_info(&priv->pdev->dev, "IB MBOX%d PCIe error\n",
1609+ mbox);
1610+
1611+ if (imsg_int & TSI721_IBDMAC_INT_FQ_LOW)
1612+ dev_info(&priv->pdev->dev,
1613+ "IB MBOX%d IB free queue low\n", mbox);
1614+
1615+ /* Clear IB channel interrupts */
1616+ iowrite32(imsg_int, priv->regs + TSI721_IBDMAC_INT(ch));
1617+
1618+ /* If an IB Msg is received notify the upper layer */
1619+ if (imsg_int & TSI721_IBDMAC_INT_DQ_RCV &&
1620+ priv->mport->inb_msg[mbox].mcback)
1621+ priv->mport->inb_msg[mbox].mcback(priv->mport,
1622+ priv->imsg_ring[mbox].dev_id, mbox, -1);
1623+
1624+ if (!(priv->flags & TSI721_USING_MSIX)) {
1625+ u32 ch_inte;
1626+
1627+ /* Re-enable channel interrupts */
1628+ ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1629+ ch_inte |= TSI721_INT_IMSG_CHAN(ch);
1630+ iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
1631+ }
1632+
1633+ spin_unlock(&priv->imsg_ring[mbox].lock);
1634+}
1635+
1636+/**
1637+ * tsi721_open_inb_mbox - Initialize Tsi721 inbound mailbox
1638+ * @mport: Master port implementing the Inbound Messaging Engine
1639+ * @dev_id: Device specific pointer to pass on event
1640+ * @mbox: Mailbox to open
1641+ * @entries: Number of entries in the inbound mailbox ring
1642+ */
1643+static int tsi721_open_inb_mbox(struct rio_mport *mport, void *dev_id,
1644+ int mbox, int entries)
1645+{
1646+ struct tsi721_device *priv = mport->priv;
1647+ int ch = mbox + 4;
1648+ int i;
1649+ u64 *free_ptr;
1650+ int rc = 0;
1651+
1652+ if ((entries < TSI721_IMSGD_MIN_RING_SIZE) ||
1653+ (entries > TSI721_IMSGD_RING_SIZE) ||
1654+ (!is_power_of_2(entries)) || mbox >= RIO_MAX_MBOX) {
1655+ rc = -EINVAL;
1656+ goto out;
1657+ }
1658+
1659+ /* Initialize IB Messaging Ring */
1660+ priv->imsg_ring[mbox].dev_id = dev_id;
1661+ priv->imsg_ring[mbox].size = entries;
1662+ priv->imsg_ring[mbox].rx_slot = 0;
1663+ priv->imsg_ring[mbox].desc_rdptr = 0;
1664+ priv->imsg_ring[mbox].fq_wrptr = 0;
1665+ for (i = 0; i < priv->imsg_ring[mbox].size; i++)
1666+ priv->imsg_ring[mbox].imq_base[i] = NULL;
1667+ spin_lock_init(&priv->imsg_ring[mbox].lock);
1668+
1669+ /* Allocate buffers for incoming messages */
1670+ priv->imsg_ring[mbox].buf_base =
1671+ dma_alloc_coherent(&priv->pdev->dev,
1672+ entries * TSI721_MSG_BUFFER_SIZE,
1673+ &priv->imsg_ring[mbox].buf_phys,
1674+ GFP_KERNEL);
1675+
1676+ if (priv->imsg_ring[mbox].buf_base == NULL) {
1677+ dev_err(&priv->pdev->dev,
1678+ "Failed to allocate buffers for IB MBOX%d\n", mbox);
1679+ rc = -ENOMEM;
1680+ goto out;
1681+ }
1682+
1683+ /* Allocate memory for circular free list */
1684+ priv->imsg_ring[mbox].imfq_base =
1685+ dma_alloc_coherent(&priv->pdev->dev,
1686+ entries * 8,
1687+ &priv->imsg_ring[mbox].imfq_phys,
1688+ GFP_KERNEL);
1689+
1690+ if (priv->imsg_ring[mbox].imfq_base == NULL) {
1691+ dev_err(&priv->pdev->dev,
1692+ "Failed to allocate free queue for IB MBOX%d\n", mbox);
1693+ rc = -ENOMEM;
1694+ goto out_buf;
1695+ }
1696+
1697+ /* Allocate memory for Inbound message descriptors */
1698+ priv->imsg_ring[mbox].imd_base =
1699+ dma_alloc_coherent(&priv->pdev->dev,
1700+ entries * sizeof(struct tsi721_imsg_desc),
1701+ &priv->imsg_ring[mbox].imd_phys, GFP_KERNEL);
1702+
1703+ if (priv->imsg_ring[mbox].imd_base == NULL) {
1704+ dev_err(&priv->pdev->dev,
1705+ "Failed to allocate descriptor memory for IB MBOX%d\n",
1706+ mbox);
1707+ rc = -ENOMEM;
1708+ goto out_dma;
1709+ }
1710+
1711+ /* Fill free buffer pointer list */
1712+ free_ptr = priv->imsg_ring[mbox].imfq_base;
1713+ for (i = 0; i < entries; i++)
1714+ free_ptr[i] = cpu_to_le64(
1715+ (u64)(priv->imsg_ring[mbox].buf_phys) +
1716+ i * 0x1000);
1717+
1718+ mb();
1719+
1720+ /*
1721+ * For mapping of inbound SRIO Messages into appropriate queues we need
1722+ * to set Inbound Device ID register in the messaging engine. We do it
1723+ * once when first inbound mailbox is requested.
1724+ */
1725+ if (!(priv->flags & TSI721_IMSGID_SET)) {
1726+ iowrite32((u32)priv->mport->host_deviceid,
1727+ priv->regs + TSI721_IB_DEVID);
1728+ priv->flags |= TSI721_IMSGID_SET;
1729+ }
1730+
1731+ /*
1732+ * Configure Inbound Messaging channel (ch = mbox + 4)
1733+ */
1734+
1735+ /* Setup Inbound Message free queue */
1736+ iowrite32(((u64)priv->imsg_ring[mbox].imfq_phys >> 32),
1737+ priv->regs + TSI721_IBDMAC_FQBH(ch));
1738+ iowrite32(((u64)priv->imsg_ring[mbox].imfq_phys &
1739+ TSI721_IBDMAC_FQBL_MASK),
1740+ priv->regs+TSI721_IBDMAC_FQBL(ch));
1741+ iowrite32(TSI721_DMAC_DSSZ_SIZE(entries),
1742+ priv->regs + TSI721_IBDMAC_FQSZ(ch));
1743+
1744+ /* Setup Inbound Message descriptor queue */
1745+ iowrite32(((u64)priv->imsg_ring[mbox].imd_phys >> 32),
1746+ priv->regs + TSI721_IBDMAC_DQBH(ch));
1747+ iowrite32(((u32)priv->imsg_ring[mbox].imd_phys &
1748+ (u32)TSI721_IBDMAC_DQBL_MASK),
1749+ priv->regs+TSI721_IBDMAC_DQBL(ch));
1750+ iowrite32(TSI721_DMAC_DSSZ_SIZE(entries),
1751+ priv->regs + TSI721_IBDMAC_DQSZ(ch));
1752+
1753+ /* Enable interrupts */
1754+
1755+#ifdef CONFIG_PCI_MSI
1756+ if (priv->flags & TSI721_USING_MSIX) {
1757+ /* Request interrupt service if we are in MSI-X mode */
1758+ rc = request_irq(priv->msix[TSI721_VECT_IMB0_RCV + mbox].vector,
1759+ tsi721_imsg_msix, 0,
1760+ priv->msix[TSI721_VECT_IMB0_RCV + mbox].irq_name,
1761+ (void *)mport);
1762+
1763+ if (rc) {
1764+ dev_dbg(&priv->pdev->dev,
1765+ "Unable to allocate MSI-X interrupt for "
1766+ "IBOX%d-DONE\n", mbox);
1767+ goto out_desc;
1768+ }
1769+
1770+ rc = request_irq(priv->msix[TSI721_VECT_IMB0_INT + mbox].vector,
1771+ tsi721_imsg_msix, 0,
1772+ priv->msix[TSI721_VECT_IMB0_INT + mbox].irq_name,
1773+ (void *)mport);
1774+
1775+ if (rc) {
1776+ dev_dbg(&priv->pdev->dev,
1777+ "Unable to allocate MSI-X interrupt for "
1778+ "IBOX%d-INT\n", mbox);
1779+ free_irq(
1780+ priv->msix[TSI721_VECT_IMB0_RCV + mbox].vector,
1781+ (void *)mport);
1782+ goto out_desc;
1783+ }
1784+ }
1785+#endif /* CONFIG_PCI_MSI */
1786+
1787+ tsi721_imsg_interrupt_enable(priv, ch, TSI721_IBDMAC_INT_ALL);
1788+
1789+ /* Initialize Inbound Message Engine */
1790+ iowrite32(TSI721_IBDMAC_CTL_INIT, priv->regs + TSI721_IBDMAC_CTL(ch));
1791+ ioread32(priv->regs + TSI721_IBDMAC_CTL(ch));
1792+ udelay(10);
1793+ priv->imsg_ring[mbox].fq_wrptr = entries - 1;
1794+ iowrite32(entries - 1, priv->regs + TSI721_IBDMAC_FQWP(ch));
1795+
1796+ priv->imsg_init[mbox] = 1;
1797+ return 0;
1798+
1799+#ifdef CONFIG_PCI_MSI
1800+out_desc:
1801+ dma_free_coherent(&priv->pdev->dev,
1802+ priv->imsg_ring[mbox].size * sizeof(struct tsi721_imsg_desc),
1803+ priv->imsg_ring[mbox].imd_base,
1804+ priv->imsg_ring[mbox].imd_phys);
1805+
1806+ priv->imsg_ring[mbox].imd_base = NULL;
1807+#endif /* CONFIG_PCI_MSI */
1808+
1809+out_dma:
1810+ dma_free_coherent(&priv->pdev->dev,
1811+ priv->imsg_ring[mbox].size * 8,
1812+ priv->imsg_ring[mbox].imfq_base,
1813+ priv->imsg_ring[mbox].imfq_phys);
1814+
1815+ priv->imsg_ring[mbox].imfq_base = NULL;
1816+
1817+out_buf:
1818+ dma_free_coherent(&priv->pdev->dev,
1819+ priv->imsg_ring[mbox].size * TSI721_MSG_BUFFER_SIZE,
1820+ priv->imsg_ring[mbox].buf_base,
1821+ priv->imsg_ring[mbox].buf_phys);
1822+
1823+ priv->imsg_ring[mbox].buf_base = NULL;
1824+
1825+out:
1826+ return rc;
1827+}
1828+
1829+/**
1830+ * tsi721_close_inb_mbox - Shut down Tsi721 inbound mailbox
1831+ * @mport: Master port implementing the Inbound Messaging Engine
1832+ * @mbox: Mailbox to close
1833+ */
1834+static void tsi721_close_inb_mbox(struct rio_mport *mport, int mbox)
1835+{
1836+ struct tsi721_device *priv = mport->priv;
1837+ u32 rx_slot;
1838+ int ch = mbox + 4;
1839+
1840+ if (!priv->imsg_init[mbox]) /* mbox isn't initialized yet */
1841+ return;
1842+ priv->imsg_init[mbox] = 0;
1843+
1844+ /* Disable Inbound Messaging Engine */
1845+
1846+ /* Disable Interrupts */
1847+ tsi721_imsg_interrupt_disable(priv, ch, TSI721_OBDMAC_INT_MASK);
1848+
1849+#ifdef CONFIG_PCI_MSI
1850+ if (priv->flags & TSI721_USING_MSIX) {
1851+ free_irq(priv->msix[TSI721_VECT_IMB0_RCV + mbox].vector,
1852+ (void *)mport);
1853+ free_irq(priv->msix[TSI721_VECT_IMB0_INT + mbox].vector,
1854+ (void *)mport);
1855+ }
1856+#endif /* CONFIG_PCI_MSI */
1857+
1858+ /* Clear Inbound Buffer Queue */
1859+ for (rx_slot = 0; rx_slot < priv->imsg_ring[mbox].size; rx_slot++)
1860+ priv->imsg_ring[mbox].imq_base[rx_slot] = NULL;
1861+
1862+ /* Free memory allocated for message buffers */
1863+ dma_free_coherent(&priv->pdev->dev,
1864+ priv->imsg_ring[mbox].size * TSI721_MSG_BUFFER_SIZE,
1865+ priv->imsg_ring[mbox].buf_base,
1866+ priv->imsg_ring[mbox].buf_phys);
1867+
1868+ priv->imsg_ring[mbox].buf_base = NULL;
1869+
1870+ /* Free memory allocated for free pointr list */
1871+ dma_free_coherent(&priv->pdev->dev,
1872+ priv->imsg_ring[mbox].size * 8,
1873+ priv->imsg_ring[mbox].imfq_base,
1874+ priv->imsg_ring[mbox].imfq_phys);
1875+
1876+ priv->imsg_ring[mbox].imfq_base = NULL;
1877+
1878+ /* Free memory allocated for RX descriptors */
1879+ dma_free_coherent(&priv->pdev->dev,
1880+ priv->imsg_ring[mbox].size * sizeof(struct tsi721_imsg_desc),
1881+ priv->imsg_ring[mbox].imd_base,
1882+ priv->imsg_ring[mbox].imd_phys);
1883+
1884+ priv->imsg_ring[mbox].imd_base = NULL;
1885+}
1886+
1887+/**
1888+ * tsi721_add_inb_buffer - Add buffer to the Tsi721 inbound message queue
1889+ * @mport: Master port implementing the Inbound Messaging Engine
1890+ * @mbox: Inbound mailbox number
1891+ * @buf: Buffer to add to inbound queue
1892+ */
1893+static int tsi721_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf)
1894+{
1895+ struct tsi721_device *priv = mport->priv;
1896+ u32 rx_slot;
1897+ int rc = 0;
1898+
1899+ rx_slot = priv->imsg_ring[mbox].rx_slot;
1900+ if (priv->imsg_ring[mbox].imq_base[rx_slot]) {
1901+ dev_err(&priv->pdev->dev,
1902+ "Error adding inbound buffer %d, buffer exists\n",
1903+ rx_slot);
1904+ rc = -EINVAL;
1905+ goto out;
1906+ }
1907+
1908+ priv->imsg_ring[mbox].imq_base[rx_slot] = buf;
1909+
1910+ if (++priv->imsg_ring[mbox].rx_slot == priv->imsg_ring[mbox].size)
1911+ priv->imsg_ring[mbox].rx_slot = 0;
1912+
1913+out:
1914+ return rc;
1915+}
1916+
1917+/**
1918+ * tsi721_get_inb_message - Fetch inbound message from the Tsi721 MSG Queue
1919+ * @mport: Master port implementing the Inbound Messaging Engine
1920+ * @mbox: Inbound mailbox number
1921+ *
1922+ * Returns pointer to the message on success or NULL on failure.
1923+ */
1924+static void *tsi721_get_inb_message(struct rio_mport *mport, int mbox)
1925+{
1926+ struct tsi721_device *priv = mport->priv;
1927+ struct tsi721_imsg_desc *desc;
1928+ u32 rx_slot;
1929+ void *rx_virt = NULL;
1930+ u64 rx_phys;
1931+ void *buf = NULL;
1932+ u64 *free_ptr;
1933+ int ch = mbox + 4;
1934+ int msg_size;
1935+
1936+ if (!priv->imsg_init[mbox])
1937+ return NULL;
1938+
1939+ desc = priv->imsg_ring[mbox].imd_base;
1940+ desc += priv->imsg_ring[mbox].desc_rdptr;
1941+
1942+ if (!(le32_to_cpu(desc->msg_info) & TSI721_IMD_HO))
1943+ goto out;
1944+
1945+ rx_slot = priv->imsg_ring[mbox].rx_slot;
1946+ while (priv->imsg_ring[mbox].imq_base[rx_slot] == NULL) {
1947+ if (++rx_slot == priv->imsg_ring[mbox].size)
1948+ rx_slot = 0;
1949+ }
1950+
1951+ rx_phys = ((u64)le32_to_cpu(desc->bufptr_hi) << 32) |
1952+ le32_to_cpu(desc->bufptr_lo);
1953+
1954+ rx_virt = priv->imsg_ring[mbox].buf_base +
1955+ (rx_phys - (u64)priv->imsg_ring[mbox].buf_phys);
1956+
1957+ buf = priv->imsg_ring[mbox].imq_base[rx_slot];
1958+ msg_size = le32_to_cpu(desc->msg_info) & TSI721_IMD_BCOUNT;
1959+ if (msg_size == 0)
1960+ msg_size = RIO_MAX_MSG_SIZE;
1961+
1962+ memcpy(buf, rx_virt, msg_size);
1963+ priv->imsg_ring[mbox].imq_base[rx_slot] = NULL;
1964+
1965+ desc->msg_info &= cpu_to_le32(~TSI721_IMD_HO);
1966+ if (++priv->imsg_ring[mbox].desc_rdptr == priv->imsg_ring[mbox].size)
1967+ priv->imsg_ring[mbox].desc_rdptr = 0;
1968+
1969+ iowrite32(priv->imsg_ring[mbox].desc_rdptr,
1970+ priv->regs + TSI721_IBDMAC_DQRP(ch));
1971+
1972+ /* Return free buffer into the pointer list */
1973+ free_ptr = priv->imsg_ring[mbox].imfq_base;
1974+ free_ptr[priv->imsg_ring[mbox].fq_wrptr] = cpu_to_le64(rx_phys);
1975+
1976+ if (++priv->imsg_ring[mbox].fq_wrptr == priv->imsg_ring[mbox].size)
1977+ priv->imsg_ring[mbox].fq_wrptr = 0;
1978+
1979+ iowrite32(priv->imsg_ring[mbox].fq_wrptr,
1980+ priv->regs + TSI721_IBDMAC_FQWP(ch));
1981+out:
1982+ return buf;
1983+}
1984+
1985+/**
1986+ * tsi721_messages_init - Initialization of Messaging Engine
1987+ * @priv: pointer to tsi721 private data
1988+ *
1989+ * Configures Tsi721 messaging engine.
1990+ */
1991+static int tsi721_messages_init(struct tsi721_device *priv)
1992+{
1993+ int ch;
1994+
1995+ iowrite32(0, priv->regs + TSI721_SMSG_ECC_LOG);
1996+ iowrite32(0, priv->regs + TSI721_RETRY_GEN_CNT);
1997+ iowrite32(0, priv->regs + TSI721_RETRY_RX_CNT);
1998+
1999+ /* Set SRIO Message Request/Response Timeout */
2000+ iowrite32(TSI721_RQRPTO_VAL, priv->regs + TSI721_RQRPTO);
2001+
2002+ /* Initialize Inbound Messaging Engine Registers */
2003+ for (ch = 0; ch < TSI721_IMSG_CHNUM; ch++) {
2004+ /* Clear interrupt bits */
2005+ iowrite32(TSI721_IBDMAC_INT_MASK,
2006+ priv->regs + TSI721_IBDMAC_INT(ch));
2007+ /* Clear Status */
2008+ iowrite32(0, priv->regs + TSI721_IBDMAC_STS(ch));
2009+
2010+ iowrite32(TSI721_SMSG_ECC_COR_LOG_MASK,
2011+ priv->regs + TSI721_SMSG_ECC_COR_LOG(ch));
2012+ iowrite32(TSI721_SMSG_ECC_NCOR_MASK,
2013+ priv->regs + TSI721_SMSG_ECC_NCOR(ch));
2014+ }
2015+
2016+ return 0;
2017+}
2018+
2019+/**
2020+ * tsi721_disable_ints - disables all device interrupts
2021+ * @priv: pointer to tsi721 private data
2022+ */
2023+static void tsi721_disable_ints(struct tsi721_device *priv)
2024+{
2025+ int ch;
2026+
2027+ /* Disable all device level interrupts */
2028+ iowrite32(0, priv->regs + TSI721_DEV_INTE);
2029+
2030+ /* Disable all Device Channel interrupts */
2031+ iowrite32(0, priv->regs + TSI721_DEV_CHAN_INTE);
2032+
2033+ /* Disable all Inbound Msg Channel interrupts */
2034+ for (ch = 0; ch < TSI721_IMSG_CHNUM; ch++)
2035+ iowrite32(0, priv->regs + TSI721_IBDMAC_INTE(ch));
2036+
2037+ /* Disable all Outbound Msg Channel interrupts */
2038+ for (ch = 0; ch < TSI721_OMSG_CHNUM; ch++)
2039+ iowrite32(0, priv->regs + TSI721_OBDMAC_INTE(ch));
2040+
2041+ /* Disable all general messaging interrupts */
2042+ iowrite32(0, priv->regs + TSI721_SMSG_INTE);
2043+
2044+ /* Disable all BDMA Channel interrupts */
2045+ for (ch = 0; ch < TSI721_DMA_MAXCH; ch++)
2046+ iowrite32(0, priv->regs + TSI721_DMAC_INTE(ch));
2047+
2048+ /* Disable all general BDMA interrupts */
2049+ iowrite32(0, priv->regs + TSI721_BDMA_INTE);
2050+
2051+ /* Disable all SRIO Channel interrupts */
2052+ for (ch = 0; ch < TSI721_SRIO_MAXCH; ch++)
2053+ iowrite32(0, priv->regs + TSI721_SR_CHINTE(ch));
2054+
2055+ /* Disable all general SR2PC interrupts */
2056+ iowrite32(0, priv->regs + TSI721_SR2PC_GEN_INTE);
2057+
2058+ /* Disable all PC2SR interrupts */
2059+ iowrite32(0, priv->regs + TSI721_PC2SR_INTE);
2060+
2061+ /* Disable all I2C interrupts */
2062+ iowrite32(0, priv->regs + TSI721_I2C_INT_ENABLE);
2063+
2064+ /* Disable SRIO MAC interrupts */
2065+ iowrite32(0, priv->regs + TSI721_RIO_EM_INT_ENABLE);
2066+ iowrite32(0, priv->regs + TSI721_RIO_EM_DEV_INT_EN);
2067+}
2068+
2069+/**
2070+ * tsi721_setup_mport - Setup Tsi721 as RapidIO subsystem master port
2071+ * @priv: pointer to tsi721 private data
2072+ *
2073+ * Configures Tsi721 as RapidIO master port.
2074+ */
2075+static int __devinit tsi721_setup_mport(struct tsi721_device *priv)
2076+{
2077+ struct pci_dev *pdev = priv->pdev;
2078+ int err = 0;
2079+ struct rio_ops *ops;
2080+
2081+ struct rio_mport *mport;
2082+
2083+ ops = kzalloc(sizeof(struct rio_ops), GFP_KERNEL);
2084+ if (!ops) {
2085+ dev_dbg(&pdev->dev, "Unable to allocate memory for rio_ops\n");
2086+ return -ENOMEM;
2087+ }
2088+
2089+ ops->lcread = tsi721_lcread;
2090+ ops->lcwrite = tsi721_lcwrite;
2091+ ops->cread = tsi721_cread_dma;
2092+ ops->cwrite = tsi721_cwrite_dma;
2093+ ops->dsend = tsi721_dsend;
2094+ ops->open_inb_mbox = tsi721_open_inb_mbox;
2095+ ops->close_inb_mbox = tsi721_close_inb_mbox;
2096+ ops->open_outb_mbox = tsi721_open_outb_mbox;
2097+ ops->close_outb_mbox = tsi721_close_outb_mbox;
2098+ ops->add_outb_message = tsi721_add_outb_message;
2099+ ops->add_inb_buffer = tsi721_add_inb_buffer;
2100+ ops->get_inb_message = tsi721_get_inb_message;
2101+
2102+ mport = kzalloc(sizeof(struct rio_mport), GFP_KERNEL);
2103+ if (!mport) {
2104+ kfree(ops);
2105+ dev_dbg(&pdev->dev, "Unable to allocate memory for mport\n");
2106+ return -ENOMEM;
2107+ }
2108+
2109+ mport->ops = ops;
2110+ mport->index = 0;
2111+ mport->sys_size = 0; /* small system */
2112+ mport->phy_type = RIO_PHY_SERIAL;
2113+ mport->priv = (void *)priv;
2114+ mport->phys_efptr = 0x100;
2115+
2116+ INIT_LIST_HEAD(&mport->dbells);
2117+
2118+ rio_init_dbell_res(&mport->riores[RIO_DOORBELL_RESOURCE], 0, 0xffff);
2119+ rio_init_mbox_res(&mport->riores[RIO_INB_MBOX_RESOURCE], 0, 0);
2120+ rio_init_mbox_res(&mport->riores[RIO_OUTB_MBOX_RESOURCE], 0, 0);
2121+ strcpy(mport->name, "Tsi721 mport");
2122+
2123+ /* Hook up interrupt handler */
2124+
2125+#ifdef CONFIG_PCI_MSI
2126+ if (!tsi721_enable_msix(priv))
2127+ priv->flags |= TSI721_USING_MSIX;
2128+ else if (!pci_enable_msi(pdev))
2129+ priv->flags |= TSI721_USING_MSI;
2130+ else
2131+ dev_info(&pdev->dev,
2132+ "MSI/MSI-X is not available. Using legacy INTx.\n");
2133+#endif /* CONFIG_PCI_MSI */
2134+
2135+ err = tsi721_request_irq(mport);
2136+
2137+ if (!err) {
2138+ tsi721_interrupts_init(priv);
2139+ ops->pwenable = tsi721_pw_enable;
2140+ } else
2141+ dev_err(&pdev->dev, "Unable to get assigned PCI IRQ "
2142+ "vector %02X err=0x%x\n", pdev->irq, err);
2143+
2144+ /* Enable SRIO link */
2145+ iowrite32(ioread32(priv->regs + TSI721_DEVCTL) |
2146+ TSI721_DEVCTL_SRBOOT_CMPL,
2147+ priv->regs + TSI721_DEVCTL);
2148+
2149+ rio_register_mport(mport);
2150+ priv->mport = mport;
2151+
2152+ if (mport->host_deviceid >= 0)
2153+ iowrite32(RIO_PORT_GEN_HOST | RIO_PORT_GEN_MASTER |
2154+ RIO_PORT_GEN_DISCOVERED,
2155+ priv->regs + (0x100 + RIO_PORT_GEN_CTL_CSR));
2156+ else
2157+ iowrite32(0, priv->regs + (0x100 + RIO_PORT_GEN_CTL_CSR));
2158+
2159+ return 0;
2160+}
2161+
2162+static int __devinit tsi721_probe(struct pci_dev *pdev,
2163+ const struct pci_device_id *id)
2164+{
2165+ struct tsi721_device *priv;
2166+ int i;
2167+ int err;
2168+ u32 regval;
2169+
2170+ priv = kzalloc(sizeof(struct tsi721_device), GFP_KERNEL);
2171+ if (priv == NULL) {
2172+ dev_err(&pdev->dev, "Failed to allocate memory for device\n");
2173+ err = -ENOMEM;
2174+ goto err_exit;
2175+ }
2176+
2177+ err = pci_enable_device(pdev);
2178+ if (err) {
2179+ dev_err(&pdev->dev, "Failed to enable PCI device\n");
2180+ goto err_clean;
2181+ }
2182+
2183+ priv->pdev = pdev;
2184+
2185+#ifdef DEBUG
2186+ for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
2187+ dev_dbg(&pdev->dev, "res[%d] @ 0x%llx (0x%lx, 0x%lx)\n",
2188+ i, (unsigned long long)pci_resource_start(pdev, i),
2189+ (unsigned long)pci_resource_len(pdev, i),
2190+ pci_resource_flags(pdev, i));
2191+ }
2192+#endif
2193+ /*
2194+ * Verify BAR configuration
2195+ */
2196+
2197+ /* BAR_0 (registers) must be 512KB+ in 32-bit address space */
2198+ if (!(pci_resource_flags(pdev, BAR_0) & IORESOURCE_MEM) ||
2199+ pci_resource_flags(pdev, BAR_0) & IORESOURCE_MEM_64 ||
2200+ pci_resource_len(pdev, BAR_0) < TSI721_REG_SPACE_SIZE) {
2201+ dev_err(&pdev->dev,
2202+ "Missing or misconfigured CSR BAR0, aborting.\n");
2203+ err = -ENODEV;
2204+ goto err_disable_pdev;
2205+ }
2206+
2207+ /* BAR_1 (outbound doorbells) must be 16MB+ in 32-bit address space */
2208+ if (!(pci_resource_flags(pdev, BAR_1) & IORESOURCE_MEM) ||
2209+ pci_resource_flags(pdev, BAR_1) & IORESOURCE_MEM_64 ||
2210+ pci_resource_len(pdev, BAR_1) < TSI721_DB_WIN_SIZE) {
2211+ dev_err(&pdev->dev,
2212+ "Missing or misconfigured Doorbell BAR1, aborting.\n");
2213+ err = -ENODEV;
2214+ goto err_disable_pdev;
2215+ }
2216+
2217+ /*
2218+ * BAR_2 and BAR_4 (outbound translation) must be in 64-bit PCIe address
2219+ * space.
2220+ * NOTE: BAR_2 and BAR_4 are not used by this version of driver.
2221+ * It may be a good idea to keep them disabled using HW configuration
2222+ * to save PCI memory space.
2223+ */
2224+ if ((pci_resource_flags(pdev, BAR_2) & IORESOURCE_MEM) &&
2225+ (pci_resource_flags(pdev, BAR_2) & IORESOURCE_MEM_64)) {
2226+ dev_info(&pdev->dev, "Outbound BAR2 is not used but enabled.\n");
2227+ }
2228+
2229+ if ((pci_resource_flags(pdev, BAR_4) & IORESOURCE_MEM) &&
2230+ (pci_resource_flags(pdev, BAR_4) & IORESOURCE_MEM_64)) {
2231+ dev_info(&pdev->dev, "Outbound BAR4 is not used but enabled.\n");
2232+ }
2233+
2234+ err = pci_request_regions(pdev, DRV_NAME);
2235+ if (err) {
2236+ dev_err(&pdev->dev, "Cannot obtain PCI resources, "
2237+ "aborting.\n");
2238+ goto err_disable_pdev;
2239+ }
2240+
2241+ pci_set_master(pdev);
2242+
2243+ priv->regs = pci_ioremap_bar(pdev, BAR_0);
2244+ if (!priv->regs) {
2245+ dev_err(&pdev->dev,
2246+ "Unable to map device registers space, aborting\n");
2247+ err = -ENOMEM;
2248+ goto err_free_res;
2249+ }
2250+
2251+ priv->odb_base = pci_ioremap_bar(pdev, BAR_1);
2252+ if (!priv->odb_base) {
2253+ dev_err(&pdev->dev,
2254+ "Unable to map outbound doorbells space, aborting\n");
2255+ err = -ENOMEM;
2256+ goto err_unmap_bars;
2257+ }
2258+
2259+ /* Configure DMA attributes. */
2260+ if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
2261+ if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
2262+ dev_info(&pdev->dev, "Unable to set DMA mask\n");
2263+ goto err_unmap_bars;
2264+ }
2265+
2266+ if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
2267+ dev_info(&pdev->dev, "Unable to set consistent DMA mask\n");
2268+ } else {
2269+ err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
2270+ if (err)
2271+ dev_info(&pdev->dev, "Unable to set consistent DMA mask\n");
2272+ }
2273+
2274+ /* Clear "no snoop" and "relaxed ordering" bits. */
2275+ pci_read_config_dword(pdev, 0x40 + PCI_EXP_DEVCTL, &regval);
2276+ regval &= ~(PCI_EXP_DEVCTL_RELAX_EN | PCI_EXP_DEVCTL_NOSNOOP_EN);
2277+ pci_write_config_dword(pdev, 0x40 + PCI_EXP_DEVCTL, regval);
2278+
2279+ /*
2280+ * FIXUP: correct offsets of MSI-X tables in the MSI-X Capability Block
2281+ */
2282+ pci_write_config_dword(pdev, TSI721_PCIECFG_EPCTL, 0x01);
2283+ pci_write_config_dword(pdev, TSI721_PCIECFG_MSIXTBL,
2284+ TSI721_MSIXTBL_OFFSET);
2285+ pci_write_config_dword(pdev, TSI721_PCIECFG_MSIXPBA,
2286+ TSI721_MSIXPBA_OFFSET);
2287+ pci_write_config_dword(pdev, TSI721_PCIECFG_EPCTL, 0);
2288+ /* End of FIXUP */
2289+
2290+ tsi721_disable_ints(priv);
2291+
2292+ tsi721_init_pc2sr_mapping(priv);
2293+ tsi721_init_sr2pc_mapping(priv);
2294+
2295+ if (tsi721_bdma_init(priv)) {
2296+ dev_err(&pdev->dev, "BDMA initialization failed, aborting\n");
2297+ err = -ENOMEM;
2298+ goto err_unmap_bars;
2299+ }
2300+
2301+ err = tsi721_doorbell_init(priv);
2302+ if (err)
2303+ goto err_free_bdma;
2304+
2305+ tsi721_port_write_init(priv);
2306+
2307+ err = tsi721_messages_init(priv);
2308+ if (err)
2309+ goto err_free_consistent;
2310+
2311+ err = tsi721_setup_mport(priv);
2312+ if (err)
2313+ goto err_free_consistent;
2314+
2315+ return 0;
2316+
2317+err_free_consistent:
2318+ tsi721_doorbell_free(priv);
2319+err_free_bdma:
2320+ tsi721_bdma_free(priv);
2321+err_unmap_bars:
2322+ if (priv->regs)
2323+ iounmap(priv->regs);
2324+ if (priv->odb_base)
2325+ iounmap(priv->odb_base);
2326+err_free_res:
2327+ pci_release_regions(pdev);
2328+ pci_clear_master(pdev);
2329+err_disable_pdev:
2330+ pci_disable_device(pdev);
2331+err_clean:
2332+ kfree(priv);
2333+err_exit:
2334+ return err;
2335+}
2336+
2337+static DEFINE_PCI_DEVICE_TABLE(tsi721_pci_tbl) = {
2338+ { PCI_DEVICE(PCI_VENDOR_ID_IDT, PCI_DEVICE_ID_TSI721) },
2339+ { 0, } /* terminate list */
2340+};
2341+
2342+MODULE_DEVICE_TABLE(pci, tsi721_pci_tbl);
2343+
2344+static struct pci_driver tsi721_driver = {
2345+ .name = "tsi721",
2346+ .id_table = tsi721_pci_tbl,
2347+ .probe = tsi721_probe,
2348+};
2349+
2350+static int __init tsi721_init(void)
2351+{
2352+ return pci_register_driver(&tsi721_driver);
2353+}
2354+
2355+static void __exit tsi721_exit(void)
2356+{
2357+ pci_unregister_driver(&tsi721_driver);
2358+}
2359+
2360+device_initcall(tsi721_init);
drivers/rapidio/devices/tsi721.h+766−0
@@ -0,0 +1,766 @@
1+/*
2+ * Tsi721 PCIExpress-to-SRIO bridge definitions
3+ *
4+ * Copyright 2011, Integrated Device Technology, Inc.
5+ *
6+ * This program is free software; you can redistribute it and/or modify it
7+ * under the terms of the GNU General Public License as published by the Free
8+ * Software Foundation; either version 2 of the License, or (at your option)
9+ * any later version.
10+ *
11+ * This program is distributed in the hope that it will be useful, but WITHOUT
12+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14+ * more details.
15+ *
16+ * You should have received a copy of the GNU General Public License along with
17+ * this program; if not, write to the Free Software Foundation, Inc., 59
18+ * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19+ */
20+
21+#ifndef __TSI721_H
22+#define __TSI721_H
23+
24+#define DRV_NAME "tsi721"
25+
26+#define DEFAULT_HOPCOUNT 0xff
27+#define DEFAULT_DESTID 0xff
28+
29+/* PCI device ID */
30+#define PCI_DEVICE_ID_TSI721 0x80ab
31+
32+#define BAR_0 0
33+#define BAR_1 1
34+#define BAR_2 2
35+#define BAR_4 4
36+
37+#define TSI721_PC2SR_BARS 2
38+#define TSI721_PC2SR_WINS 8
39+#define TSI721_PC2SR_ZONES 8
40+#define TSI721_MAINT_WIN 0 /* Window for outbound maintenance requests */
41+#define IDB_QUEUE 0 /* Inbound Doorbell Queue to use */
42+#define IDB_QSIZE 512 /* Inbound Doorbell Queue size */
43+
44+/* Memory space sizes */
45+#define TSI721_REG_SPACE_SIZE (512 * 1024) /* 512K */
46+#define TSI721_DB_WIN_SIZE (16 * 1024 * 1024) /* 16MB */
47+
48+#define RIO_TT_CODE_8 0x00000000
49+#define RIO_TT_CODE_16 0x00000001
50+
51+#define TSI721_DMA_MAXCH 8
52+#define TSI721_DMA_MINSTSSZ 32
53+#define TSI721_DMA_STSBLKSZ 8
54+
55+#define TSI721_SRIO_MAXCH 8
56+
57+#define DBELL_SID(buf) (((u8)buf[2] << 8) | (u8)buf[3])
58+#define DBELL_TID(buf) (((u8)buf[4] << 8) | (u8)buf[5])
59+#define DBELL_INF(buf) (((u8)buf[0] << 8) | (u8)buf[1])
60+
61+#define TSI721_RIO_PW_MSG_SIZE 16 /* Tsi721 saves only 16 bytes of PW msg */
62+
63+/* Register definitions */
64+
65+/*
66+ * Registers in PCIe configuration space
67+ */
68+
69+#define TSI721_PCIECFG_MSIXTBL 0x0a4
70+#define TSI721_MSIXTBL_OFFSET 0x2c000
71+#define TSI721_PCIECFG_MSIXPBA 0x0a8
72+#define TSI721_MSIXPBA_OFFSET 0x2a000
73+#define TSI721_PCIECFG_EPCTL 0x400
74+
75+/*
76+ * Event Management Registers
77+ */
78+
79+#define TSI721_RIO_EM_INT_STAT 0x10910
80+#define TSI721_RIO_EM_INT_STAT_PW_RX 0x00010000
81+
82+#define TSI721_RIO_EM_INT_ENABLE 0x10914
83+#define TSI721_RIO_EM_INT_ENABLE_PW_RX 0x00010000
84+
85+#define TSI721_RIO_EM_DEV_INT_EN 0x10930
86+#define TSI721_RIO_EM_DEV_INT_EN_INT 0x00000001
87+
88+/*
89+ * Port-Write Block Registers
90+ */
91+
92+#define TSI721_RIO_PW_CTL 0x10a04
93+#define TSI721_RIO_PW_CTL_PW_TIMER 0xf0000000
94+#define TSI721_RIO_PW_CTL_PWT_DIS (0 << 28)
95+#define TSI721_RIO_PW_CTL_PWT_103 (1 << 28)
96+#define TSI721_RIO_PW_CTL_PWT_205 (1 << 29)
97+#define TSI721_RIO_PW_CTL_PWT_410 (1 << 30)
98+#define TSI721_RIO_PW_CTL_PWT_820 (1 << 31)
99+#define TSI721_RIO_PW_CTL_PWC_MODE 0x01000000
100+#define TSI721_RIO_PW_CTL_PWC_CONT 0x00000000
101+#define TSI721_RIO_PW_CTL_PWC_REL 0x01000000
102+
103+#define TSI721_RIO_PW_RX_STAT 0x10a10
104+#define TSI721_RIO_PW_RX_STAT_WR_SIZE 0x0000f000
105+#define TSI_RIO_PW_RX_STAT_WDPTR 0x00000100
106+#define TSI721_RIO_PW_RX_STAT_PW_SHORT 0x00000008
107+#define TSI721_RIO_PW_RX_STAT_PW_TRUNC 0x00000004
108+#define TSI721_RIO_PW_RX_STAT_PW_DISC 0x00000002
109+#define TSI721_RIO_PW_RX_STAT_PW_VAL 0x00000001
110+
111+#define TSI721_RIO_PW_RX_CAPT(x) (0x10a20 + (x)*4)
112+
113+/*
114+ * Inbound Doorbells
115+ */
116+
117+#define TSI721_IDB_ENTRY_SIZE 64
118+
119+#define TSI721_IDQ_CTL(x) (0x20000 + (x) * 1000)
120+#define TSI721_IDQ_SUSPEND 0x00000002
121+#define TSI721_IDQ_INIT 0x00000001
122+
123+#define TSI721_IDQ_STS(x) (0x20004 + (x) * 1000)
124+#define TSI721_IDQ_RUN 0x00200000
125+
126+#define TSI721_IDQ_MASK(x) (0x20008 + (x) * 1000)
127+#define TSI721_IDQ_MASK_MASK 0xffff0000
128+#define TSI721_IDQ_MASK_PATT 0x0000ffff
129+
130+#define TSI721_IDQ_RP(x) (0x2000c + (x) * 1000)
131+#define TSI721_IDQ_RP_PTR 0x0007ffff
132+
133+#define TSI721_IDQ_WP(x) (0x20010 + (x) * 1000)
134+#define TSI721_IDQ_WP_PTR 0x0007ffff
135+
136+#define TSI721_IDQ_BASEL(x) (0x20014 + (x) * 1000)
137+#define TSI721_IDQ_BASEL_ADDR 0xffffffc0
138+#define TSI721_IDQ_BASEU(x) (0x20018 + (x) * 1000)
139+#define TSI721_IDQ_SIZE(x) (0x2001c + (x) * 1000)
140+#define TSI721_IDQ_SIZE_VAL(size) (__fls(size) - 4)
141+#define TSI721_IDQ_SIZE_MIN 512
142+#define TSI721_IDQ_SIZE_MAX (512 * 1024)
143+
144+#define TSI721_SR_CHINT(x) (0x20040 + (x) * 1000)
145+#define TSI721_SR_CHINTE(x) (0x20044 + (x) * 1000)
146+#define TSI721_SR_CHINTSET(x) (0x20048 + (x) * 1000)
147+#define TSI721_SR_CHINT_ODBOK 0x00000020
148+#define TSI721_SR_CHINT_IDBQRCV 0x00000010
149+#define TSI721_SR_CHINT_SUSP 0x00000008
150+#define TSI721_SR_CHINT_ODBTO 0x00000004
151+#define TSI721_SR_CHINT_ODBRTRY 0x00000002
152+#define TSI721_SR_CHINT_ODBERR 0x00000001
153+#define TSI721_SR_CHINT_ALL 0x0000003f
154+
155+#define TSI721_IBWIN_NUM 8
156+
157+#define TSI721_IBWINLB(x) (0x29000 + (x) * 20)
158+#define TSI721_IBWINLB_BA 0xfffff000
159+#define TSI721_IBWINLB_WEN 0x00000001
160+
161+#define TSI721_SR2PC_GEN_INTE 0x29800
162+#define TSI721_SR2PC_PWE 0x29804
163+#define TSI721_SR2PC_GEN_INT 0x29808
164+
165+#define TSI721_DEV_INTE 0x29840
166+#define TSI721_DEV_INT 0x29844
167+#define TSI721_DEV_INTSET 0x29848
168+#define TSI721_DEV_INT_SMSG_CH 0x00000800
169+#define TSI721_DEV_INT_SMSG_NCH 0x00000400
170+#define TSI721_DEV_INT_SR2PC_CH 0x00000200
171+#define TSI721_DEV_INT_SRIO 0x00000020
172+
173+#define TSI721_DEV_CHAN_INTE 0x2984c
174+#define TSI721_DEV_CHAN_INT 0x29850
175+
176+#define TSI721_INT_SR2PC_CHAN_M 0xff000000
177+#define TSI721_INT_SR2PC_CHAN(x) (1 << (24 + (x)))
178+#define TSI721_INT_IMSG_CHAN_M 0x00ff0000
179+#define TSI721_INT_IMSG_CHAN(x) (1 << (16 + (x)))
180+#define TSI721_INT_OMSG_CHAN_M 0x0000ff00
181+#define TSI721_INT_OMSG_CHAN(x) (1 << (8 + (x)))
182+
183+/*
184+ * PC2SR block registers
185+ */
186+#define TSI721_OBWIN_NUM TSI721_PC2SR_WINS
187+
188+#define TSI721_OBWINLB(x) (0x40000 + (x) * 20)
189+#define TSI721_OBWINLB_BA 0xffff8000
190+#define TSI721_OBWINLB_WEN 0x00000001
191+
192+#define TSI721_OBWINUB(x) (0x40004 + (x) * 20)
193+
194+#define TSI721_OBWINSZ(x) (0x40008 + (x) * 20)
195+#define TSI721_OBWINSZ_SIZE 0x00001f00
196+#define TSI721_OBWIN_SIZE(size) (__fls(size) - 15)
197+
198+#define TSI721_ZONE_SEL 0x41300
199+#define TSI721_ZONE_SEL_RD_WRB 0x00020000
200+#define TSI721_ZONE_SEL_GO 0x00010000
201+#define TSI721_ZONE_SEL_WIN 0x00000038
202+#define TSI721_ZONE_SEL_ZONE 0x00000007
203+
204+#define TSI721_LUT_DATA0 0x41304
205+#define TSI721_LUT_DATA0_ADD 0xfffff000
206+#define TSI721_LUT_DATA0_RDTYPE 0x00000f00
207+#define TSI721_LUT_DATA0_NREAD 0x00000100
208+#define TSI721_LUT_DATA0_MNTRD 0x00000200
209+#define TSI721_LUT_DATA0_RDCRF 0x00000020
210+#define TSI721_LUT_DATA0_WRCRF 0x00000010
211+#define TSI721_LUT_DATA0_WRTYPE 0x0000000f
212+#define TSI721_LUT_DATA0_NWR 0x00000001
213+#define TSI721_LUT_DATA0_MNTWR 0x00000002
214+#define TSI721_LUT_DATA0_NWR_R 0x00000004
215+
216+#define TSI721_LUT_DATA1 0x41308
217+
218+#define TSI721_LUT_DATA2 0x4130c
219+#define TSI721_LUT_DATA2_HC 0xff000000
220+#define TSI721_LUT_DATA2_ADD65 0x000c0000
221+#define TSI721_LUT_DATA2_TT 0x00030000
222+#define TSI721_LUT_DATA2_DSTID 0x0000ffff
223+
224+#define TSI721_PC2SR_INTE 0x41310
225+
226+#define TSI721_DEVCTL 0x48004
227+#define TSI721_DEVCTL_SRBOOT_CMPL 0x00000004
228+
229+#define TSI721_I2C_INT_ENABLE 0x49120
230+
231+/*
232+ * Block DMA Engine Registers
233+ * x = 0..7
234+ */
235+
236+#define TSI721_DMAC_DWRCNT(x) (0x51000 + (x) * 0x1000)
237+#define TSI721_DMAC_DRDCNT(x) (0x51004 + (x) * 0x1000)
238+
239+#define TSI721_DMAC_CTL(x) (0x51008 + (x) * 0x1000)
240+#define TSI721_DMAC_CTL_SUSP 0x00000002
241+#define TSI721_DMAC_CTL_INIT 0x00000001
242+
243+#define TSI721_DMAC_INT(x) (0x5100c + (x) * 0x1000)
244+#define TSI721_DMAC_INT_STFULL 0x00000010
245+#define TSI721_DMAC_INT_DONE 0x00000008
246+#define TSI721_DMAC_INT_SUSP 0x00000004
247+#define TSI721_DMAC_INT_ERR 0x00000002
248+#define TSI721_DMAC_INT_IOFDONE 0x00000001
249+#define TSI721_DMAC_INT_ALL 0x0000001f
250+
251+#define TSI721_DMAC_INTSET(x) (0x51010 + (x) * 0x1000)
252+
253+#define TSI721_DMAC_STS(x) (0x51014 + (x) * 0x1000)
254+#define TSI721_DMAC_STS_ABORT 0x00400000
255+#define TSI721_DMAC_STS_RUN 0x00200000
256+#define TSI721_DMAC_STS_CS 0x001f0000
257+
258+#define TSI721_DMAC_INTE(x) (0x51018 + (x) * 0x1000)
259+
260+#define TSI721_DMAC_DPTRL(x) (0x51024 + (x) * 0x1000)
261+#define TSI721_DMAC_DPTRL_MASK 0xffffffe0
262+
263+#define TSI721_DMAC_DPTRH(x) (0x51028 + (x) * 0x1000)
264+
265+#define TSI721_DMAC_DSBL(x) (0x5102c + (x) * 0x1000)
266+#define TSI721_DMAC_DSBL_MASK 0xffffffc0
267+
268+#define TSI721_DMAC_DSBH(x) (0x51030 + (x) * 0x1000)
269+
270+#define TSI721_DMAC_DSSZ(x) (0x51034 + (x) * 0x1000)
271+#define TSI721_DMAC_DSSZ_SIZE_M 0x0000000f
272+#define TSI721_DMAC_DSSZ_SIZE(size) (__fls(size) - 4)
273+
274+
275+#define TSI721_DMAC_DSRP(x) (0x51038 + (x) * 0x1000)
276+#define TSI721_DMAC_DSRP_MASK 0x0007ffff
277+
278+#define TSI721_DMAC_DSWP(x) (0x5103c + (x) * 0x1000)
279+#define TSI721_DMAC_DSWP_MASK 0x0007ffff
280+
281+#define TSI721_BDMA_INTE 0x5f000
282+
283+/*
284+ * Messaging definitions
285+ */
286+#define TSI721_MSG_BUFFER_SIZE RIO_MAX_MSG_SIZE
287+#define TSI721_MSG_MAX_SIZE RIO_MAX_MSG_SIZE
288+#define TSI721_IMSG_MAXCH 8
289+#define TSI721_IMSG_CHNUM TSI721_IMSG_MAXCH
290+#define TSI721_IMSGD_MIN_RING_SIZE 32
291+#define TSI721_IMSGD_RING_SIZE 512
292+
293+#define TSI721_OMSG_CHNUM 4 /* One channel per MBOX */
294+#define TSI721_OMSGD_MIN_RING_SIZE 32
295+#define TSI721_OMSGD_RING_SIZE 512
296+
297+/*
298+ * Outbound Messaging Engine Registers
299+ * x = 0..7
300+ */
301+
302+#define TSI721_OBDMAC_DWRCNT(x) (0x61000 + (x) * 0x1000)
303+
304+#define TSI721_OBDMAC_DRDCNT(x) (0x61004 + (x) * 0x1000)
305+
306+#define TSI721_OBDMAC_CTL(x) (0x61008 + (x) * 0x1000)
307+#define TSI721_OBDMAC_CTL_MASK 0x00000007
308+#define TSI721_OBDMAC_CTL_RETRY_THR 0x00000004
309+#define TSI721_OBDMAC_CTL_SUSPEND 0x00000002
310+#define TSI721_OBDMAC_CTL_INIT 0x00000001
311+
312+#define TSI721_OBDMAC_INT(x) (0x6100c + (x) * 0x1000)
313+#define TSI721_OBDMAC_INTSET(x) (0x61010 + (x) * 0x1000)
314+#define TSI721_OBDMAC_INTE(x) (0x61018 + (x) * 0x1000)
315+#define TSI721_OBDMAC_INT_MASK 0x0000001F
316+#define TSI721_OBDMAC_INT_ST_FULL 0x00000010
317+#define TSI721_OBDMAC_INT_DONE 0x00000008
318+#define TSI721_OBDMAC_INT_SUSPENDED 0x00000004
319+#define TSI721_OBDMAC_INT_ERROR 0x00000002
320+#define TSI721_OBDMAC_INT_IOF_DONE 0x00000001
321+#define TSI721_OBDMAC_INT_ALL TSI721_OBDMAC_INT_MASK
322+
323+#define TSI721_OBDMAC_STS(x) (0x61014 + (x) * 0x1000)
324+#define TSI721_OBDMAC_STS_MASK 0x007f0000
325+#define TSI721_OBDMAC_STS_ABORT 0x00400000
326+#define TSI721_OBDMAC_STS_RUN 0x00200000
327+#define TSI721_OBDMAC_STS_CS 0x001f0000
328+
329+#define TSI721_OBDMAC_PWE(x) (0x6101c + (x) * 0x1000)
330+#define TSI721_OBDMAC_PWE_MASK 0x00000002
331+#define TSI721_OBDMAC_PWE_ERROR_EN 0x00000002
332+
333+#define TSI721_OBDMAC_DPTRL(x) (0x61020 + (x) * 0x1000)
334+#define TSI721_OBDMAC_DPTRL_MASK 0xfffffff0
335+
336+#define TSI721_OBDMAC_DPTRH(x) (0x61024 + (x) * 0x1000)
337+#define TSI721_OBDMAC_DPTRH_MASK 0xffffffff
338+
339+#define TSI721_OBDMAC_DSBL(x) (0x61040 + (x) * 0x1000)
340+#define TSI721_OBDMAC_DSBL_MASK 0xffffffc0
341+
342+#define TSI721_OBDMAC_DSBH(x) (0x61044 + (x) * 0x1000)
343+#define TSI721_OBDMAC_DSBH_MASK 0xffffffff
344+
345+#define TSI721_OBDMAC_DSSZ(x) (0x61048 + (x) * 0x1000)
346+#define TSI721_OBDMAC_DSSZ_MASK 0x0000000f
347+
348+#define TSI721_OBDMAC_DSRP(x) (0x6104c + (x) * 0x1000)
349+#define TSI721_OBDMAC_DSRP_MASK 0x0007ffff
350+
351+#define TSI721_OBDMAC_DSWP(x) (0x61050 + (x) * 0x1000)
352+#define TSI721_OBDMAC_DSWP_MASK 0x0007ffff
353+
354+#define TSI721_RQRPTO 0x60010
355+#define TSI721_RQRPTO_MASK 0x00ffffff
356+#define TSI721_RQRPTO_VAL 400 /* Response TO value */
357+
358+/*
359+ * Inbound Messaging Engine Registers
360+ * x = 0..7
361+ */
362+
363+#define TSI721_IB_DEVID_GLOBAL 0xffff
364+#define TSI721_IBDMAC_FQBL(x) (0x61200 + (x) * 0x1000)
365+#define TSI721_IBDMAC_FQBL_MASK 0xffffffc0
366+
367+#define TSI721_IBDMAC_FQBH(x) (0x61204 + (x) * 0x1000)
368+#define TSI721_IBDMAC_FQBH_MASK 0xffffffff
369+
370+#define TSI721_IBDMAC_FQSZ_ENTRY_INX TSI721_IMSGD_RING_SIZE
371+#define TSI721_IBDMAC_FQSZ(x) (0x61208 + (x) * 0x1000)
372+#define TSI721_IBDMAC_FQSZ_MASK 0x0000000f
373+
374+#define TSI721_IBDMAC_FQRP(x) (0x6120c + (x) * 0x1000)
375+#define TSI721_IBDMAC_FQRP_MASK 0x0007ffff
376+
377+#define TSI721_IBDMAC_FQWP(x) (0x61210 + (x) * 0x1000)
378+#define TSI721_IBDMAC_FQWP_MASK 0x0007ffff
379+
380+#define TSI721_IBDMAC_FQTH(x) (0x61214 + (x) * 0x1000)
381+#define TSI721_IBDMAC_FQTH_MASK 0x0007ffff
382+
383+#define TSI721_IB_DEVID 0x60020
384+#define TSI721_IB_DEVID_MASK 0x0000ffff
385+
386+#define TSI721_IBDMAC_CTL(x) (0x61240 + (x) * 0x1000)
387+#define TSI721_IBDMAC_CTL_MASK 0x00000003
388+#define TSI721_IBDMAC_CTL_SUSPEND 0x00000002
389+#define TSI721_IBDMAC_CTL_INIT 0x00000001
390+
391+#define TSI721_IBDMAC_STS(x) (0x61244 + (x) * 0x1000)
392+#define TSI721_IBDMAC_STS_MASK 0x007f0000
393+#define TSI721_IBSMAC_STS_ABORT 0x00400000
394+#define TSI721_IBSMAC_STS_RUN 0x00200000
395+#define TSI721_IBSMAC_STS_CS 0x001f0000
396+
397+#define TSI721_IBDMAC_INT(x) (0x61248 + (x) * 0x1000)
398+#define TSI721_IBDMAC_INTSET(x) (0x6124c + (x) * 0x1000)
399+#define TSI721_IBDMAC_INTE(x) (0x61250 + (x) * 0x1000)
400+#define TSI721_IBDMAC_INT_MASK 0x0000100f
401+#define TSI721_IBDMAC_INT_SRTO 0x00001000
402+#define TSI721_IBDMAC_INT_SUSPENDED 0x00000008
403+#define TSI721_IBDMAC_INT_PC_ERROR 0x00000004
404+#define TSI721_IBDMAC_INT_FQ_LOW 0x00000002
405+#define TSI721_IBDMAC_INT_DQ_RCV 0x00000001
406+#define TSI721_IBDMAC_INT_ALL TSI721_IBDMAC_INT_MASK
407+
408+#define TSI721_IBDMAC_PWE(x) (0x61254 + (x) * 0x1000)
409+#define TSI721_IBDMAC_PWE_MASK 0x00001700
410+#define TSI721_IBDMAC_PWE_SRTO 0x00001000
411+#define TSI721_IBDMAC_PWE_ILL_FMT 0x00000400
412+#define TSI721_IBDMAC_PWE_ILL_DEC 0x00000200
413+#define TSI721_IBDMAC_PWE_IMP_SP 0x00000100
414+
415+#define TSI721_IBDMAC_DQBL(x) (0x61300 + (x) * 0x1000)
416+#define TSI721_IBDMAC_DQBL_MASK 0xffffffc0
417+#define TSI721_IBDMAC_DQBL_ADDR 0xffffffc0
418+
419+#define TSI721_IBDMAC_DQBH(x) (0x61304 + (x) * 0x1000)
420+#define TSI721_IBDMAC_DQBH_MASK 0xffffffff
421+
422+#define TSI721_IBDMAC_DQRP(x) (0x61308 + (x) * 0x1000)
423+#define TSI721_IBDMAC_DQRP_MASK 0x0007ffff
424+
425+#define TSI721_IBDMAC_DQWR(x) (0x6130c + (x) * 0x1000)
426+#define TSI721_IBDMAC_DQWR_MASK 0x0007ffff
427+
428+#define TSI721_IBDMAC_DQSZ(x) (0x61314 + (x) * 0x1000)
429+#define TSI721_IBDMAC_DQSZ_MASK 0x0000000f
430+
431+/*
432+ * Messaging Engine Interrupts
433+ */
434+
435+#define TSI721_SMSG_PWE 0x6a004
436+
437+#define TSI721_SMSG_INTE 0x6a000
438+#define TSI721_SMSG_INT 0x6a008
439+#define TSI721_SMSG_INTSET 0x6a010
440+#define TSI721_SMSG_INT_MASK 0x0086ffff
441+#define TSI721_SMSG_INT_UNS_RSP 0x00800000
442+#define TSI721_SMSG_INT_ECC_NCOR 0x00040000
443+#define TSI721_SMSG_INT_ECC_COR 0x00020000
444+#define TSI721_SMSG_INT_ECC_NCOR_CH 0x0000ff00
445+#define TSI721_SMSG_INT_ECC_COR_CH 0x000000ff
446+
447+#define TSI721_SMSG_ECC_LOG 0x6a014
448+#define TSI721_SMSG_ECC_LOG_MASK 0x00070007
449+#define TSI721_SMSG_ECC_LOG_ECC_NCOR_M 0x00070000
450+#define TSI721_SMSG_ECC_LOG_ECC_COR_M 0x00000007
451+
452+#define TSI721_RETRY_GEN_CNT 0x6a100
453+#define TSI721_RETRY_GEN_CNT_MASK 0xffffffff
454+
455+#define TSI721_RETRY_RX_CNT 0x6a104
456+#define TSI721_RETRY_RX_CNT_MASK 0xffffffff
457+
458+#define TSI721_SMSG_ECC_COR_LOG(x) (0x6a300 + (x) * 4)
459+#define TSI721_SMSG_ECC_COR_LOG_MASK 0x000000ff
460+
461+#define TSI721_SMSG_ECC_NCOR(x) (0x6a340 + (x) * 4)
462+#define TSI721_SMSG_ECC_NCOR_MASK 0x000000ff
463+
464+/*
465+ * Block DMA Descriptors
466+ */
467+
468+struct tsi721_dma_desc {
469+ __le32 type_id;
470+
471+#define TSI721_DMAD_DEVID 0x0000ffff
472+#define TSI721_DMAD_CRF 0x00010000
473+#define TSI721_DMAD_PRIO 0x00060000
474+#define TSI721_DMAD_RTYPE 0x00780000
475+#define TSI721_DMAD_IOF 0x08000000
476+#define TSI721_DMAD_DTYPE 0xe0000000
477+
478+ __le32 bcount;
479+
480+#define TSI721_DMAD_BCOUNT1 0x03ffffff /* if DTYPE == 1 */
481+#define TSI721_DMAD_BCOUNT2 0x0000000f /* if DTYPE == 2 */
482+#define TSI721_DMAD_TT 0x0c000000
483+#define TSI721_DMAD_RADDR0 0xc0000000
484+
485+ union {
486+ __le32 raddr_lo; /* if DTYPE == (1 || 2) */
487+ __le32 next_lo; /* if DTYPE == 3 */
488+ };
489+
490+#define TSI721_DMAD_CFGOFF 0x00ffffff
491+#define TSI721_DMAD_HOPCNT 0xff000000
492+
493+ union {
494+ __le32 raddr_hi; /* if DTYPE == (1 || 2) */
495+ __le32 next_hi; /* if DTYPE == 3 */
496+ };
497+
498+ union {
499+ struct { /* if DTYPE == 1 */
500+ __le32 bufptr_lo;
501+ __le32 bufptr_hi;
502+ __le32 s_dist;
503+ __le32 s_size;
504+ } t1;
505+ __le32 data[4]; /* if DTYPE == 2 */
506+ u32 reserved[4]; /* if DTYPE == 3 */
507+ };
508+} __aligned(32);
509+
510+/*
511+ * Inbound Messaging Descriptor
512+ */
513+struct tsi721_imsg_desc {
514+ __le32 type_id;
515+
516+#define TSI721_IMD_DEVID 0x0000ffff
517+#define TSI721_IMD_CRF 0x00010000
518+#define TSI721_IMD_PRIO 0x00060000
519+#define TSI721_IMD_TT 0x00180000
520+#define TSI721_IMD_DTYPE 0xe0000000
521+
522+ __le32 msg_info;
523+
524+#define TSI721_IMD_BCOUNT 0x00000ff8
525+#define TSI721_IMD_SSIZE 0x0000f000
526+#define TSI721_IMD_LETER 0x00030000
527+#define TSI721_IMD_XMBOX 0x003c0000
528+#define TSI721_IMD_MBOX 0x00c00000
529+#define TSI721_IMD_CS 0x78000000
530+#define TSI721_IMD_HO 0x80000000
531+
532+ __le32 bufptr_lo;
533+ __le32 bufptr_hi;
534+ u32 reserved[12];
535+
536+} __aligned(64);
537+
538+/*
539+ * Outbound Messaging Descriptor
540+ */
541+struct tsi721_omsg_desc {
542+ __le32 type_id;
543+
544+#define TSI721_OMD_DEVID 0x0000ffff
545+#define TSI721_OMD_CRF 0x00010000
546+#define TSI721_OMD_PRIO 0x00060000
547+#define TSI721_OMD_IOF 0x08000000
548+#define TSI721_OMD_DTYPE 0xe0000000
549+#define TSI721_OMD_RSRVD 0x17f80000
550+
551+ __le32 msg_info;
552+
553+#define TSI721_OMD_BCOUNT 0x00000ff8
554+#define TSI721_OMD_SSIZE 0x0000f000
555+#define TSI721_OMD_LETER 0x00030000
556+#define TSI721_OMD_XMBOX 0x003c0000
557+#define TSI721_OMD_MBOX 0x00c00000
558+#define TSI721_OMD_TT 0x0c000000
559+
560+ union {
561+ __le32 bufptr_lo; /* if DTYPE == 4 */
562+ __le32 next_lo; /* if DTYPE == 5 */
563+ };
564+
565+ union {
566+ __le32 bufptr_hi; /* if DTYPE == 4 */
567+ __le32 next_hi; /* if DTYPE == 5 */
568+ };
569+
570+} __aligned(16);
571+
572+struct tsi721_dma_sts {
573+ __le64 desc_sts[8];
574+} __aligned(64);
575+
576+struct tsi721_desc_sts_fifo {
577+ union {
578+ __le64 da64;
579+ struct {
580+ __le32 lo;
581+ __le32 hi;
582+ } da32;
583+ } stat[8];
584+} __aligned(64);
585+
586+/* Descriptor types for BDMA and Messaging blocks */
587+enum dma_dtype {
588+ DTYPE1 = 1, /* Data Transfer DMA Descriptor */
589+ DTYPE2 = 2, /* Immediate Data Transfer DMA Descriptor */
590+ DTYPE3 = 3, /* Block Pointer DMA Descriptor */
591+ DTYPE4 = 4, /* Outbound Msg DMA Descriptor */
592+ DTYPE5 = 5, /* OB Messaging Block Pointer Descriptor */
593+ DTYPE6 = 6 /* Inbound Messaging Descriptor */
594+};
595+
596+enum dma_rtype {
597+ NREAD = 0,
598+ LAST_NWRITE_R = 1,
599+ ALL_NWRITE = 2,
600+ ALL_NWRITE_R = 3,
601+ MAINT_RD = 4,
602+ MAINT_WR = 5
603+};
604+
605+/*
606+ * mport Driver Definitions
607+ */
608+#define TSI721_DMA_CHNUM TSI721_DMA_MAXCH
609+
610+#define TSI721_DMACH_MAINT 0 /* DMA channel for maint requests */
611+#define TSI721_DMACH_MAINT_NBD 32 /* Number of BDs for maint requests */
612+
613+#define MSG_DMA_ENTRY_INX_TO_SIZE(x) ((0x10 << (x)) & 0xFFFF0)
614+
615+enum tsi721_smsg_int_flag {
616+ SMSG_INT_NONE = 0x00000000,
617+ SMSG_INT_ECC_COR_CH = 0x000000ff,
618+ SMSG_INT_ECC_NCOR_CH = 0x0000ff00,
619+ SMSG_INT_ECC_COR = 0x00020000,
620+ SMSG_INT_ECC_NCOR = 0x00040000,
621+ SMSG_INT_UNS_RSP = 0x00800000,
622+ SMSG_INT_ALL = 0x0006ffff
623+};
624+
625+/* Structures */
626+
627+struct tsi721_bdma_chan {
628+ int bd_num; /* number of buffer descriptors */
629+ void *bd_base; /* start of DMA descriptors */
630+ dma_addr_t bd_phys;
631+ void *sts_base; /* start of DMA BD status FIFO */
632+ dma_addr_t sts_phys;
633+ int sts_size;
634+};
635+
636+struct tsi721_imsg_ring {
637+ u32 size;
638+ /* VA/PA of data buffers for incoming messages */
639+ void *buf_base;
640+ dma_addr_t buf_phys;
641+ /* VA/PA of circular free buffer list */
642+ void *imfq_base;
643+ dma_addr_t imfq_phys;
644+ /* VA/PA of Inbound message descriptors */
645+ void *imd_base;
646+ dma_addr_t imd_phys;
647+ /* Inbound Queue buffer pointers */
648+ void *imq_base[TSI721_IMSGD_RING_SIZE];
649+
650+ u32 rx_slot;
651+ void *dev_id;
652+ u32 fq_wrptr;
653+ u32 desc_rdptr;
654+ spinlock_t lock;
655+};
656+
657+struct tsi721_omsg_ring {
658+ u32 size;
659+ /* VA/PA of OB Msg descriptors */
660+ void *omd_base;
661+ dma_addr_t omd_phys;
662+ /* VA/PA of OB Msg data buffers */
663+ void *omq_base[TSI721_OMSGD_RING_SIZE];
664+ dma_addr_t omq_phys[TSI721_OMSGD_RING_SIZE];
665+ /* VA/PA of OB Msg descriptor status FIFO */
666+ void *sts_base;
667+ dma_addr_t sts_phys;
668+ u32 sts_size; /* # of allocated status entries */
669+ u32 sts_rdptr;
670+
671+ u32 tx_slot;
672+ void *dev_id;
673+ u32 wr_count;
674+ spinlock_t lock;
675+};
676+
677+enum tsi721_flags {
678+ TSI721_USING_MSI = (1 << 0),
679+ TSI721_USING_MSIX = (1 << 1),
680+ TSI721_IMSGID_SET = (1 << 2),
681+};
682+
683+#ifdef CONFIG_PCI_MSI
684+/*
685+ * MSI-X Table Entries (0 ... 69)
686+ */
687+#define TSI721_MSIX_DMACH_DONE(x) (0 + (x))
688+#define TSI721_MSIX_DMACH_INT(x) (8 + (x))
689+#define TSI721_MSIX_BDMA_INT 16
690+#define TSI721_MSIX_OMSG_DONE(x) (17 + (x))
691+#define TSI721_MSIX_OMSG_INT(x) (25 + (x))
692+#define TSI721_MSIX_IMSG_DQ_RCV(x) (33 + (x))
693+#define TSI721_MSIX_IMSG_INT(x) (41 + (x))
694+#define TSI721_MSIX_MSG_INT 49
695+#define TSI721_MSIX_SR2PC_IDBQ_RCV(x) (50 + (x))
696+#define TSI721_MSIX_SR2PC_CH_INT(x) (58 + (x))
697+#define TSI721_MSIX_SR2PC_INT 66
698+#define TSI721_MSIX_PC2SR_INT 67
699+#define TSI721_MSIX_SRIO_MAC_INT 68
700+#define TSI721_MSIX_I2C_INT 69
701+
702+/* MSI-X vector and init table entry indexes */
703+enum tsi721_msix_vect {
704+ TSI721_VECT_IDB,
705+ TSI721_VECT_PWRX, /* PW_RX is part of SRIO MAC Interrupt reporting */
706+ TSI721_VECT_OMB0_DONE,
707+ TSI721_VECT_OMB1_DONE,
708+ TSI721_VECT_OMB2_DONE,
709+ TSI721_VECT_OMB3_DONE,
710+ TSI721_VECT_OMB0_INT,
711+ TSI721_VECT_OMB1_INT,
712+ TSI721_VECT_OMB2_INT,
713+ TSI721_VECT_OMB3_INT,
714+ TSI721_VECT_IMB0_RCV,
715+ TSI721_VECT_IMB1_RCV,
716+ TSI721_VECT_IMB2_RCV,
717+ TSI721_VECT_IMB3_RCV,
718+ TSI721_VECT_IMB0_INT,
719+ TSI721_VECT_IMB1_INT,
720+ TSI721_VECT_IMB2_INT,
721+ TSI721_VECT_IMB3_INT,
722+ TSI721_VECT_MAX
723+};
724+
725+#define IRQ_DEVICE_NAME_MAX 64
726+
727+struct msix_irq {
728+ u16 vector;
729+ char irq_name[IRQ_DEVICE_NAME_MAX];
730+};
731+#endif /* CONFIG_PCI_MSI */
732+
733+struct tsi721_device {
734+ struct pci_dev *pdev;
735+ struct rio_mport *mport;
736+ u32 flags;
737+ void __iomem *regs;
738+#ifdef CONFIG_PCI_MSI
739+ struct msix_irq msix[TSI721_VECT_MAX];
740+#endif
741+ /* Doorbells */
742+ void __iomem *odb_base;
743+ void *idb_base;
744+ dma_addr_t idb_dma;
745+ struct work_struct idb_work;
746+ u32 db_discard_count;
747+
748+ /* Inbound Port-Write */
749+ struct work_struct pw_work;
750+ struct kfifo pw_fifo;
751+ spinlock_t pw_fifo_lock;
752+ u32 pw_discard_count;
753+
754+ /* BDMA Engine */
755+ struct tsi721_bdma_chan bdma[TSI721_DMA_CHNUM];
756+
757+ /* Inbound Messaging */
758+ int imsg_init[TSI721_IMSG_CHNUM];
759+ struct tsi721_imsg_ring imsg_ring[TSI721_IMSG_CHNUM];
760+
761+ /* Outbound Messaging */
762+ int omsg_init[TSI721_OMSG_CHNUM];
763+ struct tsi721_omsg_ring omsg_ring[TSI721_OMSG_CHNUM];
764+};
765+
766+#endif
drivers/rapidio/rio-scan.c+3−3
@@ -516,7 +516,7 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net, · 515 unmodified lines
516516 return rdev;
517517
518518 cleanup:
519− if (rio_is_switch(rdev))
519+ if (rswitch)
520520 kfree(rswitch->route_table);
521521
522522 kfree(rdev);
@@ -923,7 +923,7 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port, · 400 unmodified lines
923923 * rio_enum_complete- Tests if enumeration of a network is complete
924924 * @port: Master port to send transaction
925925 *
926− * Tests the Component Tag CSR for non-zero value (enumeration
926+ * Tests the PGCCSR discovered bit for non-zero value (enumeration
927927 * complete flag). Return %1 if enumeration is complete or %0 if
928928 * enumeration is incomplete.
929929 */
@@ -933,7 +933,7 @@ static int rio_enum_complete(struct rio_mport *port) · 3 unmodified lines
933933
934934 rio_local_read_config_32(port, port->phys_efptr + RIO_PORT_GEN_CTL_CSR,
935935 &regval);
936− return (regval & RIO_PORT_GEN_MASTER) ? 1 : 0;
936+ return (regval & RIO_PORT_GEN_DISCOVERED) ? 1 : 0;
937937 }
938938
939939 /**
drivers/rtc/class.c+9−23
@@ -21,16 +21,13 @@ · 20 unmodified lines
2121 #include "rtc-core.h"
2222
2323
24−static DEFINE_IDR(rtc_idr);
25−static DEFINE_MUTEX(idr_lock);
24+static DEFINE_IDA(rtc_ida);
2625 struct class *rtc_class;
2726
2827 static void rtc_device_release(struct device *dev)
2928 {
3029 struct rtc_device *rtc = to_rtc_device(dev);
31− mutex_lock(&idr_lock);
32− idr_remove(&rtc_idr, rtc->id);
33− mutex_unlock(&idr_lock);
30+ ida_simple_remove(&rtc_ida, rtc->id);
3431 kfree(rtc);
3532 }
3633
@@ -146,25 +143,16 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, · 109 unmodified lines
146143 struct rtc_wkalrm alrm;
147144 int id, err;
148145
149− if (idr_pre_get(&rtc_idr, GFP_KERNEL) == 0) {
150− err = -ENOMEM;
146+ id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL);
147+ if (id < 0) {
148+ err = id;
151149 goto exit;
152150 }
153151
154−
155− mutex_lock(&idr_lock);
156− err = idr_get_new(&rtc_idr, NULL, &id);
157− mutex_unlock(&idr_lock);
158−
159− if (err < 0)
160− goto exit;
161−
162− id = id & MAX_ID_MASK;
163−
164152 rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL);
165153 if (rtc == NULL) {
166154 err = -ENOMEM;
167− goto exit_idr;
155+ goto exit_ida;
168156 }
169157
170158 rtc->id = id;
@@ -222,10 +210,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, · 51 unmodified lines
222210 exit_kfree:
223211 kfree(rtc);
224212
225−exit_idr:
226− mutex_lock(&idr_lock);
227− idr_remove(&rtc_idr, id);
228− mutex_unlock(&idr_lock);
213+exit_ida:
214+ ida_simple_remove(&rtc_ida, id);
229215
230216 exit:
231217 dev_err(dev, "rtc core: unable to register %s, err = %d\n",
@@ -276,7 +262,7 @@ static void __exit rtc_exit(void) · 44 unmodified lines
276262 {
277263 rtc_dev_exit();
278264 class_destroy(rtc_class);
279− idr_destroy(&rtc_idr);
265+ ida_destroy(&rtc_ida);
280266 }
281267
282268 subsys_initcall(rtc_init);
drivers/rtc/rtc-ds1307.c+27−0
@@ -34,6 +34,7 @@ enum ds_type { · 33 unmodified lines
3434 ds_1388,
3535 ds_3231,
3636 m41t00,
37+ mcp7941x,
3738 rx_8025,
3839 // rs5c372 too? different address...
3940 };
@@ -43,6 +44,7 @@ enum ds_type { · 3 unmodified lines
4344 #define DS1307_REG_SECS 0x00 /* 00-59 */
4445 # define DS1307_BIT_CH 0x80
4546 # define DS1340_BIT_nEOSC 0x80
47+# define MCP7941X_BIT_ST 0x80
4648 #define DS1307_REG_MIN 0x01 /* 00-59 */
4749 #define DS1307_REG_HOUR 0x02 /* 00-23, or 1-12{am,pm} */
4850 # define DS1307_BIT_12HR 0x40 /* in REG_HOUR */
@@ -50,6 +52,7 @@ enum ds_type { · 1 unmodified line
5052 # define DS1340_BIT_CENTURY_EN 0x80 /* in REG_HOUR */
5153 # define DS1340_BIT_CENTURY 0x40 /* in REG_HOUR */
5254 #define DS1307_REG_WDAY 0x03 /* 01-07 */
55+# define MCP7941X_BIT_VBATEN 0x08
5356 #define DS1307_REG_MDAY 0x04 /* 01-31 */
5457 #define DS1307_REG_MONTH 0x05 /* 01-12 */
5558 # define DS1337_BIT_CENTURY 0x80 /* in REG_MONTH */
@@ -137,6 +140,8 @@ static const struct chip_desc chips[] = { · 81 unmodified lines
137140 },
138141 [m41t00] = {
139142 },
143+[mcp7941x] = {
144+},
140145 [rx_8025] = {
141146 }, };
142147
@@ -149,6 +154,7 @@ static const struct i2c_device_id ds1307_id[] = { · 6 unmodified lines
149154 { "ds1340", ds_1340 },
150155 { "ds3231", ds_3231 },
151156 { "m41t00", m41t00 },
157+ { "mcp7941x", mcp7941x },
152158 { "pt7c4338", ds_1307 },
153159 { "rx8025", rx_8025 },
154160 { }
@@ -365,6 +371,10 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t) · 210 unmodified lines
365371 buf[DS1307_REG_HOUR] |= DS1340_BIT_CENTURY_EN
366372 | DS1340_BIT_CENTURY;
367373 break;
374+ case mcp7941x:
375+ buf[DS1307_REG_SECS] |= MCP7941X_BIT_ST;
376+ buf[DS1307_REG_WDAY] |= MCP7941X_BIT_VBATEN;
377+ break;
368378 default:
369379 break;
370380 }
@@ -808,6 +818,23 @@ read_rtc: · 437 unmodified lines
808818 i2c_smbus_write_byte_data(client, DS1340_REG_FLAG, 0);
809819 dev_warn(&client->dev, "SET TIME!\n");
810820 }
821+ break;
822+ case mcp7941x:
823+ /* make sure that the backup battery is enabled */
824+ if (!(ds1307->regs[DS1307_REG_WDAY] & MCP7941X_BIT_VBATEN)) {
825+ i2c_smbus_write_byte_data(client, DS1307_REG_WDAY,
826+ ds1307->regs[DS1307_REG_WDAY]
827+ | MCP7941X_BIT_VBATEN);
828+ }
829+
830+ /* clock halted? turn it on, so clock can tick. */
831+ if (!(tmp & MCP7941X_BIT_ST)) {
832+ i2c_smbus_write_byte_data(client, DS1307_REG_SECS,
833+ MCP7941X_BIT_ST);
834+ dev_warn(&client->dev, "SET TIME!\n");
835+ goto read_rtc;
836+ }
837+
811838 break;
812839 case rx_8025:
813840 case ds_1337:
drivers/rtc/rtc-mc13xxx.c+3−3
@@ -309,7 +309,7 @@ static irqreturn_t mc13xxx_rtc_reset_handler(int irq, void *dev) · 308 unmodified lines
309309 return IRQ_HANDLED;
310310 }
311311
312−static int __devinit mc13xxx_rtc_probe(struct platform_device *pdev)
312+static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
313313 {
314314 int ret;
315315 struct mc13xxx_rtc *priv;
@@ -378,7 +378,7 @@ err_reset_irq_request: · 62 unmodified lines
378378 return ret;
379379 }
380380
381−static int __devexit mc13xxx_rtc_remove(struct platform_device *pdev)
381+static int __exit mc13xxx_rtc_remove(struct platform_device *pdev)
382382 {
383383 struct mc13xxx_rtc *priv = platform_get_drvdata(pdev);
384384
@@ -410,7 +410,7 @@ const struct platform_device_id mc13xxx_rtc_idtable[] = { · 25 unmodified lines
410410
411411 static struct platform_driver mc13xxx_rtc_driver = {
412412 .id_table = mc13xxx_rtc_idtable,
413− .remove = __devexit_p(mc13xxx_rtc_remove),
413+ .remove = __exit_p(mc13xxx_rtc_remove),
414414 .driver = {
415415 .name = DRIVER_NAME,
416416 .owner = THIS_MODULE,
drivers/w1/slaves/w1_ds2760.c+6−42
@@ -114,43 +114,7 @@ static struct bin_attribute w1_ds2760_bin_attr = { · 113 unmodified lines
114114 .read = w1_ds2760_read_bin,
115115 };
116116
117−static DEFINE_IDR(bat_idr);
118−static DEFINE_MUTEX(bat_idr_lock);
119−
120−static int new_bat_id(void)
121−{
122− int ret;
123−
124− while (1) {
125− int id;
126−
127− ret = idr_pre_get(&bat_idr, GFP_KERNEL);
128− if (ret == 0)
129− return -ENOMEM;
130−
131− mutex_lock(&bat_idr_lock);
132− ret = idr_get_new(&bat_idr, NULL, &id);
133− mutex_unlock(&bat_idr_lock);
134−
135− if (ret == 0) {
136− ret = id & MAX_ID_MASK;
137− break;
138− } else if (ret == -EAGAIN) {
139− continue;
140− } else {
141− break;
142− }
143− }
144−
145− return ret;
146−}
147−
148−static void release_bat_id(int id)
149−{
150− mutex_lock(&bat_idr_lock);
151− idr_remove(&bat_idr, id);
152− mutex_unlock(&bat_idr_lock);
153−}
117+static DEFINE_IDA(bat_ida);
154118
155119 static int w1_ds2760_add_slave(struct w1_slave *sl)
156120 {
@@ -158,7 +122,7 @@ static int w1_ds2760_add_slave(struct w1_slave *sl) · 1 unmodified line
158122 int id;
159123 struct platform_device *pdev;
160124
161− id = new_bat_id();
125+ id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL);
162126 if (id < 0) {
163127 ret = id;
164128 goto noid;
@@ -187,7 +151,7 @@ bin_attr_failed: · 22 unmodified lines
187151 pdev_add_failed:
188152 platform_device_unregister(pdev);
189153 pdev_alloc_failed:
190− release_bat_id(id);
154+ ida_simple_remove(&bat_ida, id);
191155 noid:
192156 success:
193157 return ret;
@@ -199,7 +163,7 @@ static void w1_ds2760_remove_slave(struct w1_slave *sl) · 5 unmodified lines
199163 int id = pdev->id;
200164
201165 platform_device_unregister(pdev);
202− release_bat_id(id);
166+ ida_simple_remove(&bat_ida, id);
203167 sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2760_bin_attr);
204168 }
205169
@@ -217,14 +181,14 @@ static int __init w1_ds2760_init(void) · 11 unmodified lines
217181 {
218182 printk(KERN_INFO "1-Wire driver for the DS2760 battery monitor "
219183 " chip - (c) 2004-2005, Szabolcs Gyurko\n");
220− idr_init(&bat_idr);
184+ ida_init(&bat_ida);
221185 return w1_register_family(&w1_ds2760_family);
222186 }
223187
224188 static void __exit w1_ds2760_exit(void)
225189 {
226190 w1_unregister_family(&w1_ds2760_family);
227− idr_destroy(&bat_idr);
191+ ida_destroy(&bat_ida);
228192 }
229193
230194 EXPORT_SYMBOL(w1_ds2760_read);
drivers/w1/slaves/w1_ds2780.c+41−55
@@ -26,20 +26,14 @@ · 25 unmodified lines
2626 #include "../w1_family.h"
2727 #include "w1_ds2780.h"
2828
29−int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
30− int io)
29+static int w1_ds2780_do_io(struct device *dev, char *buf, int addr,
30+ size_t count, int io)
3131 {
3232 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
3333
34− if (!dev)
35− return -ENODEV;
34+ if (addr > DS2780_DATA_SIZE || addr < 0)
35+ return 0;
3636
37− mutex_lock(&sl->master->mutex);
38−
39− if (addr > DS2780_DATA_SIZE || addr < 0) {
40− count = 0;
41− goto out;
42− }
4337 count = min_t(int, count, DS2780_DATA_SIZE - addr);
4438
4539 if (w1_reset_select_slave(sl) == 0) {
@@ -47,7 +41,6 @@ int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, · 1 unmodified line
4741 w1_write_8(sl->master, W1_DS2780_WRITE_DATA);
4842 w1_write_8(sl->master, addr);
4943 w1_write_block(sl->master, buf, count);
50− /* XXX w1_write_block returns void, not n_written */
5144 } else {
5245 w1_write_8(sl->master, W1_DS2780_READ_DATA);
5346 w1_write_8(sl->master, addr);
@@ -55,13 +48,42 @@ int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, · 1 unmodified line
5548 }
5649 }
5750
58−out:
51+ return count;
52+}
53+
54+int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
55+ int io)
56+{
57+ struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
58+ int ret;
59+
60+ if (!dev)
61+ return -ENODEV;
62+
63+ mutex_lock(&sl->master->mutex);
64+
65+ ret = w1_ds2780_do_io(dev, buf, addr, count, io);
66+
5967 mutex_unlock(&sl->master->mutex);
6068
61− return count;
69+ return ret;
6270 }
6371 EXPORT_SYMBOL(w1_ds2780_io);
6472
73+int w1_ds2780_io_nolock(struct device *dev, char *buf, int addr, size_t count,
74+ int io)
75+{
76+ int ret;
77+
78+ if (!dev)
79+ return -ENODEV;
80+
81+ ret = w1_ds2780_do_io(dev, buf, addr, count, io);
82+
83+ return ret;
84+}
85+EXPORT_SYMBOL(w1_ds2780_io_nolock);
86+
6587 int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd)
6688 {
6789 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
@@ -99,43 +121,7 @@ static struct bin_attribute w1_ds2780_bin_attr = { · 31 unmodified lines
99121 .read = w1_ds2780_read_bin,
100122 };
101123
102−static DEFINE_IDR(bat_idr);
103−static DEFINE_MUTEX(bat_idr_lock);
104−
105−static int new_bat_id(void)
106−{
107− int ret;
108−
109− while (1) {
110− int id;
111−
112− ret = idr_pre_get(&bat_idr, GFP_KERNEL);
113− if (ret == 0)
114− return -ENOMEM;
115−
116− mutex_lock(&bat_idr_lock);
117− ret = idr_get_new(&bat_idr, NULL, &id);
118− mutex_unlock(&bat_idr_lock);
119−
120− if (ret == 0) {
121− ret = id & MAX_ID_MASK;
122− break;
123− } else if (ret == -EAGAIN) {
124− continue;
125− } else {
126− break;
127− }
128− }
129−
130− return ret;
131−}
132−
133−static void release_bat_id(int id)
134−{
135− mutex_lock(&bat_idr_lock);
136− idr_remove(&bat_idr, id);
137− mutex_unlock(&bat_idr_lock);
138−}
124+static DEFINE_IDA(bat_ida);
139125
140126 static int w1_ds2780_add_slave(struct w1_slave *sl)
141127 {
@@ -143,7 +129,7 @@ static int w1_ds2780_add_slave(struct w1_slave *sl) · 1 unmodified line
143129 int id;
144130 struct platform_device *pdev;
145131
146− id = new_bat_id();
132+ id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL);
147133 if (id < 0) {
148134 ret = id;
149135 goto noid;
@@ -172,7 +158,7 @@ bin_attr_failed: · 22 unmodified lines
172158 pdev_add_failed:
173159 platform_device_unregister(pdev);
174160 pdev_alloc_failed:
175− release_bat_id(id);
161+ ida_simple_remove(&bat_ida, id);
176162 noid:
177163 return ret;
178164 }
@@ -183,7 +169,7 @@ static void w1_ds2780_remove_slave(struct w1_slave *sl) · 4 unmodified lines
183169 int id = pdev->id;
184170
185171 platform_device_unregister(pdev);
186− release_bat_id(id);
172+ ida_simple_remove(&bat_ida, id);
187173 sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2780_bin_attr);
188174 }
189175
@@ -199,14 +185,14 @@ static struct w1_family w1_ds2780_family = { · 9 unmodified lines
199185
200186 static int __init w1_ds2780_init(void)
201187 {
202− idr_init(&bat_idr);
188+ ida_init(&bat_ida);
203189 return w1_register_family(&w1_ds2780_family);
204190 }
205191
206192 static void __exit w1_ds2780_exit(void)
207193 {
208194 w1_unregister_family(&w1_ds2780_family);
209− idr_destroy(&bat_idr);
195+ ida_destroy(&bat_ida);
210196 }
211197
212198 module_init(w1_ds2780_init);
drivers/w1/slaves/w1_ds2780.h+2−0
@@ -124,6 +124,8 @@ · 123 unmodified lines
124124
125125 extern int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
126126 int io);
127+extern int w1_ds2780_io_nolock(struct device *dev, char *buf, int addr,
128+ size_t count, int io);
127129 extern int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd);
128130
129131 #endif /* !_W1_DS2780_H */
drivers/w1/w1_int.c+1−0
@@ -78,6 +78,7 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, · 77 unmodified lines
7878 memcpy(&dev->dev, device, sizeof(struct device));
7979 dev_set_name(&dev->dev, "w1_bus_master%u", dev->id);
8080 snprintf(dev->name, sizeof(dev->name), "w1_bus_master%u", dev->id);
81+ dev->dev.init_name = dev->name;
8182
8283 dev->driver = driver;
8384
drivers/w1/w1_io.c+5−0
@@ -158,13 +158,18 @@ EXPORT_SYMBOL_GPL(w1_write_8); · 157 unmodified lines
158158 static u8 w1_read_bit(struct w1_master *dev)
159159 {
160160 int result;
161+ unsigned long flags;
161162
163+ /* sample timing is critical here */
164+ local_irq_save(flags);
162165 dev->bus_master->write_bit(dev->bus_master->data, 0);
163166 w1_delay(6);
164167 dev->bus_master->write_bit(dev->bus_master->data, 1);
165168 w1_delay(9);
166169
167170 result = dev->bus_master->read_bit(dev->bus_master->data);
171+ local_irq_restore(flags);
172+
168173 w1_delay(55);
169174
170175 return result & 0x1;
fs/aio.c+107−29
@@ -440,8 +440,6 @@ void exit_aio(struct mm_struct *mm) · 439 unmodified lines
440440 static struct kiocb *__aio_get_req(struct kioctx *ctx)
441441 {
442442 struct kiocb *req = NULL;
443− struct aio_ring *ring;
444− int okay = 0;
445443
446444 req = kmem_cache_alloc(kiocb_cachep, GFP_KERNEL);
447445 if (unlikely(!req))
@@ -459,39 +457,114 @@ static struct kiocb *__aio_get_req(struct kioctx *ctx) · 11 unmodified lines
459457 INIT_LIST_HEAD(&req->ki_run_list);
460458 req->ki_eventfd = NULL;
461459
462− /* Check if the completion queue has enough free space to
463− * accept an event from this io.
464− */
460+ return req;
461+}
462+
463+/*
464+ * struct kiocb's are allocated in batches to reduce the number of
465+ * times the ctx lock is acquired and released.
466+ */
467+#define KIOCB_BATCH_SIZE 32L
468+struct kiocb_batch {
469+ struct list_head head;
470+ long count; /* number of requests left to allocate */
471+};
472+
473+static void kiocb_batch_init(struct kiocb_batch *batch, long total)
474+{
475+ INIT_LIST_HEAD(&batch->head);
476+ batch->count = total;
477+}
478+
479+static void kiocb_batch_free(struct kiocb_batch *batch)
480+{
481+ struct kiocb *req, *n;
482+
483+ list_for_each_entry_safe(req, n, &batch->head, ki_batch) {
484+ list_del(&req->ki_batch);
485+ kmem_cache_free(kiocb_cachep, req);
486+ }
487+}
488+
489+/*
490+ * Allocate a batch of kiocbs. This avoids taking and dropping the
491+ * context lock a lot during setup.
492+ */
493+static int kiocb_batch_refill(struct kioctx *ctx, struct kiocb_batch *batch)
494+{
495+ unsigned short allocated, to_alloc;
496+ long avail;
497+ bool called_fput = false;
498+ struct kiocb *req, *n;
499+ struct aio_ring *ring;
500+
501+ to_alloc = min(batch->count, KIOCB_BATCH_SIZE);
502+ for (allocated = 0; allocated < to_alloc; allocated++) {
503+ req = __aio_get_req(ctx);
504+ if (!req)
505+ /* allocation failed, go with what we've got */
506+ break;
507+ list_add(&req->ki_batch, &batch->head);
508+ }
509+
510+ if (allocated == 0)
511+ goto out;
512+
513+retry:
465514 spin_lock_irq(&ctx->ctx_lock);
466− ring = kmap_atomic(ctx->ring_info.ring_pages[0], KM_USER0);
467− if (ctx->reqs_active < aio_ring_avail(&ctx->ring_info, ring)) {
515+ ring = kmap_atomic(ctx->ring_info.ring_pages[0]);
516+
517+ avail = aio_ring_avail(&ctx->ring_info, ring) - ctx->reqs_active;
518+ BUG_ON(avail < 0);
519+ if (avail == 0 && !called_fput) {
520+ /*
521+ * Handle a potential starvation case. It is possible that
522+ * we hold the last reference on a struct file, causing us
523+ * to delay the final fput to non-irq context. In this case,
524+ * ctx->reqs_active is artificially high. Calling the fput
525+ * routine here may free up a slot in the event completion
526+ * ring, allowing this allocation to succeed.
527+ */
528+ kunmap_atomic(ring);
529+ spin_unlock_irq(&ctx->ctx_lock);
530+ aio_fput_routine(NULL);
531+ called_fput = true;
532+ goto retry;
533+ }
534+
535+ if (avail < allocated) {
536+ /* Trim back the number of requests. */
537+ list_for_each_entry_safe(req, n, &batch->head, ki_batch) {
538+ list_del(&req->ki_batch);
539+ kmem_cache_free(kiocb_cachep, req);
540+ if (--allocated <= avail)
541+ break;
542+ }
543+ }
544+
545+ batch->count -= allocated;
546+ list_for_each_entry(req, &batch->head, ki_batch) {
468547 list_add(&req->ki_list, &ctx->active_reqs);
469548 ctx->reqs_active++;
470− okay = 1;
471549 }
472− kunmap_atomic(ring, KM_USER0);
473− spin_unlock_irq(&ctx->ctx_lock);
474550
475− if (!okay) {
476− kmem_cache_free(kiocb_cachep, req);
477− req = NULL;
478− }
551+ kunmap_atomic(ring);
552+ spin_unlock_irq(&ctx->ctx_lock);
479553
480− return req;
554+out:
555+ return allocated;
481556 }
482557
483−static inline struct kiocb *aio_get_req(struct kioctx *ctx)
558+static inline struct kiocb *aio_get_req(struct kioctx *ctx,
559+ struct kiocb_batch *batch)
484560 {
485561 struct kiocb *req;
486− /* Handle a potential starvation case -- should be exceedingly rare as
487− * requests will be stuck on fput_head only if the aio_fput_routine is
488− * delayed and the requests were the last user of the struct file.
489− */
490− req = __aio_get_req(ctx);
491− if (unlikely(NULL == req)) {
492− aio_fput_routine(NULL);
493− req = __aio_get_req(ctx);
494− }
562+
563+ if (list_empty(&batch->head))
564+ if (kiocb_batch_refill(ctx, batch) == 0)
565+ return NULL;
566+ req = list_first_entry(&batch->head, struct kiocb, ki_batch);
567+ list_del(&req->ki_batch);
495568 return req;
496569 }
497570
@@ -1515,7 +1588,8 @@ static ssize_t aio_setup_iocb(struct kiocb *kiocb, bool compat) · 1017 unmodified lines
15151588 }
15161589
15171590 static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb,
1518− struct iocb *iocb, bool compat)
1591+ struct iocb *iocb, struct kiocb_batch *batch,
1592+ bool compat)
15191593 {
15201594 struct kiocb *req;
15211595 struct file *file;
@@ -1541,7 +1615,7 @@ static int io_submit_one(struct kioctx *ctx, struct iocb __user *user_iocb, · 19 unmodified lines
15411615 if (unlikely(!file))
15421616 return -EBADF;
15431617
1544− req = aio_get_req(ctx); /* returns with 2 references to req */
1618+ req = aio_get_req(ctx, batch); /* returns with 2 references to req */
15451619 if (unlikely(!req)) {
15461620 fput(file);
15471621 return -EAGAIN;
@@ -1621,8 +1695,9 @@ long do_io_submit(aio_context_t ctx_id, long nr, · 73 unmodified lines
16211695 {
16221696 struct kioctx *ctx;
16231697 long ret = 0;
1624− int i;
1698+ int i = 0;
16251699 struct blk_plug plug;
1700+ struct kiocb_batch batch;
16261701
16271702 if (unlikely(nr < 0))
16281703 return -EINVAL;
@@ -1639,6 +1714,8 @@ long do_io_submit(aio_context_t ctx_id, long nr, · 10 unmodified lines
16391714 return -EINVAL;
16401715 }
16411716
1717+ kiocb_batch_init(&batch, nr);
1718+
16421719 blk_start_plug(&plug);
16431720
16441721 /*
@@ -1659,12 +1736,13 @@ long do_io_submit(aio_context_t ctx_id, long nr, · 14 unmodified lines
16591736 break;
16601737 }
16611738
1662− ret = io_submit_one(ctx, user_iocb, &tmp, compat);
1739+ ret = io_submit_one(ctx, user_iocb, &tmp, &batch, compat);
16631740 if (ret)
16641741 break;
16651742 }
16661743 blk_finish_plug(&plug);
16671744
1745+ kiocb_batch_free(&batch);
16681746 put_ioctx(ctx);
16691747 return i ? i : ret;
16701748 }
fs/binfmt_elf.c+10−1
@@ -795,7 +795,16 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs) · 794 unmodified lines
795795 * might try to exec. This is because the brk will
796796 * follow the loader, and is not movable. */
797797 #if defined(CONFIG_X86) || defined(CONFIG_ARM)
798− load_bias = 0;
798+ /* Memory randomization might have been switched off
799+ * in runtime via sysctl.
800+ * If that is the case, retain the original non-zero
801+ * load_bias value in order to establish proper
802+ * non-randomized mappings.
803+ */
804+ if (current->flags & PF_RANDOMIZE)
805+ load_bias = 0;
806+ else
807+ load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
799808 #else
800809 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
801810 #endif
fs/hfs/btree.c+15−5
@@ -46,11 +46,26 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke · 45 unmodified lines
4646 case HFS_EXT_CNID:
4747 hfs_inode_read_fork(tree->inode, mdb->drXTExtRec, mdb->drXTFlSize,
4848 mdb->drXTFlSize, be32_to_cpu(mdb->drXTClpSiz));
49+ if (HFS_I(tree->inode)->alloc_blocks >
50+ HFS_I(tree->inode)->first_blocks) {
51+ printk(KERN_ERR "hfs: invalid btree extent records\n");
52+ unlock_new_inode(tree->inode);
53+ goto free_inode;
54+ }
55+
4956 tree->inode->i_mapping->a_ops = &hfs_btree_aops;
5057 break;
5158 case HFS_CAT_CNID:
5259 hfs_inode_read_fork(tree->inode, mdb->drCTExtRec, mdb->drCTFlSize,
5360 mdb->drCTFlSize, be32_to_cpu(mdb->drCTClpSiz));
61+
62+ if (!HFS_I(tree->inode)->first_blocks) {
63+ printk(KERN_ERR "hfs: invalid btree extent records "
64+ "(0 size).\n");
65+ unlock_new_inode(tree->inode);
66+ goto free_inode;
67+ }
68+
5469 tree->inode->i_mapping->a_ops = &hfs_btree_aops;
5570 break;
5671 default:
@@ -59,11 +74,6 @@ struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp ke · 2 unmodified lines
5974 }
6075 unlock_new_inode(tree->inode);
6176
62− if (!HFS_I(tree->inode)->first_blocks) {
63− printk(KERN_ERR "hfs: invalid btree extent records (0 size).\n");
64− goto free_inode;
65− }
66−
6777 mapping = tree->inode->i_mapping;
6878 page = read_mapping_page(mapping, 0, NULL);
6979 if (IS_ERR(page))
fs/isofs/inode.c+9−1
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 #include <linux/statfs.h>
2121 #include <linux/cdrom.h>
2222 #include <linux/parser.h>
23+#include <linux/mpage.h>
2324
2425 #include "isofs.h"
2526 #include "zisofs.h"
@@ -1148,7 +1149,13 @@ struct buffer_head *isofs_bread(struct inode *inode, sector_t block) · 1122 unmodified lines
11481149
11491150 static int isofs_readpage(struct file *file, struct page *page)
11501151 {
1151− return block_read_full_page(page,isofs_get_block);
1152+ return mpage_readpage(page, isofs_get_block);
1153+}
1154+
1155+static int isofs_readpages(struct file *file, struct address_space *mapping,
1156+ struct list_head *pages, unsigned nr_pages)
1157+{
1158+ return mpage_readpages(mapping, pages, nr_pages, isofs_get_block);
11521159 }
11531160
11541161 static sector_t _isofs_bmap(struct address_space *mapping, sector_t block)
@@ -1158,6 +1165,7 @@ static sector_t _isofs_bmap(struct address_space *mapping, sector_t block) · 3 unmodified lines
11581165
11591166 static const struct address_space_operations isofs_aops = {
11601167 .readpage = isofs_readpage,
1168+ .readpages = isofs_readpages,
11611169 .bmap = _isofs_bmap
11621170 };
11631171
fs/proc/base.c+103−43
@@ -1652,12 +1652,46 @@ out: · 1651 unmodified lines
16521652 return error;
16531653 }
16541654
1655+static int proc_pid_fd_link_getattr(struct vfsmount *mnt, struct dentry *dentry,
1656+ struct kstat *stat)
1657+{
1658+ struct inode *inode = dentry->d_inode;
1659+ struct task_struct *task = get_proc_task(inode);
1660+ int rc;
1661+
1662+ if (task == NULL)
1663+ return -ESRCH;
1664+
1665+ rc = -EACCES;
1666+ if (lock_trace(task))
1667+ goto out_task;
1668+
1669+ generic_fillattr(inode, stat);
1670+ unlock_trace(task);
1671+ rc = 0;
1672+out_task:
1673+ put_task_struct(task);
1674+ return rc;
1675+}
1676+
16551677 static const struct inode_operations proc_pid_link_inode_operations = {
16561678 .readlink = proc_pid_readlink,
16571679 .follow_link = proc_pid_follow_link,
16581680 .setattr = proc_setattr,
16591681 };
16601682
1683+static const struct inode_operations proc_fdinfo_link_inode_operations = {
1684+ .setattr = proc_setattr,
1685+ .getattr = proc_pid_fd_link_getattr,
1686+};
1687+
1688+static const struct inode_operations proc_fd_link_inode_operations = {
1689+ .readlink = proc_pid_readlink,
1690+ .follow_link = proc_pid_follow_link,
1691+ .setattr = proc_setattr,
1692+ .getattr = proc_pid_fd_link_getattr,
1693+};
1694+
16611695
16621696 /* building an inode */
16631697
@@ -1889,49 +1923,61 @@ out: · 225 unmodified lines
18891923
18901924 static int proc_fd_info(struct inode *inode, struct path *path, char *info)
18911925 {
1892− struct task_struct *task = get_proc_task(inode);
1893− struct files_struct *files = NULL;
1926+ struct task_struct *task;
1927+ struct files_struct *files;
18941928 struct file *file;
18951929 int fd = proc_fd(inode);
1930+ int rc;
18961931
1897− if (task) {
1898− files = get_files_struct(task);
1899− put_task_struct(task);
1900− }
1901− if (files) {
1902− /*
1903− * We are not taking a ref to the file structure, so we must
1904− * hold ->file_lock.
1905− */
1906− spin_lock(&files->file_lock);
1907− file = fcheck_files(files, fd);
1908− if (file) {
1909− unsigned int f_flags;
1910− struct fdtable *fdt;
1911−
1912− fdt = files_fdtable(files);
1913− f_flags = file->f_flags & ~O_CLOEXEC;
1914− if (FD_ISSET(fd, fdt->close_on_exec))
1915− f_flags |= O_CLOEXEC;
1916−
1917− if (path) {
1918− *path = file->f_path;
1919− path_get(&file->f_path);
1920− }
1921− if (info)
1922− snprintf(info, PROC_FDINFO_MAX,
1923− "pos:\t%lli\n"
1924− "flags:\t0%o\n",
1925− (long long) file->f_pos,
1926− f_flags);
1927− spin_unlock(&files->file_lock);
1928− put_files_struct(files);
1929− return 0;
1932+ task = get_proc_task(inode);
1933+ if (!task)
1934+ return -ENOENT;
1935+
1936+ rc = -EACCES;
1937+ if (lock_trace(task))
1938+ goto out_task;
1939+
1940+ rc = -ENOENT;
1941+ files = get_files_struct(task);
1942+ if (files == NULL)
1943+ goto out_unlock;
1944+
1945+ /*
1946+ * We are not taking a ref to the file structure, so we must
1947+ * hold ->file_lock.
1948+ */
1949+ spin_lock(&files->file_lock);
1950+ file = fcheck_files(files, fd);
1951+ if (file) {
1952+ unsigned int f_flags;
1953+ struct fdtable *fdt;
1954+
1955+ fdt = files_fdtable(files);
1956+ f_flags = file->f_flags & ~O_CLOEXEC;
1957+ if (FD_ISSET(fd, fdt->close_on_exec))
1958+ f_flags |= O_CLOEXEC;
1959+
1960+ if (path) {
1961+ *path = file->f_path;
1962+ path_get(&file->f_path);
19301963 }
1931− spin_unlock(&files->file_lock);
1932− put_files_struct(files);
1933− }
1934− return -ENOENT;
1964+ if (info)
1965+ snprintf(info, PROC_FDINFO_MAX,
1966+ "pos:\t%lli\n"
1967+ "flags:\t0%o\n",
1968+ (long long) file->f_pos,
1969+ f_flags);
1970+ rc = 0;
1971+ } else
1972+ rc = -ENOENT;
1973+ spin_unlock(&files->file_lock);
1974+ put_files_struct(files);
1975+
1976+out_unlock:
1977+ unlock_trace(task);
1978+out_task:
1979+ put_task_struct(task);
1980+ return rc;
19351981 }
19361982
19371983 static int proc_fd_link(struct inode *inode, struct path *path)
@@ -2026,7 +2072,7 @@ static struct dentry *proc_fd_instantiate(struct inode *dir, · 88 unmodified lines
20262072 spin_unlock(&files->file_lock);
20272073 put_files_struct(files);
20282074
2029− inode->i_op = &proc_pid_link_inode_operations;
2075+ inode->i_op = &proc_fd_link_inode_operations;
20302076 inode->i_size = 64;
20312077 ei->op.proc_get_link = proc_fd_link;
20322078 d_set_d_op(dentry, &tid_fd_dentry_operations);
@@ -2058,7 +2104,12 @@ static struct dentry *proc_lookupfd_common(struct inode *dir, · 25 unmodified lines
20582104 if (fd == ~0U)
20592105 goto out;
20602106
2107+ result = ERR_PTR(-EACCES);
2108+ if (lock_trace(task))
2109+ goto out;
2110+
20612111 result = instantiate(dir, dentry, task, &fd);
2112+ unlock_trace(task);
20622113 out:
20632114 put_task_struct(task);
20642115 out_no_task:
@@ -2078,23 +2129,28 @@ static int proc_readfd_common(struct file * filp, void * dirent, · 13 unmodified lines
20782129 retval = -ENOENT;
20792130 if (!p)
20802131 goto out_no_task;
2132+
2133+ retval = -EACCES;
2134+ if (lock_trace(p))
2135+ goto out;
2136+
20812137 retval = 0;
20822138
20832139 fd = filp->f_pos;
20842140 switch (fd) {
20852141 case 0:
20862142 if (filldir(dirent, ".", 1, 0, inode->i_ino, DT_DIR) < 0)
2087− goto out;
2143+ goto out_unlock;
20882144 filp->f_pos++;
20892145 case 1:
20902146 ino = parent_ino(dentry);
20912147 if (filldir(dirent, "..", 2, 1, ino, DT_DIR) < 0)
2092− goto out;
2148+ goto out_unlock;
20932149 filp->f_pos++;
20942150 default:
20952151 files = get_files_struct(p);
20962152 if (!files)
2097− goto out;
2153+ goto out_unlock;
20982154 rcu_read_lock();
20992155 for (fd = filp->f_pos-2;
21002156 fd < files_fdtable(files)->max_fds;
@@ -2118,6 +2174,9 @@ static int proc_readfd_common(struct file * filp, void * dirent, · 17 unmodified lines
21182174 rcu_read_unlock();
21192175 put_files_struct(files);
21202176 }
2177+
2178+out_unlock:
2179+ unlock_trace(p);
21212180 out:
21222181 put_task_struct(p);
21232182 out_no_task:
@@ -2195,6 +2254,7 @@ static struct dentry *proc_fdinfo_instantiate(struct inode *dir, · 71 unmodified lines
21952254 ei->fd = fd;
21962255 inode->i_mode = S_IFREG | S_IRUSR;
21972256 inode->i_fop = &proc_fdinfo_file_operations;
2257+ inode->i_op = &proc_fdinfo_link_inode_operations;
21982258 d_set_d_op(dentry, &tid_fd_dentry_operations);
21992259 d_add(dentry, inode);
22002260 /* Close the race of the process dying before we return the dentry */
fs/proc/proc_sysctl.c+46−0
@@ -3,6 +3,7 @@ · 2 unmodified lines
33 */
44 #include <linux/init.h>
55 #include <linux/sysctl.h>
6+#include <linux/poll.h>
67 #include <linux/proc_fs.h>
78 #include <linux/security.h>
89 #include <linux/namei.h>
@@ -14,6 +15,15 @@ static const struct inode_operations proc_sys_inode_operations; · 5 unmodified lines
1415 static const struct file_operations proc_sys_dir_file_operations;
1516 static const struct inode_operations proc_sys_dir_operations;
1617
18+void proc_sys_poll_notify(struct ctl_table_poll *poll)
19+{
20+ if (!poll)
21+ return;
22+
23+ atomic_inc(&poll->event);
24+ wake_up_interruptible(&poll->wait);
25+}
26+
1727 static struct inode *proc_sys_make_inode(struct super_block *sb,
1828 struct ctl_table_header *head, struct ctl_table *table)
1929 {
@@ -176,6 +186,39 @@ static ssize_t proc_sys_write(struct file *filp, const char __user *buf, · 156 unmodified lines
176186 return proc_sys_call_handler(filp, (void __user *)buf, count, ppos, 1);
177187 }
178188
189+static int proc_sys_open(struct inode *inode, struct file *filp)
190+{
191+ struct ctl_table *table = PROC_I(inode)->sysctl_entry;
192+
193+ if (table->poll)
194+ filp->private_data = proc_sys_poll_event(table->poll);
195+
196+ return 0;
197+}
198+
199+static unsigned int proc_sys_poll(struct file *filp, poll_table *wait)
200+{
201+ struct inode *inode = filp->f_path.dentry->d_inode;
202+ struct ctl_table *table = PROC_I(inode)->sysctl_entry;
203+ unsigned long event = (unsigned long)filp->private_data;
204+ unsigned int ret = DEFAULT_POLLMASK;
205+
206+ if (!table->proc_handler)
207+ goto out;
208+
209+ if (!table->poll)
210+ goto out;
211+
212+ poll_wait(filp, &table->poll->wait, wait);
213+
214+ if (event != atomic_read(&table->poll->event)) {
215+ filp->private_data = proc_sys_poll_event(table->poll);
216+ ret = POLLIN | POLLRDNORM | POLLERR | POLLPRI;
217+ }
218+
219+out:
220+ return ret;
221+}
179222
180223 static int proc_sys_fill_cache(struct file *filp, void *dirent,
181224 filldir_t filldir,
@@ -364,12 +407,15 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct · 182 unmodified lines
364407 }
365408
366409 static const struct file_operations proc_sys_file_operations = {
410+ .open = proc_sys_open,
411+ .poll = proc_sys_poll,
367412 .read = proc_sys_read,
368413 .write = proc_sys_write,
369414 .llseek = default_llseek,
370415 };
371416
372417 static const struct file_operations proc_sys_dir_file_operations = {
418+ .read = generic_read_dir,
373419 .readdir = proc_sys_readdir,
374420 .llseek = generic_file_llseek,
375421 };
fs/ramfs/inode.c+0−10
@@ -23,7 +23,6 @@ · 22 unmodified lines
2323 * caches is sufficient.
2424 */
2525
26−#include <linux/module.h>
2726 #include <linux/fs.h>
2827 #include <linux/pagemap.h>
2928 #include <linux/highmem.h>
@@ -288,14 +287,7 @@ static int __init init_ramfs_fs(void) · 258 unmodified lines
288287 {
289288 return register_filesystem(&ramfs_fs_type);
290289 }
291−
292−static void __exit exit_ramfs_fs(void)
293−{
294− unregister_filesystem(&ramfs_fs_type);
295−}
296−
297290 module_init(init_ramfs_fs)
298−module_exit(exit_ramfs_fs)
299291
300292 int __init init_rootfs(void)
301293 {
@@ -311,5 +303,3 @@ int __init init_rootfs(void) · 9 unmodified lines
311303
312304 return err;
313305 }
314−
315−MODULE_LICENSE("GPL");
include/linux/aio.h+1−0
@@ -117,6 +117,7 @@ struct kiocb { · 116 unmodified lines
117117
118118 struct list_head ki_list; /* the aio core uses this
119119 * for cancellation */
120+ struct list_head ki_batch; /* batch allocation */
120121
121122 /*
122123 * If the aio_resfd field of the userspace iocb is not zero,
include/linux/cgroup.h+1−1
@@ -516,7 +516,7 @@ struct cgroup_subsys { · 515 unmodified lines
516516 struct list_head sibling;
517517 /* used when use_id == true */
518518 struct idr idr;
519− spinlock_t id_lock;
519+ rwlock_t id_lock;
520520
521521 /* should be defined only by modular subsystems */
522522 struct module *module;
include/linux/dma-mapping.h+10−0
@@ -1,6 +1,7 @@
11 #ifndef _LINUX_DMA_MAPPING_H
22 #define _LINUX_DMA_MAPPING_H
33
4+#include <linux/string.h>
45 #include <linux/device.h>
56 #include <linux/err.h>
67 #include <linux/dma-attrs.h>
@@ -117,6 +118,15 @@ static inline int dma_set_seg_boundary(struct device *dev, unsigned long mask) · 110 unmodified lines
117118 return -EIO;
118119 }
119120
121+static inline void *dma_zalloc_coherent(struct device *dev, size_t size,
122+ dma_addr_t *dma_handle, gfp_t flag)
123+{
124+ void *ret = dma_alloc_coherent(dev, size, dma_handle, flag);
125+ if (ret)
126+ memset(ret, 0, size);
127+ return ret;
128+}
129+
120130 #ifdef CONFIG_HAS_DMA
121131 static inline int dma_get_cache_alignment(void)
122132 {
include/linux/magic.h+5−5
@@ -30,11 +30,11 @@ · 29 unmodified lines
3030 #define ANON_INODE_FS_MAGIC 0x09041934
3131 #define PSTOREFS_MAGIC 0x6165676C
3232
33−#define MINIX_SUPER_MAGIC 0x137F /* original minix fs */
34−#define MINIX_SUPER_MAGIC2 0x138F /* minix fs, 30 char names */
35−#define MINIX2_SUPER_MAGIC 0x2468 /* minix V2 fs */
36−#define MINIX2_SUPER_MAGIC2 0x2478 /* minix V2 fs, 30 char names */
37−#define MINIX3_SUPER_MAGIC 0x4d5a /* minix V3 fs */
33+#define MINIX_SUPER_MAGIC 0x137F /* minix v1 fs, 14 char names */
34+#define MINIX_SUPER_MAGIC2 0x138F /* minix v1 fs, 30 char names */
35+#define MINIX2_SUPER_MAGIC 0x2468 /* minix v2 fs, 14 char names */
36+#define MINIX2_SUPER_MAGIC2 0x2478 /* minix v2 fs, 30 char names */
37+#define MINIX3_SUPER_MAGIC 0x4d5a /* minix v3 fs, 60 char names */
3838
3939 #define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
4040 #define NCP_SUPER_MAGIC 0x564c /* Guess, what 0x564c is :-) */
include/linux/memcontrol.h+24−20
@@ -78,8 +78,8 @@ extern void mem_cgroup_uncharge_end(void); · 77 unmodified lines
7878 extern void mem_cgroup_uncharge_page(struct page *page);
7979 extern void mem_cgroup_uncharge_cache_page(struct page *page);
8080
81−extern void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask);
82−int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem);
81+extern void mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask);
82+int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg);
8383
8484 extern struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page);
8585 extern struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p);
@@ -88,26 +88,28 @@ extern struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm); · 2 unmodified lines
8888 static inline
8989 int mm_match_cgroup(const struct mm_struct *mm, const struct mem_cgroup *cgroup)
9090 {
91− struct mem_cgroup *mem;
91+ struct mem_cgroup *memcg;
9292 rcu_read_lock();
93− mem = mem_cgroup_from_task(rcu_dereference((mm)->owner));
93+ memcg = mem_cgroup_from_task(rcu_dereference((mm)->owner));
9494 rcu_read_unlock();
95− return cgroup == mem;
95+ return cgroup == memcg;
9696 }
9797
98−extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *mem);
98+extern struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg);
9999
100100 extern int
101101 mem_cgroup_prepare_migration(struct page *page,
102102 struct page *newpage, struct mem_cgroup **ptr, gfp_t gfp_mask);
103−extern void mem_cgroup_end_migration(struct mem_cgroup *mem,
103+extern void mem_cgroup_end_migration(struct mem_cgroup *memcg,
104104 struct page *oldpage, struct page *newpage, bool migration_ok);
105105
106106 /*
107107 * For memory reclaim.
108108 */
109−int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg);
110−int mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg);
109+int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg,
110+ struct zone *zone);
111+int mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg,
112+ struct zone *zone);
111113 int mem_cgroup_select_victim_node(struct mem_cgroup *memcg);
112114 unsigned long mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg,
113115 int nid, int zid, unsigned int lrumask);
@@ -148,7 +150,7 @@ static inline void mem_cgroup_dec_page_stat(struct page *page, · 34 unmodified lines
148150 unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order,
149151 gfp_t gfp_mask,
150152 unsigned long *total_scanned);
151−u64 mem_cgroup_get_limit(struct mem_cgroup *mem);
153+u64 mem_cgroup_get_limit(struct mem_cgroup *memcg);
152154
153155 void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx);
154156 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -244,18 +246,20 @@ static inline struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm · 89 unmodified lines
244246 return NULL;
245247 }
246248
247−static inline int mm_match_cgroup(struct mm_struct *mm, struct mem_cgroup *mem)
249+static inline int mm_match_cgroup(struct mm_struct *mm,
250+ struct mem_cgroup *memcg)
248251 {
249252 return 1;
250253 }
251254
252255 static inline int task_in_mem_cgroup(struct task_struct *task,
253− const struct mem_cgroup *mem)
256+ const struct mem_cgroup *memcg)
254257 {
255258 return 1;
256259 }
257260
258−static inline struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *mem)
261+static inline struct cgroup_subsys_state
262+ *mem_cgroup_css(struct mem_cgroup *memcg)
259263 {
260264 return NULL;
261265 }
@@ -267,22 +271,22 @@ mem_cgroup_prepare_migration(struct page *page, struct page *newpage, · 5 unmodified lines
267271 return 0;
268272 }
269273
270−static inline void mem_cgroup_end_migration(struct mem_cgroup *mem,
274+static inline void mem_cgroup_end_migration(struct mem_cgroup *memcg,
271275 struct page *oldpage, struct page *newpage, bool migration_ok)
272276 {
273277 }
274278
275−static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *mem)
279+static inline int mem_cgroup_get_reclaim_priority(struct mem_cgroup *memcg)
276280 {
277281 return 0;
278282 }
279283
280−static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *mem,
284+static inline void mem_cgroup_note_reclaim_priority(struct mem_cgroup *memcg,
281285 int priority)
282286 {
283287 }
284288
285−static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *mem,
289+static inline void mem_cgroup_record_reclaim_priority(struct mem_cgroup *memcg,
286290 int priority)
287291 {
288292 }
@@ -293,13 +297,13 @@ static inline bool mem_cgroup_disabled(void) · 4 unmodified lines
293297 }
294298
295299 static inline int
296−mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg)
300+mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg, struct zone *zone)
297301 {
298302 return 1;
299303 }
300304
301305 static inline int
302−mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg)
306+mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg, struct zone *zone)
303307 {
304308 return 1;
305309 }
@@ -348,7 +352,7 @@ unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, · 42 unmodified lines
348352 }
349353
350354 static inline
351−u64 mem_cgroup_get_limit(struct mem_cgroup *mem)
355+u64 mem_cgroup_get_limit(struct mem_cgroup *memcg)
352356 {
353357 return 0;
354358 }
include/linux/mm.h+33−34
@@ -356,36 +356,50 @@ static inline struct page *compound_head(struct page *page) · 355 unmodified lines
356356 return page;
357357 }
358358
359+/*
360+ * The atomic page->_mapcount, starts from -1: so that transitions
361+ * both from it and to it can be tracked, using atomic_inc_and_test
362+ * and atomic_add_negative(-1).
363+ */
364+static inline void reset_page_mapcount(struct page *page)
365+{
366+ atomic_set(&(page)->_mapcount, -1);
367+}
368+
369+static inline int page_mapcount(struct page *page)
370+{
371+ return atomic_read(&(page)->_mapcount) + 1;
372+}
373+
359374 static inline int page_count(struct page *page)
360375 {
361376 return atomic_read(&compound_head(page)->_count);
362377 }
363378
379+static inline void get_huge_page_tail(struct page *page)
380+{
381+ /*
382+ * __split_huge_page_refcount() cannot run
383+ * from under us.
384+ */
385+ VM_BUG_ON(page_mapcount(page) < 0);
386+ VM_BUG_ON(atomic_read(&page->_count) != 0);
387+ atomic_inc(&page->_mapcount);
388+}
389+
390+extern bool __get_page_tail(struct page *page);
391+
364392 static inline void get_page(struct page *page)
365393 {
394+ if (unlikely(PageTail(page)))
395+ if (likely(__get_page_tail(page)))
396+ return;
366397 /*
367398 * Getting a normal page or the head of a compound page
368− * requires to already have an elevated page->_count. Only if
369− * we're getting a tail page, the elevated page->_count is
370− * required only in the head page, so for tail pages the
371− * bugcheck only verifies that the page->_count isn't
372− * negative.
399+ * requires to already have an elevated page->_count.
373400 */
374− VM_BUG_ON(atomic_read(&page->_count) < !PageTail(page));
401+ VM_BUG_ON(atomic_read(&page->_count) <= 0);
375402 atomic_inc(&page->_count);
376− /*
377− * Getting a tail page will elevate both the head and tail
378− * page->_count(s).
379− */
380− if (unlikely(PageTail(page))) {
381− /*
382− * This is safe only because
383− * __split_huge_page_refcount can't run under
384− * get_page().
385− */
386− VM_BUG_ON(atomic_read(&page->first_page->_count) <= 0);
387− atomic_inc(&page->first_page->_count);
388− }
389403 }
390404
391405 static inline struct page *virt_to_head_page(const void *x)
@@ -803,21 +817,6 @@ static inline pgoff_t page_index(struct page *page) · 411 unmodified lines
803817 return page->index;
804818 }
805819
806−/*
807− * The atomic page->_mapcount, like _count, starts from -1:
808− * so that transitions both from it and to it can be tracked,
809− * using atomic_inc_and_test and atomic_add_negative(-1).
810− */
811−static inline void reset_page_mapcount(struct page *page)
812−{
813− atomic_set(&(page)->_mapcount, -1);
814−}
815−
816−static inline int page_mapcount(struct page *page)
817−{
818− return atomic_read(&(page)->_mapcount) + 1;
819−}
820−
821820 /*
822821 * Return true if this page is mapped into pagetables.
823822 */
include/linux/mm_types.h+17−4
@@ -62,10 +62,23 @@ struct page { · 61 unmodified lines
6262 struct {
6363
6464 union {
65− atomic_t _mapcount; /* Count of ptes mapped in mms,
66− * to show when page is mapped
67− * & limit reverse map searches.
68− */
65+ /*
66+ * Count of ptes mapped in
67+ * mms, to show when page is
68+ * mapped & limit reverse map
69+ * searches.
70+ *
71+ * Used also for tail pages
72+ * refcounting instead of
73+ * _count. Tail pages cannot
74+ * be mapped and keeping the
75+ * tail page _count zero at
76+ * all times guarantees
77+ * get_page_unless_zero() will
78+ * never succeed on tail
79+ * pages.
80+ */
81+ atomic_t _mapcount;
6982
7083 struct {
7184 unsigned inuse:16;
include/linux/pps-gpio.h+32−0
@@ -0,0 +1,32 @@
1+/*
2+ * pps-gpio.h -- PPS client for GPIOs
3+ *
4+ *
5+ * Copyright (C) 2011 James Nuss <jamesnuss@nanometrics.ca>
6+ *
7+ * This program is free software; you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation; either version 2 of the License, or
10+ * (at your option) any later version.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program; if not, write to the Free Software
19+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20+ */
21+
22+#ifndef _PPS_GPIO_H
23+#define _PPS_GPIO_H
24+
25+struct pps_gpio_platform_data {
26+ bool assert_falling_edge;
27+ bool capture_clear;
28+ unsigned int gpio_pin;
29+ const char *gpio_label;
30+};
31+
32+#endif
include/linux/rio_ids.h+1−0
@@ -39,5 +39,6 @@ · 38 unmodified lines
3939 #define RIO_DID_IDTCPS1616 0x0379
4040 #define RIO_DID_IDTVPS1616 0x0377
4141 #define RIO_DID_IDTSPS1616 0x0378
42+#define RIO_DID_TSI721 0x80ab
4243
4344 #endif /* LINUX_RIO_IDS_H */
include/linux/sem.h+6−43
@@ -83,13 +83,6 @@ struct seminfo { · 82 unmodified lines
8383
8484 struct task_struct;
8585
86−/* One semaphore structure for each semaphore in the system. */
87−struct sem {
88− int semval; /* current value */
89− int sempid; /* pid of last operation */
90− struct list_head sem_pending; /* pending single-sop operations */
91−};
92−
9386 /* One sem_array data structure for each set of semaphores in the system. */
9487 struct sem_array {
9588 struct kern_ipc_perm ____cacheline_aligned_in_smp
@@ -103,51 +96,21 @@ struct sem_array { · 7 unmodified lines
10396 int complex_count; /* pending complex operations */
10497 };
10598
106−/* One queue for each sleeping process in the system. */
107−struct sem_queue {
108− struct list_head simple_list; /* queue of pending operations */
109− struct list_head list; /* queue of pending operations */
110− struct task_struct *sleeper; /* this process */
111− struct sem_undo *undo; /* undo structure */
112− int pid; /* process id of requesting process */
113− int status; /* completion status of operation */
114− struct sembuf *sops; /* array of pending operations */
115− int nsops; /* number of operations */
116− int alter; /* does the operation alter the array? */
117−};
118−
119−/* Each task has a list of undo requests. They are executed automatically
120− * when the process exits.
121− */
122−struct sem_undo {
123− struct list_head list_proc; /* per-process list: all undos from one process. */
124− /* rcu protected */
125− struct rcu_head rcu; /* rcu struct for sem_undo() */
126− struct sem_undo_list *ulp; /* sem_undo_list for the process */
127− struct list_head list_id; /* per semaphore array list: all undos for one array */
128− int semid; /* semaphore set identifier */
129− short * semadj; /* array of adjustments, one per semaphore */
130−};
131−
132−/* sem_undo_list controls shared access to the list of sem_undo structures
133− * that may be shared among all a CLONE_SYSVSEM task group.
134− */
135−struct sem_undo_list {
136− atomic_t refcnt;
137− spinlock_t lock;
138− struct list_head list_proc;
139−};
99+#ifdef CONFIG_SYSVIPC
140100
141101 struct sysv_sem {
142102 struct sem_undo_list *undo_list;
143103 };
144104
145−#ifdef CONFIG_SYSVIPC
146−
147105 extern int copy_semundo(unsigned long clone_flags, struct task_struct *tsk);
148106 extern void exit_sem(struct task_struct *tsk);
149107
150108 #else
109+
110+struct sysv_sem {
111+ /* empty */
112+};
113+
151114 static inline int copy_semundo(unsigned long clone_flags, struct task_struct *tsk)
152115 {
153116 return 0;
include/linux/sysctl.h+22−0
@@ -931,6 +931,7 @@ enum · 930 unmodified lines
931931 #ifdef __KERNEL__
932932 #include <linux/list.h>
933933 #include <linux/rcupdate.h>
934+#include <linux/wait.h>
934935
935936 /* For the /proc/sys support */
936937 struct ctl_table;
@@ -1011,6 +1012,26 @@ extern int proc_do_large_bitmap(struct ctl_table *, int, · 74 unmodified lines
10111012 * cover common cases.
10121013 */
10131014
1015+/* Support for userspace poll() to watch for changes */
1016+struct ctl_table_poll {
1017+ atomic_t event;
1018+ wait_queue_head_t wait;
1019+};
1020+
1021+static inline void *proc_sys_poll_event(struct ctl_table_poll *poll)
1022+{
1023+ return (void *)(unsigned long)atomic_read(&poll->event);
1024+}
1025+
1026+void proc_sys_poll_notify(struct ctl_table_poll *poll);
1027+
1028+#define __CTL_TABLE_POLL_INITIALIZER(name) { \
1029+ .event = ATOMIC_INIT(0), \
1030+ .wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.wait) }
1031+
1032+#define DEFINE_CTL_TABLE_POLL(name) \
1033+ struct ctl_table_poll name = __CTL_TABLE_POLL_INITIALIZER(name)
1034+
10141035 /* A sysctl table is an array of struct ctl_table: */
10151036 struct ctl_table
10161037 {
@@ -1021,6 +1042,7 @@ struct ctl_table · 4 unmodified lines
10211042 struct ctl_table *child;
10221043 struct ctl_table *parent; /* Automatically set */
10231044 proc_handler *proc_handler; /* Callback for text formatting */
1045+ struct ctl_table_poll *poll;
10241046 void *extra1;
10251047 void *extra2;
10261048 };
include/linux/utsname.h+16−0
@@ -37,6 +37,14 @@ struct new_utsname { · 36 unmodified lines
3737 #include <linux/nsproxy.h>
3838 #include <linux/err.h>
3939
40+enum uts_proc {
41+ UTS_PROC_OSTYPE,
42+ UTS_PROC_OSRELEASE,
43+ UTS_PROC_VERSION,
44+ UTS_PROC_HOSTNAME,
45+ UTS_PROC_DOMAINNAME,
46+};
47+
4048 struct user_namespace;
4149 extern struct user_namespace init_user_ns;
4250
@@ -80,6 +88,14 @@ static inline struct uts_namespace *copy_utsname(unsigned long flags, · 37 unmodified lines
8088 }
8189 #endif
8290
91+#ifdef CONFIG_PROC_SYSCTL
92+extern void uts_proc_notify(enum uts_proc proc);
93+#else
94+static inline void uts_proc_notify(enum uts_proc proc)
95+{
96+}
97+#endif
98+
8399 static inline struct new_utsname *utsname(void)
84100 {
85101 return &current->nsproxy->uts_ns->name;
init/Kconfig+2−2
@@ -947,7 +947,7 @@ config UID16 · 946 unmodified lines
947947 config SYSCTL_SYSCALL
948948 bool "Sysctl syscall support" if EXPERT
949949 depends on PROC_SYSCTL
950− default y
950+ default n
951951 select SYSCTL
952952 ---help---
953953 sys_sysctl uses binary paths that have been found challenging
@@ -959,7 +959,7 @@ config SYSCTL_SYSCALL · 5 unmodified lines
959959 trying to save some space it is probably safe to disable this,
960960 making your kernel marginally smaller.
961961
962− If unsure say Y here.
962+ If unsure say N here.
963963
964964 config KALLSYMS
965965 bool "Load all symbols for debugging/ksymoops" if EXPERT
init/do_mounts.c+43−5
@@ -28,7 +28,7 @@ int __initdata rd_doload; /* 1 = load RAM disk, 0 = don't load */ · 27 unmodified lines
2828 int root_mountflags = MS_RDONLY | MS_SILENT;
2929 static char * __initdata root_device_name;
3030 static char __initdata saved_root_name[64];
31−static int __initdata root_wait;
31+static int root_wait;
3232
3333 dev_t ROOT_DEV;
3434
@@ -85,12 +85,15 @@ no_match: · 50 unmodified lines
8585
8686 /**
8787 * devt_from_partuuid - looks up the dev_t of a partition by its UUID
88− * @uuid: 36 byte char array containing a hex ascii UUID
88+ * @uuid: min 36 byte char array containing a hex ascii UUID
8989 *
9090 * The function will return the first partition which contains a matching
9191 * UUID value in its partition_meta_info struct. This does not search
9292 * by filesystem UUIDs.
9393 *
94+ * If @uuid is followed by a "/PARTNROFF=%d", then the number will be
95+ * extracted and used as an offset from the partition identified by the UUID.
96+ *
9497 * Returns the matching dev_t on success or 0 on failure.
9598 */
9699 static dev_t devt_from_partuuid(char *uuid_str)
@@ -98,6 +101,28 @@ static dev_t devt_from_partuuid(char *uuid_str) · 1 unmodified line
98101 dev_t res = 0;
99102 struct device *dev = NULL;
100103 u8 uuid[16];
104+ struct gendisk *disk;
105+ struct hd_struct *part;
106+ int offset = 0;
107+
108+ if (strlen(uuid_str) < 36)
109+ goto done;
110+
111+ /* Check for optional partition number offset attributes. */
112+ if (uuid_str[36]) {
113+ char c = 0;
114+ /* Explicitly fail on poor PARTUUID syntax. */
115+ if (sscanf(&uuid_str[36],
116+ "/PARTNROFF=%d%c", &offset, &c) != 1) {
117+ printk(KERN_ERR "VFS: PARTUUID= is invalid.\n"
118+ "Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n");
119+ if (root_wait)
120+ printk(KERN_ERR
121+ "Disabling rootwait; root= is invalid.\n");
122+ root_wait = 0;
123+ goto done;
124+ }
125+ }
101126
102127 /* Pack the requested UUID in the expected format. */
103128 part_pack_uuid(uuid_str, uuid);
@@ -107,8 +132,21 @@ static dev_t devt_from_partuuid(char *uuid_str) · 3 unmodified lines
107132 goto done;
108133
109134 res = dev->devt;
110− put_device(dev);
111135
136+ /* Attempt to find the partition by offset. */
137+ if (!offset)
138+ goto no_offset;
139+
140+ res = 0;
141+ disk = part_to_disk(dev_to_part(dev));
142+ part = disk_get_part(disk, dev_to_part(dev)->partno + offset);
143+ if (part) {
144+ res = part_devt(part);
145+ put_device(part_to_dev(part));
146+ }
147+
148+no_offset:
149+ put_device(dev);
112150 done:
113151 return res;
114152 }
@@ -126,6 +164,8 @@ done: · 11 unmodified lines
126164 * used when disk name of partitioned disk ends on a digit.
127165 * 6) PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF representing the
128166 * unique id of a partition if the partition table provides it.
167+ * 7) PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to
168+ * a partition with a known unique id.
129169 *
130170 * If name doesn't have fall into the categories above, we return (0,0).
131171 * block_class is used to check if something is a disk name. If the disk
@@ -143,8 +183,6 @@ dev_t name_to_dev_t(char *name) · 11 unmodified lines
143183 #ifdef CONFIG_BLOCK
144184 if (strncmp(name, "PARTUUID=", 9) == 0) {
145185 name += 9;
146− if (strlen(name) != 36)
147− goto fail;
148186 res = devt_from_partuuid(name);
149187 if (!res)
150188 goto fail;
init/do_mounts_rd.c+14−0
@@ -119,6 +119,20 @@ identify_ramdisk_image(int fd, int start_block, decompress_fn *decompressor) · 118 unmodified lines
119119 goto done;
120120 }
121121
122+ /*
123+ * Read 512 bytes further to check if cramfs is padded
124+ */
125+ sys_lseek(fd, start_block * BLOCK_SIZE + 0x200, 0);
126+ sys_read(fd, buf, size);
127+
128+ if (cramfsb->magic == CRAMFS_MAGIC) {
129+ printk(KERN_NOTICE
130+ "RAMDISK: cramfs filesystem found at block %d\n",
131+ start_block);
132+ nblocks = (cramfsb->size + BLOCK_SIZE - 1) >> BLOCK_SIZE_BITS;
133+ goto done;
134+ }
135+
122136 /*
123137 * Read block 1 to test for minix and ext2 superblock
124138 */
ipc/sem.c+55−1
@@ -90,6 +90,52 @@ · 89 unmodified lines
9090 #include <asm/uaccess.h>
9191 #include "util.h"
9292
93+/* One semaphore structure for each semaphore in the system. */
94+struct sem {
95+ int semval; /* current value */
96+ int sempid; /* pid of last operation */
97+ struct list_head sem_pending; /* pending single-sop operations */
98+};
99+
100+/* One queue for each sleeping process in the system. */
101+struct sem_queue {
102+ struct list_head simple_list; /* queue of pending operations */
103+ struct list_head list; /* queue of pending operations */
104+ struct task_struct *sleeper; /* this process */
105+ struct sem_undo *undo; /* undo structure */
106+ int pid; /* process id of requesting process */
107+ int status; /* completion status of operation */
108+ struct sembuf *sops; /* array of pending operations */
109+ int nsops; /* number of operations */
110+ int alter; /* does *sops alter the array? */
111+};
112+
113+/* Each task has a list of undo requests. They are executed automatically
114+ * when the process exits.
115+ */
116+struct sem_undo {
117+ struct list_head list_proc; /* per-process list: *
118+ * all undos from one process
119+ * rcu protected */
120+ struct rcu_head rcu; /* rcu struct for sem_undo */
121+ struct sem_undo_list *ulp; /* back ptr to sem_undo_list */
122+ struct list_head list_id; /* per semaphore array list:
123+ * all undos for one array */
124+ int semid; /* semaphore set identifier */
125+ short *semadj; /* array of adjustments */
126+ /* one per semaphore */
127+};
128+
129+/* sem_undo_list controls shared access to the list of sem_undo structures
130+ * that may be shared among all a CLONE_SYSVSEM task group.
131+ */
132+struct sem_undo_list {
133+ atomic_t refcnt;
134+ spinlock_t lock;
135+ struct list_head list_proc;
136+};
137+
138+
93139 #define sem_ids(ns) ((ns)->ids[IPC_SEM_IDS])
94140
95141 #define sem_unlock(sma) ipc_unlock(&(sma)->sem_perm)
@@ -1426,6 +1472,8 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops, · 1330 unmodified lines
14261472
14271473 queue.status = -EINTR;
14281474 queue.sleeper = current;
1475+
1476+sleep_again:
14291477 current->state = TASK_INTERRUPTIBLE;
14301478 sem_unlock(sma);
14311479
@@ -1460,7 +1508,6 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops, · 28 unmodified lines
14601508 * Array removed? If yes, leave without sem_unlock().
14611509 */
14621510 if (IS_ERR(sma)) {
1463− error = -EIDRM;
14641511 goto out_free;
14651512 }
14661513
@@ -1479,6 +1526,13 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops, · 12 unmodified lines
14791526 */
14801527 if (timeout && jiffies_left == 0)
14811528 error = -EAGAIN;
1529+
1530+ /*
1531+ * If the wakeup was spurious, just retry
1532+ */
1533+ if (error == -EINTR && !signal_pending(current))
1534+ goto sleep_again;
1535+
14821536 unlink_queue(sma, &queue);
14831537
14841538 out_unlock_free:
kernel/cgroup.c+21−18
@@ -2027,7 +2027,7 @@ int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader) · 2026 unmodified lines
20272027 goto out_free_group_list;
20282028
20292029 /* prevent changes to the threadgroup list while we take a snapshot. */
2030− rcu_read_lock();
2030+ read_lock(&tasklist_lock);
20312031 if (!thread_group_leader(leader)) {
20322032 /*
20332033 * a race with de_thread from another thread's exec() may strip
@@ -2036,7 +2036,7 @@ int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader) · 2 unmodified lines
20362036 * throw this task away and try again (from cgroup_procs_write);
20372037 * this is "double-double-toil-and-trouble-check locking".
20382038 */
2039− rcu_read_unlock();
2039+ read_unlock(&tasklist_lock);
20402040 retval = -EAGAIN;
20412041 goto out_free_group_list;
20422042 }
@@ -2057,7 +2057,7 @@ int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader) · 14 unmodified lines
20572057 } while_each_thread(leader, tsk);
20582058 /* remember the number of threads in the array for later. */
20592059 group_size = i;
2060− rcu_read_unlock();
2060+ read_unlock(&tasklist_lock);
20612061
20622062 /*
20632063 * step 1: check that we can legitimately attach to the cgroup.
@@ -2135,14 +2135,17 @@ int cgroup_attach_proc(struct cgroup *cgrp, struct task_struct *leader) · 71 unmodified lines
21352135 oldcgrp = task_cgroup_from_root(tsk, root);
21362136 if (cgrp == oldcgrp)
21372137 continue;
2138− /* attach each task to each subsystem */
2139− for_each_subsys(root, ss) {
2140− if (ss->attach_task)
2141− ss->attach_task(cgrp, tsk);
2142− }
21432138 /* if the thread is PF_EXITING, it can just get skipped. */
21442139 retval = cgroup_task_migrate(cgrp, oldcgrp, tsk, true);
2145− BUG_ON(retval != 0 && retval != -ESRCH);
2140+ if (retval == 0) {
2141+ /* attach each task to each subsystem */
2142+ for_each_subsys(root, ss) {
2143+ if (ss->attach_task)
2144+ ss->attach_task(cgrp, tsk);
2145+ }
2146+ } else {
2147+ BUG_ON(retval != -ESRCH);
2148+ }
21462149 }
21472150 /* nothing is sensitive to fork() after this point. */
21482151
@@ -4880,9 +4883,9 @@ void free_css_id(struct cgroup_subsys *ss, struct cgroup_subsys_state *css) · 2731 unmodified lines
48804883
48814884 rcu_assign_pointer(id->css, NULL);
48824885 rcu_assign_pointer(css->id, NULL);
4883− spin_lock(&ss->id_lock);
4886+ write_lock(&ss->id_lock);
48844887 idr_remove(&ss->idr, id->id);
4885− spin_unlock(&ss->id_lock);
4888+ write_unlock(&ss->id_lock);
48864889 kfree_rcu(id, rcu_head);
48874890 }
48884891 EXPORT_SYMBOL_GPL(free_css_id);
@@ -4908,10 +4911,10 @@ static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth) · 19 unmodified lines
49084911 error = -ENOMEM;
49094912 goto err_out;
49104913 }
4911− spin_lock(&ss->id_lock);
4914+ write_lock(&ss->id_lock);
49124915 /* Don't use 0. allocates an ID of 1-65535 */
49134916 error = idr_get_new_above(&ss->idr, newid, 1, &myid);
4914− spin_unlock(&ss->id_lock);
4917+ write_unlock(&ss->id_lock);
49154918
49164919 /* Returns error when there are no free spaces for new ID.*/
49174920 if (error) {
@@ -4926,9 +4929,9 @@ static struct css_id *get_new_cssid(struct cgroup_subsys *ss, int depth) · 8 unmodified lines
49264929 return newid;
49274930 remove_idr:
49284931 error = -ENOSPC;
4929− spin_lock(&ss->id_lock);
4932+ write_lock(&ss->id_lock);
49304933 idr_remove(&ss->idr, myid);
4931− spin_unlock(&ss->id_lock);
4934+ write_unlock(&ss->id_lock);
49324935 err_out:
49334936 kfree(newid);
49344937 return ERR_PTR(error);
@@ -4940,7 +4943,7 @@ static int __init_or_module cgroup_init_idr(struct cgroup_subsys *ss, · 5 unmodified lines
49404943 {
49414944 struct css_id *newid;
49424945
4943− spin_lock_init(&ss->id_lock);
4946+ rwlock_init(&ss->id_lock);
49444947 idr_init(&ss->idr);
49454948
49464949 newid = get_new_cssid(ss, 0);
@@ -5035,9 +5038,9 @@ css_get_next(struct cgroup_subsys *ss, int id, · 88 unmodified lines
50355038 * scan next entry from bitmap(tree), tmpid is updated after
50365039 * idr_get_next().
50375040 */
5038− spin_lock(&ss->id_lock);
5041+ read_lock(&ss->id_lock);
50395042 tmp = idr_get_next(&ss->idr, &tmpid);
5040− spin_unlock(&ss->id_lock);
5043+ read_unlock(&ss->id_lock);
50415044
50425045 if (!tmp)
50435046 break;
kernel/cpuset.c+6−3
@@ -949,6 +949,8 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from, · 948 unmodified lines
949949 static void cpuset_change_task_nodemask(struct task_struct *tsk,
950950 nodemask_t *newmems)
951951 {
952+ bool masks_disjoint = !nodes_intersects(*newmems, tsk->mems_allowed);
953+
952954 repeat:
953955 /*
954956 * Allow tasks that have access to memory reserves because they have
@@ -963,7 +965,6 @@ repeat: · 8 unmodified lines
963965 nodes_or(tsk->mems_allowed, tsk->mems_allowed, *newmems);
964966 mpol_rebind_task(tsk, newmems, MPOL_REBIND_STEP1);
965967
966−
967968 /*
968969 * ensure checking ->mems_allowed_change_disable after setting all new
969970 * allowed nodes.
@@ -980,9 +981,11 @@ repeat: · 10 unmodified lines
980981
981982 /*
982983 * Allocation of memory is very fast, we needn't sleep when waiting
983− * for the read-side.
984+ * for the read-side. No wait is necessary, however, if at least one
985+ * node remains unchanged.
984986 */
985− while (ACCESS_ONCE(tsk->mems_allowed_change_disable)) {
987+ while (masks_disjoint &&
988+ ACCESS_ONCE(tsk->mems_allowed_change_disable)) {
986989 task_unlock(tsk);
987990 if (!task_curr(tsk))
988991 yield();
kernel/sys.c+2−0
@@ -1286,6 +1286,7 @@ SYSCALL_DEFINE2(sethostname, char __user *, name, int, len) · 1285 unmodified lines
12861286 memset(u->nodename + len, 0, sizeof(u->nodename) - len);
12871287 errno = 0;
12881288 }
1289+ uts_proc_notify(UTS_PROC_HOSTNAME);
12891290 up_write(&uts_sem);
12901291 return errno;
12911292 }
@@ -1336,6 +1337,7 @@ SYSCALL_DEFINE2(setdomainname, char __user *, name, int, len) · 44 unmodified lines
13361337 memset(u->domainname + len, 0, sizeof(u->domainname) - len);
13371338 errno = 0;
13381339 }
1340+ uts_proc_notify(UTS_PROC_DOMAINNAME);
13391341 up_write(&uts_sem);
13401342 return errno;
13411343 }
kernel/utsname_sysctl.c+23−0
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313 #include <linux/uts.h>
1414 #include <linux/utsname.h>
1515 #include <linux/sysctl.h>
16+#include <linux/wait.h>
1617
1718 static void *get_uts(ctl_table *table, int write)
1819 {
@@ -51,12 +52,19 @@ static int proc_do_uts_string(ctl_table *table, int write, · 32 unmodified lines
5152 uts_table.data = get_uts(table, write);
5253 r = proc_dostring(&uts_table,write,buffer,lenp, ppos);
5354 put_uts(table, write, uts_table.data);
55+
56+ if (write)
57+ proc_sys_poll_notify(table->poll);
58+
5459 return r;
5560 }
5661 #else
5762 #define proc_do_uts_string NULL
5863 #endif
5964
65+static DEFINE_CTL_TABLE_POLL(hostname_poll);
66+static DEFINE_CTL_TABLE_POLL(domainname_poll);
67+
6068 static struct ctl_table uts_kern_table[] = {
6169 {
6270 .procname = "ostype",
@@ -85,6 +93,7 @@ static struct ctl_table uts_kern_table[] = { · 22 unmodified lines
8593 .maxlen = sizeof(init_uts_ns.name.nodename),
8694 .mode = 0644,
8795 .proc_handler = proc_do_uts_string,
96+ .poll = &hostname_poll,
8897 },
8998 {
9099 .procname = "domainname",
@@ -92,6 +101,7 @@ static struct ctl_table uts_kern_table[] = { · 1 unmodified line
92101 .maxlen = sizeof(init_uts_ns.name.domainname),
93102 .mode = 0644,
94103 .proc_handler = proc_do_uts_string,
104+ .poll = &domainname_poll,
95105 },
96106 {}
97107 };
@@ -105,6 +115,19 @@ static struct ctl_table uts_root_table[] = { · 7 unmodified lines
105115 {}
106116 };
107117
118+#ifdef CONFIG_PROC_SYSCTL
119+/*
120+ * Notify userspace about a change in a certain entry of uts_kern_table,
121+ * identified by the parameter proc.
122+ */
123+void uts_proc_notify(enum uts_proc proc)
124+{
125+ struct ctl_table *table = &uts_kern_table[proc];
126+
127+ proc_sys_poll_notify(table->poll);
128+}
129+#endif
130+
108131 static int __init utsname_sysctl_init(void)
109132 {
110133 register_sysctl_table(uts_root_table);
lib/idr.c+7−4
@@ -944,6 +944,7 @@ int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, · 943 unmodified lines
944944 {
945945 int ret, id;
946946 unsigned int max;
947+ unsigned long flags;
947948
948949 BUG_ON((int)start < 0);
949950 BUG_ON((int)end < 0);
@@ -959,7 +960,7 @@ again: · 9 unmodified lines
959960 if (!ida_pre_get(ida, gfp_mask))
960961 return -ENOMEM;
961962
962− spin_lock(&simple_ida_lock);
963+ spin_lock_irqsave(&simple_ida_lock, flags);
963964 ret = ida_get_new_above(ida, start, &id);
964965 if (!ret) {
965966 if (id > max) {
@@ -969,7 +970,7 @@ again: · 3 unmodified lines
969970 ret = id;
970971 }
971972 }
972− spin_unlock(&simple_ida_lock);
973+ spin_unlock_irqrestore(&simple_ida_lock, flags);
973974
974975 if (unlikely(ret == -EAGAIN))
975976 goto again;
@@ -985,10 +986,12 @@ EXPORT_SYMBOL(ida_simple_get); · 9 unmodified lines
985986 */
986987 void ida_simple_remove(struct ida *ida, unsigned int id)
987988 {
989+ unsigned long flags;
990+
988991 BUG_ON((int)id < 0);
989− spin_lock(&simple_ida_lock);
992+ spin_lock_irqsave(&simple_ida_lock, flags);
990993 ida_remove(ida, id);
991− spin_unlock(&simple_ida_lock);
994+ spin_unlock_irqrestore(&simple_ida_lock, flags);
992995 }
993996 EXPORT_SYMBOL(ida_simple_remove);
994997
mm/huge_memory.c+26−11
@@ -990,7 +990,7 @@ struct page *follow_trans_huge_pmd(struct mm_struct *mm, · 989 unmodified lines
990990 page += (addr & ~HPAGE_PMD_MASK) >> PAGE_SHIFT;
991991 VM_BUG_ON(!PageCompound(page));
992992 if (flags & FOLL_GET)
993− get_page(page);
993+ get_page_foll(page);
994994
995995 out:
996996 return page;
@@ -1202,6 +1202,7 @@ static void __split_huge_page_refcount(struct page *page) · 205 unmodified lines
12021202 unsigned long head_index = page->index;
12031203 struct zone *zone = page_zone(page);
12041204 int zonestat;
1205+ int tail_count = 0;
12051206
12061207 /* prevent PageLRU to go away from under us, and freeze lru stats */
12071208 spin_lock_irq(&zone->lru_lock);
@@ -1210,11 +1211,27 @@ static void __split_huge_page_refcount(struct page *page) · 2 unmodified lines
12101211 for (i = 1; i < HPAGE_PMD_NR; i++) {
12111212 struct page *page_tail = page + i;
12121213
1213− /* tail_page->_count cannot change */
1214− atomic_sub(atomic_read(&page_tail->_count), &page->_count);
1215− BUG_ON(page_count(page) <= 0);
1216− atomic_add(page_mapcount(page) + 1, &page_tail->_count);
1217− BUG_ON(atomic_read(&page_tail->_count) <= 0);
1214+ /* tail_page->_mapcount cannot change */
1215+ BUG_ON(page_mapcount(page_tail) < 0);
1216+ tail_count += page_mapcount(page_tail);
1217+ /* check for overflow */
1218+ BUG_ON(tail_count < 0);
1219+ BUG_ON(atomic_read(&page_tail->_count) != 0);
1220+ /*
1221+ * tail_page->_count is zero and not changing from
1222+ * under us. But get_page_unless_zero() may be running
1223+ * from under us on the tail_page. If we used
1224+ * atomic_set() below instead of atomic_add(), we
1225+ * would then run atomic_set() concurrently with
1226+ * get_page_unless_zero(), and atomic_set() is
1227+ * implemented in C not using locked ops. spin_unlock
1228+ * on x86 sometime uses locked ops because of PPro
1229+ * errata 66, 92, so unless somebody can guarantee
1230+ * atomic_set() here would be safe on all archs (and
1231+ * not only on x86), it's safer to use atomic_add().
1232+ */
1233+ atomic_add(page_mapcount(page) + page_mapcount(page_tail) + 1,
1234+ &page_tail->_count);
12181235
12191236 /* after clearing PageTail the gup refcount can be released */
12201237 smp_mb();
@@ -1232,10 +1249,7 @@ static void __split_huge_page_refcount(struct page *page) · 11 unmodified lines
12321249 (1L << PG_uptodate)));
12331250 page_tail->flags |= (1L << PG_dirty);
12341251
1235− /*
1236− * 1) clear PageTail before overwriting first_page
1237− * 2) clear PageTail before clearing PageHead for VM_BUG_ON
1238− */
1252+ /* clear PageTail before overwriting first_page */
12391253 smp_wmb();
12401254
12411255 /*
@@ -1252,7 +1266,6 @@ static void __split_huge_page_refcount(struct page *page) · 10 unmodified lines
12521266 * status is achieved setting a reserved bit in the
12531267 * pmd, not by clearing the present bit.
12541268 */
1255− BUG_ON(page_mapcount(page_tail));
12561269 page_tail->_mapcount = page->_mapcount;
12571270
12581271 BUG_ON(page_tail->mapping);
@@ -1269,6 +1282,8 @@ static void __split_huge_page_refcount(struct page *page) · 10 unmodified lines
12691282
12701283 lru_add_page_tail(zone, page, page_tail);
12711284 }
1285+ atomic_sub(tail_count, &page->_count);
1286+ BUG_ON(atomic_read(&page->_count) <= 0);
12721287
12731288 __dec_zone_page_state(page, NR_ANON_TRANSPARENT_HUGEPAGES);
12741289 __mod_zone_page_state(zone, NR_ANON_PAGES, HPAGE_PMD_NR);
mm/internal.h+46−0
@@ -37,6 +37,52 @@ static inline void __put_page(struct page *page) · 36 unmodified lines
3737 atomic_dec(&page->_count);
3838 }
3939
40+static inline void __get_page_tail_foll(struct page *page,
41+ bool get_page_head)
42+{
43+ /*
44+ * If we're getting a tail page, the elevated page->_count is
45+ * required only in the head page and we will elevate the head
46+ * page->_count and tail page->_mapcount.
47+ *
48+ * We elevate page_tail->_mapcount for tail pages to force
49+ * page_tail->_count to be zero at all times to avoid getting
50+ * false positives from get_page_unless_zero() with
51+ * speculative page access (like in
52+ * page_cache_get_speculative()) on tail pages.
53+ */
54+ VM_BUG_ON(atomic_read(&page->first_page->_count) <= 0);
55+ VM_BUG_ON(atomic_read(&page->_count) != 0);
56+ VM_BUG_ON(page_mapcount(page) < 0);
57+ if (get_page_head)
58+ atomic_inc(&page->first_page->_count);
59+ atomic_inc(&page->_mapcount);
60+}
61+
62+/*
63+ * This is meant to be called as the FOLL_GET operation of
64+ * follow_page() and it must be called while holding the proper PT
65+ * lock while the pte (or pmd_trans_huge) is still mapping the page.
66+ */
67+static inline void get_page_foll(struct page *page)
68+{
69+ if (unlikely(PageTail(page)))
70+ /*
71+ * This is safe only because
72+ * __split_huge_page_refcount() can't run under
73+ * get_page_foll() because we hold the proper PT lock.
74+ */
75+ __get_page_tail_foll(page, true);
76+ else {
77+ /*
78+ * Getting a normal page or the head of a compound page
79+ * requires to already have an elevated page->_count.
80+ */
81+ VM_BUG_ON(atomic_read(&page->_count) <= 0);
82+ atomic_inc(&page->_count);
83+ }
84+}
85+
4086 extern unsigned long highest_memmap_pfn;
4187
4288 /*
mm/memcontrol.c+507−499
@@ -201,8 +201,8 @@ struct mem_cgroup_eventfd_list { · 200 unmodified lines
201201 struct eventfd_ctx *eventfd;
202202 };
203203
204−static void mem_cgroup_threshold(struct mem_cgroup *mem);
205−static void mem_cgroup_oom_notify(struct mem_cgroup *mem);
204+static void mem_cgroup_threshold(struct mem_cgroup *memcg);
205+static void mem_cgroup_oom_notify(struct mem_cgroup *memcg);
206206
207207 /*
208208 * The memory controller data structure. The memory controller controls both
@@ -362,29 +362,29 @@ enum charge_type { · 153 unmodified lines
362362 #define MEM_CGROUP_RECLAIM_SOFT_BIT 0x2
363363 #define MEM_CGROUP_RECLAIM_SOFT (1 << MEM_CGROUP_RECLAIM_SOFT_BIT)
364364
365−static void mem_cgroup_get(struct mem_cgroup *mem);
366−static void mem_cgroup_put(struct mem_cgroup *mem);
367−static struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *mem);
368−static void drain_all_stock_async(struct mem_cgroup *mem);
365+static void mem_cgroup_get(struct mem_cgroup *memcg);
366+static void mem_cgroup_put(struct mem_cgroup *memcg);
367+static struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg);
368+static void drain_all_stock_async(struct mem_cgroup *memcg);
369369
370370 static struct mem_cgroup_per_zone *
371−mem_cgroup_zoneinfo(struct mem_cgroup *mem, int nid, int zid)
371+mem_cgroup_zoneinfo(struct mem_cgroup *memcg, int nid, int zid)
372372 {
373− return &mem->info.nodeinfo[nid]->zoneinfo[zid];
373+ return &memcg->info.nodeinfo[nid]->zoneinfo[zid];
374374 }
375375
376−struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *mem)
376+struct cgroup_subsys_state *mem_cgroup_css(struct mem_cgroup *memcg)
377377 {
378− return &mem->css;
378+ return &memcg->css;
379379 }
380380
381381 static struct mem_cgroup_per_zone *
382−page_cgroup_zoneinfo(struct mem_cgroup *mem, struct page *page)
382+page_cgroup_zoneinfo(struct mem_cgroup *memcg, struct page *page)
383383 {
384384 int nid = page_to_nid(page);
385385 int zid = page_zonenum(page);
386386
387− return mem_cgroup_zoneinfo(mem, nid, zid);
387+ return mem_cgroup_zoneinfo(memcg, nid, zid);
388388 }
389389
390390 static struct mem_cgroup_tree_per_zone *
@@ -403,7 +403,7 @@ soft_limit_tree_from_page(struct page *page) · 12 unmodified lines
403403 }
404404
405405 static void
406−__mem_cgroup_insert_exceeded(struct mem_cgroup *mem,
406+__mem_cgroup_insert_exceeded(struct mem_cgroup *memcg,
407407 struct mem_cgroup_per_zone *mz,
408408 struct mem_cgroup_tree_per_zone *mctz,
409409 unsigned long long new_usage_in_excess)
@@ -437,7 +437,7 @@ __mem_cgroup_insert_exceeded(struct mem_cgroup *mem, · 27 unmodified lines
437437 }
438438
439439 static void
440−__mem_cgroup_remove_exceeded(struct mem_cgroup *mem,
440+__mem_cgroup_remove_exceeded(struct mem_cgroup *memcg,
441441 struct mem_cgroup_per_zone *mz,
442442 struct mem_cgroup_tree_per_zone *mctz)
443443 {
@@ -448,17 +448,17 @@ __mem_cgroup_remove_exceeded(struct mem_cgroup *mem, · 4 unmodified lines
448448 }
449449
450450 static void
451−mem_cgroup_remove_exceeded(struct mem_cgroup *mem,
451+mem_cgroup_remove_exceeded(struct mem_cgroup *memcg,
452452 struct mem_cgroup_per_zone *mz,
453453 struct mem_cgroup_tree_per_zone *mctz)
454454 {
455455 spin_lock(&mctz->lock);
456− __mem_cgroup_remove_exceeded(mem, mz, mctz);
456+ __mem_cgroup_remove_exceeded(memcg, mz, mctz);
457457 spin_unlock(&mctz->lock);
458458 }
459459
460460
461−static void mem_cgroup_update_tree(struct mem_cgroup *mem, struct page *page)
461+static void mem_cgroup_update_tree(struct mem_cgroup *memcg, struct page *page)
462462 {
463463 unsigned long long excess;
464464 struct mem_cgroup_per_zone *mz;
@@ -471,9 +471,9 @@ static void mem_cgroup_update_tree(struct mem_cgroup *mem, struct page *page) · 6 unmodified lines
471471 * Necessary to update all ancestors when hierarchy is used.
472472 * because their event counter is not touched.
473473 */
474− for (; mem; mem = parent_mem_cgroup(mem)) {
475− mz = mem_cgroup_zoneinfo(mem, nid, zid);
476− excess = res_counter_soft_limit_excess(&mem->res);
474+ for (; memcg; memcg = parent_mem_cgroup(memcg)) {
475+ mz = mem_cgroup_zoneinfo(memcg, nid, zid);
476+ excess = res_counter_soft_limit_excess(&memcg->res);
477477 /*
478478 * We have to update the tree if mz is on RB-tree or
479479 * mem is over its softlimit.
@@ -482,18 +482,18 @@ static void mem_cgroup_update_tree(struct mem_cgroup *mem, struct page *page) · 2 unmodified lines
482482 spin_lock(&mctz->lock);
483483 /* if on-tree, remove it */
484484 if (mz->on_tree)
485− __mem_cgroup_remove_exceeded(mem, mz, mctz);
485+ __mem_cgroup_remove_exceeded(memcg, mz, mctz);
486486 /*
487487 * Insert again. mz->usage_in_excess will be updated.
488488 * If excess is 0, no tree ops.
489489 */
490− __mem_cgroup_insert_exceeded(mem, mz, mctz, excess);
490+ __mem_cgroup_insert_exceeded(memcg, mz, mctz, excess);
491491 spin_unlock(&mctz->lock);
492492 }
493493 }
494494 }
495495
496−static void mem_cgroup_remove_from_trees(struct mem_cgroup *mem)
496+static void mem_cgroup_remove_from_trees(struct mem_cgroup *memcg)
497497 {
498498 int node, zone;
499499 struct mem_cgroup_per_zone *mz;
@@ -501,9 +501,9 @@ static void mem_cgroup_remove_from_trees(struct mem_cgroup *mem) · 1 unmodified line
501501
502502 for_each_node_state(node, N_POSSIBLE) {
503503 for (zone = 0; zone < MAX_NR_ZONES; zone++) {
504− mz = mem_cgroup_zoneinfo(mem, node, zone);
504+ mz = mem_cgroup_zoneinfo(memcg, node, zone);
505505 mctz = soft_limit_tree_node_zone(node, zone);
506− mem_cgroup_remove_exceeded(mem, mz, mctz);
506+ mem_cgroup_remove_exceeded(memcg, mz, mctz);
507507 }
508508 }
509509 }
@@ -564,7 +564,7 @@ mem_cgroup_largest_soft_limit_node(struct mem_cgroup_tree_per_zone *mctz) · 54 unmodified lines
564564 * common workload, threashold and synchonization as vmstat[] should be
565565 * implemented.
566566 */
567−static long mem_cgroup_read_stat(struct mem_cgroup *mem,
567+static long mem_cgroup_read_stat(struct mem_cgroup *memcg,
568568 enum mem_cgroup_stat_index idx)
569569 {
570570 long val = 0;
@@ -572,81 +572,83 @@ static long mem_cgroup_read_stat(struct mem_cgroup *mem, · 1 unmodified line
572572
573573 get_online_cpus();
574574 for_each_online_cpu(cpu)
575− val += per_cpu(mem->stat->count[idx], cpu);
575+ val += per_cpu(memcg->stat->count[idx], cpu);
576576 #ifdef CONFIG_HOTPLUG_CPU
577− spin_lock(&mem->pcp_counter_lock);
578− val += mem->nocpu_base.count[idx];
579− spin_unlock(&mem->pcp_counter_lock);
577+ spin_lock(&memcg->pcp_counter_lock);
578+ val += memcg->nocpu_base.count[idx];
579+ spin_unlock(&memcg->pcp_counter_lock);
580580 #endif
581581 put_online_cpus();
582582 return val;
583583 }
584584
585−static void mem_cgroup_swap_statistics(struct mem_cgroup *mem,
585+static void mem_cgroup_swap_statistics(struct mem_cgroup *memcg,
586586 bool charge)
587587 {
588588 int val = (charge) ? 1 : -1;
589− this_cpu_add(mem->stat->count[MEM_CGROUP_STAT_SWAPOUT], val);
589+ this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_SWAPOUT], val);
590590 }
591591
592−void mem_cgroup_pgfault(struct mem_cgroup *mem, int val)
592+void mem_cgroup_pgfault(struct mem_cgroup *memcg, int val)
593593 {
594− this_cpu_add(mem->stat->events[MEM_CGROUP_EVENTS_PGFAULT], val);
594+ this_cpu_add(memcg->stat->events[MEM_CGROUP_EVENTS_PGFAULT], val);
595595 }
596596
597−void mem_cgroup_pgmajfault(struct mem_cgroup *mem, int val)
597+void mem_cgroup_pgmajfault(struct mem_cgroup *memcg, int val)
598598 {
599− this_cpu_add(mem->stat->events[MEM_CGROUP_EVENTS_PGMAJFAULT], val);
599+ this_cpu_add(memcg->stat->events[MEM_CGROUP_EVENTS_PGMAJFAULT], val);
600600 }
601601
602−static unsigned long mem_cgroup_read_events(struct mem_cgroup *mem,
602+static unsigned long mem_cgroup_read_events(struct mem_cgroup *memcg,
603603 enum mem_cgroup_events_index idx)
604604 {
605605 unsigned long val = 0;
606606 int cpu;
607607
608608 for_each_online_cpu(cpu)
609− val += per_cpu(mem->stat->events[idx], cpu);
609+ val += per_cpu(memcg->stat->events[idx], cpu);
610610 #ifdef CONFIG_HOTPLUG_CPU
611− spin_lock(&mem->pcp_counter_lock);
612− val += mem->nocpu_base.events[idx];
613− spin_unlock(&mem->pcp_counter_lock);
611+ spin_lock(&memcg->pcp_counter_lock);
612+ val += memcg->nocpu_base.events[idx];
613+ spin_unlock(&memcg->pcp_counter_lock);
614614 #endif
615615 return val;
616616 }
617617
618−static void mem_cgroup_charge_statistics(struct mem_cgroup *mem,
618+static void mem_cgroup_charge_statistics(struct mem_cgroup *memcg,
619619 bool file, int nr_pages)
620620 {
621621 preempt_disable();
622622
623623 if (file)
624− __this_cpu_add(mem->stat->count[MEM_CGROUP_STAT_CACHE], nr_pages);
624+ __this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_CACHE],
625+ nr_pages);
625626 else
626− __this_cpu_add(mem->stat->count[MEM_CGROUP_STAT_RSS], nr_pages);
627+ __this_cpu_add(memcg->stat->count[MEM_CGROUP_STAT_RSS],
628+ nr_pages);
627629
628630 /* pagein of a big page is an event. So, ignore page size */
629631 if (nr_pages > 0)
630− __this_cpu_inc(mem->stat->events[MEM_CGROUP_EVENTS_PGPGIN]);
632+ __this_cpu_inc(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGIN]);
631633 else {
632− __this_cpu_inc(mem->stat->events[MEM_CGROUP_EVENTS_PGPGOUT]);
634+ __this_cpu_inc(memcg->stat->events[MEM_CGROUP_EVENTS_PGPGOUT]);
633635 nr_pages = -nr_pages; /* for event */
634636 }
635637
636− __this_cpu_add(mem->stat->events[MEM_CGROUP_EVENTS_COUNT], nr_pages);
638+ __this_cpu_add(memcg->stat->events[MEM_CGROUP_EVENTS_COUNT], nr_pages);
637639
638640 preempt_enable();
639641 }
640642
641643 unsigned long
642−mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *mem, int nid, int zid,
644+mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *memcg, int nid, int zid,
643645 unsigned int lru_mask)
644646 {
645647 struct mem_cgroup_per_zone *mz;
646648 enum lru_list l;
647649 unsigned long ret = 0;
648650
649− mz = mem_cgroup_zoneinfo(mem, nid, zid);
651+ mz = mem_cgroup_zoneinfo(memcg, nid, zid);
650652
651653 for_each_lru(l) {
652654 if (BIT(l) & lru_mask)
@@ -656,44 +658,45 @@ mem_cgroup_zone_nr_lru_pages(struct mem_cgroup *mem, int nid, int zid, · 3 unmodified lines
656658 }
657659
658660 static unsigned long
659−mem_cgroup_node_nr_lru_pages(struct mem_cgroup *mem,
661+mem_cgroup_node_nr_lru_pages(struct mem_cgroup *memcg,
660662 int nid, unsigned int lru_mask)
661663 {
662664 u64 total = 0;
663665 int zid;
664666
665667 for (zid = 0; zid < MAX_NR_ZONES; zid++)
666− total += mem_cgroup_zone_nr_lru_pages(mem, nid, zid, lru_mask);
668+ total += mem_cgroup_zone_nr_lru_pages(memcg,
669+ nid, zid, lru_mask);
667670
668671 return total;
669672 }
670673
671−static unsigned long mem_cgroup_nr_lru_pages(struct mem_cgroup *mem,
674+static unsigned long mem_cgroup_nr_lru_pages(struct mem_cgroup *memcg,
672675 unsigned int lru_mask)
673676 {
674677 int nid;
675678 u64 total = 0;
676679
677680 for_each_node_state(nid, N_HIGH_MEMORY)
678− total += mem_cgroup_node_nr_lru_pages(mem, nid, lru_mask);
681+ total += mem_cgroup_node_nr_lru_pages(memcg, nid, lru_mask);
679682 return total;
680683 }
681684
682−static bool __memcg_event_check(struct mem_cgroup *mem, int target)
685+static bool __memcg_event_check(struct mem_cgroup *memcg, int target)
683686 {
684687 unsigned long val, next;
685688
686− val = this_cpu_read(mem->stat->events[MEM_CGROUP_EVENTS_COUNT]);
687− next = this_cpu_read(mem->stat->targets[target]);
689+ val = __this_cpu_read(memcg->stat->events[MEM_CGROUP_EVENTS_COUNT]);
690+ next = __this_cpu_read(memcg->stat->targets[target]);
688691 /* from time_after() in jiffies.h */
689692 return ((long)next - (long)val < 0);
690693 }
691694
692−static void __mem_cgroup_target_update(struct mem_cgroup *mem, int target)
695+static void __mem_cgroup_target_update(struct mem_cgroup *memcg, int target)
693696 {
694697 unsigned long val, next;
695698
696− val = this_cpu_read(mem->stat->events[MEM_CGROUP_EVENTS_COUNT]);
699+ val = __this_cpu_read(memcg->stat->events[MEM_CGROUP_EVENTS_COUNT]);
697700
698701 switch (target) {
699702 case MEM_CGROUP_TARGET_THRESH:
@@ -709,34 +712,36 @@ static void __mem_cgroup_target_update(struct mem_cgroup *mem, int target) · 9 unmodified lines
709712 return;
710713 }
711714
712− this_cpu_write(mem->stat->targets[target], next);
715+ __this_cpu_write(memcg->stat->targets[target], next);
713716 }
714717
715718 /*
716719 * Check events in order.
717720 *
718721 */
719−static void memcg_check_events(struct mem_cgroup *mem, struct page *page)
722+static void memcg_check_events(struct mem_cgroup *memcg, struct page *page)
720723 {
724+ preempt_disable();
721725 /* threshold event is triggered in finer grain than soft limit */
722− if (unlikely(__memcg_event_check(mem, MEM_CGROUP_TARGET_THRESH))) {
723− mem_cgroup_threshold(mem);
724− __mem_cgroup_target_update(mem, MEM_CGROUP_TARGET_THRESH);
725− if (unlikely(__memcg_event_check(mem,
726+ if (unlikely(__memcg_event_check(memcg, MEM_CGROUP_TARGET_THRESH))) {
727+ mem_cgroup_threshold(memcg);
728+ __mem_cgroup_target_update(memcg, MEM_CGROUP_TARGET_THRESH);
729+ if (unlikely(__memcg_event_check(memcg,
726730 MEM_CGROUP_TARGET_SOFTLIMIT))) {
727− mem_cgroup_update_tree(mem, page);
728− __mem_cgroup_target_update(mem,
731+ mem_cgroup_update_tree(memcg, page);
732+ __mem_cgroup_target_update(memcg,
729733 MEM_CGROUP_TARGET_SOFTLIMIT);
730734 }
731735 #if MAX_NUMNODES > 1
732− if (unlikely(__memcg_event_check(mem,
736+ if (unlikely(__memcg_event_check(memcg,
733737 MEM_CGROUP_TARGET_NUMAINFO))) {
734− atomic_inc(&mem->numainfo_events);
735− __mem_cgroup_target_update(mem,
738+ atomic_inc(&memcg->numainfo_events);
739+ __mem_cgroup_target_update(memcg,
736740 MEM_CGROUP_TARGET_NUMAINFO);
737741 }
738742 #endif
739743 }
744+ preempt_enable();
740745 }
741746
742747 static struct mem_cgroup *mem_cgroup_from_cont(struct cgroup *cont)
@@ -762,7 +767,7 @@ struct mem_cgroup *mem_cgroup_from_task(struct task_struct *p) · 19 unmodified lines
762767
763768 struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm)
764769 {
765− struct mem_cgroup *mem = NULL;
770+ struct mem_cgroup *memcg = NULL;
766771
767772 if (!mm)
768773 return NULL;
@@ -773,25 +778,25 @@ struct mem_cgroup *try_get_mem_cgroup_from_mm(struct mm_struct *mm) · 4 unmodified lines
773778 */
774779 rcu_read_lock();
775780 do {
776− mem = mem_cgroup_from_task(rcu_dereference(mm->owner));
777− if (unlikely(!mem))
781+ memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
782+ if (unlikely(!memcg))
778783 break;
779− } while (!css_tryget(&mem->css));
784+ } while (!css_tryget(&memcg->css));
780785 rcu_read_unlock();
781− return mem;
786+ return memcg;
782787 }
783788
784789 /* The caller has to guarantee "mem" exists before calling this */
785−static struct mem_cgroup *mem_cgroup_start_loop(struct mem_cgroup *mem)
790+static struct mem_cgroup *mem_cgroup_start_loop(struct mem_cgroup *memcg)
786791 {
787792 struct cgroup_subsys_state *css;
788793 int found;
789794
790− if (!mem) /* ROOT cgroup has the smallest ID */
795+ if (!memcg) /* ROOT cgroup has the smallest ID */
791796 return root_mem_cgroup; /*css_put/get against root is ignored*/
792− if (!mem->use_hierarchy) {
793− if (css_tryget(&mem->css))
794− return mem;
797+ if (!memcg->use_hierarchy) {
798+ if (css_tryget(&memcg->css))
799+ return memcg;
795800 return NULL;
796801 }
797802 rcu_read_lock();
@@ -799,13 +804,13 @@ static struct mem_cgroup *mem_cgroup_start_loop(struct mem_cgroup *mem) · 1 unmodified line
799804 * searching a memory cgroup which has the smallest ID under given
800805 * ROOT cgroup. (ID >= 1)
801806 */
802− css = css_get_next(&mem_cgroup_subsys, 1, &mem->css, &found);
807+ css = css_get_next(&mem_cgroup_subsys, 1, &memcg->css, &found);
803808 if (css && css_tryget(css))
804− mem = container_of(css, struct mem_cgroup, css);
809+ memcg = container_of(css, struct mem_cgroup, css);
805810 else
806− mem = NULL;
811+ memcg = NULL;
807812 rcu_read_unlock();
808− return mem;
813+ return memcg;
809814 }
810815
811816 static struct mem_cgroup *mem_cgroup_get_next(struct mem_cgroup *iter,
@@ -859,29 +864,29 @@ static struct mem_cgroup *mem_cgroup_get_next(struct mem_cgroup *iter, · 47 unmodified lines
859864 for_each_mem_cgroup_tree_cond(iter, NULL, true)
860865
861866
862−static inline bool mem_cgroup_is_root(struct mem_cgroup *mem)
867+static inline bool mem_cgroup_is_root(struct mem_cgroup *memcg)
863868 {
864− return (mem == root_mem_cgroup);
869+ return (memcg == root_mem_cgroup);
865870 }
866871
867872 void mem_cgroup_count_vm_event(struct mm_struct *mm, enum vm_event_item idx)
868873 {
869− struct mem_cgroup *mem;
874+ struct mem_cgroup *memcg;
870875
871876 if (!mm)
872877 return;
873878
874879 rcu_read_lock();
875− mem = mem_cgroup_from_task(rcu_dereference(mm->owner));
876− if (unlikely(!mem))
880+ memcg = mem_cgroup_from_task(rcu_dereference(mm->owner));
881+ if (unlikely(!memcg))
877882 goto out;
878883
879884 switch (idx) {
880885 case PGMAJFAULT:
881− mem_cgroup_pgmajfault(mem, 1);
886+ mem_cgroup_pgmajfault(memcg, 1);
882887 break;
883888 case PGFAULT:
884− mem_cgroup_pgfault(mem, 1);
889+ mem_cgroup_pgfault(memcg, 1);
885890 break;
886891 default:
887892 BUG();
@@ -990,6 +995,16 @@ void mem_cgroup_add_lru_list(struct page *page, enum lru_list lru) · 102 unmodified lines
990995 return;
991996 pc = lookup_page_cgroup(page);
992997 VM_BUG_ON(PageCgroupAcctLRU(pc));
998+ /*
999+ * putback: charge:
1000+ * SetPageLRU SetPageCgroupUsed
1001+ * smp_mb smp_mb
1002+ * PageCgroupUsed && add to memcg LRU PageLRU && add to memcg LRU
1003+ *
1004+ * Ensure that one of the two sides adds the page to the memcg
1005+ * LRU during a race.
1006+ */
1007+ smp_mb();
9931008 if (!PageCgroupUsed(pc))
9941009 return;
9951010 /* Ensure pc->mem_cgroup is visible after reading PCG_USED. */
@@ -1041,7 +1056,16 @@ static void mem_cgroup_lru_add_after_commit(struct page *page) · 45 unmodified lines
10411056 unsigned long flags;
10421057 struct zone *zone = page_zone(page);
10431058 struct page_cgroup *pc = lookup_page_cgroup(page);
1044−
1059+ /*
1060+ * putback: charge:
1061+ * SetPageLRU SetPageCgroupUsed
1062+ * smp_mb smp_mb
1063+ * PageCgroupUsed && add to memcg LRU PageLRU && add to memcg LRU
1064+ *
1065+ * Ensure that one of the two sides adds the page to the memcg
1066+ * LRU during a race.
1067+ */
1068+ smp_mb();
10451069 /* taking care of that the page is added to LRU while we commit it */
10461070 if (likely(!PageLRU(page)))
10471071 return;
@@ -1063,21 +1087,21 @@ void mem_cgroup_move_lists(struct page *page, · 15 unmodified lines
10631087 }
10641088
10651089 /*
1066− * Checks whether given mem is same or in the root_mem's
1090+ * Checks whether given mem is same or in the root_mem_cgroup's
10671091 * hierarchy subtree
10681092 */
1069−static bool mem_cgroup_same_or_subtree(const struct mem_cgroup *root_mem,
1070− struct mem_cgroup *mem)
1093+static bool mem_cgroup_same_or_subtree(const struct mem_cgroup *root_memcg,
1094+ struct mem_cgroup *memcg)
10711095 {
1072− if (root_mem != mem) {
1073− return (root_mem->use_hierarchy &&
1074− css_is_ancestor(&mem->css, &root_mem->css));
1096+ if (root_memcg != memcg) {
1097+ return (root_memcg->use_hierarchy &&
1098+ css_is_ancestor(&memcg->css, &root_memcg->css));
10751099 }
10761100
10771101 return true;
10781102 }
10791103
1080−int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem)
1104+int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *memcg)
10811105 {
10821106 int ret;
10831107 struct mem_cgroup *curr = NULL;
@@ -1091,25 +1115,29 @@ int task_in_mem_cgroup(struct task_struct *task, const struct mem_cgroup *mem) · 7 unmodified lines
10911115 if (!curr)
10921116 return 0;
10931117 /*
1094− * We should check use_hierarchy of "mem" not "curr". Because checking
1118+ * We should check use_hierarchy of "memcg" not "curr". Because checking
10951119 * use_hierarchy of "curr" here make this function true if hierarchy is
1096− * enabled in "curr" and "curr" is a child of "mem" in *cgroup*
1097− * hierarchy(even if use_hierarchy is disabled in "mem").
1120+ * enabled in "curr" and "curr" is a child of "memcg" in *cgroup*
1121+ * hierarchy(even if use_hierarchy is disabled in "memcg").
10981122 */
1099− ret = mem_cgroup_same_or_subtree(mem, curr);
1123+ ret = mem_cgroup_same_or_subtree(memcg, curr);
11001124 css_put(&curr->css);
11011125 return ret;
11021126 }
11031127
1104−static int calc_inactive_ratio(struct mem_cgroup *memcg, unsigned long *present_pages)
1128+int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg, struct zone *zone)
11051129 {
1106− unsigned long active;
1130+ unsigned long inactive_ratio;
1131+ int nid = zone_to_nid(zone);
1132+ int zid = zone_idx(zone);
11071133 unsigned long inactive;
1134+ unsigned long active;
11081135 unsigned long gb;
1109− unsigned long inactive_ratio;
11101136
1111− inactive = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_INACTIVE_ANON));
1112− active = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_ACTIVE_ANON));
1137+ inactive = mem_cgroup_zone_nr_lru_pages(memcg, nid, zid,
1138+ BIT(LRU_INACTIVE_ANON));
1139+ active = mem_cgroup_zone_nr_lru_pages(memcg, nid, zid,
1140+ BIT(LRU_ACTIVE_ANON));
11131141
11141142 gb = (inactive + active) >> (30 - PAGE_SHIFT);
11151143 if (gb)
@@ -1117,39 +1145,20 @@ static int calc_inactive_ratio(struct mem_cgroup *memcg, unsigned long *present_ · 1 unmodified line
11171145 else
11181146 inactive_ratio = 1;
11191147
1120− if (present_pages) {
1121− present_pages[0] = inactive;
1122− present_pages[1] = active;
1123− }
1124−
1125− return inactive_ratio;
1148+ return inactive * inactive_ratio < active;
11261149 }
11271150
1128−int mem_cgroup_inactive_anon_is_low(struct mem_cgroup *memcg)
1129−{
1130− unsigned long active;
1131− unsigned long inactive;
1132− unsigned long present_pages[2];
1133− unsigned long inactive_ratio;
1134−
1135− inactive_ratio = calc_inactive_ratio(memcg, present_pages);
1136−
1137− inactive = present_pages[0];
1138− active = present_pages[1];
1139−
1140− if (inactive * inactive_ratio < active)
1141− return 1;
1142−
1143− return 0;
1144−}
1145−
1146−int mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg)
1151+int mem_cgroup_inactive_file_is_low(struct mem_cgroup *memcg, struct zone *zone)
11471152 {
11481153 unsigned long active;
11491154 unsigned long inactive;
1155+ int zid = zone_idx(zone);
1156+ int nid = zone_to_nid(zone);
11501157
1151− inactive = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_INACTIVE_FILE));
1152− active = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_ACTIVE_FILE));
1158+ inactive = mem_cgroup_zone_nr_lru_pages(memcg, nid, zid,
1159+ BIT(LRU_INACTIVE_FILE));
1160+ active = mem_cgroup_zone_nr_lru_pages(memcg, nid, zid,
1161+ BIT(LRU_ACTIVE_FILE));
11531162
11541163 return (active > inactive);
11551164 }
@@ -1254,13 +1263,13 @@ unsigned long mem_cgroup_isolate_pages(unsigned long nr_to_scan, · 98 unmodified lines
12541263 * Returns the maximum amount of memory @mem can be charged with, in
12551264 * pages.
12561265 */
1257−static unsigned long mem_cgroup_margin(struct mem_cgroup *mem)
1266+static unsigned long mem_cgroup_margin(struct mem_cgroup *memcg)
12581267 {
12591268 unsigned long long margin;
12601269
1261− margin = res_counter_margin(&mem->res);
1270+ margin = res_counter_margin(&memcg->res);
12621271 if (do_swap_account)
1263− margin = min(margin, res_counter_margin(&mem->memsw));
1272+ margin = min(margin, res_counter_margin(&memcg->memsw));
12641273 return margin >> PAGE_SHIFT;
12651274 }
12661275
@@ -1275,33 +1284,33 @@ int mem_cgroup_swappiness(struct mem_cgroup *memcg) · 8 unmodified lines
12751284 return memcg->swappiness;
12761285 }
12771286
1278−static void mem_cgroup_start_move(struct mem_cgroup *mem)
1287+static void mem_cgroup_start_move(struct mem_cgroup *memcg)
12791288 {
12801289 int cpu;
12811290
12821291 get_online_cpus();
1283− spin_lock(&mem->pcp_counter_lock);
1292+ spin_lock(&memcg->pcp_counter_lock);
12841293 for_each_online_cpu(cpu)
1285− per_cpu(mem->stat->count[MEM_CGROUP_ON_MOVE], cpu) += 1;
1286− mem->nocpu_base.count[MEM_CGROUP_ON_MOVE] += 1;
1287− spin_unlock(&mem->pcp_counter_lock);
1294+ per_cpu(memcg->stat->count[MEM_CGROUP_ON_MOVE], cpu) += 1;
1295+ memcg->nocpu_base.count[MEM_CGROUP_ON_MOVE] += 1;
1296+ spin_unlock(&memcg->pcp_counter_lock);
12881297 put_online_cpus();
12891298
12901299 synchronize_rcu();
12911300 }
12921301
1293−static void mem_cgroup_end_move(struct mem_cgroup *mem)
1302+static void mem_cgroup_end_move(struct mem_cgroup *memcg)
12941303 {
12951304 int cpu;
12961305
1297− if (!mem)
1306+ if (!memcg)
12981307 return;
12991308 get_online_cpus();
1300− spin_lock(&mem->pcp_counter_lock);
1309+ spin_lock(&memcg->pcp_counter_lock);
13011310 for_each_online_cpu(cpu)
1302− per_cpu(mem->stat->count[MEM_CGROUP_ON_MOVE], cpu) -= 1;
1303− mem->nocpu_base.count[MEM_CGROUP_ON_MOVE] -= 1;
1304− spin_unlock(&mem->pcp_counter_lock);
1311+ per_cpu(memcg->stat->count[MEM_CGROUP_ON_MOVE], cpu) -= 1;
1312+ memcg->nocpu_base.count[MEM_CGROUP_ON_MOVE] -= 1;
1313+ spin_unlock(&memcg->pcp_counter_lock);
13051314 put_online_cpus();
13061315 }
13071316 /*
@@ -1316,13 +1325,13 @@ static void mem_cgroup_end_move(struct mem_cgroup *mem) · 8 unmodified lines
13161325 * waiting at hith-memory prressure caused by "move".
13171326 */
13181327
1319−static bool mem_cgroup_stealed(struct mem_cgroup *mem)
1328+static bool mem_cgroup_stealed(struct mem_cgroup *memcg)
13201329 {
13211330 VM_BUG_ON(!rcu_read_lock_held());
1322− return this_cpu_read(mem->stat->count[MEM_CGROUP_ON_MOVE]) > 0;
1331+ return this_cpu_read(memcg->stat->count[MEM_CGROUP_ON_MOVE]) > 0;
13231332 }
13241333
1325−static bool mem_cgroup_under_move(struct mem_cgroup *mem)
1334+static bool mem_cgroup_under_move(struct mem_cgroup *memcg)
13261335 {
13271336 struct mem_cgroup *from;
13281337 struct mem_cgroup *to;
@@ -1337,17 +1346,17 @@ static bool mem_cgroup_under_move(struct mem_cgroup *mem) · 8 unmodified lines
13371346 if (!from)
13381347 goto unlock;
13391348
1340− ret = mem_cgroup_same_or_subtree(mem, from)
1341− || mem_cgroup_same_or_subtree(mem, to);
1349+ ret = mem_cgroup_same_or_subtree(memcg, from)
1350+ || mem_cgroup_same_or_subtree(memcg, to);
13421351 unlock:
13431352 spin_unlock(&mc.lock);
13441353 return ret;
13451354 }
13461355
1347−static bool mem_cgroup_wait_acct_move(struct mem_cgroup *mem)
1356+static bool mem_cgroup_wait_acct_move(struct mem_cgroup *memcg)
13481357 {
13491358 if (mc.moving_task && current != mc.moving_task) {
1350− if (mem_cgroup_under_move(mem)) {
1359+ if (mem_cgroup_under_move(memcg)) {
13511360 DEFINE_WAIT(wait);
13521361 prepare_to_wait(&mc.waitq, &wait, TASK_INTERRUPTIBLE);
13531362 /* moving charge context might have finished. */
@@ -1431,12 +1440,12 @@ done: · 77 unmodified lines
14311440 * This function returns the number of memcg under hierarchy tree. Returns
14321441 * 1(self count) if no children.
14331442 */
1434−static int mem_cgroup_count_children(struct mem_cgroup *mem)
1443+static int mem_cgroup_count_children(struct mem_cgroup *memcg)
14351444 {
14361445 int num = 0;
14371446 struct mem_cgroup *iter;
14381447
1439− for_each_mem_cgroup_tree(iter, mem)
1448+ for_each_mem_cgroup_tree(iter, memcg)
14401449 num++;
14411450 return num;
14421451 }
@@ -1466,21 +1475,21 @@ u64 mem_cgroup_get_limit(struct mem_cgroup *memcg) · 23 unmodified lines
14661475 * that to reclaim free pages from.
14671476 */
14681477 static struct mem_cgroup *
1469−mem_cgroup_select_victim(struct mem_cgroup *root_mem)
1478+mem_cgroup_select_victim(struct mem_cgroup *root_memcg)
14701479 {
14711480 struct mem_cgroup *ret = NULL;
14721481 struct cgroup_subsys_state *css;
14731482 int nextid, found;
14741483
1475− if (!root_mem->use_hierarchy) {
1476− css_get(&root_mem->css);
1477− ret = root_mem;
1484+ if (!root_memcg->use_hierarchy) {
1485+ css_get(&root_memcg->css);
1486+ ret = root_memcg;
14781487 }
14791488
14801489 while (!ret) {
14811490 rcu_read_lock();
1482− nextid = root_mem->last_scanned_child + 1;
1483− css = css_get_next(&mem_cgroup_subsys, nextid, &root_mem->css,
1491+ nextid = root_memcg->last_scanned_child + 1;
1492+ css = css_get_next(&mem_cgroup_subsys, nextid, &root_memcg->css,
14841493 &found);
14851494 if (css && css_tryget(css))
14861495 ret = container_of(css, struct mem_cgroup, css);
@@ -1489,9 +1498,9 @@ mem_cgroup_select_victim(struct mem_cgroup *root_mem) · 2 unmodified lines
14891498 /* Updates scanning parameter */
14901499 if (!css) {
14911500 /* this means start scan from ID:1 */
1492− root_mem->last_scanned_child = 0;
1501+ root_memcg->last_scanned_child = 0;
14931502 } else
1494− root_mem->last_scanned_child = found;
1503+ root_memcg->last_scanned_child = found;
14951504 }
14961505
14971506 return ret;
@@ -1507,14 +1516,14 @@ mem_cgroup_select_victim(struct mem_cgroup *root_mem) · 9 unmodified lines
15071516 * reclaimable pages on a node. Returns true if there are any reclaimable
15081517 * pages in the node.
15091518 */
1510−static bool test_mem_cgroup_node_reclaimable(struct mem_cgroup *mem,
1519+static bool test_mem_cgroup_node_reclaimable(struct mem_cgroup *memcg,
15111520 int nid, bool noswap)
15121521 {
1513− if (mem_cgroup_node_nr_lru_pages(mem, nid, LRU_ALL_FILE))
1522+ if (mem_cgroup_node_nr_lru_pages(memcg, nid, LRU_ALL_FILE))
15141523 return true;
15151524 if (noswap || !total_swap_pages)
15161525 return false;
1517− if (mem_cgroup_node_nr_lru_pages(mem, nid, LRU_ALL_ANON))
1526+ if (mem_cgroup_node_nr_lru_pages(memcg, nid, LRU_ALL_ANON))
15181527 return true;
15191528 return false;
15201529
@@ -1527,29 +1536,29 @@ static bool test_mem_cgroup_node_reclaimable(struct mem_cgroup *mem, · 6 unmodified lines
15271536 * nodes based on the zonelist. So update the list loosely once per 10 secs.
15281537 *
15291538 */
1530−static void mem_cgroup_may_update_nodemask(struct mem_cgroup *mem)
1539+static void mem_cgroup_may_update_nodemask(struct mem_cgroup *memcg)
15311540 {
15321541 int nid;
15331542 /*
15341543 * numainfo_events > 0 means there was at least NUMAINFO_EVENTS_TARGET
15351544 * pagein/pageout changes since the last update.
15361545 */
1537− if (!atomic_read(&mem->numainfo_events))
1546+ if (!atomic_read(&memcg->numainfo_events))
15381547 return;
1539− if (atomic_inc_return(&mem->numainfo_updating) > 1)
1548+ if (atomic_inc_return(&memcg->numainfo_updating) > 1)
15401549 return;
15411550
15421551 /* make a nodemask where this memcg uses memory from */
1543− mem->scan_nodes = node_states[N_HIGH_MEMORY];
1552+ memcg->scan_nodes = node_states[N_HIGH_MEMORY];
15441553
15451554 for_each_node_mask(nid, node_states[N_HIGH_MEMORY]) {
15461555
1547− if (!test_mem_cgroup_node_reclaimable(mem, nid, false))
1548− node_clear(nid, mem->scan_nodes);
1556+ if (!test_mem_cgroup_node_reclaimable(memcg, nid, false))
1557+ node_clear(nid, memcg->scan_nodes);
15491558 }
15501559
1551− atomic_set(&mem->numainfo_events, 0);
1552− atomic_set(&mem->numainfo_updating, 0);
1560+ atomic_set(&memcg->numainfo_events, 0);
1561+ atomic_set(&memcg->numainfo_updating, 0);
15531562 }
15541563
15551564 /*
@@ -1564,16 +1573,16 @@ static void mem_cgroup_may_update_nodemask(struct mem_cgroup *mem) · 8 unmodified lines
15641573 *
15651574 * Now, we use round-robin. Better algorithm is welcomed.
15661575 */
1567−int mem_cgroup_select_victim_node(struct mem_cgroup *mem)
1576+int mem_cgroup_select_victim_node(struct mem_cgroup *memcg)
15681577 {
15691578 int node;
15701579
1571− mem_cgroup_may_update_nodemask(mem);
1572− node = mem->last_scanned_node;
1580+ mem_cgroup_may_update_nodemask(memcg);
1581+ node = memcg->last_scanned_node;
15731582
1574− node = next_node(node, mem->scan_nodes);
1583+ node = next_node(node, memcg->scan_nodes);
15751584 if (node == MAX_NUMNODES)
1576− node = first_node(mem->scan_nodes);
1585+ node = first_node(memcg->scan_nodes);
15771586 /*
15781587 * We call this when we hit limit, not when pages are added to LRU.
15791588 * No LRU may hold pages because all pages are UNEVICTABLE or
@@ -1583,7 +1592,7 @@ int mem_cgroup_select_victim_node(struct mem_cgroup *mem) · 3 unmodified lines
15831592 if (unlikely(node == MAX_NUMNODES))
15841593 node = numa_node_id();
15851594
1586− mem->last_scanned_node = node;
1595+ memcg->last_scanned_node = node;
15871596 return node;
15881597 }
15891598
@@ -1593,7 +1602,7 @@ int mem_cgroup_select_victim_node(struct mem_cgroup *mem) · 3 unmodified lines
15931602 * unused nodes. But scan_nodes is lazily updated and may not cotain
15941603 * enough new information. We need to do double check.
15951604 */
1596−bool mem_cgroup_reclaimable(struct mem_cgroup *mem, bool noswap)
1605+bool mem_cgroup_reclaimable(struct mem_cgroup *memcg, bool noswap)
15971606 {
15981607 int nid;
15991608
@@ -1601,12 +1610,12 @@ bool mem_cgroup_reclaimable(struct mem_cgroup *mem, bool noswap) · 1 unmodified line
16011610 * quick check...making use of scan_node.
16021611 * We can skip unused nodes.
16031612 */
1604− if (!nodes_empty(mem->scan_nodes)) {
1605− for (nid = first_node(mem->scan_nodes);
1613+ if (!nodes_empty(memcg->scan_nodes)) {
1614+ for (nid = first_node(memcg->scan_nodes);
16061615 nid < MAX_NUMNODES;
1607− nid = next_node(nid, mem->scan_nodes)) {
1616+ nid = next_node(nid, memcg->scan_nodes)) {
16081617
1609− if (test_mem_cgroup_node_reclaimable(mem, nid, noswap))
1618+ if (test_mem_cgroup_node_reclaimable(memcg, nid, noswap))
16101619 return true;
16111620 }
16121621 }
@@ -1614,23 +1623,23 @@ bool mem_cgroup_reclaimable(struct mem_cgroup *mem, bool noswap) · 1 unmodified line
16141623 * Check rest of nodes.
16151624 */
16161625 for_each_node_state(nid, N_HIGH_MEMORY) {
1617− if (node_isset(nid, mem->scan_nodes))
1626+ if (node_isset(nid, memcg->scan_nodes))
16181627 continue;
1619− if (test_mem_cgroup_node_reclaimable(mem, nid, noswap))
1628+ if (test_mem_cgroup_node_reclaimable(memcg, nid, noswap))
16201629 return true;
16211630 }
16221631 return false;
16231632 }
16241633
16251634 #else
1626−int mem_cgroup_select_victim_node(struct mem_cgroup *mem)
1635+int mem_cgroup_select_victim_node(struct mem_cgroup *memcg)
16271636 {
16281637 return 0;
16291638 }
16301639
1631−bool mem_cgroup_reclaimable(struct mem_cgroup *mem, bool noswap)
1640+bool mem_cgroup_reclaimable(struct mem_cgroup *memcg, bool noswap)
16321641 {
1633− return test_mem_cgroup_node_reclaimable(mem, 0, noswap);
1642+ return test_mem_cgroup_node_reclaimable(memcg, 0, noswap);
16341643 }
16351644 #endif
16361645
@@ -1639,14 +1648,14 @@ bool mem_cgroup_reclaimable(struct mem_cgroup *mem, bool noswap) · 2 unmodified lines
16391648 * we reclaimed from, so that we don't end up penalizing one child extensively
16401649 * based on its position in the children list.
16411650 *
1642− * root_mem is the original ancestor that we've been reclaim from.
1651+ * root_memcg is the original ancestor that we've been reclaim from.
16431652 *
1644− * We give up and return to the caller when we visit root_mem twice.
1653+ * We give up and return to the caller when we visit root_memcg twice.
16451654 * (other groups can be removed while we're walking....)
16461655 *
16471656 * If shrink==true, for avoiding to free too much, this returns immedieately.
16481657 */
1649−static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem,
1658+static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_memcg,
16501659 struct zone *zone,
16511660 gfp_t gfp_mask,
16521661 unsigned long reclaim_options,
@@ -1661,15 +1670,15 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem, · 8 unmodified lines
16611670 unsigned long excess;
16621671 unsigned long nr_scanned;
16631672
1664− excess = res_counter_soft_limit_excess(&root_mem->res) >> PAGE_SHIFT;
1673+ excess = res_counter_soft_limit_excess(&root_memcg->res) >> PAGE_SHIFT;
16651674
16661675 /* If memsw_is_minimum==1, swap-out is of-no-use. */
1667− if (!check_soft && !shrink && root_mem->memsw_is_minimum)
1676+ if (!check_soft && !shrink && root_memcg->memsw_is_minimum)
16681677 noswap = true;
16691678
16701679 while (1) {
1671− victim = mem_cgroup_select_victim(root_mem);
1672− if (victim == root_mem) {
1680+ victim = mem_cgroup_select_victim(root_memcg);
1681+ if (victim == root_memcg) {
16731682 loop++;
16741683 /*
16751684 * We are not draining per cpu cached charges during
@@ -1678,7 +1687,7 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem, · 2 unmodified lines
16781687 * charges will not give any.
16791688 */
16801689 if (!check_soft && loop >= 1)
1681− drain_all_stock_async(root_mem);
1690+ drain_all_stock_async(root_memcg);
16821691 if (loop >= 2) {
16831692 /*
16841693 * If we have not been able to reclaim
@@ -1725,9 +1734,9 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem, · 40 unmodified lines
17251734 return ret;
17261735 total += ret;
17271736 if (check_soft) {
1728− if (!res_counter_soft_limit_excess(&root_mem->res))
1737+ if (!res_counter_soft_limit_excess(&root_memcg->res))
17291738 return total;
1730− } else if (mem_cgroup_margin(root_mem))
1739+ } else if (mem_cgroup_margin(root_memcg))
17311740 return total;
17321741 }
17331742 return total;
@@ -1738,12 +1747,12 @@ static int mem_cgroup_hierarchical_reclaim(struct mem_cgroup *root_mem, · 4 unmodified lines
17381747 * If someone is running, return false.
17391748 * Has to be called with memcg_oom_lock
17401749 */
1741−static bool mem_cgroup_oom_lock(struct mem_cgroup *mem)
1750+static bool mem_cgroup_oom_lock(struct mem_cgroup *memcg)
17421751 {
17431752 struct mem_cgroup *iter, *failed = NULL;
17441753 bool cond = true;
17451754
1746− for_each_mem_cgroup_tree_cond(iter, mem, cond) {
1755+ for_each_mem_cgroup_tree_cond(iter, memcg, cond) {
17471756 if (iter->oom_lock) {
17481757 /*
17491758 * this subtree of our hierarchy is already locked
@@ -1763,7 +1772,7 @@ static bool mem_cgroup_oom_lock(struct mem_cgroup *mem) · 13 unmodified lines
17631772 * what we set up to the failing subtree
17641773 */
17651774 cond = true;
1766− for_each_mem_cgroup_tree_cond(iter, mem, cond) {
1775+ for_each_mem_cgroup_tree_cond(iter, memcg, cond) {
17671776 if (iter == failed) {
17681777 cond = false;
17691778 continue;
@@ -1776,24 +1785,24 @@ static bool mem_cgroup_oom_lock(struct mem_cgroup *mem) · 6 unmodified lines
17761785 /*
17771786 * Has to be called with memcg_oom_lock
17781787 */
1779−static int mem_cgroup_oom_unlock(struct mem_cgroup *mem)
1788+static int mem_cgroup_oom_unlock(struct mem_cgroup *memcg)
17801789 {
17811790 struct mem_cgroup *iter;
17821791
1783− for_each_mem_cgroup_tree(iter, mem)
1792+ for_each_mem_cgroup_tree(iter, memcg)
17841793 iter->oom_lock = false;
17851794 return 0;
17861795 }
17871796
1788−static void mem_cgroup_mark_under_oom(struct mem_cgroup *mem)
1797+static void mem_cgroup_mark_under_oom(struct mem_cgroup *memcg)
17891798 {
17901799 struct mem_cgroup *iter;
17911800
1792− for_each_mem_cgroup_tree(iter, mem)
1801+ for_each_mem_cgroup_tree(iter, memcg)
17931802 atomic_inc(&iter->under_oom);
17941803 }
17951804
1796−static void mem_cgroup_unmark_under_oom(struct mem_cgroup *mem)
1805+static void mem_cgroup_unmark_under_oom(struct mem_cgroup *memcg)
17971806 {
17981807 struct mem_cgroup *iter;
17991808
@@ -1802,7 +1811,7 @@ static void mem_cgroup_unmark_under_oom(struct mem_cgroup *mem) · 2 unmodified lines
18021811 * mem_cgroup_oom_lock() may not be called. We have to use
18031812 * atomic_add_unless() here.
18041813 */
1805− for_each_mem_cgroup_tree(iter, mem)
1814+ for_each_mem_cgroup_tree(iter, memcg)
18061815 atomic_add_unless(&iter->under_oom, -1, 0);
18071816 }
18081817
@@ -1817,85 +1826,85 @@ struct oom_wait_info { · 8 unmodified lines
18171826 static int memcg_oom_wake_function(wait_queue_t *wait,
18181827 unsigned mode, int sync, void *arg)
18191828 {
1820− struct mem_cgroup *wake_mem = (struct mem_cgroup *)arg,
1821− *oom_wait_mem;
1829+ struct mem_cgroup *wake_memcg = (struct mem_cgroup *)arg,
1830+ *oom_wait_memcg;
18221831 struct oom_wait_info *oom_wait_info;
18231832
18241833 oom_wait_info = container_of(wait, struct oom_wait_info, wait);
1825− oom_wait_mem = oom_wait_info->mem;
1834+ oom_wait_memcg = oom_wait_info->mem;
18261835
18271836 /*
18281837 * Both of oom_wait_info->mem and wake_mem are stable under us.
18291838 * Then we can use css_is_ancestor without taking care of RCU.
18301839 */
1831− if (!mem_cgroup_same_or_subtree(oom_wait_mem, wake_mem)
1832− && !mem_cgroup_same_or_subtree(wake_mem, oom_wait_mem))
1840+ if (!mem_cgroup_same_or_subtree(oom_wait_memcg, wake_memcg)
1841+ && !mem_cgroup_same_or_subtree(wake_memcg, oom_wait_memcg))
18331842 return 0;
18341843 return autoremove_wake_function(wait, mode, sync, arg);
18351844 }
18361845
1837−static void memcg_wakeup_oom(struct mem_cgroup *mem)
1846+static void memcg_wakeup_oom(struct mem_cgroup *memcg)
18381847 {
1839− /* for filtering, pass "mem" as argument. */
1840− __wake_up(&memcg_oom_waitq, TASK_NORMAL, 0, mem);
1848+ /* for filtering, pass "memcg" as argument. */
1849+ __wake_up(&memcg_oom_waitq, TASK_NORMAL, 0, memcg);
18411850 }
18421851
1843−static void memcg_oom_recover(struct mem_cgroup *mem)
1852+static void memcg_oom_recover(struct mem_cgroup *memcg)
18441853 {
1845− if (mem && atomic_read(&mem->under_oom))
1846− memcg_wakeup_oom(mem);
1854+ if (memcg && atomic_read(&memcg->under_oom))
1855+ memcg_wakeup_oom(memcg);
18471856 }
18481857
18491858 /*
18501859 * try to call OOM killer. returns false if we should exit memory-reclaim loop.
18511860 */
1852−bool mem_cgroup_handle_oom(struct mem_cgroup *mem, gfp_t mask)
1861+bool mem_cgroup_handle_oom(struct mem_cgroup *memcg, gfp_t mask)
18531862 {
18541863 struct oom_wait_info owait;
18551864 bool locked, need_to_kill;
18561865
1857− owait.mem = mem;
1866+ owait.mem = memcg;
18581867 owait.wait.flags = 0;
18591868 owait.wait.func = memcg_oom_wake_function;
18601869 owait.wait.private = current;
18611870 INIT_LIST_HEAD(&owait.wait.task_list);
18621871 need_to_kill = true;
1863− mem_cgroup_mark_under_oom(mem);
1872+ mem_cgroup_mark_under_oom(memcg);
18641873
1865− /* At first, try to OOM lock hierarchy under mem.*/
1874+ /* At first, try to OOM lock hierarchy under memcg.*/
18661875 spin_lock(&memcg_oom_lock);
1867− locked = mem_cgroup_oom_lock(mem);
1876+ locked = mem_cgroup_oom_lock(memcg);
18681877 /*
18691878 * Even if signal_pending(), we can't quit charge() loop without
18701879 * accounting. So, UNINTERRUPTIBLE is appropriate. But SIGKILL
18711880 * under OOM is always welcomed, use TASK_KILLABLE here.
18721881 */
18731882 prepare_to_wait(&memcg_oom_waitq, &owait.wait, TASK_KILLABLE);
1874− if (!locked || mem->oom_kill_disable)
1883+ if (!locked || memcg->oom_kill_disable)
18751884 need_to_kill = false;
18761885 if (locked)
1877− mem_cgroup_oom_notify(mem);
1886+ mem_cgroup_oom_notify(memcg);
18781887 spin_unlock(&memcg_oom_lock);
18791888
18801889 if (need_to_kill) {
18811890 finish_wait(&memcg_oom_waitq, &owait.wait);
1882− mem_cgroup_out_of_memory(mem, mask);
1891+ mem_cgroup_out_of_memory(memcg, mask);
18831892 } else {
18841893 schedule();
18851894 finish_wait(&memcg_oom_waitq, &owait.wait);
18861895 }
18871896 spin_lock(&memcg_oom_lock);
18881897 if (locked)
1889− mem_cgroup_oom_unlock(mem);
1890− memcg_wakeup_oom(mem);
1898+ mem_cgroup_oom_unlock(memcg);
1899+ memcg_wakeup_oom(memcg);
18911900 spin_unlock(&memcg_oom_lock);
18921901
1893− mem_cgroup_unmark_under_oom(mem);
1902+ mem_cgroup_unmark_under_oom(memcg);
18941903
18951904 if (test_thread_flag(TIF_MEMDIE) || fatal_signal_pending(current))
18961905 return false;
18971906 /* Give chance to dying process */
1898− schedule_timeout(1);
1907+ schedule_timeout_uninterruptible(1);
18991908 return true;
19001909 }
19011910
@@ -1926,7 +1935,7 @@ bool mem_cgroup_handle_oom(struct mem_cgroup *mem, gfp_t mask) · 24 unmodified lines
19261935 void mem_cgroup_update_page_stat(struct page *page,
19271936 enum mem_cgroup_page_stat_item idx, int val)
19281937 {
1929− struct mem_cgroup *mem;
1938+ struct mem_cgroup *memcg;
19301939 struct page_cgroup *pc = lookup_page_cgroup(page);
19311940 bool need_unlock = false;
19321941 unsigned long uninitialized_var(flags);
@@ -1935,16 +1944,16 @@ void mem_cgroup_update_page_stat(struct page *page, · 2 unmodified lines
19351944 return;
19361945
19371946 rcu_read_lock();
1938− mem = pc->mem_cgroup;
1939− if (unlikely(!mem || !PageCgroupUsed(pc)))
1947+ memcg = pc->mem_cgroup;
1948+ if (unlikely(!memcg || !PageCgroupUsed(pc)))
19401949 goto out;
19411950 /* pc->mem_cgroup is unstable ? */
1942− if (unlikely(mem_cgroup_stealed(mem)) || PageTransHuge(page)) {
1951+ if (unlikely(mem_cgroup_stealed(memcg)) || PageTransHuge(page)) {
19431952 /* take a lock against to access pc->mem_cgroup */
19441953 move_lock_page_cgroup(pc, &flags);
19451954 need_unlock = true;
1946− mem = pc->mem_cgroup;
1947− if (!mem || !PageCgroupUsed(pc))
1955+ memcg = pc->mem_cgroup;
1956+ if (!memcg || !PageCgroupUsed(pc))
19481957 goto out;
19491958 }
19501959
@@ -1960,7 +1969,7 @@ void mem_cgroup_update_page_stat(struct page *page, · 9 unmodified lines
19601969 BUG();
19611970 }
19621971
1963− this_cpu_add(mem->stat->count[idx], val);
1972+ this_cpu_add(memcg->stat->count[idx], val);
19641973
19651974 out:
19661975 if (unlikely(need_unlock))
@@ -1991,13 +2000,13 @@ static DEFINE_MUTEX(percpu_charge_mutex); · 24 unmodified lines
19912000 * cgroup which is not current target, returns false. This stock will be
19922001 * refilled.
19932002 */
1994−static bool consume_stock(struct mem_cgroup *mem)
2003+static bool consume_stock(struct mem_cgroup *memcg)
19952004 {
19962005 struct memcg_stock_pcp *stock;
19972006 bool ret = true;
19982007
19992008 stock = &get_cpu_var(memcg_stock);
2000− if (mem == stock->cached && stock->nr_pages)
2009+ if (memcg == stock->cached && stock->nr_pages)
20012010 stock->nr_pages--;
20022011 else /* need to call res_counter_charge */
20032012 ret = false;
@@ -2038,24 +2047,24 @@ static void drain_local_stock(struct work_struct *dummy) · 34 unmodified lines
20382047 * Cache charges(val) which is from res_counter, to local per_cpu area.
20392048 * This will be consumed by consume_stock() function, later.
20402049 */
2041−static void refill_stock(struct mem_cgroup *mem, unsigned int nr_pages)
2050+static void refill_stock(struct mem_cgroup *memcg, unsigned int nr_pages)
20422051 {
20432052 struct memcg_stock_pcp *stock = &get_cpu_var(memcg_stock);
20442053
2045− if (stock->cached != mem) { /* reset if necessary */
2054+ if (stock->cached != memcg) { /* reset if necessary */
20462055 drain_stock(stock);
2047− stock->cached = mem;
2056+ stock->cached = memcg;
20482057 }
20492058 stock->nr_pages += nr_pages;
20502059 put_cpu_var(memcg_stock);
20512060 }
20522061
20532062 /*
2054− * Drains all per-CPU charge caches for given root_mem resp. subtree
2063+ * Drains all per-CPU charge caches for given root_memcg resp. subtree
20552064 * of the hierarchy under it. sync flag says whether we should block
20562065 * until the work is done.
20572066 */
2058−static void drain_all_stock(struct mem_cgroup *root_mem, bool sync)
2067+static void drain_all_stock(struct mem_cgroup *root_memcg, bool sync)
20592068 {
20602069 int cpu, curcpu;
20612070
@@ -2064,12 +2073,12 @@ static void drain_all_stock(struct mem_cgroup *root_mem, bool sync) · 2 unmodified lines
20642073 curcpu = get_cpu();
20652074 for_each_online_cpu(cpu) {
20662075 struct memcg_stock_pcp *stock = &per_cpu(memcg_stock, cpu);
2067− struct mem_cgroup *mem;
2076+ struct mem_cgroup *memcg;
20682077
2069− mem = stock->cached;
2070− if (!mem || !stock->nr_pages)
2078+ memcg = stock->cached;
2079+ if (!memcg || !stock->nr_pages)
20712080 continue;
2072− if (!mem_cgroup_same_or_subtree(root_mem, mem))
2081+ if (!mem_cgroup_same_or_subtree(root_memcg, memcg))
20732082 continue;
20742083 if (!test_and_set_bit(FLUSHING_CACHED_CHARGE, &stock->flags)) {
20752084 if (cpu == curcpu)
@@ -2098,23 +2107,23 @@ out: · 22 unmodified lines
20982107 * expects some charges will be back to res_counter later but cannot wait for
20992108 * it.
21002109 */
2101−static void drain_all_stock_async(struct mem_cgroup *root_mem)
2110+static void drain_all_stock_async(struct mem_cgroup *root_memcg)
21022111 {
21032112 /*
21042113 * If someone calls draining, avoid adding more kworker runs.
21052114 */
21062115 if (!mutex_trylock(&percpu_charge_mutex))
21072116 return;
2108− drain_all_stock(root_mem, false);
2117+ drain_all_stock(root_memcg, false);
21092118 mutex_unlock(&percpu_charge_mutex);
21102119 }
21112120
21122121 /* This is a synchronous drain interface. */
2113−static void drain_all_stock_sync(struct mem_cgroup *root_mem)
2122+static void drain_all_stock_sync(struct mem_cgroup *root_memcg)
21142123 {
21152124 /* called when force_empty is called */
21162125 mutex_lock(&percpu_charge_mutex);
2117− drain_all_stock(root_mem, true);
2126+ drain_all_stock(root_memcg, true);
21182127 mutex_unlock(&percpu_charge_mutex);
21192128 }
21202129
@@ -2122,35 +2131,35 @@ static void drain_all_stock_sync(struct mem_cgroup *root_mem) · 1 unmodified line
21222131 * This function drains percpu counter value from DEAD cpu and
21232132 * move it to local cpu. Note that this function can be preempted.
21242133 */
2125−static void mem_cgroup_drain_pcp_counter(struct mem_cgroup *mem, int cpu)
2134+static void mem_cgroup_drain_pcp_counter(struct mem_cgroup *memcg, int cpu)
21262135 {
21272136 int i;
21282137
2129− spin_lock(&mem->pcp_counter_lock);
2138+ spin_lock(&memcg->pcp_counter_lock);
21302139 for (i = 0; i < MEM_CGROUP_STAT_DATA; i++) {
2131− long x = per_cpu(mem->stat->count[i], cpu);
2140+ long x = per_cpu(memcg->stat->count[i], cpu);
21322141
2133− per_cpu(mem->stat->count[i], cpu) = 0;
2134− mem->nocpu_base.count[i] += x;
2142+ per_cpu(memcg->stat->count[i], cpu) = 0;
2143+ memcg->nocpu_base.count[i] += x;
21352144 }
21362145 for (i = 0; i < MEM_CGROUP_EVENTS_NSTATS; i++) {
2137− unsigned long x = per_cpu(mem->stat->events[i], cpu);
2146+ unsigned long x = per_cpu(memcg->stat->events[i], cpu);
21382147
2139− per_cpu(mem->stat->events[i], cpu) = 0;
2140− mem->nocpu_base.events[i] += x;
2148+ per_cpu(memcg->stat->events[i], cpu) = 0;
2149+ memcg->nocpu_base.events[i] += x;
21412150 }
21422151 /* need to clear ON_MOVE value, works as a kind of lock. */
2143− per_cpu(mem->stat->count[MEM_CGROUP_ON_MOVE], cpu) = 0;
2144− spin_unlock(&mem->pcp_counter_lock);
2152+ per_cpu(memcg->stat->count[MEM_CGROUP_ON_MOVE], cpu) = 0;
2153+ spin_unlock(&memcg->pcp_counter_lock);
21452154 }
21462155
2147−static void synchronize_mem_cgroup_on_move(struct mem_cgroup *mem, int cpu)
2156+static void synchronize_mem_cgroup_on_move(struct mem_cgroup *memcg, int cpu)
21482157 {
21492158 int idx = MEM_CGROUP_ON_MOVE;
21502159
2151− spin_lock(&mem->pcp_counter_lock);
2152− per_cpu(mem->stat->count[idx], cpu) = mem->nocpu_base.count[idx];
2153− spin_unlock(&mem->pcp_counter_lock);
2160+ spin_lock(&memcg->pcp_counter_lock);
2161+ per_cpu(memcg->stat->count[idx], cpu) = memcg->nocpu_base.count[idx];
2162+ spin_unlock(&memcg->pcp_counter_lock);
21542163 }
21552164
21562165 static int __cpuinit memcg_cpu_hotplug_callback(struct notifier_block *nb,
@@ -2188,7 +2197,7 @@ enum { · 31 unmodified lines
21882197 CHARGE_OOM_DIE, /* the current is killed because of OOM */
21892198 };
21902199
2191−static int mem_cgroup_do_charge(struct mem_cgroup *mem, gfp_t gfp_mask,
2200+static int mem_cgroup_do_charge(struct mem_cgroup *memcg, gfp_t gfp_mask,
21922201 unsigned int nr_pages, bool oom_check)
21932202 {
21942203 unsigned long csize = nr_pages * PAGE_SIZE;
@@ -2197,16 +2206,16 @@ static int mem_cgroup_do_charge(struct mem_cgroup *mem, gfp_t gfp_mask, · 2 unmodified lines
21972206 unsigned long flags = 0;
21982207 int ret;
21992208
2200− ret = res_counter_charge(&mem->res, csize, &fail_res);
2209+ ret = res_counter_charge(&memcg->res, csize, &fail_res);
22012210
22022211 if (likely(!ret)) {
22032212 if (!do_swap_account)
22042213 return CHARGE_OK;
2205− ret = res_counter_charge(&mem->memsw, csize, &fail_res);
2214+ ret = res_counter_charge(&memcg->memsw, csize, &fail_res);
22062215 if (likely(!ret))
22072216 return CHARGE_OK;
22082217
2209− res_counter_uncharge(&mem->res, csize);
2218+ res_counter_uncharge(&memcg->res, csize);
22102219 mem_over_limit = mem_cgroup_from_res_counter(fail_res, memsw);
22112220 flags |= MEM_CGROUP_RECLAIM_NOSWAP;
22122221 } else
@@ -2264,12 +2273,12 @@ static int mem_cgroup_do_charge(struct mem_cgroup *mem, gfp_t gfp_mask, · 51 unmodified lines
22642273 static int __mem_cgroup_try_charge(struct mm_struct *mm,
22652274 gfp_t gfp_mask,
22662275 unsigned int nr_pages,
2267− struct mem_cgroup **memcg,
2276+ struct mem_cgroup **ptr,
22682277 bool oom)
22692278 {
22702279 unsigned int batch = max(CHARGE_BATCH, nr_pages);
22712280 int nr_oom_retries = MEM_CGROUP_RECLAIM_RETRIES;
2272− struct mem_cgroup *mem = NULL;
2281+ struct mem_cgroup *memcg = NULL;
22732282 int ret;
22742283
22752284 /*
@@ -2287,17 +2296,17 @@ static int __mem_cgroup_try_charge(struct mm_struct *mm, · 11 unmodified lines
22872296 * thread group leader migrates. It's possible that mm is not
22882297 * set, if so charge the init_mm (happens for pagecache usage).
22892298 */
2290− if (!*memcg && !mm)
2299+ if (!*ptr && !mm)
22912300 goto bypass;
22922301 again:
2293− if (*memcg) { /* css should be a valid one */
2294− mem = *memcg;
2295− VM_BUG_ON(css_is_removed(&mem->css));
2296− if (mem_cgroup_is_root(mem))
2302+ if (*ptr) { /* css should be a valid one */
2303+ memcg = *ptr;
2304+ VM_BUG_ON(css_is_removed(&memcg->css));
2305+ if (mem_cgroup_is_root(memcg))
22972306 goto done;
2298− if (nr_pages == 1 && consume_stock(mem))
2307+ if (nr_pages == 1 && consume_stock(memcg))
22992308 goto done;
2300− css_get(&mem->css);
2309+ css_get(&memcg->css);
23012310 } else {
23022311 struct task_struct *p;
23032312
@@ -2305,7 +2314,7 @@ again: · 1 unmodified line
23052314 p = rcu_dereference(mm->owner);
23062315 /*
23072316 * Because we don't have task_lock(), "p" can exit.
2308− * In that case, "mem" can point to root or p can be NULL with
2317+ * In that case, "memcg" can point to root or p can be NULL with
23092318 * race with swapoff. Then, we have small risk of mis-accouning.
23102319 * But such kind of mis-account by race always happens because
23112320 * we don't have cgroup_mutex(). It's overkill and we allo that
@@ -2313,12 +2322,12 @@ again: · 1 unmodified line
23132322 * (*) swapoff at el will charge against mm-struct not against
23142323 * task-struct. So, mm->owner can be NULL.
23152324 */
2316− mem = mem_cgroup_from_task(p);
2317− if (!mem || mem_cgroup_is_root(mem)) {
2325+ memcg = mem_cgroup_from_task(p);
2326+ if (!memcg || mem_cgroup_is_root(memcg)) {
23182327 rcu_read_unlock();
23192328 goto done;
23202329 }
2321− if (nr_pages == 1 && consume_stock(mem)) {
2330+ if (nr_pages == 1 && consume_stock(memcg)) {
23222331 /*
23232332 * It seems dagerous to access memcg without css_get().
23242333 * But considering how consume_stok works, it's not
@@ -2331,7 +2340,7 @@ again: · 6 unmodified lines
23312340 goto done;
23322341 }
23332342 /* after here, we may be blocked. we need to get refcnt */
2334− if (!css_tryget(&mem->css)) {
2343+ if (!css_tryget(&memcg->css)) {
23352344 rcu_read_unlock();
23362345 goto again;
23372346 }
@@ -2343,7 +2352,7 @@ again: · 5 unmodified lines
23432352
23442353 /* If killed, bypass charge */
23452354 if (fatal_signal_pending(current)) {
2346− css_put(&mem->css);
2355+ css_put(&memcg->css);
23472356 goto bypass;
23482357 }
23492358
@@ -2353,43 +2362,43 @@ again: · 3 unmodified lines
23532362 nr_oom_retries = MEM_CGROUP_RECLAIM_RETRIES;
23542363 }
23552364
2356− ret = mem_cgroup_do_charge(mem, gfp_mask, batch, oom_check);
2365+ ret = mem_cgroup_do_charge(memcg, gfp_mask, batch, oom_check);
23572366 switch (ret) {
23582367 case CHARGE_OK:
23592368 break;
23602369 case CHARGE_RETRY: /* not in OOM situation but retry */
23612370 batch = nr_pages;
2362− css_put(&mem->css);
2363− mem = NULL;
2371+ css_put(&memcg->css);
2372+ memcg = NULL;
23642373 goto again;
23652374 case CHARGE_WOULDBLOCK: /* !__GFP_WAIT */
2366− css_put(&mem->css);
2375+ css_put(&memcg->css);
23672376 goto nomem;
23682377 case CHARGE_NOMEM: /* OOM routine works */
23692378 if (!oom) {
2370− css_put(&mem->css);
2379+ css_put(&memcg->css);
23712380 goto nomem;
23722381 }
23732382 /* If oom, we never return -ENOMEM */
23742383 nr_oom_retries--;
23752384 break;
23762385 case CHARGE_OOM_DIE: /* Killed by OOM Killer */
2377− css_put(&mem->css);
2386+ css_put(&memcg->css);
23782387 goto bypass;
23792388 }
23802389 } while (ret != CHARGE_OK);
23812390
23822391 if (batch > nr_pages)
2383− refill_stock(mem, batch - nr_pages);
2384− css_put(&mem->css);
2392+ refill_stock(memcg, batch - nr_pages);
2393+ css_put(&memcg->css);
23852394 done:
2386− *memcg = mem;
2395+ *ptr = memcg;
23872396 return 0;
23882397 nomem:
2389− *memcg = NULL;
2398+ *ptr = NULL;
23902399 return -ENOMEM;
23912400 bypass:
2392− *memcg = NULL;
2401+ *ptr = NULL;
23932402 return 0;
23942403 }
23952404
@@ -2398,15 +2407,15 @@ bypass: · 2 unmodified lines
23982407 * This function is for that and do uncharge, put css's refcnt.
23992408 * gotten by try_charge().
24002409 */
2401−static void __mem_cgroup_cancel_charge(struct mem_cgroup *mem,
2410+static void __mem_cgroup_cancel_charge(struct mem_cgroup *memcg,
24022411 unsigned int nr_pages)
24032412 {
2404− if (!mem_cgroup_is_root(mem)) {
2413+ if (!mem_cgroup_is_root(memcg)) {
24052414 unsigned long bytes = nr_pages * PAGE_SIZE;
24062415
2407− res_counter_uncharge(&mem->res, bytes);
2416+ res_counter_uncharge(&memcg->res, bytes);
24082417 if (do_swap_account)
2409− res_counter_uncharge(&mem->memsw, bytes);
2418+ res_counter_uncharge(&memcg->memsw, bytes);
24102419 }
24112420 }
24122421
@@ -2431,7 +2440,7 @@ static struct mem_cgroup *mem_cgroup_lookup(unsigned short id) · 18 unmodified lines
24312440
24322441 struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
24332442 {
2434− struct mem_cgroup *mem = NULL;
2443+ struct mem_cgroup *memcg = NULL;
24352444 struct page_cgroup *pc;
24362445 unsigned short id;
24372446 swp_entry_t ent;
@@ -2441,23 +2450,23 @@ struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) · 3 unmodified lines
24412450 pc = lookup_page_cgroup(page);
24422451 lock_page_cgroup(pc);
24432452 if (PageCgroupUsed(pc)) {
2444− mem = pc->mem_cgroup;
2445− if (mem && !css_tryget(&mem->css))
2446− mem = NULL;
2453+ memcg = pc->mem_cgroup;
2454+ if (memcg && !css_tryget(&memcg->css))
2455+ memcg = NULL;
24472456 } else if (PageSwapCache(page)) {
24482457 ent.val = page_private(page);
24492458 id = lookup_swap_cgroup(ent);
24502459 rcu_read_lock();
2451− mem = mem_cgroup_lookup(id);
2452− if (mem && !css_tryget(&mem->css))
2453− mem = NULL;
2460+ memcg = mem_cgroup_lookup(id);
2461+ if (memcg && !css_tryget(&memcg->css))
2462+ memcg = NULL;
24542463 rcu_read_unlock();
24552464 }
24562465 unlock_page_cgroup(pc);
2457− return mem;
2466+ return memcg;
24582467 }
24592468
2460−static void __mem_cgroup_commit_charge(struct mem_cgroup *mem,
2469+static void __mem_cgroup_commit_charge(struct mem_cgroup *memcg,
24612470 struct page *page,
24622471 unsigned int nr_pages,
24632472 struct page_cgroup *pc,
@@ -2466,14 +2475,14 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *mem, · 2 unmodified lines
24662475 lock_page_cgroup(pc);
24672476 if (unlikely(PageCgroupUsed(pc))) {
24682477 unlock_page_cgroup(pc);
2469− __mem_cgroup_cancel_charge(mem, nr_pages);
2478+ __mem_cgroup_cancel_charge(memcg, nr_pages);
24702479 return;
24712480 }
24722481 /*
24732482 * we don't need page_cgroup_lock about tail pages, becase they are not
24742483 * accessed by any other context at this point.
24752484 */
2476− pc->mem_cgroup = mem;
2485+ pc->mem_cgroup = memcg;
24772486 /*
24782487 * We access a page_cgroup asynchronously without lock_page_cgroup().
24792488 * Especially when a page_cgroup is taken from a page, pc->mem_cgroup
@@ -2496,14 +2505,14 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *mem, · 16 unmodified lines
24962505 break;
24972506 }
24982507
2499− mem_cgroup_charge_statistics(mem, PageCgroupCache(pc), nr_pages);
2508+ mem_cgroup_charge_statistics(memcg, PageCgroupCache(pc), nr_pages);
25002509 unlock_page_cgroup(pc);
25012510 /*
25022511 * "charge_statistics" updated event counter. Then, check it.
25032512 * Insert ancestor (and ancestor's ancestors), to softlimit RB-tree.
25042513 * if they exceeds softlimit.
25052514 */
2506− memcg_check_events(mem, page);
2515+ memcg_check_events(memcg, page);
25072516 }
25082517
25092518 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
@@ -2690,7 +2699,7 @@ out: · 180 unmodified lines
26902699 static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
26912700 gfp_t gfp_mask, enum charge_type ctype)
26922701 {
2693− struct mem_cgroup *mem = NULL;
2702+ struct mem_cgroup *memcg = NULL;
26942703 unsigned int nr_pages = 1;
26952704 struct page_cgroup *pc;
26962705 bool oom = true;
@@ -2709,11 +2718,11 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm, · 12 unmodified lines
27092718 pc = lookup_page_cgroup(page);
27102719 BUG_ON(!pc); /* XXX: remove this and move pc lookup into commit */
27112720
2712− ret = __mem_cgroup_try_charge(mm, gfp_mask, nr_pages, &mem, oom);
2713− if (ret || !mem)
2721+ ret = __mem_cgroup_try_charge(mm, gfp_mask, nr_pages, &memcg, oom);
2722+ if (ret || !memcg)
27142723 return ret;
27152724
2716− __mem_cgroup_commit_charge(mem, page, nr_pages, pc, ctype);
2725+ __mem_cgroup_commit_charge(memcg, page, nr_pages, pc, ctype);
27172726 return 0;
27182727 }
27192728
@@ -2742,7 +2751,7 @@ __mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr, · 22 unmodified lines
27422751 enum charge_type ctype);
27432752
27442753 static void
2745−__mem_cgroup_commit_charge_lrucare(struct page *page, struct mem_cgroup *mem,
2754+__mem_cgroup_commit_charge_lrucare(struct page *page, struct mem_cgroup *memcg,
27462755 enum charge_type ctype)
27472756 {
27482757 struct page_cgroup *pc = lookup_page_cgroup(page);
@@ -2752,7 +2761,7 @@ __mem_cgroup_commit_charge_lrucare(struct page *page, struct mem_cgroup *mem, · 3 unmodified lines
27522761 * LRU. Take care of it.
27532762 */
27542763 mem_cgroup_lru_del_before_commit(page);
2755− __mem_cgroup_commit_charge(mem, page, 1, pc, ctype);
2764+ __mem_cgroup_commit_charge(memcg, page, 1, pc, ctype);
27562765 mem_cgroup_lru_add_after_commit(page);
27572766 return;
27582767 }
@@ -2760,7 +2769,7 @@ __mem_cgroup_commit_charge_lrucare(struct page *page, struct mem_cgroup *mem, · 1 unmodified line
27602769 int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm,
27612770 gfp_t gfp_mask)
27622771 {
2763− struct mem_cgroup *mem = NULL;
2772+ struct mem_cgroup *memcg = NULL;
27642773 int ret;
27652774
27662775 if (mem_cgroup_disabled())
@@ -2772,8 +2781,8 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm, · 5 unmodified lines
27722781 mm = &init_mm;
27732782
27742783 if (page_is_file_cache(page)) {
2775− ret = __mem_cgroup_try_charge(mm, gfp_mask, 1, &mem, true);
2776− if (ret || !mem)
2784+ ret = __mem_cgroup_try_charge(mm, gfp_mask, 1, &memcg, true);
2785+ if (ret || !memcg)
27772786 return ret;
27782787
27792788 /*
@@ -2781,15 +2790,15 @@ int mem_cgroup_cache_charge(struct page *page, struct mm_struct *mm, · 1 unmodified line
27812790 * put that would remove them from the LRU list, make
27822791 * sure that they get relinked properly.
27832792 */
2784− __mem_cgroup_commit_charge_lrucare(page, mem,
2793+ __mem_cgroup_commit_charge_lrucare(page, memcg,
27852794 MEM_CGROUP_CHARGE_TYPE_CACHE);
27862795 return ret;
27872796 }
27882797 /* shmem */
27892798 if (PageSwapCache(page)) {
2790− ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &mem);
2799+ ret = mem_cgroup_try_charge_swapin(mm, page, gfp_mask, &memcg);
27912800 if (!ret)
2792− __mem_cgroup_commit_charge_swapin(page, mem,
2801+ __mem_cgroup_commit_charge_swapin(page, memcg,
27932802 MEM_CGROUP_CHARGE_TYPE_SHMEM);
27942803 } else
27952804 ret = mem_cgroup_charge_common(page, mm, gfp_mask,
@@ -2808,7 +2817,7 @@ int mem_cgroup_try_charge_swapin(struct mm_struct *mm, · 12 unmodified lines
28082817 struct page *page,
28092818 gfp_t mask, struct mem_cgroup **ptr)
28102819 {
2811− struct mem_cgroup *mem;
2820+ struct mem_cgroup *memcg;
28122821 int ret;
28132822
28142823 *ptr = NULL;
@@ -2826,12 +2835,12 @@ int mem_cgroup_try_charge_swapin(struct mm_struct *mm, · 11 unmodified lines
28262835 */
28272836 if (!PageSwapCache(page))
28282837 goto charge_cur_mm;
2829− mem = try_get_mem_cgroup_from_page(page);
2830− if (!mem)
2838+ memcg = try_get_mem_cgroup_from_page(page);
2839+ if (!memcg)
28312840 goto charge_cur_mm;
2832− *ptr = mem;
2841+ *ptr = memcg;
28332842 ret = __mem_cgroup_try_charge(NULL, mask, 1, ptr, true);
2834− css_put(&mem->css);
2843+ css_put(&memcg->css);
28352844 return ret;
28362845 charge_cur_mm:
28372846 if (unlikely(!mm))
@@ -2891,16 +2900,16 @@ void mem_cgroup_commit_charge_swapin(struct page *page, struct mem_cgroup *ptr) · 53 unmodified lines
28912900 MEM_CGROUP_CHARGE_TYPE_MAPPED);
28922901 }
28932902
2894−void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *mem)
2903+void mem_cgroup_cancel_charge_swapin(struct mem_cgroup *memcg)
28952904 {
28962905 if (mem_cgroup_disabled())
28972906 return;
2898− if (!mem)
2907+ if (!memcg)
28992908 return;
2900− __mem_cgroup_cancel_charge(mem, 1);
2909+ __mem_cgroup_cancel_charge(memcg, 1);
29012910 }
29022911
2903−static void mem_cgroup_do_uncharge(struct mem_cgroup *mem,
2912+static void mem_cgroup_do_uncharge(struct mem_cgroup *memcg,
29042913 unsigned int nr_pages,
29052914 const enum charge_type ctype)
29062915 {
@@ -2918,7 +2927,7 @@ static void mem_cgroup_do_uncharge(struct mem_cgroup *mem, · 11 unmodified lines
29182927 * uncharges. Then, it's ok to ignore memcg's refcnt.
29192928 */
29202929 if (!batch->memcg)
2921− batch->memcg = mem;
2930+ batch->memcg = memcg;
29222931 /*
29232932 * do_batch > 0 when unmapping pages or inode invalidate/truncate.
29242933 * In those cases, all pages freed continuously can be expected to be in
@@ -2938,7 +2947,7 @@ static void mem_cgroup_do_uncharge(struct mem_cgroup *mem, · 13 unmodified lines
29382947 * merge a series of uncharges to an uncharge of res_counter.
29392948 * If not, we uncharge res_counter ony by one.
29402949 */
2941− if (batch->memcg != mem)
2950+ if (batch->memcg != memcg)
29422951 goto direct_uncharge;
29432952 /* remember freed charge and uncharge it later */
29442953 batch->nr_pages++;
@@ -2946,11 +2955,11 @@ static void mem_cgroup_do_uncharge(struct mem_cgroup *mem, · 1 unmodified line
29462955 batch->memsw_nr_pages++;
29472956 return;
29482957 direct_uncharge:
2949− res_counter_uncharge(&mem->res, nr_pages * PAGE_SIZE);
2958+ res_counter_uncharge(&memcg->res, nr_pages * PAGE_SIZE);
29502959 if (uncharge_memsw)
2951− res_counter_uncharge(&mem->memsw, nr_pages * PAGE_SIZE);
2952− if (unlikely(batch->memcg != mem))
2953− memcg_oom_recover(mem);
2960+ res_counter_uncharge(&memcg->memsw, nr_pages * PAGE_SIZE);
2961+ if (unlikely(batch->memcg != memcg))
2962+ memcg_oom_recover(memcg);
29542963 return;
29552964 }
29562965
@@ -2960,7 +2969,7 @@ direct_uncharge: · 3 unmodified lines
29602969 static struct mem_cgroup *
29612970 __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
29622971 {
2963− struct mem_cgroup *mem = NULL;
2972+ struct mem_cgroup *memcg = NULL;
29642973 unsigned int nr_pages = 1;
29652974 struct page_cgroup *pc;
29662975
@@ -2983,7 +2992,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) · 16 unmodified lines
29832992
29842993 lock_page_cgroup(pc);
29852994
2986− mem = pc->mem_cgroup;
2995+ memcg = pc->mem_cgroup;
29872996
29882997 if (!PageCgroupUsed(pc))
29892998 goto unlock_out;
@@ -3006,7 +3015,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) · 16 unmodified lines
30063015 break;
30073016 }
30083017
3009− mem_cgroup_charge_statistics(mem, PageCgroupCache(pc), -nr_pages);
3018+ mem_cgroup_charge_statistics(memcg, PageCgroupCache(pc), -nr_pages);
30103019
30113020 ClearPageCgroupUsed(pc);
30123021 /*
@@ -3018,18 +3027,18 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) · 5 unmodified lines
30183027
30193028 unlock_page_cgroup(pc);
30203029 /*
3021− * even after unlock, we have mem->res.usage here and this memcg
3030+ * even after unlock, we have memcg->res.usage here and this memcg
30223031 * will never be freed.
30233032 */
3024− memcg_check_events(mem, page);
3033+ memcg_check_events(memcg, page);
30253034 if (do_swap_account && ctype == MEM_CGROUP_CHARGE_TYPE_SWAPOUT) {
3026− mem_cgroup_swap_statistics(mem, true);
3027− mem_cgroup_get(mem);
3035+ mem_cgroup_swap_statistics(memcg, true);
3036+ mem_cgroup_get(memcg);
30283037 }
3029− if (!mem_cgroup_is_root(mem))
3030− mem_cgroup_do_uncharge(mem, nr_pages, ctype);
3038+ if (!mem_cgroup_is_root(memcg))
3039+ mem_cgroup_do_uncharge(memcg, nr_pages, ctype);
30313040
3032− return mem;
3041+ return memcg;
30333042
30343043 unlock_out:
30353044 unlock_page_cgroup(pc);
@@ -3219,7 +3228,7 @@ static inline int mem_cgroup_move_swap_account(swp_entry_t entry, · 183 unmodified lines
32193228 int mem_cgroup_prepare_migration(struct page *page,
32203229 struct page *newpage, struct mem_cgroup **ptr, gfp_t gfp_mask)
32213230 {
3222− struct mem_cgroup *mem = NULL;
3231+ struct mem_cgroup *memcg = NULL;
32233232 struct page_cgroup *pc;
32243233 enum charge_type ctype;
32253234 int ret = 0;
@@ -3233,8 +3242,8 @@ int mem_cgroup_prepare_migration(struct page *page, · 7 unmodified lines
32333242 pc = lookup_page_cgroup(page);
32343243 lock_page_cgroup(pc);
32353244 if (PageCgroupUsed(pc)) {
3236− mem = pc->mem_cgroup;
3237− css_get(&mem->css);
3245+ memcg = pc->mem_cgroup;
3246+ css_get(&memcg->css);
32383247 /*
32393248 * At migrating an anonymous page, its mapcount goes down
32403249 * to 0 and uncharge() will be called. But, even if it's fully
@@ -3272,12 +3281,12 @@ int mem_cgroup_prepare_migration(struct page *page, · 31 unmodified lines
32723281 * If the page is not charged at this point,
32733282 * we return here.
32743283 */
3275− if (!mem)
3284+ if (!memcg)
32763285 return 0;
32773286
3278− *ptr = mem;
3287+ *ptr = memcg;
32793288 ret = __mem_cgroup_try_charge(NULL, gfp_mask, 1, ptr, false);
3280− css_put(&mem->css);/* drop extra refcnt */
3289+ css_put(&memcg->css);/* drop extra refcnt */
32813290 if (ret || *ptr == NULL) {
32823291 if (PageAnon(page)) {
32833292 lock_page_cgroup(pc);
@@ -3303,21 +3312,21 @@ int mem_cgroup_prepare_migration(struct page *page, · 19 unmodified lines
33033312 ctype = MEM_CGROUP_CHARGE_TYPE_CACHE;
33043313 else
33053314 ctype = MEM_CGROUP_CHARGE_TYPE_SHMEM;
3306− __mem_cgroup_commit_charge(mem, page, 1, pc, ctype);
3315+ __mem_cgroup_commit_charge(memcg, page, 1, pc, ctype);
33073316 return ret;
33083317 }
33093318
33103319 /* remove redundant charge if migration failed*/
3311−void mem_cgroup_end_migration(struct mem_cgroup *mem,
3320+void mem_cgroup_end_migration(struct mem_cgroup *memcg,
33123321 struct page *oldpage, struct page *newpage, bool migration_ok)
33133322 {
33143323 struct page *used, *unused;
33153324 struct page_cgroup *pc;
33163325
3317− if (!mem)
3326+ if (!memcg)
33183327 return;
33193328 /* blocks rmdir() */
3320− cgroup_exclude_rmdir(&mem->css);
3329+ cgroup_exclude_rmdir(&memcg->css);
33213330 if (!migration_ok) {
33223331 used = oldpage;
33233332 unused = newpage;
@@ -3353,7 +3362,7 @@ void mem_cgroup_end_migration(struct mem_cgroup *mem, · 29 unmodified lines
33533362 * So, rmdir()->pre_destroy() can be called while we do this charge.
33543363 * In that case, we need to call pre_destroy() again. check it here.
33553364 */
3356− cgroup_release_and_wakeup_rmdir(&mem->css);
3365+ cgroup_release_and_wakeup_rmdir(&memcg->css);
33573366 }
33583367
33593368 #ifdef CONFIG_DEBUG_VM
@@ -3432,7 +3441,7 @@ static int mem_cgroup_resize_limit(struct mem_cgroup *memcg, · 72 unmodified lines
34323441 /*
34333442 * Rather than hide all in some function, I do this in
34343443 * open coded manner. You see what this really does.
3435− * We have to guarantee mem->res.limit < mem->memsw.limit.
3444+ * We have to guarantee memcg->res.limit < memcg->memsw.limit.
34363445 */
34373446 mutex_lock(&set_limit_mutex);
34383447 memswlimit = res_counter_read_u64(&memcg->memsw, RES_LIMIT);
@@ -3494,7 +3503,7 @@ static int mem_cgroup_resize_memsw_limit(struct mem_cgroup *memcg, · 55 unmodified lines
34943503 /*
34953504 * Rather than hide all in some function, I do this in
34963505 * open coded manner. You see what this really does.
3497− * We have to guarantee mem->res.limit < mem->memsw.limit.
3506+ * We have to guarantee memcg->res.limit < memcg->memsw.limit.
34983507 */
34993508 mutex_lock(&set_limit_mutex);
35003509 memlimit = res_counter_read_u64(&memcg->res, RES_LIMIT);
@@ -3632,7 +3641,7 @@ unsigned long mem_cgroup_soft_limit_reclaim(struct zone *zone, int order, · 131 unmodified lines
36323641 * This routine traverse page_cgroup in given list and drop them all.
36333642 * *And* this routine doesn't reclaim page itself, just removes page_cgroup.
36343643 */
3635−static int mem_cgroup_force_empty_list(struct mem_cgroup *mem,
3644+static int mem_cgroup_force_empty_list(struct mem_cgroup *memcg,
36363645 int node, int zid, enum lru_list lru)
36373646 {
36383647 struct zone *zone;
@@ -3643,7 +3652,7 @@ static int mem_cgroup_force_empty_list(struct mem_cgroup *mem, · 4 unmodified lines
36433652 int ret = 0;
36443653
36453654 zone = &NODE_DATA(node)->node_zones[zid];
3646− mz = mem_cgroup_zoneinfo(mem, node, zid);
3655+ mz = mem_cgroup_zoneinfo(memcg, node, zid);
36473656 list = &mz->lists[lru];
36483657
36493658 loop = MEM_CGROUP_ZSTAT(mz, lru);
@@ -3670,7 +3679,7 @@ static int mem_cgroup_force_empty_list(struct mem_cgroup *mem, · 20 unmodified lines
36703679
36713680 page = lookup_cgroup_page(pc);
36723681
3673− ret = mem_cgroup_move_parent(page, pc, mem, GFP_KERNEL);
3682+ ret = mem_cgroup_move_parent(page, pc, memcg, GFP_KERNEL);
36743683 if (ret == -ENOMEM)
36753684 break;
36763685
@@ -3691,14 +3700,14 @@ static int mem_cgroup_force_empty_list(struct mem_cgroup *mem, · 14 unmodified lines
36913700 * make mem_cgroup's charge to be 0 if there is no task.
36923701 * This enables deleting this mem_cgroup.
36933702 */
3694−static int mem_cgroup_force_empty(struct mem_cgroup *mem, bool free_all)
3703+static int mem_cgroup_force_empty(struct mem_cgroup *memcg, bool free_all)
36953704 {
36963705 int ret;
36973706 int node, zid, shrink;
36983707 int nr_retries = MEM_CGROUP_RECLAIM_RETRIES;
3699− struct cgroup *cgrp = mem->css.cgroup;
3708+ struct cgroup *cgrp = memcg->css.cgroup;
37003709
3701− css_get(&mem->css);
3710+ css_get(&memcg->css);
37023711
37033712 shrink = 0;
37043713 /* should free all ? */
@@ -3714,14 +3723,14 @@ move_account: · 9 unmodified lines
37143723 goto out;
37153724 /* This is for making all *used* pages to be on LRU. */
37163725 lru_add_drain_all();
3717− drain_all_stock_sync(mem);
3726+ drain_all_stock_sync(memcg);
37183727 ret = 0;
3719− mem_cgroup_start_move(mem);
3728+ mem_cgroup_start_move(memcg);
37203729 for_each_node_state(node, N_HIGH_MEMORY) {
37213730 for (zid = 0; !ret && zid < MAX_NR_ZONES; zid++) {
37223731 enum lru_list l;
37233732 for_each_lru(l) {
3724− ret = mem_cgroup_force_empty_list(mem,
3733+ ret = mem_cgroup_force_empty_list(memcg,
37253734 node, zid, l);
37263735 if (ret)
37273736 break;
@@ -3730,16 +3739,16 @@ move_account: · 2 unmodified lines
37303739 if (ret)
37313740 break;
37323741 }
3733− mem_cgroup_end_move(mem);
3734− memcg_oom_recover(mem);
3742+ mem_cgroup_end_move(memcg);
3743+ memcg_oom_recover(memcg);
37353744 /* it seems parent cgroup doesn't have enough mem */
37363745 if (ret == -ENOMEM)
37373746 goto try_to_free;
37383747 cond_resched();
37393748 /* "ret" should also be checked to ensure all lists are empty. */
3740− } while (mem->res.usage > 0 || ret);
3749+ } while (memcg->res.usage > 0 || ret);
37413750 out:
3742− css_put(&mem->css);
3751+ css_put(&memcg->css);
37433752 return ret;
37443753
37453754 try_to_free:
@@ -3752,14 +3761,14 @@ try_to_free: · 6 unmodified lines
37523761 lru_add_drain_all();
37533762 /* try to free all pages in this cgroup */
37543763 shrink = 1;
3755− while (nr_retries && mem->res.usage > 0) {
3764+ while (nr_retries && memcg->res.usage > 0) {
37563765 int progress;
37573766
37583767 if (signal_pending(current)) {
37593768 ret = -EINTR;
37603769 goto out;
37613770 }
3762− progress = try_to_free_mem_cgroup_pages(mem, GFP_KERNEL,
3771+ progress = try_to_free_mem_cgroup_pages(memcg, GFP_KERNEL,
37633772 false);
37643773 if (!progress) {
37653774 nr_retries--;
@@ -3788,12 +3797,12 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft, · 22 unmodified lines
37883797 u64 val)
37893798 {
37903799 int retval = 0;
3791− struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
3800+ struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
37923801 struct cgroup *parent = cont->parent;
3793− struct mem_cgroup *parent_mem = NULL;
3802+ struct mem_cgroup *parent_memcg = NULL;
37943803
37953804 if (parent)
3796− parent_mem = mem_cgroup_from_cont(parent);
3805+ parent_memcg = mem_cgroup_from_cont(parent);
37973806
37983807 cgroup_lock();
37993808 /*
@@ -3804,10 +3813,10 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft, · 4 unmodified lines
38043813 * For the root cgroup, parent_mem is NULL, we allow value to be
38053814 * set if there are no children.
38063815 */
3807− if ((!parent_mem || !parent_mem->use_hierarchy) &&
3816+ if ((!parent_memcg || !parent_memcg->use_hierarchy) &&
38083817 (val == 1 || val == 0)) {
38093818 if (list_empty(&cont->children))
3810− mem->use_hierarchy = val;
3819+ memcg->use_hierarchy = val;
38113820 else
38123821 retval = -EBUSY;
38133822 } else
@@ -3818,14 +3827,14 @@ static int mem_cgroup_hierarchy_write(struct cgroup *cont, struct cftype *cft, · 4 unmodified lines
38183827 }
38193828
38203829
3821−static unsigned long mem_cgroup_recursive_stat(struct mem_cgroup *mem,
3830+static unsigned long mem_cgroup_recursive_stat(struct mem_cgroup *memcg,
38223831 enum mem_cgroup_stat_index idx)
38233832 {
38243833 struct mem_cgroup *iter;
38253834 long val = 0;
38263835
38273836 /* Per-cpu values can be negative, use a signed accumulator */
3828− for_each_mem_cgroup_tree(iter, mem)
3837+ for_each_mem_cgroup_tree(iter, memcg)
38293838 val += mem_cgroup_read_stat(iter, idx);
38303839
38313840 if (val < 0) /* race ? */
@@ -3833,29 +3842,29 @@ static unsigned long mem_cgroup_recursive_stat(struct mem_cgroup *mem, · 1 unmodified line
38333842 return val;
38343843 }
38353844
3836−static inline u64 mem_cgroup_usage(struct mem_cgroup *mem, bool swap)
3845+static inline u64 mem_cgroup_usage(struct mem_cgroup *memcg, bool swap)
38373846 {
38383847 u64 val;
38393848
3840− if (!mem_cgroup_is_root(mem)) {
3849+ if (!mem_cgroup_is_root(memcg)) {
38413850 if (!swap)
3842− return res_counter_read_u64(&mem->res, RES_USAGE);
3851+ return res_counter_read_u64(&memcg->res, RES_USAGE);
38433852 else
3844− return res_counter_read_u64(&mem->memsw, RES_USAGE);
3853+ return res_counter_read_u64(&memcg->memsw, RES_USAGE);
38453854 }
38463855
3847− val = mem_cgroup_recursive_stat(mem, MEM_CGROUP_STAT_CACHE);
3848− val += mem_cgroup_recursive_stat(mem, MEM_CGROUP_STAT_RSS);
3856+ val = mem_cgroup_recursive_stat(memcg, MEM_CGROUP_STAT_CACHE);
3857+ val += mem_cgroup_recursive_stat(memcg, MEM_CGROUP_STAT_RSS);
38493858
38503859 if (swap)
3851− val += mem_cgroup_recursive_stat(mem, MEM_CGROUP_STAT_SWAPOUT);
3860+ val += mem_cgroup_recursive_stat(memcg, MEM_CGROUP_STAT_SWAPOUT);
38523861
38533862 return val << PAGE_SHIFT;
38543863 }
38553864
38563865 static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft)
38573866 {
3858− struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
3867+ struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
38593868 u64 val;
38603869 int type, name;
38613870
@@ -3864,15 +3873,15 @@ static u64 mem_cgroup_read(struct cgroup *cont, struct cftype *cft) · 2 unmodified lines
38643873 switch (type) {
38653874 case _MEM:
38663875 if (name == RES_USAGE)
3867− val = mem_cgroup_usage(mem, false);
3876+ val = mem_cgroup_usage(memcg, false);
38683877 else
3869− val = res_counter_read_u64(&mem->res, name);
3878+ val = res_counter_read_u64(&memcg->res, name);
38703879 break;
38713880 case _MEMSWAP:
38723881 if (name == RES_USAGE)
3873− val = mem_cgroup_usage(mem, true);
3882+ val = mem_cgroup_usage(memcg, true);
38743883 else
3875− val = res_counter_read_u64(&mem->memsw, name);
3884+ val = res_counter_read_u64(&memcg->memsw, name);
38763885 break;
38773886 default:
38783887 BUG();
@@ -3960,24 +3969,24 @@ out: · 81 unmodified lines
39603969
39613970 static int mem_cgroup_reset(struct cgroup *cont, unsigned int event)
39623971 {
3963− struct mem_cgroup *mem;
3972+ struct mem_cgroup *memcg;
39643973 int type, name;
39653974
3966− mem = mem_cgroup_from_cont(cont);
3975+ memcg = mem_cgroup_from_cont(cont);
39673976 type = MEMFILE_TYPE(event);
39683977 name = MEMFILE_ATTR(event);
39693978 switch (name) {
39703979 case RES_MAX_USAGE:
39713980 if (type == _MEM)
3972− res_counter_reset_max(&mem->res);
3981+ res_counter_reset_max(&memcg->res);
39733982 else
3974− res_counter_reset_max(&mem->memsw);
3983+ res_counter_reset_max(&memcg->memsw);
39753984 break;
39763985 case RES_FAILCNT:
39773986 if (type == _MEM)
3978− res_counter_reset_failcnt(&mem->res);
3987+ res_counter_reset_failcnt(&memcg->res);
39793988 else
3980− res_counter_reset_failcnt(&mem->memsw);
3989+ res_counter_reset_failcnt(&memcg->memsw);
39813990 break;
39823991 }
39833992
@@ -3994,7 +4003,7 @@ static u64 mem_cgroup_move_charge_read(struct cgroup *cgrp, · 10 unmodified lines
39944003 static int mem_cgroup_move_charge_write(struct cgroup *cgrp,
39954004 struct cftype *cft, u64 val)
39964005 {
3997− struct mem_cgroup *mem = mem_cgroup_from_cont(cgrp);
4006+ struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
39984007
39994008 if (val >= (1 << NR_MOVE_TYPE))
40004009 return -EINVAL;
@@ -4004,7 +4013,7 @@ static int mem_cgroup_move_charge_write(struct cgroup *cgrp, · 3 unmodified lines
40044013 * inconsistent.
40054014 */
40064015 cgroup_lock();
4007− mem->move_charge_at_immigrate = val;
4016+ memcg->move_charge_at_immigrate = val;
40084017 cgroup_unlock();
40094018
40104019 return 0;
@@ -4061,49 +4070,49 @@ struct { · 50 unmodified lines
40614070
40624071
40634072 static void
4064−mem_cgroup_get_local_stat(struct mem_cgroup *mem, struct mcs_total_stat *s)
4073+mem_cgroup_get_local_stat(struct mem_cgroup *memcg, struct mcs_total_stat *s)
40654074 {
40664075 s64 val;
40674076
40684077 /* per cpu stat */
4069− val = mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_CACHE);
4078+ val = mem_cgroup_read_stat(memcg, MEM_CGROUP_STAT_CACHE);
40704079 s->stat[MCS_CACHE] += val * PAGE_SIZE;
4071− val = mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_RSS);
4080+ val = mem_cgroup_read_stat(memcg, MEM_CGROUP_STAT_RSS);
40724081 s->stat[MCS_RSS] += val * PAGE_SIZE;
4073− val = mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_FILE_MAPPED);
4082+ val = mem_cgroup_read_stat(memcg, MEM_CGROUP_STAT_FILE_MAPPED);
40744083 s->stat[MCS_FILE_MAPPED] += val * PAGE_SIZE;
4075− val = mem_cgroup_read_events(mem, MEM_CGROUP_EVENTS_PGPGIN);
4084+ val = mem_cgroup_read_events(memcg, MEM_CGROUP_EVENTS_PGPGIN);
40764085 s->stat[MCS_PGPGIN] += val;
4077− val = mem_cgroup_read_events(mem, MEM_CGROUP_EVENTS_PGPGOUT);
4086+ val = mem_cgroup_read_events(memcg, MEM_CGROUP_EVENTS_PGPGOUT);
40784087 s->stat[MCS_PGPGOUT] += val;
40794088 if (do_swap_account) {
4080− val = mem_cgroup_read_stat(mem, MEM_CGROUP_STAT_SWAPOUT);
4089+ val = mem_cgroup_read_stat(memcg, MEM_CGROUP_STAT_SWAPOUT);
40814090 s->stat[MCS_SWAP] += val * PAGE_SIZE;
40824091 }
4083− val = mem_cgroup_read_events(mem, MEM_CGROUP_EVENTS_PGFAULT);
4092+ val = mem_cgroup_read_events(memcg, MEM_CGROUP_EVENTS_PGFAULT);
40844093 s->stat[MCS_PGFAULT] += val;
4085− val = mem_cgroup_read_events(mem, MEM_CGROUP_EVENTS_PGMAJFAULT);
4094+ val = mem_cgroup_read_events(memcg, MEM_CGROUP_EVENTS_PGMAJFAULT);
40864095 s->stat[MCS_PGMAJFAULT] += val;
40874096
40884097 /* per zone stat */
4089− val = mem_cgroup_nr_lru_pages(mem, BIT(LRU_INACTIVE_ANON));
4098+ val = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_INACTIVE_ANON));
40904099 s->stat[MCS_INACTIVE_ANON] += val * PAGE_SIZE;
4091− val = mem_cgroup_nr_lru_pages(mem, BIT(LRU_ACTIVE_ANON));
4100+ val = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_ACTIVE_ANON));
40924101 s->stat[MCS_ACTIVE_ANON] += val * PAGE_SIZE;
4093− val = mem_cgroup_nr_lru_pages(mem, BIT(LRU_INACTIVE_FILE));
4102+ val = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_INACTIVE_FILE));
40944103 s->stat[MCS_INACTIVE_FILE] += val * PAGE_SIZE;
4095− val = mem_cgroup_nr_lru_pages(mem, BIT(LRU_ACTIVE_FILE));
4104+ val = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_ACTIVE_FILE));
40964105 s->stat[MCS_ACTIVE_FILE] += val * PAGE_SIZE;
4097− val = mem_cgroup_nr_lru_pages(mem, BIT(LRU_UNEVICTABLE));
4106+ val = mem_cgroup_nr_lru_pages(memcg, BIT(LRU_UNEVICTABLE));
40984107 s->stat[MCS_UNEVICTABLE] += val * PAGE_SIZE;
40994108 }
41004109
41014110 static void
4102−mem_cgroup_get_total_stat(struct mem_cgroup *mem, struct mcs_total_stat *s)
4111+mem_cgroup_get_total_stat(struct mem_cgroup *memcg, struct mcs_total_stat *s)
41034112 {
41044113 struct mem_cgroup *iter;
41054114
4106− for_each_mem_cgroup_tree(iter, mem)
4115+ for_each_mem_cgroup_tree(iter, memcg)
41074116 mem_cgroup_get_local_stat(iter, s);
41084117 }
41094118
@@ -4189,8 +4198,6 @@ static int mem_control_stat_show(struct cgroup *cont, struct cftype *cft, · 79 unmodified lines
41894198 }
41904199
41914200 #ifdef CONFIG_DEBUG_VM
4192− cb->fill(cb, "inactive_ratio", calc_inactive_ratio(mem_cont, NULL));
4193−
41944201 {
41954202 int nid, zid;
41964203 struct mem_cgroup_per_zone *mz;
@@ -4327,20 +4334,20 @@ static int compare_thresholds(const void *a, const void *b) · 130 unmodified lines
43274334 return _a->threshold - _b->threshold;
43284335 }
43294336
4330−static int mem_cgroup_oom_notify_cb(struct mem_cgroup *mem)
4337+static int mem_cgroup_oom_notify_cb(struct mem_cgroup *memcg)
43314338 {
43324339 struct mem_cgroup_eventfd_list *ev;
43334340
4334− list_for_each_entry(ev, &mem->oom_notify, list)
4341+ list_for_each_entry(ev, &memcg->oom_notify, list)
43354342 eventfd_signal(ev->eventfd, 1);
43364343 return 0;
43374344 }
43384345
4339−static void mem_cgroup_oom_notify(struct mem_cgroup *mem)
4346+static void mem_cgroup_oom_notify(struct mem_cgroup *memcg)
43404347 {
43414348 struct mem_cgroup *iter;
43424349
4343− for_each_mem_cgroup_tree(iter, mem)
4350+ for_each_mem_cgroup_tree(iter, memcg)
43444351 mem_cgroup_oom_notify_cb(iter);
43454352 }
43464353
@@ -4530,7 +4537,7 @@ static int mem_cgroup_oom_register_event(struct cgroup *cgrp, · 183 unmodified lines
45304537 static void mem_cgroup_oom_unregister_event(struct cgroup *cgrp,
45314538 struct cftype *cft, struct eventfd_ctx *eventfd)
45324539 {
4533− struct mem_cgroup *mem = mem_cgroup_from_cont(cgrp);
4540+ struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
45344541 struct mem_cgroup_eventfd_list *ev, *tmp;
45354542 int type = MEMFILE_TYPE(cft->private);
45364543
@@ -4538,7 +4545,7 @@ static void mem_cgroup_oom_unregister_event(struct cgroup *cgrp, · 1 unmodified line
45384545
45394546 spin_lock(&memcg_oom_lock);
45404547
4541− list_for_each_entry_safe(ev, tmp, &mem->oom_notify, list) {
4548+ list_for_each_entry_safe(ev, tmp, &memcg->oom_notify, list) {
45424549 if (ev->eventfd == eventfd) {
45434550 list_del(&ev->list);
45444551 kfree(ev);
@@ -4551,11 +4558,11 @@ static void mem_cgroup_oom_unregister_event(struct cgroup *cgrp, · 6 unmodified lines
45514558 static int mem_cgroup_oom_control_read(struct cgroup *cgrp,
45524559 struct cftype *cft, struct cgroup_map_cb *cb)
45534560 {
4554− struct mem_cgroup *mem = mem_cgroup_from_cont(cgrp);
4561+ struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
45554562
4556− cb->fill(cb, "oom_kill_disable", mem->oom_kill_disable);
4563+ cb->fill(cb, "oom_kill_disable", memcg->oom_kill_disable);
45574564
4558− if (atomic_read(&mem->under_oom))
4565+ if (atomic_read(&memcg->under_oom))
45594566 cb->fill(cb, "under_oom", 1);
45604567 else
45614568 cb->fill(cb, "under_oom", 0);
@@ -4565,7 +4572,7 @@ static int mem_cgroup_oom_control_read(struct cgroup *cgrp, · 3 unmodified lines
45654572 static int mem_cgroup_oom_control_write(struct cgroup *cgrp,
45664573 struct cftype *cft, u64 val)
45674574 {
4568− struct mem_cgroup *mem = mem_cgroup_from_cont(cgrp);
4575+ struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
45694576 struct mem_cgroup *parent;
45704577
45714578 /* cannot set to root cgroup and only 0 and 1 are allowed */
@@ -4577,13 +4584,13 @@ static int mem_cgroup_oom_control_write(struct cgroup *cgrp, · 5 unmodified lines
45774584 cgroup_lock();
45784585 /* oom-kill-disable is a flag for subhierarchy. */
45794586 if ((parent->use_hierarchy) ||
4580− (mem->use_hierarchy && !list_empty(&cgrp->children))) {
4587+ (memcg->use_hierarchy && !list_empty(&cgrp->children))) {
45814588 cgroup_unlock();
45824589 return -EINVAL;
45834590 }
4584− mem->oom_kill_disable = val;
4591+ memcg->oom_kill_disable = val;
45854592 if (!val)
4586− memcg_oom_recover(mem);
4593+ memcg_oom_recover(memcg);
45874594 cgroup_unlock();
45884595 return 0;
45894596 }
@@ -4719,7 +4726,7 @@ static int register_memsw_files(struct cgroup *cont, struct cgroup_subsys *ss) · 129 unmodified lines
47194726 }
47204727 #endif
47214728
4722−static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node)
4729+static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *memcg, int node)
47234730 {
47244731 struct mem_cgroup_per_node *pn;
47254732 struct mem_cgroup_per_zone *mz;
@@ -4739,21 +4746,21 @@ static int alloc_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node) · 13 unmodified lines
47394746 if (!pn)
47404747 return 1;
47414748
4742− mem->info.nodeinfo[node] = pn;
47434749 for (zone = 0; zone < MAX_NR_ZONES; zone++) {
47444750 mz = &pn->zoneinfo[zone];
47454751 for_each_lru(l)
47464752 INIT_LIST_HEAD(&mz->lists[l]);
47474753 mz->usage_in_excess = 0;
47484754 mz->on_tree = false;
4749− mz->mem = mem;
4755+ mz->mem = memcg;
47504756 }
4757+ memcg->info.nodeinfo[node] = pn;
47514758 return 0;
47524759 }
47534760
4754−static void free_mem_cgroup_per_zone_info(struct mem_cgroup *mem, int node)
4761+static void free_mem_cgroup_per_zone_info(struct mem_cgroup *memcg, int node)
47554762 {
4756− kfree(mem->info.nodeinfo[node]);
4763+ kfree(memcg->info.nodeinfo[node]);
47574764 }
47584765
47594766 static struct mem_cgroup *mem_cgroup_alloc(void)
@@ -4795,51 +4802,51 @@ out_free: · 35 unmodified lines
47954802 * Removal of cgroup itself succeeds regardless of refs from swap.
47964803 */
47974804
4798−static void __mem_cgroup_free(struct mem_cgroup *mem)
4805+static void __mem_cgroup_free(struct mem_cgroup *memcg)
47994806 {
48004807 int node;
48014808
4802− mem_cgroup_remove_from_trees(mem);
4803− free_css_id(&mem_cgroup_subsys, &mem->css);
4809+ mem_cgroup_remove_from_trees(memcg);
4810+ free_css_id(&mem_cgroup_subsys, &memcg->css);
48044811
48054812 for_each_node_state(node, N_POSSIBLE)
4806− free_mem_cgroup_per_zone_info(mem, node);
4813+ free_mem_cgroup_per_zone_info(memcg, node);
48074814
4808− free_percpu(mem->stat);
4815+ free_percpu(memcg->stat);
48094816 if (sizeof(struct mem_cgroup) < PAGE_SIZE)
4810− kfree(mem);
4817+ kfree(memcg);
48114818 else
4812− vfree(mem);
4819+ vfree(memcg);
48134820 }
48144821
4815−static void mem_cgroup_get(struct mem_cgroup *mem)
4822+static void mem_cgroup_get(struct mem_cgroup *memcg)
48164823 {
4817− atomic_inc(&mem->refcnt);
4824+ atomic_inc(&memcg->refcnt);
48184825 }
48194826
4820−static void __mem_cgroup_put(struct mem_cgroup *mem, int count)
4827+static void __mem_cgroup_put(struct mem_cgroup *memcg, int count)
48214828 {
4822− if (atomic_sub_and_test(count, &mem->refcnt)) {
4823− struct mem_cgroup *parent = parent_mem_cgroup(mem);
4824− __mem_cgroup_free(mem);
4829+ if (atomic_sub_and_test(count, &memcg->refcnt)) {
4830+ struct mem_cgroup *parent = parent_mem_cgroup(memcg);
4831+ __mem_cgroup_free(memcg);
48254832 if (parent)
48264833 mem_cgroup_put(parent);
48274834 }
48284835 }
48294836
4830−static void mem_cgroup_put(struct mem_cgroup *mem)
4837+static void mem_cgroup_put(struct mem_cgroup *memcg)
48314838 {
4832− __mem_cgroup_put(mem, 1);
4839+ __mem_cgroup_put(memcg, 1);
48334840 }
48344841
48354842 /*
48364843 * Returns the parent mem_cgroup in memcgroup hierarchy with hierarchy enabled.
48374844 */
4838−static struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *mem)
4845+static struct mem_cgroup *parent_mem_cgroup(struct mem_cgroup *memcg)
48394846 {
4840− if (!mem->res.parent)
4847+ if (!memcg->res.parent)
48414848 return NULL;
4842− return mem_cgroup_from_res_counter(mem->res.parent, res);
4849+ return mem_cgroup_from_res_counter(memcg->res.parent, res);
48434850 }
48444851
48454852 #ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
@@ -4882,16 +4889,16 @@ static int mem_cgroup_soft_limit_tree_init(void) · 36 unmodified lines
48824889 static struct cgroup_subsys_state * __ref
48834890 mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont)
48844891 {
4885− struct mem_cgroup *mem, *parent;
4892+ struct mem_cgroup *memcg, *parent;
48864893 long error = -ENOMEM;
48874894 int node;
48884895
4889− mem = mem_cgroup_alloc();
4890− if (!mem)
4896+ memcg = mem_cgroup_alloc();
4897+ if (!memcg)
48914898 return ERR_PTR(error);
48924899
48934900 for_each_node_state(node, N_POSSIBLE)
4894− if (alloc_mem_cgroup_per_zone_info(mem, node))
4901+ if (alloc_mem_cgroup_per_zone_info(memcg, node))
48954902 goto free_out;
48964903
48974904 /* root ? */
@@ -4899,7 +4906,7 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont) · 1 unmodified line
48994906 int cpu;
49004907 enable_swap_cgroup();
49014908 parent = NULL;
4902− root_mem_cgroup = mem;
4909+ root_mem_cgroup = memcg;
49034910 if (mem_cgroup_soft_limit_tree_init())
49044911 goto free_out;
49054912 for_each_possible_cpu(cpu) {
@@ -4910,13 +4917,13 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont) · 4 unmodified lines
49104917 hotcpu_notifier(memcg_cpu_hotplug_callback, 0);
49114918 } else {
49124919 parent = mem_cgroup_from_cont(cont->parent);
4913− mem->use_hierarchy = parent->use_hierarchy;
4914− mem->oom_kill_disable = parent->oom_kill_disable;
4920+ memcg->use_hierarchy = parent->use_hierarchy;
4921+ memcg->oom_kill_disable = parent->oom_kill_disable;
49154922 }
49164923
49174924 if (parent && parent->use_hierarchy) {
4918− res_counter_init(&mem->res, &parent->res);
4919− res_counter_init(&mem->memsw, &parent->memsw);
4925+ res_counter_init(&memcg->res, &parent->res);
4926+ res_counter_init(&memcg->memsw, &parent->memsw);
49204927 /*
49214928 * We increment refcnt of the parent to ensure that we can
49224929 * safely access it on res_counter_charge/uncharge.
@@ -4925,21 +4932,21 @@ mem_cgroup_create(struct cgroup_subsys *ss, struct cgroup *cont) · 2 unmodified lines
49254932 */
49264933 mem_cgroup_get(parent);
49274934 } else {
4928− res_counter_init(&mem->res, NULL);
4929− res_counter_init(&mem->memsw, NULL);
4935+ res_counter_init(&memcg->res, NULL);
4936+ res_counter_init(&memcg->memsw, NULL);
49304937 }
4931− mem->last_scanned_child = 0;
4932− mem->last_scanned_node = MAX_NUMNODES;
4933− INIT_LIST_HEAD(&mem->oom_notify);
4938+ memcg->last_scanned_child = 0;
4939+ memcg->last_scanned_node = MAX_NUMNODES;
4940+ INIT_LIST_HEAD(&memcg->oom_notify);
49344941
49354942 if (parent)
4936− mem->swappiness = mem_cgroup_swappiness(parent);
4937− atomic_set(&mem->refcnt, 1);
4938− mem->move_charge_at_immigrate = 0;
4939− mutex_init(&mem->thresholds_lock);
4940− return &mem->css;
4943+ memcg->swappiness = mem_cgroup_swappiness(parent);
4944+ atomic_set(&memcg->refcnt, 1);
4945+ memcg->move_charge_at_immigrate = 0;
4946+ mutex_init(&memcg->thresholds_lock);
4947+ return &memcg->css;
49414948 free_out:
4942− __mem_cgroup_free(mem);
4949+ __mem_cgroup_free(memcg);
49434950 root_mem_cgroup = NULL;
49444951 return ERR_PTR(error);
49454952 }
@@ -4947,17 +4954,17 @@ free_out: · 1 unmodified line
49474954 static int mem_cgroup_pre_destroy(struct cgroup_subsys *ss,
49484955 struct cgroup *cont)
49494956 {
4950− struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
4957+ struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
49514958
4952− return mem_cgroup_force_empty(mem, false);
4959+ return mem_cgroup_force_empty(memcg, false);
49534960 }
49544961
49554962 static void mem_cgroup_destroy(struct cgroup_subsys *ss,
49564963 struct cgroup *cont)
49574964 {
4958− struct mem_cgroup *mem = mem_cgroup_from_cont(cont);
4965+ struct mem_cgroup *memcg = mem_cgroup_from_cont(cont);
49594966
4960− mem_cgroup_put(mem);
4967+ mem_cgroup_put(memcg);
49614968 }
49624969
49634970 static int mem_cgroup_populate(struct cgroup_subsys *ss,
@@ -4980,9 +4987,9 @@ static int mem_cgroup_do_precharge(unsigned long count) · 16 unmodified lines
49804987 {
49814988 int ret = 0;
49824989 int batch_count = PRECHARGE_COUNT_AT_ONCE;
4983− struct mem_cgroup *mem = mc.to;
4990+ struct mem_cgroup *memcg = mc.to;
49844991
4985− if (mem_cgroup_is_root(mem)) {
4992+ if (mem_cgroup_is_root(memcg)) {
49864993 mc.precharge += count;
49874994 /* we don't need css_get for root */
49884995 return ret;
@@ -4991,16 +4998,16 @@ static int mem_cgroup_do_precharge(unsigned long count) · 2 unmodified lines
49914998 if (count > 1) {
49924999 struct res_counter *dummy;
49935000 /*
4994− * "mem" cannot be under rmdir() because we've already checked
5001+ * "memcg" cannot be under rmdir() because we've already checked
49955002 * by cgroup_lock_live_cgroup() that it is not removed and we
49965003 * are still under the same cgroup_mutex. So we can postpone
49975004 * css_get().
49985005 */
4999− if (res_counter_charge(&mem->res, PAGE_SIZE * count, &dummy))
5006+ if (res_counter_charge(&memcg->res, PAGE_SIZE * count, &dummy))
50005007 goto one_by_one;
5001− if (do_swap_account && res_counter_charge(&mem->memsw,
5008+ if (do_swap_account && res_counter_charge(&memcg->memsw,
50025009 PAGE_SIZE * count, &dummy)) {
5003− res_counter_uncharge(&mem->res, PAGE_SIZE * count);
5010+ res_counter_uncharge(&memcg->res, PAGE_SIZE * count);
50045011 goto one_by_one;
50055012 }
50065013 mc.precharge += count;
@@ -5017,8 +5024,9 @@ one_by_one: · 10 unmodified lines
50175024 batch_count = PRECHARGE_COUNT_AT_ONCE;
50185025 cond_resched();
50195026 }
5020− ret = __mem_cgroup_try_charge(NULL, GFP_KERNEL, 1, &mem, false);
5021− if (ret || !mem)
5027+ ret = __mem_cgroup_try_charge(NULL,
5028+ GFP_KERNEL, 1, &memcg, false);
5029+ if (ret || !memcg)
50225030 /* mem_cgroup_clear_mc() will do uncharge later */
50235031 return -ENOMEM;
50245032 mc.precharge++;
@@ -5292,13 +5300,13 @@ static int mem_cgroup_can_attach(struct cgroup_subsys *ss, · 267 unmodified lines
52925300 struct task_struct *p)
52935301 {
52945302 int ret = 0;
5295− struct mem_cgroup *mem = mem_cgroup_from_cont(cgroup);
5303+ struct mem_cgroup *memcg = mem_cgroup_from_cont(cgroup);
52965304
5297− if (mem->move_charge_at_immigrate) {
5305+ if (memcg->move_charge_at_immigrate) {
52985306 struct mm_struct *mm;
52995307 struct mem_cgroup *from = mem_cgroup_from_task(p);
53005308
5301− VM_BUG_ON(from == mem);
5309+ VM_BUG_ON(from == memcg);
53025310
53035311 mm = get_task_mm(p);
53045312 if (!mm)
@@ -5313,7 +5321,7 @@ static int mem_cgroup_can_attach(struct cgroup_subsys *ss, · 8 unmodified lines
53135321 mem_cgroup_start_move(from);
53145322 spin_lock(&mc.lock);
53155323 mc.from = from;
5316− mc.to = mem;
5324+ mc.to = memcg;
53175325 spin_unlock(&mc.lock);
53185326 /* We set mc.moving_task later */
53195327
mm/memory.c+1−1
@@ -1503,7 +1503,7 @@ split_fallthrough: · 1502 unmodified lines
15031503 }
15041504
15051505 if (flags & FOLL_GET)
1506− get_page(page);
1506+ get_page_foll(page);
15071507 if (flags & FOLL_TOUCH) {
15081508 if ((flags & FOLL_WRITE) &&
15091509 !pte_dirty(pte) && !PageDirty(page))
mm/page_cgroup.c+6−3
@@ -133,10 +133,13 @@ struct page *lookup_cgroup_page(struct page_cgroup *pc) · 132 unmodified lines
133133 static void *__meminit alloc_page_cgroup(size_t size, int nid)
134134 {
135135 void *addr = NULL;
136+ gfp_t flags = GFP_KERNEL | __GFP_NOWARN;
136137
137− addr = alloc_pages_exact_nid(nid, size, GFP_KERNEL | __GFP_NOWARN);
138− if (addr)
138+ addr = alloc_pages_exact_nid(nid, size, flags);
139+ if (addr) {
140+ kmemleak_alloc(addr, size, 1, flags);
139141 return addr;
142+ }
140143
141144 if (node_state(nid, N_HIGH_MEMORY))
142145 addr = vmalloc_node(size, nid);
@@ -357,7 +360,7 @@ struct swap_cgroup_ctrl { · 214 unmodified lines
357360 spinlock_t lock;
358361 };
359362
360−struct swap_cgroup_ctrl swap_cgroup_ctrl[MAX_SWAPFILES];
363+static struct swap_cgroup_ctrl swap_cgroup_ctrl[MAX_SWAPFILES];
361364
362365 struct swap_cgroup {
363366 unsigned short id;
mm/swap.c+53−30
@@ -78,39 +78,22 @@ static void put_compound_page(struct page *page) · 77 unmodified lines
7878 {
7979 if (unlikely(PageTail(page))) {
8080 /* __split_huge_page_refcount can run under us */
81− struct page *page_head = page->first_page;
82− smp_rmb();
83− /*
84− * If PageTail is still set after smp_rmb() we can be sure
85− * that the page->first_page we read wasn't a dangling pointer.
86− * See __split_huge_page_refcount() smp_wmb().
87− */
88− if (likely(PageTail(page) && get_page_unless_zero(page_head))) {
81+ struct page *page_head = compound_trans_head(page);
82+
83+ if (likely(page != page_head &&
84+ get_page_unless_zero(page_head))) {
8985 unsigned long flags;
9086 /*
91− * Verify that our page_head wasn't converted
92− * to a a regular page before we got a
93− * reference on it.
87+ * page_head wasn't a dangling pointer but it
88+ * may not be a head page anymore by the time
89+ * we obtain the lock. That is ok as long as it
90+ * can't be freed from under us.
9491 */
95− if (unlikely(!PageHead(page_head))) {
96− /* PageHead is cleared after PageTail */
97− smp_rmb();
98− VM_BUG_ON(PageTail(page));
99− goto out_put_head;
100− }
101− /*
102− * Only run compound_lock on a valid PageHead,
103− * after having it pinned with
104− * get_page_unless_zero() above.
105− */
106− smp_mb();
107− /* page_head wasn't a dangling pointer */
10892 flags = compound_lock_irqsave(page_head);
10993 if (unlikely(!PageTail(page))) {
11094 /* __split_huge_page_refcount run before us */
11195 compound_unlock_irqrestore(page_head, flags);
11296 VM_BUG_ON(PageHead(page_head));
113− out_put_head:
11497 if (put_page_testzero(page_head))
11598 __put_single_page(page_head);
11699 out_put_single:
@@ -121,16 +104,17 @@ static void put_compound_page(struct page *page) · 4 unmodified lines
121104 VM_BUG_ON(page_head != page->first_page);
122105 /*
123106 * We can release the refcount taken by
124− * get_page_unless_zero now that
125− * split_huge_page_refcount is blocked on the
126− * compound_lock.
107+ * get_page_unless_zero() now that
108+ * __split_huge_page_refcount() is blocked on
109+ * the compound_lock.
127110 */
128111 if (put_page_testzero(page_head))
129112 VM_BUG_ON(1);
130113 /* __split_huge_page_refcount will wait now */
131− VM_BUG_ON(atomic_read(&page->_count) <= 0);
132− atomic_dec(&page->_count);
114+ VM_BUG_ON(page_mapcount(page) <= 0);
115+ atomic_dec(&page->_mapcount);
133116 VM_BUG_ON(atomic_read(&page_head->_count) <= 0);
117+ VM_BUG_ON(atomic_read(&page->_count) != 0);
134118 compound_unlock_irqrestore(page_head, flags);
135119 if (put_page_testzero(page_head)) {
136120 if (PageHead(page_head))
@@ -160,6 +144,45 @@ void put_page(struct page *page) · 23 unmodified lines
160144 }
161145 EXPORT_SYMBOL(put_page);
162146
147+/*
148+ * This function is exported but must not be called by anything other
149+ * than get_page(). It implements the slow path of get_page().
150+ */
151+bool __get_page_tail(struct page *page)
152+{
153+ /*
154+ * This takes care of get_page() if run on a tail page
155+ * returned by one of the get_user_pages/follow_page variants.
156+ * get_user_pages/follow_page itself doesn't need the compound
157+ * lock because it runs __get_page_tail_foll() under the
158+ * proper PT lock that already serializes against
159+ * split_huge_page().
160+ */
161+ unsigned long flags;
162+ bool got = false;
163+ struct page *page_head = compound_trans_head(page);
164+
165+ if (likely(page != page_head && get_page_unless_zero(page_head))) {
166+ /*
167+ * page_head wasn't a dangling pointer but it
168+ * may not be a head page anymore by the time
169+ * we obtain the lock. That is ok as long as it
170+ * can't be freed from under us.
171+ */
172+ flags = compound_lock_irqsave(page_head);
173+ /* here __split_huge_page_refcount won't run anymore */
174+ if (likely(PageTail(page))) {
175+ __get_page_tail_foll(page, false);
176+ got = true;
177+ }
178+ compound_unlock_irqrestore(page_head, flags);
179+ if (unlikely(!got))
180+ put_page(page_head);
181+ }
182+ return got;
183+}
184+EXPORT_SYMBOL(__get_page_tail);
185+
163186 /**
164187 * put_pages_list() - release a list of pages
165188 * @pages: list of pages threaded on page->lru
mm/vmscan.c+2−2
@@ -1767,7 +1767,7 @@ static int inactive_anon_is_low(struct zone *zone, struct scan_control *sc) · 1766 unmodified lines
17671767 if (scanning_global_lru(sc))
17681768 low = inactive_anon_is_low_global(zone);
17691769 else
1770− low = mem_cgroup_inactive_anon_is_low(sc->mem_cgroup);
1770+ low = mem_cgroup_inactive_anon_is_low(sc->mem_cgroup, zone);
17711771 return low;
17721772 }
17731773 #else
@@ -1810,7 +1810,7 @@ static int inactive_file_is_low(struct zone *zone, struct scan_control *sc) · 36 unmodified lines
18101810 if (scanning_global_lru(sc))
18111811 low = inactive_file_is_low_global(zone);
18121812 else
1813− low = mem_cgroup_inactive_file_is_low(sc->mem_cgroup);
1813+ low = mem_cgroup_inactive_file_is_low(sc->mem_cgroup, zone);
18141814 return low;
18151815 }
18161816

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t