aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/ABI/stable/sysfs-firmware-efi-vars75
-rw-r--r--Documentation/ABI/testing/sysfs-firmware-dmi110
-rw-r--r--Documentation/ABI/testing/sysfs-platform-kim48
-rw-r--r--Documentation/dynamic-debug-howto.txt12
-rw-r--r--Documentation/filesystems/sysfs.txt16
-rw-r--r--Documentation/kref.txt2
-rw-r--r--Documentation/memory-hotplug.txt47
-rw-r--r--Documentation/zh_CN/SecurityBugs50
-rw-r--r--Documentation/zh_CN/SubmitChecklist109
-rw-r--r--Documentation/zh_CN/SubmittingPatches4
-rw-r--r--Documentation/zh_CN/magic-number.txt167
-rw-r--r--arch/powerpc/platforms/pseries/hotplug-memory.c66
-rw-r--r--arch/x86/mm/init_64.c14
-rw-r--r--drivers/base/core.c34
-rw-r--r--drivers/base/firmware_class.c7
-rw-r--r--drivers/base/memory.c197
-rw-r--r--drivers/base/node.c12
-rw-r--r--drivers/base/sys.c65
-rw-r--r--drivers/firmware/Kconfig11
-rw-r--r--drivers/firmware/Makefile1
-rw-r--r--drivers/firmware/dmi-sysfs.c696
-rw-r--r--drivers/firmware/efivars.c343
-rw-r--r--drivers/misc/Kconfig7
-rw-r--r--drivers/misc/pch_phub.c69
-rw-r--r--drivers/misc/ti-st/st_core.c419
-rw-r--r--drivers/misc/ti-st/st_kim.c491
-rw-r--r--drivers/misc/ti-st/st_ll.c10
-rw-r--r--drivers/uio/Kconfig17
-rw-r--r--drivers/uio/Makefile1
-rw-r--r--drivers/uio/uio_pruss.c247
-rw-r--r--fs/debugfs/inode.c26
-rw-r--r--include/linux/dmi.h47
-rw-r--r--include/linux/dynamic_debug.h8
-rw-r--r--include/linux/efi.h37
-rw-r--r--include/linux/firmware.h4
-rw-r--r--include/linux/kobject.h10
-rw-r--r--include/linux/memory.h3
-rw-r--r--include/linux/node.h6
-rw-r--r--include/linux/platform_data/uio_pruss.h25
-rw-r--r--include/linux/platform_device.h11
-rw-r--r--include/linux/ti_wilink_st.h76
-rw-r--r--init/Kconfig4
-rw-r--r--kernel/printk.c138
-rw-r--r--lib/dynamic_debug.c61
44 files changed, 2890 insertions, 913 deletions
diff --git a/Documentation/ABI/stable/sysfs-firmware-efi-vars b/Documentation/ABI/stable/sysfs-firmware-efi-vars
new file mode 100644
index 000000000000..5def20b9019e
--- /dev/null
+++ b/Documentation/ABI/stable/sysfs-firmware-efi-vars
@@ -0,0 +1,75 @@
1What: /sys/firmware/efi/vars
2Date: April 2004
3Contact: Matt Domsch <Matt_Domsch@dell.com>
4Description:
5 This directory exposes interfaces for interactive with
6 EFI variables. For more information on EFI variables,
7 see 'Variable Services' in the UEFI specification
8 (section 7.2 in specification version 2.3 Errata D).
9
10 In summary, EFI variables are named, and are classified
11 into separate namespaces through the use of a vendor
12 GUID. They also have an arbitrary binary value
13 associated with them.
14
15 The efivars module enumerates these variables and
16 creates a separate directory for each one found. Each
17 directory has a name of the form "<key>-<vendor guid>"
18 and contains the following files:
19
20 attributes: A read-only text file enumerating the
21 EFI variable flags. Potential values
22 include:
23
24 EFI_VARIABLE_NON_VOLATILE
25 EFI_VARIABLE_BOOTSERVICE_ACCESS
26 EFI_VARIABLE_RUNTIME_ACCESS
27 EFI_VARIABLE_HARDWARE_ERROR_RECORD
28 EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS
29
30 See the EFI documentation for an
31 explanation of each of these variables.
32
33 data: A read-only binary file that can be read
34 to attain the value of the EFI variable
35
36 guid: The vendor GUID of the variable. This
37 should always match the GUID in the
38 variable's name.
39
40 raw_var: A binary file that can be read to obtain
41 a structure that contains everything
42 there is to know about the variable.
43 For structure definition see "struct
44 efi_variable" in the kernel sources.
45
46 This file can also be written to in
47 order to update the value of a variable.
48 For this to work however, all fields of
49 the "struct efi_variable" passed must
50 match byte for byte with the structure
51 read out of the file, save for the value
52 portion.
53
54 **Note** the efi_variable structure
55 read/written with this file contains a
56 'long' type that may change widths
57 depending on your underlying
58 architecture.
59
60 size: As ASCII representation of the size of
61 the variable's value.
62
63
64 In addition, two other magic binary files are provided
65 in the top-level directory and are used for adding and
66 removing variables:
67
68 new_var: Takes a "struct efi_variable" and
69 instructs the EFI firmware to create a
70 new variable.
71
72 del_var: Takes a "struct efi_variable" and
73 instructs the EFI firmware to remove any
74 variable that has a matching vendor GUID
75 and variable key name.
diff --git a/Documentation/ABI/testing/sysfs-firmware-dmi b/Documentation/ABI/testing/sysfs-firmware-dmi
new file mode 100644
index 000000000000..ba9da9503c23
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-firmware-dmi
@@ -0,0 +1,110 @@
1What: /sys/firmware/dmi/
2Date: February 2011
3Contact: Mike Waychison <mikew@google.com>
4Description:
5 Many machines' firmware (x86 and ia64) export DMI /
6 SMBIOS tables to the operating system. Getting at this
7 information is often valuable to userland, especially in
8 cases where there are OEM extensions used.
9
10 The kernel itself does not rely on the majority of the
11 information in these tables being correct. It equally
12 cannot ensure that the data as exported to userland is
13 without error either.
14
15 DMI is structured as a large table of entries, where
16 each entry has a common header indicating the type and
17 length of the entry, as well as 'handle' that is
18 supposed to be unique amongst all entries.
19
20 Some entries are required by the specification, but many
21 others are optional. In general though, users should
22 never expect to find a specific entry type on their
23 system unless they know for certain what their firmware
24 is doing. Machine to machine will vary.
25
26 Multiple entries of the same type are allowed. In order
27 to handle these duplicate entry types, each entry is
28 assigned by the operating system an 'instance', which is
29 derived from an entry type's ordinal position. That is
30 to say, if there are 'N' multiple entries with the same type
31 'T' in the DMI tables (adjacent or spread apart, it
32 doesn't matter), they will be represented in sysfs as
33 entries "T-0" through "T-(N-1)":
34
35 Example entry directories:
36
37 /sys/firmware/dmi/entries/17-0
38 /sys/firmware/dmi/entries/17-1
39 /sys/firmware/dmi/entries/17-2
40 /sys/firmware/dmi/entries/17-3
41 ...
42
43 Instance numbers are used in lieu of the firmware
44 assigned entry handles as the kernel itself makes no
45 guarantees that handles as exported are unique, and
46 there are likely firmware images that get this wrong in
47 the wild.
48
49 Each DMI entry in sysfs has the common header values
50 exported as attributes:
51
52 handle : The 16bit 'handle' that is assigned to this
53 entry by the firmware. This handle may be
54 referred to by other entries.
55 length : The length of the entry, as presented in the
56 entry itself. Note that this is _not the
57 total count of bytes associated with the
58 entry_. This value represents the length of
59 the "formatted" portion of the entry. This
60 "formatted" region is sometimes followed by
61 the "unformatted" region composed of nul
62 terminated strings, with termination signalled
63 by a two nul characters in series.
64 raw : The raw bytes of the entry. This includes the
65 "formatted" portion of the entry, the
66 "unformatted" strings portion of the entry,
67 and the two terminating nul characters.
68 type : The type of the entry. This value is the same
69 as found in the directory name. It indicates
70 how the rest of the entry should be
71 interpreted.
72 instance: The instance ordinal of the entry for the
73 given type. This value is the same as found
74 in the parent directory name.
75 position: The position of the entry within the entirety
76 of the entirety.
77
78 === Entry Specialization ===
79
80 Some entry types may have other information available in
81 sysfs.
82
83 --- Type 15 - System Event Log ---
84
85 This entry allows the firmware to export a log of
86 events the system has taken. This information is
87 typically backed by nvram, but the implementation
88 details are abstracted by this table. This entries data
89 is exported in the directory:
90
91 /sys/firmware/dmi/entries/15-0/system_event_log
92
93 and has the following attributes (documented in the
94 SMBIOS / DMI specification under "System Event Log (Type 15)":
95
96 area_length
97 header_start_offset
98 data_start_offset
99 access_method
100 status
101 change_token
102 access_method_address
103 header_format
104 per_log_type_descriptor_length
105 type_descriptors_supported_count
106
107 As well, the kernel exports the binary attribute:
108
109 raw_event_log : The raw binary bits of the event log
110 as described by the DMI entry.
diff --git a/Documentation/ABI/testing/sysfs-platform-kim b/Documentation/ABI/testing/sysfs-platform-kim
new file mode 100644
index 000000000000..c1653271872a
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-kim
@@ -0,0 +1,48 @@
1What: /sys/devices/platform/kim/dev_name
2Date: January 2010
3KernelVersion: 2.6.38
4Contact: "Pavan Savoy" <pavan_savoy@ti.com>
5Description:
6 Name of the UART device at which the WL128x chip
7 is connected. example: "/dev/ttyS0".
8 The device name flows down to architecture specific board
9 initialization file from the SFI/ATAGS bootloader
10 firmware. The name exposed is read from the user-space
11 dameon and opens the device when install is requested.
12
13What: /sys/devices/platform/kim/baud_rate
14Date: January 2010
15KernelVersion: 2.6.38
16Contact: "Pavan Savoy" <pavan_savoy@ti.com>
17Description:
18 The maximum reliable baud-rate the host can support.
19 Different platforms tend to have different high-speed
20 UART configurations, so the baud-rate needs to be set
21 locally and also sent across to the WL128x via a HCI-VS
22 command. The entry is read and made use by the user-space
23 daemon when the ldisc install is requested.
24
25What: /sys/devices/platform/kim/flow_cntrl
26Date: January 2010
27KernelVersion: 2.6.38
28Contact: "Pavan Savoy" <pavan_savoy@ti.com>
29Description:
30 The WL128x makes use of flow control mechanism, and this
31 entry most often should be 1, the host's UART is required
32 to have the capability of flow-control, or else this
33 entry can be made use of for exceptions.
34
35What: /sys/devices/platform/kim/install
36Date: January 2010
37KernelVersion: 2.6.38
38Contact: "Pavan Savoy" <pavan_savoy@ti.com>
39Description:
40 When one of the protocols Bluetooth, FM or GPS wants to make
41 use of the shared UART transport, it registers to the shared
42 transport driver, which will signal the user-space for opening,
43 configuring baud and install line discipline via this sysfs
44 entry. This entry would be polled upon by the user-space
45 daemon managing the UART, and is notified about the change
46 by the sysfs_notify. The value would be '1' when UART needs
47 to be opened/ldisc installed, and would be '0' when UART
48 is no more required and needs to be closed.
diff --git a/Documentation/dynamic-debug-howto.txt b/Documentation/dynamic-debug-howto.txt
index 58ea64a96165..e6c4b757025b 100644
--- a/Documentation/dynamic-debug-howto.txt
+++ b/Documentation/dynamic-debug-howto.txt
@@ -205,12 +205,20 @@ of the characters:
205 205
206The flags are: 206The flags are:
207 207
208f
209 Include the function name in the printed message
210l
211 Include line number in the printed message
212m
213 Include module name in the printed message
208p 214p
209 Causes a printk() message to be emitted to dmesg 215 Causes a printk() message to be emitted to dmesg
216t
217 Include thread ID in messages not generated from interrupt context
210 218
211Note the regexp ^[-+=][scp]+$ matches a flags specification. 219Note the regexp ^[-+=][flmpt]+$ matches a flags specification.
212Note also that there is no convenient syntax to remove all 220Note also that there is no convenient syntax to remove all
213the flags at once, you need to use "-psc". 221the flags at once, you need to use "-flmpt".
214 222
215 223
216Debug messages during boot process 224Debug messages during boot process
diff --git a/Documentation/filesystems/sysfs.txt b/Documentation/filesystems/sysfs.txt
index 5d1335faec2d..f806e50aaa63 100644
--- a/Documentation/filesystems/sysfs.txt
+++ b/Documentation/filesystems/sysfs.txt
@@ -39,10 +39,12 @@ userspace. Top-level directories in sysfs represent the common
39ancestors of object hierarchies; i.e. the subsystems the objects 39ancestors of object hierarchies; i.e. the subsystems the objects
40belong to. 40belong to.
41 41
42Sysfs internally stores the kobject that owns the directory in the 42Sysfs internally stores a pointer to the kobject that implements a
43->d_fsdata pointer of the directory's dentry. This allows sysfs to do 43directory in the sysfs_dirent object associated with the directory. In
44reference counting directly on the kobject when the file is opened and 44the past this kobject pointer has been used by sysfs to do reference
45closed. 45counting directly on the kobject whenever the file is opened or closed.
46With the current sysfs implementation the kobject reference count is
47only modified directly by the function sysfs_schedule_callback().
46 48
47 49
48Attributes 50Attributes
@@ -208,9 +210,9 @@ Other notes:
208 is 4096. 210 is 4096.
209 211
210- show() methods should return the number of bytes printed into the 212- show() methods should return the number of bytes printed into the
211 buffer. This is the return value of snprintf(). 213 buffer. This is the return value of scnprintf().
212 214
213- show() should always use snprintf(). 215- show() should always use scnprintf().
214 216
215- store() should return the number of bytes used from the buffer. If the 217- store() should return the number of bytes used from the buffer. If the
216 entire buffer has been used, just return the count argument. 218 entire buffer has been used, just return the count argument.
@@ -229,7 +231,7 @@ A very simple (and naive) implementation of a device attribute is:
229static ssize_t show_name(struct device *dev, struct device_attribute *attr, 231static ssize_t show_name(struct device *dev, struct device_attribute *attr,
230 char *buf) 232 char *buf)
231{ 233{
232 return snprintf(buf, PAGE_SIZE, "%s\n", dev->name); 234 return scnprintf(buf, PAGE_SIZE, "%s\n", dev->name);
233} 235}
234 236
235static ssize_t store_name(struct device *dev, struct device_attribute *attr, 237static ssize_t store_name(struct device *dev, struct device_attribute *attr,
diff --git a/Documentation/kref.txt b/Documentation/kref.txt
index ae203f91ee9b..48ba715d5a63 100644
--- a/Documentation/kref.txt
+++ b/Documentation/kref.txt
@@ -156,7 +156,7 @@ static struct my_data *get_entry()
156 struct my_data *entry = NULL; 156 struct my_data *entry = NULL;
157 mutex_lock(&mutex); 157 mutex_lock(&mutex);
158 if (!list_empty(&q)) { 158 if (!list_empty(&q)) {
159 entry = container_of(q.next, struct my_q_entry, link); 159 entry = container_of(q.next, struct my_data, link);
160 kref_get(&entry->refcount); 160 kref_get(&entry->refcount);
161 } 161 }
162 mutex_unlock(&mutex); 162 mutex_unlock(&mutex);
diff --git a/Documentation/memory-hotplug.txt b/Documentation/memory-hotplug.txt
index 57e7e9cc1870..8f485d72cf25 100644
--- a/Documentation/memory-hotplug.txt
+++ b/Documentation/memory-hotplug.txt
@@ -126,36 +126,51 @@ config options.
126-------------------------------- 126--------------------------------
1274 sysfs files for memory hotplug 1274 sysfs files for memory hotplug
128-------------------------------- 128--------------------------------
129All sections have their device information under /sys/devices/system/memory as 129All sections have their device information in sysfs. Each section is part of
130a memory block under /sys/devices/system/memory as
130 131
131/sys/devices/system/memory/memoryXXX 132/sys/devices/system/memory/memoryXXX
132(XXX is section id.) 133(XXX is the section id.)
133 134
134Now, XXX is defined as start_address_of_section / section_size. 135Now, XXX is defined as (start_address_of_section / section_size) of the first
136section contained in the memory block. The files 'phys_index' and
137'end_phys_index' under each directory report the beginning and end section id's
138for the memory block covered by the sysfs directory. It is expected that all
139memory sections in this range are present and no memory holes exist in the
140range. Currently there is no way to determine if there is a memory hole, but
141the existence of one should not affect the hotplug capabilities of the memory
142block.
135 143
136For example, assume 1GiB section size. A device for a memory starting at 144For example, assume 1GiB section size. A device for a memory starting at
1370x100000000 is /sys/device/system/memory/memory4 1450x100000000 is /sys/device/system/memory/memory4
138(0x100000000 / 1Gib = 4) 146(0x100000000 / 1Gib = 4)
139This device covers address range [0x100000000 ... 0x140000000) 147This device covers address range [0x100000000 ... 0x140000000)
140 148
141Under each section, you can see 4 files. 149Under each section, you can see 4 or 5 files, the end_phys_index file being
150a recent addition and not present on older kernels.
142 151
143/sys/devices/system/memory/memoryXXX/phys_index 152/sys/devices/system/memory/memoryXXX/start_phys_index
153/sys/devices/system/memory/memoryXXX/end_phys_index
144/sys/devices/system/memory/memoryXXX/phys_device 154/sys/devices/system/memory/memoryXXX/phys_device
145/sys/devices/system/memory/memoryXXX/state 155/sys/devices/system/memory/memoryXXX/state
146/sys/devices/system/memory/memoryXXX/removable 156/sys/devices/system/memory/memoryXXX/removable
147 157
148'phys_index' : read-only and contains section id, same as XXX. 158'phys_index' : read-only and contains section id of the first section
149'state' : read-write 159 in the memory block, same as XXX.
150 at read: contains online/offline state of memory. 160'end_phys_index' : read-only and contains section id of the last section
151 at write: user can specify "online", "offline" command 161 in the memory block.
152'phys_device': read-only: designed to show the name of physical memory device. 162'state' : read-write
153 This is not well implemented now. 163 at read: contains online/offline state of memory.
154'removable' : read-only: contains an integer value indicating 164 at write: user can specify "online", "offline" command
155 whether the memory section is removable or not 165 which will be performed on al sections in the block.
156 removable. A value of 1 indicates that the memory 166'phys_device' : read-only: designed to show the name of physical memory
157 section is removable and a value of 0 indicates that 167 device. This is not well implemented now.
158 it is not removable. 168'removable' : read-only: contains an integer value indicating
169 whether the memory block is removable or not
170 removable. A value of 1 indicates that the memory
171 block is removable and a value of 0 indicates that
172 it is not removable. A memory block is removable only if
173 every section in the block is removable.
159 174
160NOTE: 175NOTE:
161 These directories/files appear after physical memory hotplug phase. 176 These directories/files appear after physical memory hotplug phase.
diff --git a/Documentation/zh_CN/SecurityBugs b/Documentation/zh_CN/SecurityBugs
new file mode 100644
index 000000000000..d21eb07fe943
--- /dev/null
+++ b/Documentation/zh_CN/SecurityBugs
@@ -0,0 +1,50 @@
1Chinese translated version of Documentation/SecurityBugs
2
3If you have any comment or update to the content, please contact the
4original document maintainer directly. However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for
6help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation.
8
9Chinese maintainer: Harry Wei <harryxiyou@gmail.com>
10---------------------------------------------------------------------
11Documentation/SecurityBugs 的中文翻译
12
13如果想评论或更新本文的内容,请直接è”系原文档的维护者。如果你使用英文
14交æµæœ‰å›°éš¾çš„è¯ï¼Œä¹Ÿå¯ä»¥å‘中文版维护者求助。如果本翻译更新ä¸åŠæ—¶æˆ–者翻
15译存在问题,请è”系中文版维护者。
16
17中文版维护者: è´¾å¨å¨ Harry Wei <harryxiyou@gmail.com>
18中文版翻译者: è´¾å¨å¨ Harry Wei <harryxiyou@gmail.com>
19中文版校译者: è´¾å¨å¨ Harry Wei <harryxiyou@gmail.com>
20
21
22以下为正文
23---------------------------------------------------------------------
24Linux内核开å‘者认为安全éžå¸¸é‡è¦ã€‚因此,我们想è¦çŸ¥é“当一个有关于
25安全的æ¼æ´žè¢«å‘现的时候,并且它å¯èƒ½ä¼šè¢«å°½å¿«çš„ä¿®å¤æˆ–者公开。请把这个安全
26æ¼æ´žæŠ¥å‘Šç»™Linux内核安全团队。
27
281) è”ç³»
29
30linux内核安全团队å¯ä»¥é€šè¿‡email<security@kernel.org>æ¥è”系。这是
31一组独立的安全工作人员,å¯ä»¥å¸®åŠ©æ”¹å–„æ¼æ´žæŠ¥å‘Šå¹¶ä¸”公布和å–消一个修å¤ã€‚安
32全团队有å¯èƒ½ä¼šä»Žéƒ¨åˆ†çš„维护者那里引进é¢å¤–的帮助æ¥äº†è§£å¹¶ä¸”ä¿®å¤å®‰å…¨æ¼æ´žã€‚
33当é‡åˆ°ä»»ä½•æ¼æ´žï¼Œæ‰€èƒ½æ供的信æ¯è¶Šå¤šå°±è¶Šèƒ½è¯Šæ–­å’Œä¿®å¤ã€‚如果你ä¸æ¸…楚什么
34是有帮助的信æ¯ï¼Œé‚£å°±è¯·é‡æ¸©ä¸€ä¸‹REPORTING-BUGS文件中的概述过程。任
35何攻击性的代ç éƒ½æ˜¯éžå¸¸æœ‰ç”¨çš„,未ç»æŠ¥å‘Šè€…çš„åŒæ„ä¸ä¼šè¢«å–消,除éžå®ƒå·²ç»
36被公布于众。
37
382) 公开
39
40Linux内核安全团队的宗旨就是和æ¼æ´žæ交者一起处ç†æ¼æ´žçš„解决方案直
41到公开。我们喜欢尽快地完全公开æ¼æ´žã€‚当一个æ¼æ´žæˆ–者修å¤è¿˜æ²¡æœ‰è¢«å®Œå…¨åœ°ç†
42解,解决方案没有通过测试或者供应商å调,å¯ä»¥åˆç†åœ°å»¶è¿Ÿå…¬å¼€ã€‚然而,我们
43期望这些延迟尽å¯èƒ½çš„短些,是å¯æ•°çš„几天,而ä¸æ˜¯å‡ ä¸ªæ˜ŸæœŸæˆ–者几个月。公开
44日期是通过安全团队和æ¼æ´žæ供者以åŠä¾›åº”商洽谈åŽçš„结果。公开时间表是从很
45短(特殊的,它已ç»è¢«å…¬ä¼—所知é“)到几个星期。作为一个基本的默认政策,我
46们所期望通知公众的日期是7天的安排。
47
483) ä¿å¯†åè®®
49
50Linux内核安全团队ä¸æ˜¯ä¸€ä¸ªæ­£å¼çš„团体,因此ä¸èƒ½åŠ å…¥ä»»ä½•çš„ä¿å¯†å议。
diff --git a/Documentation/zh_CN/SubmitChecklist b/Documentation/zh_CN/SubmitChecklist
new file mode 100644
index 000000000000..951415bbab0c
--- /dev/null
+++ b/Documentation/zh_CN/SubmitChecklist
@@ -0,0 +1,109 @@
1Chinese translated version of Documentation/SubmitChecklist
2
3If you have any comment or update to the content, please contact the
4original document maintainer directly. However, if you have a problem
5communicating in English you can also ask the Chinese maintainer for
6help. Contact the Chinese maintainer if this translation is outdated
7or if there is a problem with the translation.
8
9Chinese maintainer: Harry Wei <harryxiyou@gmail.com>
10---------------------------------------------------------------------
11Documentation/SubmitChecklist µÄÖÐÎÄ·­Òë
12
13Èç¹ûÏëÆÀÂÛ»ò¸üб¾ÎĵÄÄÚÈÝ£¬ÇëÖ±½ÓÁªÏµÔ­ÎĵµµÄά»¤Õß¡£Èç¹ûÄãʹÓÃÓ¢ÎÄ
14½»Á÷ÓÐÀ§ÄѵĻ°£¬Ò²¿ÉÒÔÏòÖÐÎÄ°æά»¤ÕßÇóÖú¡£Èç¹û±¾·­Òë¸üв»¼°Ê±»òÕß·­
15Òë´æÔÚÎÊÌ⣬ÇëÁªÏµÖÐÎÄ°æά»¤Õß¡£
16
17ÖÐÎÄ°æά»¤Õߣº ¼ÖÍþÍþ Harry Wei <harryxiyou@gmail.com>
18ÖÐÎÄ°æ·­ÒëÕߣº ¼ÖÍþÍþ Harry Wei <harryxiyou@gmail.com>
19ÖÐÎÄ°æУÒëÕߣº ¼ÖÍþÍþ Harry Wei <harryxiyou@gmail.com>
20
21
22ÒÔÏÂΪÕýÎÄ
23---------------------------------------------------------------------
24LinuxÄÚºËÌá½»Çåµ¥
25~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26
27ÕâÀïÓÐһЩÄں˿ª·¢ÕßÓ¦¸Ã×öµÄ»ù±¾ÊÂÇ飬Èç¹ûËûÃÇÏë¿´µ½×Ô¼ºµÄÄں˲¹¶¡Ìá½»
28±»½ÓÊܵĸü¿ì¡£
29
30ÕâЩ¶¼Êdz¬³öDocumentation/SubmittingPatchesÎĵµÀïËùÌṩµÄÒÔ¼°ÆäËû
31¹ØÓÚÌá½»LinuxÄں˲¹¶¡µÄ˵Ã÷¡£
32
331£ºÈç¹ûÄãʹÓÃÁËÒ»¸ö¹¦ÄÜÄÇô¾Í#include¶¨Òå/ÉùÃ÷ÄǸö¹¦ÄܵÄÄǸöÎļþ¡£
34 ²»ÒªÒÀ¿¿ÆäËû¼ä½ÓÒýÈ붨Òå/ÉùÃ÷ÄǸö¹¦ÄܵÄÍ·Îļþ¡£
35
362£º¹¹½¨¼ò½àÊÊÓûòÕ߸ü¸ÄCONFIGÑ¡Ïî =y£¬=m£¬»òÕß=n¡£
37 ²»ÒªÓбàÒ뾯¸æ/´íÎó£¬ ²»ÒªÓÐÁ´½Ó¾¯¸æ/´íÎó¡£
38
392b£ºÍ¨¹ý allnoconfig, allmodconfig
40
412c£ºµ±Ê¹Óà 0=builddir ³É¹¦µØ¹¹½¨
42
433£ºÍ¨¹ýʹÓñ¾µØ½»²æ±àÒ빤¾ß»òÕßÆäËûһЩ¹¹½¨²úËù£¬ÔÚ¶àCPU¿ò¼ÜÉϹ¹½¨¡£
44
454£ºppc64 ÊÇÒ»¸öºÜºÃµÄ¼ì²é½»²æ±àÒëµÄ¿ò¼Ü£¬ÒòΪËüÍùÍù°Ñ¡®unsigned long¡¯
46 µ±64λֵÀ´Ê¹Óá£
47
485£º°´ÕÕDocumentation/CodingStyleÎļþÀïµÄÏêϸÃèÊö£¬¼ì²éÄã²¹¶¡µÄÕûÌå·ç¸ñ¡£
49 ʹÓò¹¶¡·ç¸ñ¼ì²éËöËéµÄÎ¥¹æ(scripts/checkpatch.pl)£¬ÉóºËÔ±ÓÅÏÈÌá½»¡£
50 ÄãÓ¦¸Ãµ÷ÕûÒÅÁôÔÚÄã²¹¶¡ÖеÄËùÓÐÎ¥¹æ¡£
51
526£ºÈκθüлòÕ߸Ķ¯CONFIGÑ¡Ï²»ÄÜ´òÂÒÅäÖò˵¥¡£
53
547£ºËùÓеÄKconfigÑ¡Ïî¸üж¼ÒªÓÐ˵Ã÷ÎÄ×Ö¡£
55
568£ºÒѾ­ÈÏÕæµØ×ܽáÁËÏà¹ØµÄKconfig×éºÏ¡£ÕâÊǺÜÄÑͨ¹ý²âÊÔ×öºÃµÄ--ÄÔÁ¦ÔÚÕâÀïϽµ¡£
57
589£º¼ì²é¾ßÓмò½àÐÔ¡£
59
6010£ºÊ¹ÓÃ'make checkstack'ºÍ'make namespacecheck'¼ì²é£¬È»ºóÐÞ¸ÄËùÕÒµ½µÄÎÊÌâ¡£
61 ×¢Ò⣺¶ÑÕ»¼ì²é²»»áÃ÷È·µØ³öÏÖÎÊÌ⣬µ«ÊÇÈκεÄÒ»¸öº¯ÊýÔÚ¶ÑÕ»ÉÏʹÓöàÓÚ512×Ö½Ú
62 ¶¼Òª×¼±¸Ð޸ġ£
63
6411£º°üº¬kernel-docµ½È«¾ÖÄÚºËAPIsÎļþ¡££¨²»ÒªÇó¾²Ì¬µÄº¯Êý£¬µ«ÊÇ°üº¬Ò²ÎÞËùν¡££©
65 ʹÓÃ'make htmldocs'»òÕß'make mandocs'À´¼ì²ékernel-doc£¬È»ºóÐÞ¸ÄÈκÎ
66 ·¢ÏÖµÄÎÊÌâ¡£
67
6812£ºÒѾ­Í¨¹ýCONFIG_PREEMPT, CONFIG_DEBUG_PREEMPT,
69 CONFIG_DEBUG_SLAB, CONFIG_DEBUG_PAGEALLOC, CONFIG_DEBUG_MUTEXES,
70 CONFIG_DEBUG_SPINLOCK, CONFIG_DEBUG_SPINLOCK_SLEEP²âÊÔ£¬²¢ÇÒͬʱ¶¼
71 ʹÄÜ¡£
72
7313£ºÒѾ­¶¼¹¹½¨²¢ÇÒʹÓûòÕß²»Ê¹Óà CONFIG_SMP ºÍ CONFIG_PREEMPT²âÊÔÖ´ÐÐʱ¼ä¡£
74
7514£ºÈç¹û²¹¶¡Ó°ÏìIO/Disk£¬µÈµÈ£ºÒѾ­Í¨¹ýʹÓûòÕß²»Ê¹Óà CONFIG_LBDAF ²âÊÔ¡£
76
7715£ºËùÓеÄcodepathsÒѾ­ÐÐʹËùÓÐlockdepÆôÓù¦ÄÜ¡£
78
7916£ºËùÓеÄ/proc¼Ç¼¸üж¼Òª×÷³ÉÎļþ·ÅÔÚDocumentation/Ŀ¼Ï¡£
80
8117£ºËùÓеÄÄÚºËÆô¶¯²ÎÊý¸üж¼±»¼Ç¼µ½Documentation/kernel-parameters.txtÎļþÖС£
82
8318£ºËùÓеÄÄ£¿é²ÎÊý¸üж¼ÓÃMODULE_PARM_DESC()¼Ç¼¡£
84
8519£ºËùÓеÄÓû§¿Õ¼ä½Ó¿Ú¸üж¼±»¼Ç¼µ½Documentation/ABI/¡£²é¿´Documentation/ABI/README
86 ¿ÉÒÔ»ñµÃ¸ü¶àµÄÐÅÏ¢¡£¸Ä±äÓû§¿Õ¼ä½Ó¿ÚµÄ²¹¶¡Ó¦¸Ã±»Óʼþ³­Ë͸ølinux-api@vger.kernel.org¡£
87
8820£º¼ì²éËüÊDz»ÊǶ¼Í¨¹ý`make headers_check'¡£
89
9021£ºÒѾ­Í¨¹ýÖÁÉÙÒýÈëslabºÍpage-allocationʧ°Ü¼ì²é¡£²é¿´Documentation/fault-injection/¡£
91
9222£ºÐ¼ÓÈëµÄÔ´ÂëÒѾ­Í¨¹ý`gcc -W'£¨Ê¹ÓÃ"make EXTRA_CFLAGS=-W"£©±àÒë¡£ÕâÑù½«²úÉúºÜ¶à·³ÄÕ£¬
93 µ«ÊǶÔÓÚÑ°ÕÒ©¶´ºÜÓÐÒæ´¦£¬ÀýÈç:"warning: comparison between signed and unsigned"¡£
94
9523£ºµ±Ëü±»ºÏ²¢µ½-mm²¹¶¡¼¯ºóÔÙ²âÊÔ£¬ÓÃÀ´È·¶¨ËüÊÇ·ñ»¹ºÍ²¹¶¡¶ÓÁÐÖеÄÆäËû²¹¶¡Ò»Æð¹¤×÷ÒÔ¼°ÔÚVM£¬VFS
96 ºÍÆäËû×ÓϵͳÖи÷¸ö±ä»¯¡£
97
9824£ºËùÓеÄÄÚ´æÆÁÕÏ{e.g., barrier(), rmb(), wmb()}ÐèÒªÔÚÔ´´úÂëÖеÄÒ»¸ö×¢ÊÍÀ´½âÊÍËûÃǶ¼ÊǸÉʲôµÄ
99 ÒÔ¼°Ô­Òò¡£
100
10125£ºÈç¹ûÓÐÈκÎÊäÈëÊä³ö¿ØÖƵIJ¹¶¡±»Ìí¼Ó£¬Ò²Òª¸üÐÂDocumentation/ioctl/ioctl-number.txt¡£
102
10326£ºÈç¹ûÄãµÄ¸ü¸Ä´úÂëÒÀ¿¿»òÕßʹÓÃÈκεÄÄÚºËAPIs»òÕßÓëÏÂÃæµÄkconfig·ûºÅÓйØϵµÄ¹¦ÄÜ£¬Äã¾ÍÒª
104 ʹÓÃÏà¹ØµÄkconfig·ûºÅ¹Ø±Õ£¬ and/or =m£¨Èç¹ûÑ¡ÏîÌṩ£©[ÔÚͬһʱ¼ä²»ÊÇËùÓõĶ¼ÆôÓ㬽ö½ö¸÷¸ö»òÕß×ÔÓÉ
105 ×éºÏËûÃÇ]£º
106
107 CONFIG_SMP, CONFIG_SYSFS, CONFIG_PROC_FS, CONFIG_INPUT, CONFIG_PCI,
108 CONFIG_BLOCK, CONFIG_PM, CONFIG_HOTPLUG, CONFIG_MAGIC_SYSRQ,
109 CONFIG_NET, CONFIG_INET=n (ºóÒ»¸öʹÓà CONFIG_NET=y)
diff --git a/Documentation/zh_CN/SubmittingPatches b/Documentation/zh_CN/SubmittingPatches
index 9a1a6e1ed09e..0f4385a62a49 100644
--- a/Documentation/zh_CN/SubmittingPatches
+++ b/Documentation/zh_CN/SubmittingPatches
@@ -100,7 +100,7 @@ http://userweb.kernel.org/~akpm/stuff/patch-scripts.tar.gz
100 100
101将改动拆分,逻辑类似的放到åŒä¸€ä¸ªè¡¥ä¸æ–‡ä»¶é‡Œã€‚ 101将改动拆分,逻辑类似的放到åŒä¸€ä¸ªè¡¥ä¸æ–‡ä»¶é‡Œã€‚
102 102
103例如,如果你的改动里åŒæ—¶æœ‰bug修正和性能优化,那么把这些改动æ分到两个或 103例如,如果你的改动里åŒæ—¶æœ‰bug修正和性能优化,那么把这些改动拆分到两个或
104者更多的补ä¸æ–‡ä»¶ä¸­ã€‚如果你的改动包å«å¯¹API的修改,并且修改了驱动程åºæ¥é€‚ 104者更多的补ä¸æ–‡ä»¶ä¸­ã€‚如果你的改动包å«å¯¹API的修改,并且修改了驱动程åºæ¥é€‚
105应这些新的API,那么把这些修改分æˆä¸¤ä¸ªè¡¥ä¸ã€‚ 105应这些新的API,那么把这些修改分æˆä¸¤ä¸ªè¡¥ä¸ã€‚
106 106
@@ -230,7 +230,7 @@ pref("mailnews.display.disable_format_flowed_support", true);
230些原因,修正错误,é‡æ–°æ交更新åŽçš„改动,是你自己的工作。 230些原因,修正错误,é‡æ–°æ交更新åŽçš„改动,是你自己的工作。
231 231
232Linusä¸ç»™å‡ºä»»ä½•è¯„论就“丢弃â€ä½ çš„è¡¥ä¸æ˜¯å¸¸è§çš„事情。在系统中这样的事情很 232Linusä¸ç»™å‡ºä»»ä½•è¯„论就“丢弃â€ä½ çš„è¡¥ä¸æ˜¯å¸¸è§çš„事情。在系统中这样的事情很
233平常。如果他没有接å—ä½ çš„è¡¥ä¸ï¼Œä¹Ÿè®¸æ˜¯ç”±äºŽä»¥ä¸‹åŽŸæœ¬ï¼š 233平常。如果他没有接å—ä½ çš„è¡¥ä¸ï¼Œä¹Ÿè®¸æ˜¯ç”±äºŽä»¥ä¸‹åŽŸå› ï¼š
234* ä½ çš„è¡¥ä¸ä¸èƒ½åœ¨æœ€æ–°ç‰ˆæœ¬çš„内核上干净的打上。 234* ä½ çš„è¡¥ä¸ä¸èƒ½åœ¨æœ€æ–°ç‰ˆæœ¬çš„内核上干净的打上。
235* ä½ çš„è¡¥ä¸åœ¨ linux-kernel 邮件列表中没有得到充分的讨论。 235* ä½ çš„è¡¥ä¸åœ¨ linux-kernel 邮件列表中没有得到充分的讨论。
236* 风格问题(å‚照第2å°èŠ‚) 236* 风格问题(å‚照第2å°èŠ‚)
diff --git a/Documentation/zh_CN/magic-number.txt b/Documentation/zh_CN/magic-number.txt
new file mode 100644
index 000000000000..4c4ce853577b
--- /dev/null
+++ b/Documentation/zh_CN/magic-number.txt
@@ -0,0 +1,167 @@
1Chinese translated version of Documentation/magic-number.txt
2
3If you have any comment or update to the content, please post to LKML directly.
4However, if you have problem communicating in English you can also ask the
5Chinese maintainer for help. Contact the Chinese maintainer, if this
6translation is outdated or there is problem with translation.
7
8Chinese maintainer: Jia Wei Wei <harryxiyou@gmail.com>
9---------------------------------------------------------------------
10Documentation/magic-number.txt的中文翻译
11
12如果想评论或更新本文的内容,请直接å‘信到LKML。如果你使用英文交æµæœ‰å›°éš¾çš„è¯ï¼Œä¹Ÿå¯
13以å‘中文版维护者求助。如果本翻译更新ä¸åŠæ—¶æˆ–者翻译存在问题,请è”系中文版维护者。
14
15中文版维护者: è´¾å¨å¨ Jia Wei Wei <harryxiyou@gmail.com>
16中文版翻译者: è´¾å¨å¨ Jia Wei Wei <harryxiyou@gmail.com>
17中文版校译者: è´¾å¨å¨ Jia Wei Wei <harryxiyou@gmail.com>
18
19以下为正文
20---------------------------------------------------------------------
21这个文件是有关当å‰ä½¿ç”¨çš„魔术值注册表。当你给一个结构添加了一个魔术值,你也应该把这个魔术值添加到这个文件,因为我们最好把用于å„ç§ç»“构的魔术值统一起æ¥ã€‚
22
23使用魔术值æ¥ä¿æŠ¤å†…核数æ®ç»“构是一个éžå¸¸å¥½çš„主æ„。这就å…许你在è¿è¡ŒæœŸæ£€æŸ¥(a)一个结构是å¦å·²ç»è¢«æ”»å‡»ï¼Œæˆ–者(b)ä½ å·²ç»ç»™ä¸€ä¸ªä¾‹è¡Œç¨‹åºé€šè¿‡äº†ä¸€ä¸ªé”™è¯¯çš„结构。åŽä¸€ç§æƒ…况特别地有用---特别是当你通过一个空指针指å‘结构体的时候。ttyæºç ï¼Œä¾‹å¦‚,ç»å¸¸é€šè¿‡ç‰¹å®šé©±åŠ¨ä½¿ç”¨è¿™ç§æ–¹æ³•å¹¶ä¸”åå¤åœ°æŽ’列特定方é¢çš„结构。
24
25使用魔术值的方法是在结构的开始处声明的,如下:
26
27struct tty_ldisc {
28 int magic;
29 ...
30};
31
32当你以åŽç»™å†…核添加增强功能的时候,请éµå®ˆè¿™æ¡è§„则ï¼è¿™æ ·å°±ä¼šèŠ‚çœæ•°ä¸æ¸…的调试时间,特别是一些å¤æ€ªçš„情况,例如,数组超出范围并且é‡æ–°å†™äº†è¶…出部分。éµå®ˆè¿™ä¸ªè§„则,‪这些情况å¯ä»¥è¢«å¿«é€Ÿåœ°ï¼Œå®‰å…¨åœ°é¿å…。
33
34 Theodore Ts'o
35 31 Mar 94
36
37给当å‰çš„Linux 2.1.55添加魔术表。
38
39 Michael Chastain
40 <mailto:mec@shout.net>
41 22 Sep 1997
42
43现在应该最新的Linux 2.1.112.因为在特性冻结期间,ä¸èƒ½åœ¨2.2.xå‰æ”¹å˜ä»»ä½•ä¸œè¥¿ã€‚这些æ¡ç›®è¢«æ•°åŸŸæ‰€æŽ’åºã€‚
44
45 Krzysztof G.Baranowski
46 <mailto: kgb@knm.org.pl>
47 29 Jul 1998
48
49更新魔术表到Linux 2.5.45。刚好越过特性冻结,但是有å¯èƒ½è¿˜ä¼šæœ‰ä¸€äº›æ–°çš„魔术值在2.6.x之å‰èžå…¥åˆ°å†…核中。
50
51 Petr Baudis
52 <pasky@ucw.cz>
53 03 Nov 2002
54
55更新魔术表到Linux 2.5.74。
56
57 Fabian Frederick
58 <ffrederick@users.sourceforge.net>
59 09 Jul 2003
60
61魔术å åœ°å€ ç»“æž„ 所在文件
62===========================================================================
63PG_MAGIC 'P' pg_{read,write}_hdr include/linux/pg.h
64CMAGIC 0x0111 user include/linux/a.out.h
65MKISS_DRIVER_MAGIC 0x04bf mkiss_channel drivers/net/mkiss.h
66RISCOM8_MAGIC 0x0907 riscom_port drivers/char/riscom8.h
67SPECIALIX_MAGIC 0x0907 specialix_port drivers/char/specialix_io8.h
68HDLC_MAGIC 0x239e n_hdlc drivers/char/n_hdlc.c
69APM_BIOS_MAGIC 0x4101 apm_user arch/i386/kernel/apm.c
70CYCLADES_MAGIC 0x4359 cyclades_port include/linux/cyclades.h
71DB_MAGIC 0x4442 fc_info drivers/net/iph5526_novram.c
72DL_MAGIC 0x444d fc_info drivers/net/iph5526_novram.c
73FASYNC_MAGIC 0x4601 fasync_struct include/linux/fs.h
74FF_MAGIC 0x4646 fc_info drivers/net/iph5526_novram.c
75ISICOM_MAGIC 0x4d54 isi_port include/linux/isicom.h
76PTY_MAGIC 0x5001 drivers/char/pty.c
77PPP_MAGIC 0x5002 ppp include/linux/if_pppvar.h
78SERIAL_MAGIC 0x5301 async_struct include/linux/serial.h
79SSTATE_MAGIC 0x5302 serial_state include/linux/serial.h
80SLIP_MAGIC 0x5302 slip drivers/net/slip.h
81STRIP_MAGIC 0x5303 strip drivers/net/strip.c
82X25_ASY_MAGIC 0x5303 x25_asy drivers/net/x25_asy.h
83SIXPACK_MAGIC 0x5304 sixpack drivers/net/hamradio/6pack.h
84AX25_MAGIC 0x5316 ax_disp drivers/net/mkiss.h
85ESP_MAGIC 0x53ee esp_struct drivers/char/esp.h
86TTY_MAGIC 0x5401 tty_struct include/linux/tty.h
87MGSL_MAGIC 0x5401 mgsl_info drivers/char/synclink.c
88TTY_DRIVER_MAGIC 0x5402 tty_driver include/linux/tty_driver.h
89MGSLPC_MAGIC 0x5402 mgslpc_info drivers/char/pcmcia/synclink_cs.c
90TTY_LDISC_MAGIC 0x5403 tty_ldisc include/linux/tty_ldisc.h
91USB_SERIAL_MAGIC 0x6702 usb_serial drivers/usb/serial/usb-serial.h
92FULL_DUPLEX_MAGIC 0x6969 drivers/net/tulip/de2104x.c
93USB_BLUETOOTH_MAGIC 0x6d02 usb_bluetooth drivers/usb/class/bluetty.c
94RFCOMM_TTY_MAGIC 0x6d02 net/bluetooth/rfcomm/tty.c
95USB_SERIAL_PORT_MAGIC 0x7301 usb_serial_port drivers/usb/serial/usb-serial.h
96CG_MAGIC 0x00090255 ufs_cylinder_group include/linux/ufs_fs.h
97A2232_MAGIC 0x000a2232 gs_port drivers/char/ser_a2232.h
98RPORT_MAGIC 0x00525001 r_port drivers/char/rocket_int.h
99LSEMAGIC 0x05091998 lse drivers/fc4/fc.c
100GDTIOCTL_MAGIC 0x06030f07 gdth_iowr_str drivers/scsi/gdth_ioctl.h
101RIEBL_MAGIC 0x09051990 drivers/net/atarilance.c
102RIO_MAGIC 0x12345678 gs_port drivers/char/rio/rio_linux.c
103SX_MAGIC 0x12345678 gs_port drivers/char/sx.h
104NBD_REQUEST_MAGIC 0x12560953 nbd_request include/linux/nbd.h
105RED_MAGIC2 0x170fc2a5 (any) mm/slab.c
106BAYCOM_MAGIC 0x19730510 baycom_state drivers/net/baycom_epp.c
107ISDN_X25IFACE_MAGIC 0x1e75a2b9 isdn_x25iface_proto_data
108 drivers/isdn/isdn_x25iface.h
109ECP_MAGIC 0x21504345 cdkecpsig include/linux/cdk.h
110LSOMAGIC 0x27091997 lso drivers/fc4/fc.c
111LSMAGIC 0x2a3b4d2a ls drivers/fc4/fc.c
112WANPIPE_MAGIC 0x414C4453 sdla_{dump,exec} include/linux/wanpipe.h
113CS_CARD_MAGIC 0x43525553 cs_card sound/oss/cs46xx.c
114LABELCL_MAGIC 0x4857434c labelcl_info_s include/asm/ia64/sn/labelcl.h
115ISDN_ASYNC_MAGIC 0x49344C01 modem_info include/linux/isdn.h
116CTC_ASYNC_MAGIC 0x49344C01 ctc_tty_info drivers/s390/net/ctctty.c
117ISDN_NET_MAGIC 0x49344C02 isdn_net_local_s drivers/isdn/i4l/isdn_net_lib.h
118SAVEKMSG_MAGIC2 0x4B4D5347 savekmsg arch/*/amiga/config.c
119STLI_BOARDMAGIC 0x4bc6c825 stlibrd include/linux/istallion.h
120CS_STATE_MAGIC 0x4c4f4749 cs_state sound/oss/cs46xx.c
121SLAB_C_MAGIC 0x4f17a36d kmem_cache mm/slab.c
122COW_MAGIC 0x4f4f4f4d cow_header_v1 arch/um/drivers/ubd_user.c
123I810_CARD_MAGIC 0x5072696E i810_card sound/oss/i810_audio.c
124TRIDENT_CARD_MAGIC 0x5072696E trident_card sound/oss/trident.c
125ROUTER_MAGIC 0x524d4157 wan_device include/linux/wanrouter.h
126SCC_MAGIC 0x52696368 gs_port drivers/char/scc.h
127SAVEKMSG_MAGIC1 0x53415645 savekmsg arch/*/amiga/config.c
128GDA_MAGIC 0x58464552 gda arch/mips/include/asm/sn/gda.h
129RED_MAGIC1 0x5a2cf071 (any) mm/slab.c
130STL_PORTMAGIC 0x5a7182c9 stlport include/linux/stallion.h
131EEPROM_MAGIC_VALUE 0x5ab478d2 lanai_dev drivers/atm/lanai.c
132HDLCDRV_MAGIC 0x5ac6e778 hdlcdrv_state include/linux/hdlcdrv.h
133EPCA_MAGIC 0x5c6df104 channel include/linux/epca.h
134PCXX_MAGIC 0x5c6df104 channel drivers/char/pcxx.h
135KV_MAGIC 0x5f4b565f kernel_vars_s arch/mips/include/asm/sn/klkernvars.h
136I810_STATE_MAGIC 0x63657373 i810_state sound/oss/i810_audio.c
137TRIDENT_STATE_MAGIC 0x63657373 trient_state sound/oss/trident.c
138M3_CARD_MAGIC 0x646e6f50 m3_card sound/oss/maestro3.c
139FW_HEADER_MAGIC 0x65726F66 fw_header drivers/atm/fore200e.h
140SLOT_MAGIC 0x67267321 slot drivers/hotplug/cpqphp.h
141SLOT_MAGIC 0x67267322 slot drivers/hotplug/acpiphp.h
142LO_MAGIC 0x68797548 nbd_device include/linux/nbd.h
143OPROFILE_MAGIC 0x6f70726f super_block drivers/oprofile/oprofilefs.h
144M3_STATE_MAGIC 0x734d724d m3_state sound/oss/maestro3.c
145STL_PANELMAGIC 0x7ef621a1 stlpanel include/linux/stallion.h
146VMALLOC_MAGIC 0x87654320 snd_alloc_track sound/core/memory.c
147KMALLOC_MAGIC 0x87654321 snd_alloc_track sound/core/memory.c
148PWC_MAGIC 0x89DC10AB pwc_device drivers/usb/media/pwc.h
149NBD_REPLY_MAGIC 0x96744668 nbd_reply include/linux/nbd.h
150STL_BOARDMAGIC 0xa2267f52 stlbrd include/linux/stallion.h
151ENI155_MAGIC 0xa54b872d midway_eprom drivers/atm/eni.h
152SCI_MAGIC 0xbabeface gs_port drivers/char/sh-sci.h
153CODA_MAGIC 0xC0DAC0DA coda_file_info include/linux/coda_fs_i.h
154DPMEM_MAGIC 0xc0ffee11 gdt_pci_sram drivers/scsi/gdth.h
155STLI_PORTMAGIC 0xe671c7a1 stliport include/linux/istallion.h
156YAM_MAGIC 0xF10A7654 yam_port drivers/net/hamradio/yam.c
157CCB_MAGIC 0xf2691ad2 ccb drivers/scsi/ncr53c8xx.c
158QUEUE_MAGIC_FREE 0xf7e1c9a3 queue_entry drivers/scsi/arm/queue.c
159QUEUE_MAGIC_USED 0xf7e1cc33 queue_entry drivers/scsi/arm/queue.c
160HTB_CMAGIC 0xFEFAFEF1 htb_class net/sched/sch_htb.c
161NMI_MAGIC 0x48414d4d455201 nmi_s arch/mips/include/asm/sn/nmi.h
162
163请注æ„,在声音记忆管ç†ä¸­ä»ç„¶æœ‰æ¯ä¸€äº›è¢«å®šä¹‰çš„驱动魔术值。查看include/sound/sndmagic.hæ¥èŽ·å–他们完整的列表信æ¯ã€‚很多OSS声音驱动拥有自己从声å¡PCI ID构建的魔术值-他们也没有被列在这里。
164
165IrDAå­ç³»ç»Ÿä¹Ÿä½¿ç”¨äº†å¤§é‡çš„自己的魔术值,查看include/net/irda/irda.hæ¥èŽ·å–他们完整的信æ¯ã€‚
166
167HFS是å¦å¤–一个比较大的使用魔术值的文件系统-ä½ å¯ä»¥åœ¨fs/hfs/hfs.h中找到他们。
diff --git a/arch/powerpc/platforms/pseries/hotplug-memory.c b/arch/powerpc/platforms/pseries/hotplug-memory.c
index bc8803664140..33867ec4a234 100644
--- a/arch/powerpc/platforms/pseries/hotplug-memory.c
+++ b/arch/powerpc/platforms/pseries/hotplug-memory.c
@@ -17,6 +17,54 @@
17#include <asm/pSeries_reconfig.h> 17#include <asm/pSeries_reconfig.h>
18#include <asm/sparsemem.h> 18#include <asm/sparsemem.h>
19 19
20static unsigned long get_memblock_size(void)
21{
22 struct device_node *np;
23 unsigned int memblock_size = 0;
24
25 np = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory");
26 if (np) {
27 const unsigned long *size;
28
29 size = of_get_property(np, "ibm,lmb-size", NULL);
30 memblock_size = size ? *size : 0;
31
32 of_node_put(np);
33 } else {
34 unsigned int memzero_size = 0;
35 const unsigned int *regs;
36
37 np = of_find_node_by_path("/memory@0");
38 if (np) {
39 regs = of_get_property(np, "reg", NULL);
40 memzero_size = regs ? regs[3] : 0;
41 of_node_put(np);
42 }
43
44 if (memzero_size) {
45 /* We now know the size of memory@0, use this to find
46 * the first memoryblock and get its size.
47 */
48 char buf[64];
49
50 sprintf(buf, "/memory@%x", memzero_size);
51 np = of_find_node_by_path(buf);
52 if (np) {
53 regs = of_get_property(np, "reg", NULL);
54 memblock_size = regs ? regs[3] : 0;
55 of_node_put(np);
56 }
57 }
58 }
59
60 return memblock_size;
61}
62
63unsigned long memory_block_size_bytes(void)
64{
65 return get_memblock_size();
66}
67
20static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size) 68static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size)
21{ 69{
22 unsigned long start, start_pfn; 70 unsigned long start, start_pfn;
@@ -127,30 +175,22 @@ static int pseries_add_memory(struct device_node *np)
127 175
128static int pseries_drconf_memory(unsigned long *base, unsigned int action) 176static int pseries_drconf_memory(unsigned long *base, unsigned int action)
129{ 177{
130 struct device_node *np; 178 unsigned long memblock_size;
131 const unsigned long *lmb_size;
132 int rc; 179 int rc;
133 180
134 np = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory"); 181 memblock_size = get_memblock_size();
135 if (!np) 182 if (!memblock_size)
136 return -EINVAL; 183 return -EINVAL;
137 184
138 lmb_size = of_get_property(np, "ibm,lmb-size", NULL);
139 if (!lmb_size) {
140 of_node_put(np);
141 return -EINVAL;
142 }
143
144 if (action == PSERIES_DRCONF_MEM_ADD) { 185 if (action == PSERIES_DRCONF_MEM_ADD) {
145 rc = memblock_add(*base, *lmb_size); 186 rc = memblock_add(*base, memblock_size);
146 rc = (rc < 0) ? -EINVAL : 0; 187 rc = (rc < 0) ? -EINVAL : 0;
147 } else if (action == PSERIES_DRCONF_MEM_REMOVE) { 188 } else if (action == PSERIES_DRCONF_MEM_REMOVE) {
148 rc = pseries_remove_memblock(*base, *lmb_size); 189 rc = pseries_remove_memblock(*base, memblock_size);
149 } else { 190 } else {
150 rc = -EINVAL; 191 rc = -EINVAL;
151 } 192 }
152 193
153 of_node_put(np);
154 return rc; 194 return rc;
155} 195}
156 196
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index a08a62cb136e..0aa34669ed3f 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -51,6 +51,7 @@
51#include <asm/numa.h> 51#include <asm/numa.h>
52#include <asm/cacheflush.h> 52#include <asm/cacheflush.h>
53#include <asm/init.h> 53#include <asm/init.h>
54#include <asm/uv/uv.h>
54 55
55static int __init parse_direct_gbpages_off(char *arg) 56static int __init parse_direct_gbpages_off(char *arg)
56{ 57{
@@ -898,6 +899,19 @@ const char *arch_vma_name(struct vm_area_struct *vma)
898 return NULL; 899 return NULL;
899} 900}
900 901
902#ifdef CONFIG_X86_UV
903#define MIN_MEMORY_BLOCK_SIZE (1 << SECTION_SIZE_BITS)
904
905unsigned long memory_block_size_bytes(void)
906{
907 if (is_uv_system()) {
908 printk(KERN_INFO "UV: memory block size 2GB\n");
909 return 2UL * 1024 * 1024 * 1024;
910 }
911 return MIN_MEMORY_BLOCK_SIZE;
912}
913#endif
914
901#ifdef CONFIG_SPARSEMEM_VMEMMAP 915#ifdef CONFIG_SPARSEMEM_VMEMMAP
902/* 916/*
903 * Initialise the sparsemem vmemmap using huge-pages at the PMD level. 917 * Initialise the sparsemem vmemmap using huge-pages at the PMD level.
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 080e9ca11017..81b78ede37c4 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -1320,7 +1320,10 @@ struct root_device
1320 struct module *owner; 1320 struct module *owner;
1321}; 1321};
1322 1322
1323#define to_root_device(dev) container_of(dev, struct root_device, dev) 1323inline struct root_device *to_root_device(struct device *d)
1324{
1325 return container_of(d, struct root_device, dev);
1326}
1324 1327
1325static void root_device_release(struct device *dev) 1328static void root_device_release(struct device *dev)
1326{ 1329{
@@ -1551,7 +1554,34 @@ EXPORT_SYMBOL_GPL(device_destroy);
1551 * on the same device to ensure that new_name is valid and 1554 * on the same device to ensure that new_name is valid and
1552 * won't conflict with other devices. 1555 * won't conflict with other devices.
1553 * 1556 *
1554 * "Never use this function, bad things will happen" - gregkh 1557 * Note: Don't call this function. Currently, the networking layer calls this
1558 * function, but that will change. The following text from Kay Sievers offers
1559 * some insight:
1560 *
1561 * Renaming devices is racy at many levels, symlinks and other stuff are not
1562 * replaced atomically, and you get a "move" uevent, but it's not easy to
1563 * connect the event to the old and new device. Device nodes are not renamed at
1564 * all, there isn't even support for that in the kernel now.
1565 *
1566 * In the meantime, during renaming, your target name might be taken by another
1567 * driver, creating conflicts. Or the old name is taken directly after you
1568 * renamed it -- then you get events for the same DEVPATH, before you even see
1569 * the "move" event. It's just a mess, and nothing new should ever rely on
1570 * kernel device renaming. Besides that, it's not even implemented now for
1571 * other things than (driver-core wise very simple) network devices.
1572 *
1573 * We are currently about to change network renaming in udev to completely
1574 * disallow renaming of devices in the same namespace as the kernel uses,
1575 * because we can't solve the problems properly, that arise with swapping names
1576 * of multiple interfaces without races. Means, renaming of eth[0-9]* will only
1577 * be allowed to some other name than eth[0-9]*, for the aforementioned
1578 * reasons.
1579 *
1580 * Make up a "real" name in the driver before you register anything, or add
1581 * some other attributes for userspace to find the device, or use udev to add
1582 * symlinks -- but never rename kernel devices later, it's a complete mess. We
1583 * don't even want to get into that and try to implement the missing pieces in
1584 * the core. We really have other pieces to fix in the driver core mess. :)
1555 */ 1585 */
1556int device_rename(struct device *dev, const char *new_name) 1586int device_rename(struct device *dev, const char *new_name)
1557{ 1587{
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 40af43ebd92d..8c798ef7f13f 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -593,8 +593,7 @@ int
593request_firmware(const struct firmware **firmware_p, const char *name, 593request_firmware(const struct firmware **firmware_p, const char *name,
594 struct device *device) 594 struct device *device)
595{ 595{
596 int uevent = 1; 596 return _request_firmware(firmware_p, name, device, true, false);
597 return _request_firmware(firmware_p, name, device, uevent, false);
598} 597}
599 598
600/** 599/**
@@ -618,7 +617,7 @@ struct firmware_work {
618 struct device *device; 617 struct device *device;
619 void *context; 618 void *context;
620 void (*cont)(const struct firmware *fw, void *context); 619 void (*cont)(const struct firmware *fw, void *context);
621 int uevent; 620 bool uevent;
622}; 621};
623 622
624static int request_firmware_work_func(void *arg) 623static int request_firmware_work_func(void *arg)
@@ -661,7 +660,7 @@ static int request_firmware_work_func(void *arg)
661 **/ 660 **/
662int 661int
663request_firmware_nowait( 662request_firmware_nowait(
664 struct module *module, int uevent, 663 struct module *module, bool uevent,
665 const char *name, struct device *device, gfp_t gfp, void *context, 664 const char *name, struct device *device, gfp_t gfp, void *context,
666 void (*cont)(const struct firmware *fw, void *context)) 665 void (*cont)(const struct firmware *fw, void *context))
667{ 666{
diff --git a/drivers/base/memory.c b/drivers/base/memory.c
index cafeaaf0428f..3da6a43b7756 100644
--- a/drivers/base/memory.c
+++ b/drivers/base/memory.c
@@ -30,6 +30,14 @@
30static DEFINE_MUTEX(mem_sysfs_mutex); 30static DEFINE_MUTEX(mem_sysfs_mutex);
31 31
32#define MEMORY_CLASS_NAME "memory" 32#define MEMORY_CLASS_NAME "memory"
33#define MIN_MEMORY_BLOCK_SIZE (1 << SECTION_SIZE_BITS)
34
35static int sections_per_block;
36
37static inline int base_memory_block_id(int section_nr)
38{
39 return section_nr / sections_per_block;
40}
33 41
34static struct sysdev_class memory_sysdev_class = { 42static struct sysdev_class memory_sysdev_class = {
35 .name = MEMORY_CLASS_NAME, 43 .name = MEMORY_CLASS_NAME,
@@ -84,39 +92,72 @@ EXPORT_SYMBOL(unregister_memory_isolate_notifier);
84 * register_memory - Setup a sysfs device for a memory block 92 * register_memory - Setup a sysfs device for a memory block
85 */ 93 */
86static 94static
87int register_memory(struct memory_block *memory, struct mem_section *section) 95int register_memory(struct memory_block *memory)
88{ 96{
89 int error; 97 int error;
90 98
91 memory->sysdev.cls = &memory_sysdev_class; 99 memory->sysdev.cls = &memory_sysdev_class;
92 memory->sysdev.id = __section_nr(section); 100 memory->sysdev.id = memory->start_section_nr / sections_per_block;
93 101
94 error = sysdev_register(&memory->sysdev); 102 error = sysdev_register(&memory->sysdev);
95 return error; 103 return error;
96} 104}
97 105
98static void 106static void
99unregister_memory(struct memory_block *memory, struct mem_section *section) 107unregister_memory(struct memory_block *memory)
100{ 108{
101 BUG_ON(memory->sysdev.cls != &memory_sysdev_class); 109 BUG_ON(memory->sysdev.cls != &memory_sysdev_class);
102 BUG_ON(memory->sysdev.id != __section_nr(section));
103 110
104 /* drop the ref. we got in remove_memory_block() */ 111 /* drop the ref. we got in remove_memory_block() */
105 kobject_put(&memory->sysdev.kobj); 112 kobject_put(&memory->sysdev.kobj);
106 sysdev_unregister(&memory->sysdev); 113 sysdev_unregister(&memory->sysdev);
107} 114}
108 115
116unsigned long __weak memory_block_size_bytes(void)
117{
118 return MIN_MEMORY_BLOCK_SIZE;
119}
120
121static unsigned long get_memory_block_size(void)
122{
123 unsigned long block_sz;
124
125 block_sz = memory_block_size_bytes();
126
127 /* Validate blk_sz is a power of 2 and not less than section size */
128 if ((block_sz & (block_sz - 1)) || (block_sz < MIN_MEMORY_BLOCK_SIZE)) {
129 WARN_ON(1);
130 block_sz = MIN_MEMORY_BLOCK_SIZE;
131 }
132
133 return block_sz;
134}
135
109/* 136/*
110 * use this as the physical section index that this memsection 137 * use this as the physical section index that this memsection
111 * uses. 138 * uses.
112 */ 139 */
113 140
114static ssize_t show_mem_phys_index(struct sys_device *dev, 141static ssize_t show_mem_start_phys_index(struct sys_device *dev,
115 struct sysdev_attribute *attr, char *buf) 142 struct sysdev_attribute *attr, char *buf)
116{ 143{
117 struct memory_block *mem = 144 struct memory_block *mem =
118 container_of(dev, struct memory_block, sysdev); 145 container_of(dev, struct memory_block, sysdev);
119 return sprintf(buf, "%08lx\n", mem->phys_index); 146 unsigned long phys_index;
147
148 phys_index = mem->start_section_nr / sections_per_block;
149 return sprintf(buf, "%08lx\n", phys_index);
150}
151
152static ssize_t show_mem_end_phys_index(struct sys_device *dev,
153 struct sysdev_attribute *attr, char *buf)
154{
155 struct memory_block *mem =
156 container_of(dev, struct memory_block, sysdev);
157 unsigned long phys_index;
158
159 phys_index = mem->end_section_nr / sections_per_block;
160 return sprintf(buf, "%08lx\n", phys_index);
120} 161}
121 162
122/* 163/*
@@ -125,13 +166,16 @@ static ssize_t show_mem_phys_index(struct sys_device *dev,
125static ssize_t show_mem_removable(struct sys_device *dev, 166static ssize_t show_mem_removable(struct sys_device *dev,
126 struct sysdev_attribute *attr, char *buf) 167 struct sysdev_attribute *attr, char *buf)
127{ 168{
128 unsigned long start_pfn; 169 unsigned long i, pfn;
129 int ret; 170 int ret = 1;
130 struct memory_block *mem = 171 struct memory_block *mem =
131 container_of(dev, struct memory_block, sysdev); 172 container_of(dev, struct memory_block, sysdev);
132 173
133 start_pfn = section_nr_to_pfn(mem->phys_index); 174 for (i = 0; i < sections_per_block; i++) {
134 ret = is_mem_section_removable(start_pfn, PAGES_PER_SECTION); 175 pfn = section_nr_to_pfn(mem->start_section_nr + i);
176 ret &= is_mem_section_removable(pfn, PAGES_PER_SECTION);
177 }
178
135 return sprintf(buf, "%d\n", ret); 179 return sprintf(buf, "%d\n", ret);
136} 180}
137 181
@@ -184,17 +228,14 @@ int memory_isolate_notify(unsigned long val, void *v)
184 * OK to have direct references to sparsemem variables in here. 228 * OK to have direct references to sparsemem variables in here.
185 */ 229 */
186static int 230static int
187memory_block_action(struct memory_block *mem, unsigned long action) 231memory_section_action(unsigned long phys_index, unsigned long action)
188{ 232{
189 int i; 233 int i;
190 unsigned long psection;
191 unsigned long start_pfn, start_paddr; 234 unsigned long start_pfn, start_paddr;
192 struct page *first_page; 235 struct page *first_page;
193 int ret; 236 int ret;
194 int old_state = mem->state;
195 237
196 psection = mem->phys_index; 238 first_page = pfn_to_page(phys_index << PFN_SECTION_SHIFT);
197 first_page = pfn_to_page(psection << PFN_SECTION_SHIFT);
198 239
199 /* 240 /*
200 * The probe routines leave the pages reserved, just 241 * The probe routines leave the pages reserved, just
@@ -207,8 +248,8 @@ memory_block_action(struct memory_block *mem, unsigned long action)
207 continue; 248 continue;
208 249
209 printk(KERN_WARNING "section number %ld page number %d " 250 printk(KERN_WARNING "section number %ld page number %d "
210 "not reserved, was it already online? \n", 251 "not reserved, was it already online?\n",
211 psection, i); 252 phys_index, i);
212 return -EBUSY; 253 return -EBUSY;
213 } 254 }
214 } 255 }
@@ -219,18 +260,13 @@ memory_block_action(struct memory_block *mem, unsigned long action)
219 ret = online_pages(start_pfn, PAGES_PER_SECTION); 260 ret = online_pages(start_pfn, PAGES_PER_SECTION);
220 break; 261 break;
221 case MEM_OFFLINE: 262 case MEM_OFFLINE:
222 mem->state = MEM_GOING_OFFLINE;
223 start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; 263 start_paddr = page_to_pfn(first_page) << PAGE_SHIFT;
224 ret = remove_memory(start_paddr, 264 ret = remove_memory(start_paddr,
225 PAGES_PER_SECTION << PAGE_SHIFT); 265 PAGES_PER_SECTION << PAGE_SHIFT);
226 if (ret) {
227 mem->state = old_state;
228 break;
229 }
230 break; 266 break;
231 default: 267 default:
232 WARN(1, KERN_WARNING "%s(%p, %ld) unknown action: %ld\n", 268 WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: "
233 __func__, mem, action, action); 269 "%ld\n", __func__, phys_index, action, action);
234 ret = -EINVAL; 270 ret = -EINVAL;
235 } 271 }
236 272
@@ -240,7 +276,8 @@ memory_block_action(struct memory_block *mem, unsigned long action)
240static int memory_block_change_state(struct memory_block *mem, 276static int memory_block_change_state(struct memory_block *mem,
241 unsigned long to_state, unsigned long from_state_req) 277 unsigned long to_state, unsigned long from_state_req)
242{ 278{
243 int ret = 0; 279 int i, ret = 0;
280
244 mutex_lock(&mem->state_mutex); 281 mutex_lock(&mem->state_mutex);
245 282
246 if (mem->state != from_state_req) { 283 if (mem->state != from_state_req) {
@@ -248,8 +285,23 @@ static int memory_block_change_state(struct memory_block *mem,
248 goto out; 285 goto out;
249 } 286 }
250 287
251 ret = memory_block_action(mem, to_state); 288 if (to_state == MEM_OFFLINE)
252 if (!ret) 289 mem->state = MEM_GOING_OFFLINE;
290
291 for (i = 0; i < sections_per_block; i++) {
292 ret = memory_section_action(mem->start_section_nr + i,
293 to_state);
294 if (ret)
295 break;
296 }
297
298 if (ret) {
299 for (i = 0; i < sections_per_block; i++)
300 memory_section_action(mem->start_section_nr + i,
301 from_state_req);
302
303 mem->state = from_state_req;
304 } else
253 mem->state = to_state; 305 mem->state = to_state;
254 306
255out: 307out:
@@ -262,20 +314,15 @@ store_mem_state(struct sys_device *dev,
262 struct sysdev_attribute *attr, const char *buf, size_t count) 314 struct sysdev_attribute *attr, const char *buf, size_t count)
263{ 315{
264 struct memory_block *mem; 316 struct memory_block *mem;
265 unsigned int phys_section_nr;
266 int ret = -EINVAL; 317 int ret = -EINVAL;
267 318
268 mem = container_of(dev, struct memory_block, sysdev); 319 mem = container_of(dev, struct memory_block, sysdev);
269 phys_section_nr = mem->phys_index;
270
271 if (!present_section_nr(phys_section_nr))
272 goto out;
273 320
274 if (!strncmp(buf, "online", min((int)count, 6))) 321 if (!strncmp(buf, "online", min((int)count, 6)))
275 ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); 322 ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE);
276 else if(!strncmp(buf, "offline", min((int)count, 7))) 323 else if(!strncmp(buf, "offline", min((int)count, 7)))
277 ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); 324 ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE);
278out: 325
279 if (ret) 326 if (ret)
280 return ret; 327 return ret;
281 return count; 328 return count;
@@ -298,7 +345,8 @@ static ssize_t show_phys_device(struct sys_device *dev,
298 return sprintf(buf, "%d\n", mem->phys_device); 345 return sprintf(buf, "%d\n", mem->phys_device);
299} 346}
300 347
301static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL); 348static SYSDEV_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL);
349static SYSDEV_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL);
302static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state); 350static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state);
303static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL); 351static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL);
304static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL); 352static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL);
@@ -315,7 +363,7 @@ static ssize_t
315print_block_size(struct sysdev_class *class, struct sysdev_class_attribute *attr, 363print_block_size(struct sysdev_class *class, struct sysdev_class_attribute *attr,
316 char *buf) 364 char *buf)
317{ 365{
318 return sprintf(buf, "%lx\n", (unsigned long)PAGES_PER_SECTION * PAGE_SIZE); 366 return sprintf(buf, "%lx\n", get_memory_block_size());
319} 367}
320 368
321static SYSDEV_CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL); 369static SYSDEV_CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL);
@@ -339,12 +387,19 @@ memory_probe_store(struct class *class, struct class_attribute *attr,
339{ 387{
340 u64 phys_addr; 388 u64 phys_addr;
341 int nid; 389 int nid;
342 int ret; 390 int i, ret;
343 391
344 phys_addr = simple_strtoull(buf, NULL, 0); 392 phys_addr = simple_strtoull(buf, NULL, 0);
345 393
346 nid = memory_add_physaddr_to_nid(phys_addr); 394 for (i = 0; i < sections_per_block; i++) {
347 ret = add_memory(nid, phys_addr, PAGES_PER_SECTION << PAGE_SHIFT); 395 nid = memory_add_physaddr_to_nid(phys_addr);
396 ret = add_memory(nid, phys_addr,
397 PAGES_PER_SECTION << PAGE_SHIFT);
398 if (ret)
399 break;
400
401 phys_addr += MIN_MEMORY_BLOCK_SIZE;
402 }
348 403
349 if (ret) 404 if (ret)
350 count = ret; 405 count = ret;
@@ -444,6 +499,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section,
444 struct sys_device *sysdev; 499 struct sys_device *sysdev;
445 struct memory_block *mem; 500 struct memory_block *mem;
446 char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1]; 501 char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1];
502 int block_id = base_memory_block_id(__section_nr(section));
447 503
448 kobj = hint ? &hint->sysdev.kobj : NULL; 504 kobj = hint ? &hint->sysdev.kobj : NULL;
449 505
@@ -451,7 +507,7 @@ struct memory_block *find_memory_block_hinted(struct mem_section *section,
451 * This only works because we know that section == sysdev->id 507 * This only works because we know that section == sysdev->id
452 * slightly redundant with sysdev_register() 508 * slightly redundant with sysdev_register()
453 */ 509 */
454 sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, __section_nr(section)); 510 sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, block_id);
455 511
456 kobj = kset_find_obj_hinted(&memory_sysdev_class.kset, name, kobj); 512 kobj = kset_find_obj_hinted(&memory_sysdev_class.kset, name, kobj);
457 if (!kobj) 513 if (!kobj)
@@ -476,36 +532,62 @@ struct memory_block *find_memory_block(struct mem_section *section)
476 return find_memory_block_hinted(section, NULL); 532 return find_memory_block_hinted(section, NULL);
477} 533}
478 534
479static int add_memory_block(int nid, struct mem_section *section, 535static int init_memory_block(struct memory_block **memory,
480 unsigned long state, enum mem_add_context context) 536 struct mem_section *section, unsigned long state)
481{ 537{
482 struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL); 538 struct memory_block *mem;
483 unsigned long start_pfn; 539 unsigned long start_pfn;
540 int scn_nr;
484 int ret = 0; 541 int ret = 0;
485 542
543 mem = kzalloc(sizeof(*mem), GFP_KERNEL);
486 if (!mem) 544 if (!mem)
487 return -ENOMEM; 545 return -ENOMEM;
488 546
489 mutex_lock(&mem_sysfs_mutex); 547 scn_nr = __section_nr(section);
490 548 mem->start_section_nr =
491 mem->phys_index = __section_nr(section); 549 base_memory_block_id(scn_nr) * sections_per_block;
550 mem->end_section_nr = mem->start_section_nr + sections_per_block - 1;
492 mem->state = state; 551 mem->state = state;
493 mem->section_count++; 552 mem->section_count++;
494 mutex_init(&mem->state_mutex); 553 mutex_init(&mem->state_mutex);
495 start_pfn = section_nr_to_pfn(mem->phys_index); 554 start_pfn = section_nr_to_pfn(mem->start_section_nr);
496 mem->phys_device = arch_get_memory_phys_device(start_pfn); 555 mem->phys_device = arch_get_memory_phys_device(start_pfn);
497 556
498 ret = register_memory(mem, section); 557 ret = register_memory(mem);
499 if (!ret) 558 if (!ret)
500 ret = mem_create_simple_file(mem, phys_index); 559 ret = mem_create_simple_file(mem, phys_index);
501 if (!ret) 560 if (!ret)
561 ret = mem_create_simple_file(mem, end_phys_index);
562 if (!ret)
502 ret = mem_create_simple_file(mem, state); 563 ret = mem_create_simple_file(mem, state);
503 if (!ret) 564 if (!ret)
504 ret = mem_create_simple_file(mem, phys_device); 565 ret = mem_create_simple_file(mem, phys_device);
505 if (!ret) 566 if (!ret)
506 ret = mem_create_simple_file(mem, removable); 567 ret = mem_create_simple_file(mem, removable);
568
569 *memory = mem;
570 return ret;
571}
572
573static int add_memory_section(int nid, struct mem_section *section,
574 unsigned long state, enum mem_add_context context)
575{
576 struct memory_block *mem;
577 int ret = 0;
578
579 mutex_lock(&mem_sysfs_mutex);
580
581 mem = find_memory_block(section);
582 if (mem) {
583 mem->section_count++;
584 kobject_put(&mem->sysdev.kobj);
585 } else
586 ret = init_memory_block(&mem, section, state);
587
507 if (!ret) { 588 if (!ret) {
508 if (context == HOTPLUG) 589 if (context == HOTPLUG &&
590 mem->section_count == sections_per_block)
509 ret = register_mem_sect_under_node(mem, nid); 591 ret = register_mem_sect_under_node(mem, nid);
510 } 592 }
511 593
@@ -520,16 +602,19 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
520 602
521 mutex_lock(&mem_sysfs_mutex); 603 mutex_lock(&mem_sysfs_mutex);
522 mem = find_memory_block(section); 604 mem = find_memory_block(section);
605 unregister_mem_sect_under_nodes(mem, __section_nr(section));
523 606
524 mem->section_count--; 607 mem->section_count--;
525 if (mem->section_count == 0) { 608 if (mem->section_count == 0) {
526 unregister_mem_sect_under_nodes(mem);
527 mem_remove_simple_file(mem, phys_index); 609 mem_remove_simple_file(mem, phys_index);
610 mem_remove_simple_file(mem, end_phys_index);
528 mem_remove_simple_file(mem, state); 611 mem_remove_simple_file(mem, state);
529 mem_remove_simple_file(mem, phys_device); 612 mem_remove_simple_file(mem, phys_device);
530 mem_remove_simple_file(mem, removable); 613 mem_remove_simple_file(mem, removable);
531 unregister_memory(mem, section); 614 unregister_memory(mem);
532 } 615 kfree(mem);
616 } else
617 kobject_put(&mem->sysdev.kobj);
533 618
534 mutex_unlock(&mem_sysfs_mutex); 619 mutex_unlock(&mem_sysfs_mutex);
535 return 0; 620 return 0;
@@ -541,7 +626,7 @@ int remove_memory_block(unsigned long node_id, struct mem_section *section,
541 */ 626 */
542int register_new_memory(int nid, struct mem_section *section) 627int register_new_memory(int nid, struct mem_section *section)
543{ 628{
544 return add_memory_block(nid, section, MEM_OFFLINE, HOTPLUG); 629 return add_memory_section(nid, section, MEM_OFFLINE, HOTPLUG);
545} 630}
546 631
547int unregister_memory_section(struct mem_section *section) 632int unregister_memory_section(struct mem_section *section)
@@ -560,12 +645,16 @@ int __init memory_dev_init(void)
560 unsigned int i; 645 unsigned int i;
561 int ret; 646 int ret;
562 int err; 647 int err;
648 unsigned long block_sz;
563 649
564 memory_sysdev_class.kset.uevent_ops = &memory_uevent_ops; 650 memory_sysdev_class.kset.uevent_ops = &memory_uevent_ops;
565 ret = sysdev_class_register(&memory_sysdev_class); 651 ret = sysdev_class_register(&memory_sysdev_class);
566 if (ret) 652 if (ret)
567 goto out; 653 goto out;
568 654
655 block_sz = get_memory_block_size();
656 sections_per_block = block_sz / MIN_MEMORY_BLOCK_SIZE;
657
569 /* 658 /*
570 * Create entries for memory sections that were found 659 * Create entries for memory sections that were found
571 * during boot and have been initialized 660 * during boot and have been initialized
@@ -573,8 +662,8 @@ int __init memory_dev_init(void)
573 for (i = 0; i < NR_MEM_SECTIONS; i++) { 662 for (i = 0; i < NR_MEM_SECTIONS; i++) {
574 if (!present_section_nr(i)) 663 if (!present_section_nr(i))
575 continue; 664 continue;
576 err = add_memory_block(0, __nr_to_section(i), MEM_ONLINE, 665 err = add_memory_section(0, __nr_to_section(i), MEM_ONLINE,
577 BOOT); 666 BOOT);
578 if (!ret) 667 if (!ret)
579 ret = err; 668 ret = err;
580 } 669 }
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 36b43052001d..b3b72d64e805 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -375,8 +375,10 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
375 return -EFAULT; 375 return -EFAULT;
376 if (!node_online(nid)) 376 if (!node_online(nid))
377 return 0; 377 return 0;
378 sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index); 378
379 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; 379 sect_start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
380 sect_end_pfn = section_nr_to_pfn(mem_blk->end_section_nr);
381 sect_end_pfn += PAGES_PER_SECTION - 1;
380 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { 382 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
381 int page_nid; 383 int page_nid;
382 384
@@ -400,7 +402,8 @@ int register_mem_sect_under_node(struct memory_block *mem_blk, int nid)
400} 402}
401 403
402/* unregister memory section under all nodes that it spans */ 404/* unregister memory section under all nodes that it spans */
403int unregister_mem_sect_under_nodes(struct memory_block *mem_blk) 405int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
406 unsigned long phys_index)
404{ 407{
405 NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); 408 NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL);
406 unsigned long pfn, sect_start_pfn, sect_end_pfn; 409 unsigned long pfn, sect_start_pfn, sect_end_pfn;
@@ -412,7 +415,8 @@ int unregister_mem_sect_under_nodes(struct memory_block *mem_blk)
412 if (!unlinked_nodes) 415 if (!unlinked_nodes)
413 return -ENOMEM; 416 return -ENOMEM;
414 nodes_clear(*unlinked_nodes); 417 nodes_clear(*unlinked_nodes);
415 sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index); 418
419 sect_start_pfn = section_nr_to_pfn(phys_index);
416 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; 420 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1;
417 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { 421 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) {
418 int nid; 422 int nid;
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index 1667aaf4fde6..f6fb54741602 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -166,6 +166,36 @@ EXPORT_SYMBOL_GPL(sysdev_class_unregister);
166 166
167static DEFINE_MUTEX(sysdev_drivers_lock); 167static DEFINE_MUTEX(sysdev_drivers_lock);
168 168
169/*
170 * @dev != NULL means that we're unwinding because some drv->add()
171 * failed for some reason. You need to grab sysdev_drivers_lock before
172 * calling this.
173 */
174static void __sysdev_driver_remove(struct sysdev_class *cls,
175 struct sysdev_driver *drv,
176 struct sys_device *from_dev)
177{
178 struct sys_device *dev = from_dev;
179
180 list_del_init(&drv->entry);
181 if (!cls)
182 return;
183
184 if (!drv->remove)
185 goto kset_put;
186
187 if (dev)
188 list_for_each_entry_continue_reverse(dev, &cls->kset.list,
189 kobj.entry)
190 drv->remove(dev);
191 else
192 list_for_each_entry(dev, &cls->kset.list, kobj.entry)
193 drv->remove(dev);
194
195kset_put:
196 kset_put(&cls->kset);
197}
198
169/** 199/**
170 * sysdev_driver_register - Register auxillary driver 200 * sysdev_driver_register - Register auxillary driver
171 * @cls: Device class driver belongs to. 201 * @cls: Device class driver belongs to.
@@ -175,14 +205,14 @@ static DEFINE_MUTEX(sysdev_drivers_lock);
175 * called on each operation on devices of that class. The refcount 205 * called on each operation on devices of that class. The refcount
176 * of @cls is incremented. 206 * of @cls is incremented.
177 */ 207 */
178
179int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) 208int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv)
180{ 209{
210 struct sys_device *dev = NULL;
181 int err = 0; 211 int err = 0;
182 212
183 if (!cls) { 213 if (!cls) {
184 WARN(1, KERN_WARNING "sysdev: invalid class passed to " 214 WARN(1, KERN_WARNING "sysdev: invalid class passed to %s!\n",
185 "sysdev_driver_register!\n"); 215 __func__);
186 return -EINVAL; 216 return -EINVAL;
187 } 217 }
188 218
@@ -198,19 +228,27 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv)
198 228
199 /* If devices of this class already exist, tell the driver */ 229 /* If devices of this class already exist, tell the driver */
200 if (drv->add) { 230 if (drv->add) {
201 struct sys_device *dev; 231 list_for_each_entry(dev, &cls->kset.list, kobj.entry) {
202 list_for_each_entry(dev, &cls->kset.list, kobj.entry) 232 err = drv->add(dev);
203 drv->add(dev); 233 if (err)
234 goto unwind;
235 }
204 } 236 }
205 } else { 237 } else {
206 err = -EINVAL; 238 err = -EINVAL;
207 WARN(1, KERN_ERR "%s: invalid device class\n", __func__); 239 WARN(1, KERN_ERR "%s: invalid device class\n", __func__);
208 } 240 }
241
242 goto unlock;
243
244unwind:
245 __sysdev_driver_remove(cls, drv, dev);
246
247unlock:
209 mutex_unlock(&sysdev_drivers_lock); 248 mutex_unlock(&sysdev_drivers_lock);
210 return err; 249 return err;
211} 250}
212 251
213
214/** 252/**
215 * sysdev_driver_unregister - Remove an auxillary driver. 253 * sysdev_driver_unregister - Remove an auxillary driver.
216 * @cls: Class driver belongs to. 254 * @cls: Class driver belongs to.
@@ -220,23 +258,12 @@ void sysdev_driver_unregister(struct sysdev_class *cls,
220 struct sysdev_driver *drv) 258 struct sysdev_driver *drv)
221{ 259{
222 mutex_lock(&sysdev_drivers_lock); 260 mutex_lock(&sysdev_drivers_lock);
223 list_del_init(&drv->entry); 261 __sysdev_driver_remove(cls, drv, NULL);
224 if (cls) {
225 if (drv->remove) {
226 struct sys_device *dev;
227 list_for_each_entry(dev, &cls->kset.list, kobj.entry)
228 drv->remove(dev);
229 }
230 kset_put(&cls->kset);
231 }
232 mutex_unlock(&sysdev_drivers_lock); 262 mutex_unlock(&sysdev_drivers_lock);
233} 263}
234
235EXPORT_SYMBOL_GPL(sysdev_driver_register); 264EXPORT_SYMBOL_GPL(sysdev_driver_register);
236EXPORT_SYMBOL_GPL(sysdev_driver_unregister); 265EXPORT_SYMBOL_GPL(sysdev_driver_unregister);
237 266
238
239
240/** 267/**
241 * sysdev_register - add a system device to the tree 268 * sysdev_register - add a system device to the tree
242 * @sysdev: device in question 269 * @sysdev: device in question
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig
index e710424b59ea..3c56afc5eb1b 100644
--- a/drivers/firmware/Kconfig
+++ b/drivers/firmware/Kconfig
@@ -113,6 +113,17 @@ config DMIID
113 information from userspace through /sys/class/dmi/id/ or if you want 113 information from userspace through /sys/class/dmi/id/ or if you want
114 DMI-based module auto-loading. 114 DMI-based module auto-loading.
115 115
116config DMI_SYSFS
117 tristate "DMI table support in sysfs"
118 depends on SYSFS && DMI
119 default n
120 help
121 Say Y or M here to enable the exporting of the raw DMI table
122 data via sysfs. This is useful for consuming the data without
123 requiring any access to /dev/mem at all. Tables are found
124 under /sys/firmware/dmi when this option is enabled and
125 loaded.
126
116config ISCSI_IBFT_FIND 127config ISCSI_IBFT_FIND
117 bool "iSCSI Boot Firmware Table Attributes" 128 bool "iSCSI Boot Firmware Table Attributes"
118 depends on X86 129 depends on X86
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile
index 1c3c17343dbe..20c17fca1232 100644
--- a/drivers/firmware/Makefile
+++ b/drivers/firmware/Makefile
@@ -2,6 +2,7 @@
2# Makefile for the linux kernel. 2# Makefile for the linux kernel.
3# 3#
4obj-$(CONFIG_DMI) += dmi_scan.o 4obj-$(CONFIG_DMI) += dmi_scan.o
5obj-$(CONFIG_DMI_SYSFS) += dmi-sysfs.o
5obj-$(CONFIG_EDD) += edd.o 6obj-$(CONFIG_EDD) += edd.o
6obj-$(CONFIG_EFI_VARS) += efivars.o 7obj-$(CONFIG_EFI_VARS) += efivars.o
7obj-$(CONFIG_EFI_PCDP) += pcdp.o 8obj-$(CONFIG_EFI_PCDP) += pcdp.o
diff --git a/drivers/firmware/dmi-sysfs.c b/drivers/firmware/dmi-sysfs.c
new file mode 100644
index 000000000000..eb26d62e5188
--- /dev/null
+++ b/drivers/firmware/dmi-sysfs.c
@@ -0,0 +1,696 @@
1/*
2 * dmi-sysfs.c
3 *
4 * This module exports the DMI tables read-only to userspace through the
5 * sysfs file system.
6 *
7 * Data is currently found below
8 * /sys/firmware/dmi/...
9 *
10 * DMI attributes are presented in attribute files with names
11 * formatted using %d-%d, so that the first integer indicates the
12 * structure type (0-255), and the second field is the instance of that
13 * entry.
14 *
15 * Copyright 2011 Google, Inc.
16 */
17
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/types.h>
22#include <linux/kobject.h>
23#include <linux/dmi.h>
24#include <linux/capability.h>
25#include <linux/slab.h>
26#include <linux/list.h>
27#include <linux/io.h>
28
29#define MAX_ENTRY_TYPE 255 /* Most of these aren't used, but we consider
30 the top entry type is only 8 bits */
31
32struct dmi_sysfs_entry {
33 struct dmi_header dh;
34 struct kobject kobj;
35 int instance;
36 int position;
37 struct list_head list;
38 struct kobject *child;
39};
40
41/*
42 * Global list of dmi_sysfs_entry. Even though this should only be
43 * manipulated at setup and teardown, the lazy nature of the kobject
44 * system means we get lazy removes.
45 */
46static LIST_HEAD(entry_list);
47static DEFINE_SPINLOCK(entry_list_lock);
48
49/* dmi_sysfs_attribute - Top level attribute. used by all entries. */
50struct dmi_sysfs_attribute {
51 struct attribute attr;
52 ssize_t (*show)(struct dmi_sysfs_entry *entry, char *buf);
53};
54
55#define DMI_SYSFS_ATTR(_entry, _name) \
56struct dmi_sysfs_attribute dmi_sysfs_attr_##_entry##_##_name = { \
57 .attr = {.name = __stringify(_name), .mode = 0400}, \
58 .show = dmi_sysfs_##_entry##_##_name, \
59}
60
61/*
62 * dmi_sysfs_mapped_attribute - Attribute where we require the entry be
63 * mapped in. Use in conjunction with dmi_sysfs_specialize_attr_ops.
64 */
65struct dmi_sysfs_mapped_attribute {
66 struct attribute attr;
67 ssize_t (*show)(struct dmi_sysfs_entry *entry,
68 const struct dmi_header *dh,
69 char *buf);
70};
71
72#define DMI_SYSFS_MAPPED_ATTR(_entry, _name) \
73struct dmi_sysfs_mapped_attribute dmi_sysfs_attr_##_entry##_##_name = { \
74 .attr = {.name = __stringify(_name), .mode = 0400}, \
75 .show = dmi_sysfs_##_entry##_##_name, \
76}
77
78/*************************************************
79 * Generic DMI entry support.
80 *************************************************/
81static void dmi_entry_free(struct kobject *kobj)
82{
83 kfree(kobj);
84}
85
86static struct dmi_sysfs_entry *to_entry(struct kobject *kobj)
87{
88 return container_of(kobj, struct dmi_sysfs_entry, kobj);
89}
90
91static struct dmi_sysfs_attribute *to_attr(struct attribute *attr)
92{
93 return container_of(attr, struct dmi_sysfs_attribute, attr);
94}
95
96static ssize_t dmi_sysfs_attr_show(struct kobject *kobj,
97 struct attribute *_attr, char *buf)
98{
99 struct dmi_sysfs_entry *entry = to_entry(kobj);
100 struct dmi_sysfs_attribute *attr = to_attr(_attr);
101
102 /* DMI stuff is only ever admin visible */
103 if (!capable(CAP_SYS_ADMIN))
104 return -EACCES;
105
106 return attr->show(entry, buf);
107}
108
109static const struct sysfs_ops dmi_sysfs_attr_ops = {
110 .show = dmi_sysfs_attr_show,
111};
112
113typedef ssize_t (*dmi_callback)(struct dmi_sysfs_entry *,
114 const struct dmi_header *dh, void *);
115
116struct find_dmi_data {
117 struct dmi_sysfs_entry *entry;
118 dmi_callback callback;
119 void *private;
120 int instance_countdown;
121 ssize_t ret;
122};
123
124static void find_dmi_entry_helper(const struct dmi_header *dh,
125 void *_data)
126{
127 struct find_dmi_data *data = _data;
128 struct dmi_sysfs_entry *entry = data->entry;
129
130 /* Is this the entry we want? */
131 if (dh->type != entry->dh.type)
132 return;
133
134 if (data->instance_countdown != 0) {
135 /* try the next instance? */
136 data->instance_countdown--;
137 return;
138 }
139
140 /*
141 * Don't ever revisit the instance. Short circuit later
142 * instances by letting the instance_countdown run negative
143 */
144 data->instance_countdown--;
145
146 /* Found the entry */
147 data->ret = data->callback(entry, dh, data->private);
148}
149
150/* State for passing the read parameters through dmi_find_entry() */
151struct dmi_read_state {
152 char *buf;
153 loff_t pos;
154 size_t count;
155};
156
157static ssize_t find_dmi_entry(struct dmi_sysfs_entry *entry,
158 dmi_callback callback, void *private)
159{
160 struct find_dmi_data data = {
161 .entry = entry,
162 .callback = callback,
163 .private = private,
164 .instance_countdown = entry->instance,
165 .ret = -EIO, /* To signal the entry disappeared */
166 };
167 int ret;
168
169 ret = dmi_walk(find_dmi_entry_helper, &data);
170 /* This shouldn't happen, but just in case. */
171 if (ret)
172 return -EINVAL;
173 return data.ret;
174}
175
176/*
177 * Calculate and return the byte length of the dmi entry identified by
178 * dh. This includes both the formatted portion as well as the
179 * unformatted string space, including the two trailing nul characters.
180 */
181static size_t dmi_entry_length(const struct dmi_header *dh)
182{
183 const char *p = (const char *)dh;
184
185 p += dh->length;
186
187 while (p[0] || p[1])
188 p++;
189
190 return 2 + p - (const char *)dh;
191}
192
193/*************************************************
194 * Support bits for specialized DMI entry support
195 *************************************************/
196struct dmi_entry_attr_show_data {
197 struct attribute *attr;
198 char *buf;
199};
200
201static ssize_t dmi_entry_attr_show_helper(struct dmi_sysfs_entry *entry,
202 const struct dmi_header *dh,
203 void *_data)
204{
205 struct dmi_entry_attr_show_data *data = _data;
206 struct dmi_sysfs_mapped_attribute *attr;
207
208 attr = container_of(data->attr,
209 struct dmi_sysfs_mapped_attribute, attr);
210 return attr->show(entry, dh, data->buf);
211}
212
213static ssize_t dmi_entry_attr_show(struct kobject *kobj,
214 struct attribute *attr,
215 char *buf)
216{
217 struct dmi_entry_attr_show_data data = {
218 .attr = attr,
219 .buf = buf,
220 };
221 /* Find the entry according to our parent and call the
222 * normalized show method hanging off of the attribute */
223 return find_dmi_entry(to_entry(kobj->parent),
224 dmi_entry_attr_show_helper, &data);
225}
226
227static const struct sysfs_ops dmi_sysfs_specialize_attr_ops = {
228 .show = dmi_entry_attr_show,
229};
230
231/*************************************************
232 * Specialized DMI entry support.
233 *************************************************/
234
235/*** Type 15 - System Event Table ***/
236
237#define DMI_SEL_ACCESS_METHOD_IO8 0x00
238#define DMI_SEL_ACCESS_METHOD_IO2x8 0x01
239#define DMI_SEL_ACCESS_METHOD_IO16 0x02
240#define DMI_SEL_ACCESS_METHOD_PHYS32 0x03
241#define DMI_SEL_ACCESS_METHOD_GPNV 0x04
242
243struct dmi_system_event_log {
244 struct dmi_header header;
245 u16 area_length;
246 u16 header_start_offset;
247 u16 data_start_offset;
248 u8 access_method;
249 u8 status;
250 u32 change_token;
251 union {
252 struct {
253 u16 index_addr;
254 u16 data_addr;
255 } io;
256 u32 phys_addr32;
257 u16 gpnv_handle;
258 u32 access_method_address;
259 };
260 u8 header_format;
261 u8 type_descriptors_supported_count;
262 u8 per_log_type_descriptor_length;
263 u8 supported_log_type_descriptos[0];
264} __packed;
265
266#define DMI_SYSFS_SEL_FIELD(_field) \
267static ssize_t dmi_sysfs_sel_##_field(struct dmi_sysfs_entry *entry, \
268 const struct dmi_header *dh, \
269 char *buf) \
270{ \
271 struct dmi_system_event_log sel; \
272 if (sizeof(sel) > dmi_entry_length(dh)) \
273 return -EIO; \
274 memcpy(&sel, dh, sizeof(sel)); \
275 return sprintf(buf, "%u\n", sel._field); \
276} \
277static DMI_SYSFS_MAPPED_ATTR(sel, _field)
278
279DMI_SYSFS_SEL_FIELD(area_length);
280DMI_SYSFS_SEL_FIELD(header_start_offset);
281DMI_SYSFS_SEL_FIELD(data_start_offset);
282DMI_SYSFS_SEL_FIELD(access_method);
283DMI_SYSFS_SEL_FIELD(status);
284DMI_SYSFS_SEL_FIELD(change_token);
285DMI_SYSFS_SEL_FIELD(access_method_address);
286DMI_SYSFS_SEL_FIELD(header_format);
287DMI_SYSFS_SEL_FIELD(type_descriptors_supported_count);
288DMI_SYSFS_SEL_FIELD(per_log_type_descriptor_length);
289
290static struct attribute *dmi_sysfs_sel_attrs[] = {
291 &dmi_sysfs_attr_sel_area_length.attr,
292 &dmi_sysfs_attr_sel_header_start_offset.attr,
293 &dmi_sysfs_attr_sel_data_start_offset.attr,
294 &dmi_sysfs_attr_sel_access_method.attr,
295 &dmi_sysfs_attr_sel_status.attr,
296 &dmi_sysfs_attr_sel_change_token.attr,
297 &dmi_sysfs_attr_sel_access_method_address.attr,
298 &dmi_sysfs_attr_sel_header_format.attr,
299 &dmi_sysfs_attr_sel_type_descriptors_supported_count.attr,
300 &dmi_sysfs_attr_sel_per_log_type_descriptor_length.attr,
301 NULL,
302};
303
304
305static struct kobj_type dmi_system_event_log_ktype = {
306 .release = dmi_entry_free,
307 .sysfs_ops = &dmi_sysfs_specialize_attr_ops,
308 .default_attrs = dmi_sysfs_sel_attrs,
309};
310
311typedef u8 (*sel_io_reader)(const struct dmi_system_event_log *sel,
312 loff_t offset);
313
314static DEFINE_MUTEX(io_port_lock);
315
316static u8 read_sel_8bit_indexed_io(const struct dmi_system_event_log *sel,
317 loff_t offset)
318{
319 u8 ret;
320
321 mutex_lock(&io_port_lock);
322 outb((u8)offset, sel->io.index_addr);
323 ret = inb(sel->io.data_addr);
324 mutex_unlock(&io_port_lock);
325 return ret;
326}
327
328static u8 read_sel_2x8bit_indexed_io(const struct dmi_system_event_log *sel,
329 loff_t offset)
330{
331 u8 ret;
332
333 mutex_lock(&io_port_lock);
334 outb((u8)offset, sel->io.index_addr);
335 outb((u8)(offset >> 8), sel->io.index_addr + 1);
336 ret = inb(sel->io.data_addr);
337 mutex_unlock(&io_port_lock);
338 return ret;
339}
340
341static u8 read_sel_16bit_indexed_io(const struct dmi_system_event_log *sel,
342 loff_t offset)
343{
344 u8 ret;
345
346 mutex_lock(&io_port_lock);
347 outw((u16)offset, sel->io.index_addr);
348 ret = inb(sel->io.data_addr);
349 mutex_unlock(&io_port_lock);
350 return ret;
351}
352
353static sel_io_reader sel_io_readers[] = {
354 [DMI_SEL_ACCESS_METHOD_IO8] = read_sel_8bit_indexed_io,
355 [DMI_SEL_ACCESS_METHOD_IO2x8] = read_sel_2x8bit_indexed_io,
356 [DMI_SEL_ACCESS_METHOD_IO16] = read_sel_16bit_indexed_io,
357};
358
359static ssize_t dmi_sel_raw_read_io(struct dmi_sysfs_entry *entry,
360 const struct dmi_system_event_log *sel,
361 char *buf, loff_t pos, size_t count)
362{
363 ssize_t wrote = 0;
364
365 sel_io_reader io_reader = sel_io_readers[sel->access_method];
366
367 while (count && pos < sel->area_length) {
368 count--;
369 *(buf++) = io_reader(sel, pos++);
370 wrote++;
371 }
372
373 return wrote;
374}
375
376static ssize_t dmi_sel_raw_read_phys32(struct dmi_sysfs_entry *entry,
377 const struct dmi_system_event_log *sel,
378 char *buf, loff_t pos, size_t count)
379{
380 u8 __iomem *mapped;
381 ssize_t wrote = 0;
382
383 mapped = ioremap(sel->access_method_address, sel->area_length);
384 if (!mapped)
385 return -EIO;
386
387 while (count && pos < sel->area_length) {
388 count--;
389 *(buf++) = readb(mapped + pos++);
390 wrote++;
391 }
392
393 iounmap(mapped);
394 return wrote;
395}
396
397static ssize_t dmi_sel_raw_read_helper(struct dmi_sysfs_entry *entry,
398 const struct dmi_header *dh,
399 void *_state)
400{
401 struct dmi_read_state *state = _state;
402 struct dmi_system_event_log sel;
403
404 if (sizeof(sel) > dmi_entry_length(dh))
405 return -EIO;
406
407 memcpy(&sel, dh, sizeof(sel));
408
409 switch (sel.access_method) {
410 case DMI_SEL_ACCESS_METHOD_IO8:
411 case DMI_SEL_ACCESS_METHOD_IO2x8:
412 case DMI_SEL_ACCESS_METHOD_IO16:
413 return dmi_sel_raw_read_io(entry, &sel, state->buf,
414 state->pos, state->count);
415 case DMI_SEL_ACCESS_METHOD_PHYS32:
416 return dmi_sel_raw_read_phys32(entry, &sel, state->buf,
417 state->pos, state->count);
418 case DMI_SEL_ACCESS_METHOD_GPNV:
419 pr_info("dmi-sysfs: GPNV support missing.\n");
420 return -EIO;
421 default:
422 pr_info("dmi-sysfs: Unknown access method %02x\n",
423 sel.access_method);
424 return -EIO;
425 }
426}
427
428static ssize_t dmi_sel_raw_read(struct file *filp, struct kobject *kobj,
429 struct bin_attribute *bin_attr,
430 char *buf, loff_t pos, size_t count)
431{
432 struct dmi_sysfs_entry *entry = to_entry(kobj->parent);
433 struct dmi_read_state state = {
434 .buf = buf,
435 .pos = pos,
436 .count = count,
437 };
438
439 return find_dmi_entry(entry, dmi_sel_raw_read_helper, &state);
440}
441
442static struct bin_attribute dmi_sel_raw_attr = {
443 .attr = {.name = "raw_event_log", .mode = 0400},
444 .read = dmi_sel_raw_read,
445};
446
447static int dmi_system_event_log(struct dmi_sysfs_entry *entry)
448{
449 int ret;
450
451 entry->child = kzalloc(sizeof(*entry->child), GFP_KERNEL);
452 if (!entry->child)
453 return -ENOMEM;
454 ret = kobject_init_and_add(entry->child,
455 &dmi_system_event_log_ktype,
456 &entry->kobj,
457 "system_event_log");
458 if (ret)
459 goto out_free;
460
461 ret = sysfs_create_bin_file(entry->child, &dmi_sel_raw_attr);
462 if (ret)
463 goto out_del;
464
465 return 0;
466
467out_del:
468 kobject_del(entry->child);
469out_free:
470 kfree(entry->child);
471 return ret;
472}
473
474/*************************************************
475 * Generic DMI entry support.
476 *************************************************/
477
478static ssize_t dmi_sysfs_entry_length(struct dmi_sysfs_entry *entry, char *buf)
479{
480 return sprintf(buf, "%d\n", entry->dh.length);
481}
482
483static ssize_t dmi_sysfs_entry_handle(struct dmi_sysfs_entry *entry, char *buf)
484{
485 return sprintf(buf, "%d\n", entry->dh.handle);
486}
487
488static ssize_t dmi_sysfs_entry_type(struct dmi_sysfs_entry *entry, char *buf)
489{
490 return sprintf(buf, "%d\n", entry->dh.type);
491}
492
493static ssize_t dmi_sysfs_entry_instance(struct dmi_sysfs_entry *entry,
494 char *buf)
495{
496 return sprintf(buf, "%d\n", entry->instance);
497}
498
499static ssize_t dmi_sysfs_entry_position(struct dmi_sysfs_entry *entry,
500 char *buf)
501{
502 return sprintf(buf, "%d\n", entry->position);
503}
504
505static DMI_SYSFS_ATTR(entry, length);
506static DMI_SYSFS_ATTR(entry, handle);
507static DMI_SYSFS_ATTR(entry, type);
508static DMI_SYSFS_ATTR(entry, instance);
509static DMI_SYSFS_ATTR(entry, position);
510
511static struct attribute *dmi_sysfs_entry_attrs[] = {
512 &dmi_sysfs_attr_entry_length.attr,
513 &dmi_sysfs_attr_entry_handle.attr,
514 &dmi_sysfs_attr_entry_type.attr,
515 &dmi_sysfs_attr_entry_instance.attr,
516 &dmi_sysfs_attr_entry_position.attr,
517 NULL,
518};
519
520static ssize_t dmi_entry_raw_read_helper(struct dmi_sysfs_entry *entry,
521 const struct dmi_header *dh,
522 void *_state)
523{
524 struct dmi_read_state *state = _state;
525 size_t entry_length;
526
527 entry_length = dmi_entry_length(dh);
528
529 return memory_read_from_buffer(state->buf, state->count,
530 &state->pos, dh, entry_length);
531}
532
533static ssize_t dmi_entry_raw_read(struct file *filp,
534 struct kobject *kobj,
535 struct bin_attribute *bin_attr,
536 char *buf, loff_t pos, size_t count)
537{
538 struct dmi_sysfs_entry *entry = to_entry(kobj);
539 struct dmi_read_state state = {
540 .buf = buf,
541 .pos = pos,
542 .count = count,
543 };
544
545 return find_dmi_entry(entry, dmi_entry_raw_read_helper, &state);
546}
547
548static const struct bin_attribute dmi_entry_raw_attr = {
549 .attr = {.name = "raw", .mode = 0400},
550 .read = dmi_entry_raw_read,
551};
552
553static void dmi_sysfs_entry_release(struct kobject *kobj)
554{
555 struct dmi_sysfs_entry *entry = to_entry(kobj);
556 sysfs_remove_bin_file(&entry->kobj, &dmi_entry_raw_attr);
557 spin_lock(&entry_list_lock);
558 list_del(&entry->list);
559 spin_unlock(&entry_list_lock);
560 kfree(entry);
561}
562
563static struct kobj_type dmi_sysfs_entry_ktype = {
564 .release = dmi_sysfs_entry_release,
565 .sysfs_ops = &dmi_sysfs_attr_ops,
566 .default_attrs = dmi_sysfs_entry_attrs,
567};
568
569static struct kobject *dmi_kobj;
570static struct kset *dmi_kset;
571
572/* Global count of all instances seen. Only for setup */
573static int __initdata instance_counts[MAX_ENTRY_TYPE + 1];
574
575/* Global positional count of all entries seen. Only for setup */
576static int __initdata position_count;
577
578static void __init dmi_sysfs_register_handle(const struct dmi_header *dh,
579 void *_ret)
580{
581 struct dmi_sysfs_entry *entry;
582 int *ret = _ret;
583
584 /* If a previous entry saw an error, short circuit */
585 if (*ret)
586 return;
587
588 /* Allocate and register a new entry into the entries set */
589 entry = kzalloc(sizeof(*entry), GFP_KERNEL);
590 if (!entry) {
591 *ret = -ENOMEM;
592 return;
593 }
594
595 /* Set the key */
596 memcpy(&entry->dh, dh, sizeof(*dh));
597 entry->instance = instance_counts[dh->type]++;
598 entry->position = position_count++;
599
600 entry->kobj.kset = dmi_kset;
601 *ret = kobject_init_and_add(&entry->kobj, &dmi_sysfs_entry_ktype, NULL,
602 "%d-%d", dh->type, entry->instance);
603
604 if (*ret) {
605 kfree(entry);
606 return;
607 }
608
609 /* Thread on the global list for cleanup */
610 spin_lock(&entry_list_lock);
611 list_add_tail(&entry->list, &entry_list);
612 spin_unlock(&entry_list_lock);
613
614 /* Handle specializations by type */
615 switch (dh->type) {
616 case DMI_ENTRY_SYSTEM_EVENT_LOG:
617 *ret = dmi_system_event_log(entry);
618 break;
619 default:
620 /* No specialization */
621 break;
622 }
623 if (*ret)
624 goto out_err;
625
626 /* Create the raw binary file to access the entry */
627 *ret = sysfs_create_bin_file(&entry->kobj, &dmi_entry_raw_attr);
628 if (*ret)
629 goto out_err;
630
631 return;
632out_err:
633 kobject_put(entry->child);
634 kobject_put(&entry->kobj);
635 return;
636}
637
638static void cleanup_entry_list(void)
639{
640 struct dmi_sysfs_entry *entry, *next;
641
642 /* No locks, we are on our way out */
643 list_for_each_entry_safe(entry, next, &entry_list, list) {
644 kobject_put(entry->child);
645 kobject_put(&entry->kobj);
646 }
647}
648
649static int __init dmi_sysfs_init(void)
650{
651 int error = -ENOMEM;
652 int val;
653
654 /* Set up our directory */
655 dmi_kobj = kobject_create_and_add("dmi", firmware_kobj);
656 if (!dmi_kobj)
657 goto err;
658
659 dmi_kset = kset_create_and_add("entries", NULL, dmi_kobj);
660 if (!dmi_kset)
661 goto err;
662
663 val = 0;
664 error = dmi_walk(dmi_sysfs_register_handle, &val);
665 if (error)
666 goto err;
667 if (val) {
668 error = val;
669 goto err;
670 }
671
672 pr_debug("dmi-sysfs: loaded.\n");
673
674 return 0;
675err:
676 cleanup_entry_list();
677 kset_unregister(dmi_kset);
678 kobject_put(dmi_kobj);
679 return error;
680}
681
682/* clean up everything. */
683static void __exit dmi_sysfs_exit(void)
684{
685 pr_debug("dmi-sysfs: unloading.\n");
686 cleanup_entry_list();
687 kset_unregister(dmi_kset);
688 kobject_put(dmi_kobj);
689}
690
691module_init(dmi_sysfs_init);
692module_exit(dmi_sysfs_exit);
693
694MODULE_AUTHOR("Mike Waychison <mikew@google.com>");
695MODULE_DESCRIPTION("DMI sysfs support");
696MODULE_LICENSE("GPL");
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
index 2a62ec6390e0..ff0c373e3bbf 100644
--- a/drivers/firmware/efivars.c
+++ b/drivers/firmware/efivars.c
@@ -90,17 +90,6 @@ MODULE_LICENSE("GPL");
90MODULE_VERSION(EFIVARS_VERSION); 90MODULE_VERSION(EFIVARS_VERSION);
91 91
92/* 92/*
93 * efivars_lock protects two things:
94 * 1) efivar_list - adds, removals, reads, writes
95 * 2) efi.[gs]et_variable() calls.
96 * It must not be held when creating sysfs entries or calling kmalloc.
97 * efi.get_next_variable() is only called from efivars_init(),
98 * which is protected by the BKL, so that path is safe.
99 */
100static DEFINE_SPINLOCK(efivars_lock);
101static LIST_HEAD(efivar_list);
102
103/*
104 * The maximum size of VariableName + Data = 1024 93 * The maximum size of VariableName + Data = 1024
105 * Therefore, it's reasonable to save that much 94 * Therefore, it's reasonable to save that much
106 * space in each part of the structure, 95 * space in each part of the structure,
@@ -118,6 +107,7 @@ struct efi_variable {
118 107
119 108
120struct efivar_entry { 109struct efivar_entry {
110 struct efivars *efivars;
121 struct efi_variable var; 111 struct efi_variable var;
122 struct list_head list; 112 struct list_head list;
123 struct kobject kobj; 113 struct kobject kobj;
@@ -144,9 +134,10 @@ struct efivar_attribute efivar_attr_##_name = { \
144 * Prototype for sysfs creation function 134 * Prototype for sysfs creation function
145 */ 135 */
146static int 136static int
147efivar_create_sysfs_entry(unsigned long variable_name_size, 137efivar_create_sysfs_entry(struct efivars *efivars,
148 efi_char16_t *variable_name, 138 unsigned long variable_name_size,
149 efi_guid_t *vendor_guid); 139 efi_char16_t *variable_name,
140 efi_guid_t *vendor_guid);
150 141
151/* Return the number of unicode characters in data */ 142/* Return the number of unicode characters in data */
152static unsigned long 143static unsigned long
@@ -170,18 +161,18 @@ utf8_strsize(efi_char16_t *data, unsigned long maxlength)
170} 161}
171 162
172static efi_status_t 163static efi_status_t
173get_var_data(struct efi_variable *var) 164get_var_data(struct efivars *efivars, struct efi_variable *var)
174{ 165{
175 efi_status_t status; 166 efi_status_t status;
176 167
177 spin_lock(&efivars_lock); 168 spin_lock(&efivars->lock);
178 var->DataSize = 1024; 169 var->DataSize = 1024;
179 status = efi.get_variable(var->VariableName, 170 status = efivars->ops->get_variable(var->VariableName,
180 &var->VendorGuid, 171 &var->VendorGuid,
181 &var->Attributes, 172 &var->Attributes,
182 &var->DataSize, 173 &var->DataSize,
183 var->Data); 174 var->Data);
184 spin_unlock(&efivars_lock); 175 spin_unlock(&efivars->lock);
185 if (status != EFI_SUCCESS) { 176 if (status != EFI_SUCCESS) {
186 printk(KERN_WARNING "efivars: get_variable() failed 0x%lx!\n", 177 printk(KERN_WARNING "efivars: get_variable() failed 0x%lx!\n",
187 status); 178 status);
@@ -215,7 +206,7 @@ efivar_attr_read(struct efivar_entry *entry, char *buf)
215 if (!entry || !buf) 206 if (!entry || !buf)
216 return -EINVAL; 207 return -EINVAL;
217 208
218 status = get_var_data(var); 209 status = get_var_data(entry->efivars, var);
219 if (status != EFI_SUCCESS) 210 if (status != EFI_SUCCESS)
220 return -EIO; 211 return -EIO;
221 212
@@ -238,7 +229,7 @@ efivar_size_read(struct efivar_entry *entry, char *buf)
238 if (!entry || !buf) 229 if (!entry || !buf)
239 return -EINVAL; 230 return -EINVAL;
240 231
241 status = get_var_data(var); 232 status = get_var_data(entry->efivars, var);
242 if (status != EFI_SUCCESS) 233 if (status != EFI_SUCCESS)
243 return -EIO; 234 return -EIO;
244 235
@@ -255,7 +246,7 @@ efivar_data_read(struct efivar_entry *entry, char *buf)
255 if (!entry || !buf) 246 if (!entry || !buf)
256 return -EINVAL; 247 return -EINVAL;
257 248
258 status = get_var_data(var); 249 status = get_var_data(entry->efivars, var);
259 if (status != EFI_SUCCESS) 250 if (status != EFI_SUCCESS)
260 return -EIO; 251 return -EIO;
261 252
@@ -270,6 +261,7 @@ static ssize_t
270efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count) 261efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
271{ 262{
272 struct efi_variable *new_var, *var = &entry->var; 263 struct efi_variable *new_var, *var = &entry->var;
264 struct efivars *efivars = entry->efivars;
273 efi_status_t status = EFI_NOT_FOUND; 265 efi_status_t status = EFI_NOT_FOUND;
274 266
275 if (count != sizeof(struct efi_variable)) 267 if (count != sizeof(struct efi_variable))
@@ -291,14 +283,14 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
291 return -EINVAL; 283 return -EINVAL;
292 } 284 }
293 285
294 spin_lock(&efivars_lock); 286 spin_lock(&efivars->lock);
295 status = efi.set_variable(new_var->VariableName, 287 status = efivars->ops->set_variable(new_var->VariableName,
296 &new_var->VendorGuid, 288 &new_var->VendorGuid,
297 new_var->Attributes, 289 new_var->Attributes,
298 new_var->DataSize, 290 new_var->DataSize,
299 new_var->Data); 291 new_var->Data);
300 292
301 spin_unlock(&efivars_lock); 293 spin_unlock(&efivars->lock);
302 294
303 if (status != EFI_SUCCESS) { 295 if (status != EFI_SUCCESS) {
304 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", 296 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
@@ -319,7 +311,7 @@ efivar_show_raw(struct efivar_entry *entry, char *buf)
319 if (!entry || !buf) 311 if (!entry || !buf)
320 return 0; 312 return 0;
321 313
322 status = get_var_data(var); 314 status = get_var_data(entry->efivars, var);
323 if (status != EFI_SUCCESS) 315 if (status != EFI_SUCCESS)
324 return -EIO; 316 return -EIO;
325 317
@@ -407,6 +399,7 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
407 char *buf, loff_t pos, size_t count) 399 char *buf, loff_t pos, size_t count)
408{ 400{
409 struct efi_variable *new_var = (struct efi_variable *)buf; 401 struct efi_variable *new_var = (struct efi_variable *)buf;
402 struct efivars *efivars = bin_attr->private;
410 struct efivar_entry *search_efivar, *n; 403 struct efivar_entry *search_efivar, *n;
411 unsigned long strsize1, strsize2; 404 unsigned long strsize1, strsize2;
412 efi_status_t status = EFI_NOT_FOUND; 405 efi_status_t status = EFI_NOT_FOUND;
@@ -415,12 +408,12 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
415 if (!capable(CAP_SYS_ADMIN)) 408 if (!capable(CAP_SYS_ADMIN))
416 return -EACCES; 409 return -EACCES;
417 410
418 spin_lock(&efivars_lock); 411 spin_lock(&efivars->lock);
419 412
420 /* 413 /*
421 * Does this variable already exist? 414 * Does this variable already exist?
422 */ 415 */
423 list_for_each_entry_safe(search_efivar, n, &efivar_list, list) { 416 list_for_each_entry_safe(search_efivar, n, &efivars->list, list) {
424 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); 417 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024);
425 strsize2 = utf8_strsize(new_var->VariableName, 1024); 418 strsize2 = utf8_strsize(new_var->VariableName, 1024);
426 if (strsize1 == strsize2 && 419 if (strsize1 == strsize2 &&
@@ -433,28 +426,31 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
433 } 426 }
434 } 427 }
435 if (found) { 428 if (found) {
436 spin_unlock(&efivars_lock); 429 spin_unlock(&efivars->lock);
437 return -EINVAL; 430 return -EINVAL;
438 } 431 }
439 432
440 /* now *really* create the variable via EFI */ 433 /* now *really* create the variable via EFI */
441 status = efi.set_variable(new_var->VariableName, 434 status = efivars->ops->set_variable(new_var->VariableName,
442 &new_var->VendorGuid, 435 &new_var->VendorGuid,
443 new_var->Attributes, 436 new_var->Attributes,
444 new_var->DataSize, 437 new_var->DataSize,
445 new_var->Data); 438 new_var->Data);
446 439
447 if (status != EFI_SUCCESS) { 440 if (status != EFI_SUCCESS) {
448 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", 441 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
449 status); 442 status);
450 spin_unlock(&efivars_lock); 443 spin_unlock(&efivars->lock);
451 return -EIO; 444 return -EIO;
452 } 445 }
453 spin_unlock(&efivars_lock); 446 spin_unlock(&efivars->lock);
454 447
455 /* Create the entry in sysfs. Locking is not required here */ 448 /* Create the entry in sysfs. Locking is not required here */
456 status = efivar_create_sysfs_entry(utf8_strsize(new_var->VariableName, 449 status = efivar_create_sysfs_entry(efivars,
457 1024), new_var->VariableName, &new_var->VendorGuid); 450 utf8_strsize(new_var->VariableName,
451 1024),
452 new_var->VariableName,
453 &new_var->VendorGuid);
458 if (status) { 454 if (status) {
459 printk(KERN_WARNING "efivars: variable created, but sysfs entry wasn't.\n"); 455 printk(KERN_WARNING "efivars: variable created, but sysfs entry wasn't.\n");
460 } 456 }
@@ -466,6 +462,7 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
466 char *buf, loff_t pos, size_t count) 462 char *buf, loff_t pos, size_t count)
467{ 463{
468 struct efi_variable *del_var = (struct efi_variable *)buf; 464 struct efi_variable *del_var = (struct efi_variable *)buf;
465 struct efivars *efivars = bin_attr->private;
469 struct efivar_entry *search_efivar, *n; 466 struct efivar_entry *search_efivar, *n;
470 unsigned long strsize1, strsize2; 467 unsigned long strsize1, strsize2;
471 efi_status_t status = EFI_NOT_FOUND; 468 efi_status_t status = EFI_NOT_FOUND;
@@ -474,12 +471,12 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
474 if (!capable(CAP_SYS_ADMIN)) 471 if (!capable(CAP_SYS_ADMIN))
475 return -EACCES; 472 return -EACCES;
476 473
477 spin_lock(&efivars_lock); 474 spin_lock(&efivars->lock);
478 475
479 /* 476 /*
480 * Does this variable already exist? 477 * Does this variable already exist?
481 */ 478 */
482 list_for_each_entry_safe(search_efivar, n, &efivar_list, list) { 479 list_for_each_entry_safe(search_efivar, n, &efivars->list, list) {
483 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); 480 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024);
484 strsize2 = utf8_strsize(del_var->VariableName, 1024); 481 strsize2 = utf8_strsize(del_var->VariableName, 1024);
485 if (strsize1 == strsize2 && 482 if (strsize1 == strsize2 &&
@@ -492,44 +489,34 @@ static ssize_t efivar_delete(struct file *filp, struct kobject *kobj,
492 } 489 }
493 } 490 }
494 if (!found) { 491 if (!found) {
495 spin_unlock(&efivars_lock); 492 spin_unlock(&efivars->lock);
496 return -EINVAL; 493 return -EINVAL;
497 } 494 }
498 /* force the Attributes/DataSize to 0 to ensure deletion */ 495 /* force the Attributes/DataSize to 0 to ensure deletion */
499 del_var->Attributes = 0; 496 del_var->Attributes = 0;
500 del_var->DataSize = 0; 497 del_var->DataSize = 0;
501 498
502 status = efi.set_variable(del_var->VariableName, 499 status = efivars->ops->set_variable(del_var->VariableName,
503 &del_var->VendorGuid, 500 &del_var->VendorGuid,
504 del_var->Attributes, 501 del_var->Attributes,
505 del_var->DataSize, 502 del_var->DataSize,
506 del_var->Data); 503 del_var->Data);
507 504
508 if (status != EFI_SUCCESS) { 505 if (status != EFI_SUCCESS) {
509 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", 506 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n",
510 status); 507 status);
511 spin_unlock(&efivars_lock); 508 spin_unlock(&efivars->lock);
512 return -EIO; 509 return -EIO;
513 } 510 }
514 list_del(&search_efivar->list); 511 list_del(&search_efivar->list);
515 /* We need to release this lock before unregistering. */ 512 /* We need to release this lock before unregistering. */
516 spin_unlock(&efivars_lock); 513 spin_unlock(&efivars->lock);
517 efivar_unregister(search_efivar); 514 efivar_unregister(search_efivar);
518 515
519 /* It's dead Jim.... */ 516 /* It's dead Jim.... */
520 return count; 517 return count;
521} 518}
522 519
523static struct bin_attribute var_subsys_attr_new_var = {
524 .attr = {.name = "new_var", .mode = 0200},
525 .write = efivar_create,
526};
527
528static struct bin_attribute var_subsys_attr_del_var = {
529 .attr = {.name = "del_var", .mode = 0200},
530 .write = efivar_delete,
531};
532
533/* 520/*
534 * Let's not leave out systab information that snuck into 521 * Let's not leave out systab information that snuck into
535 * the efivars driver 522 * the efivars driver
@@ -572,8 +559,6 @@ static struct attribute_group efi_subsys_attr_group = {
572 .attrs = efi_subsys_attrs, 559 .attrs = efi_subsys_attrs,
573}; 560};
574 561
575
576static struct kset *vars_kset;
577static struct kobject *efi_kobj; 562static struct kobject *efi_kobj;
578 563
579/* 564/*
@@ -582,13 +567,14 @@ static struct kobject *efi_kobj;
582 * variable_name_size = number of bytes required to hold 567 * variable_name_size = number of bytes required to hold
583 * variable_name (not counting the NULL 568 * variable_name (not counting the NULL
584 * character at the end. 569 * character at the end.
585 * efivars_lock is not held on entry or exit. 570 * efivars->lock is not held on entry or exit.
586 * Returns 1 on failure, 0 on success 571 * Returns 1 on failure, 0 on success
587 */ 572 */
588static int 573static int
589efivar_create_sysfs_entry(unsigned long variable_name_size, 574efivar_create_sysfs_entry(struct efivars *efivars,
590 efi_char16_t *variable_name, 575 unsigned long variable_name_size,
591 efi_guid_t *vendor_guid) 576 efi_char16_t *variable_name,
577 efi_guid_t *vendor_guid)
592{ 578{
593 int i, short_name_size = variable_name_size / sizeof(efi_char16_t) + 38; 579 int i, short_name_size = variable_name_size / sizeof(efi_char16_t) + 38;
594 char *short_name; 580 char *short_name;
@@ -603,6 +589,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
603 return 1; 589 return 1;
604 } 590 }
605 591
592 new_efivar->efivars = efivars;
606 memcpy(new_efivar->var.VariableName, variable_name, 593 memcpy(new_efivar->var.VariableName, variable_name,
607 variable_name_size); 594 variable_name_size);
608 memcpy(&(new_efivar->var.VendorGuid), vendor_guid, sizeof(efi_guid_t)); 595 memcpy(&(new_efivar->var.VendorGuid), vendor_guid, sizeof(efi_guid_t));
@@ -618,7 +605,7 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
618 *(short_name + strlen(short_name)) = '-'; 605 *(short_name + strlen(short_name)) = '-';
619 efi_guid_unparse(vendor_guid, short_name + strlen(short_name)); 606 efi_guid_unparse(vendor_guid, short_name + strlen(short_name));
620 607
621 new_efivar->kobj.kset = vars_kset; 608 new_efivar->kobj.kset = efivars->kset;
622 i = kobject_init_and_add(&new_efivar->kobj, &efivar_ktype, NULL, 609 i = kobject_init_and_add(&new_efivar->kobj, &efivar_ktype, NULL,
623 "%s", short_name); 610 "%s", short_name);
624 if (i) { 611 if (i) {
@@ -631,22 +618,95 @@ efivar_create_sysfs_entry(unsigned long variable_name_size,
631 kfree(short_name); 618 kfree(short_name);
632 short_name = NULL; 619 short_name = NULL;
633 620
634 spin_lock(&efivars_lock); 621 spin_lock(&efivars->lock);
635 list_add(&new_efivar->list, &efivar_list); 622 list_add(&new_efivar->list, &efivars->list);
636 spin_unlock(&efivars_lock); 623 spin_unlock(&efivars->lock);
637 624
638 return 0; 625 return 0;
639} 626}
640/*
641 * For now we register the efi subsystem with the firmware subsystem
642 * and the vars subsystem with the efi subsystem. In the future, it
643 * might make sense to split off the efi subsystem into its own
644 * driver, but for now only efivars will register with it, so just
645 * include it here.
646 */
647 627
648static int __init 628static int
649efivars_init(void) 629create_efivars_bin_attributes(struct efivars *efivars)
630{
631 struct bin_attribute *attr;
632 int error;
633
634 /* new_var */
635 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
636 if (!attr)
637 return -ENOMEM;
638
639 attr->attr.name = "new_var";
640 attr->attr.mode = 0200;
641 attr->write = efivar_create;
642 attr->private = efivars;
643 efivars->new_var = attr;
644
645 /* del_var */
646 attr = kzalloc(sizeof(*attr), GFP_KERNEL);
647 if (!attr) {
648 error = -ENOMEM;
649 goto out_free;
650 }
651 attr->attr.name = "del_var";
652 attr->attr.mode = 0200;
653 attr->write = efivar_delete;
654 attr->private = efivars;
655 efivars->del_var = attr;
656
657 sysfs_bin_attr_init(efivars->new_var);
658 sysfs_bin_attr_init(efivars->del_var);
659
660 /* Register */
661 error = sysfs_create_bin_file(&efivars->kset->kobj,
662 efivars->new_var);
663 if (error) {
664 printk(KERN_ERR "efivars: unable to create new_var sysfs file"
665 " due to error %d\n", error);
666 goto out_free;
667 }
668 error = sysfs_create_bin_file(&efivars->kset->kobj,
669 efivars->del_var);
670 if (error) {
671 printk(KERN_ERR "efivars: unable to create del_var sysfs file"
672 " due to error %d\n", error);
673 sysfs_remove_bin_file(&efivars->kset->kobj,
674 efivars->new_var);
675 goto out_free;
676 }
677
678 return 0;
679out_free:
680 kfree(efivars->new_var);
681 efivars->new_var = NULL;
682 kfree(efivars->new_var);
683 efivars->new_var = NULL;
684 return error;
685}
686
687void unregister_efivars(struct efivars *efivars)
688{
689 struct efivar_entry *entry, *n;
690
691 list_for_each_entry_safe(entry, n, &efivars->list, list) {
692 spin_lock(&efivars->lock);
693 list_del(&entry->list);
694 spin_unlock(&efivars->lock);
695 efivar_unregister(entry);
696 }
697 if (efivars->new_var)
698 sysfs_remove_bin_file(&efivars->kset->kobj, efivars->new_var);
699 if (efivars->del_var)
700 sysfs_remove_bin_file(&efivars->kset->kobj, efivars->del_var);
701 kfree(efivars->new_var);
702 kfree(efivars->del_var);
703 kset_unregister(efivars->kset);
704}
705EXPORT_SYMBOL_GPL(unregister_efivars);
706
707int register_efivars(struct efivars *efivars,
708 const struct efivar_operations *ops,
709 struct kobject *parent_kobj)
650{ 710{
651 efi_status_t status = EFI_NOT_FOUND; 711 efi_status_t status = EFI_NOT_FOUND;
652 efi_guid_t vendor_guid; 712 efi_guid_t vendor_guid;
@@ -654,31 +714,21 @@ efivars_init(void)
654 unsigned long variable_name_size = 1024; 714 unsigned long variable_name_size = 1024;
655 int error = 0; 715 int error = 0;
656 716
657 if (!efi_enabled)
658 return -ENODEV;
659
660 variable_name = kzalloc(variable_name_size, GFP_KERNEL); 717 variable_name = kzalloc(variable_name_size, GFP_KERNEL);
661 if (!variable_name) { 718 if (!variable_name) {
662 printk(KERN_ERR "efivars: Memory allocation failed.\n"); 719 printk(KERN_ERR "efivars: Memory allocation failed.\n");
663 return -ENOMEM; 720 return -ENOMEM;
664 } 721 }
665 722
666 printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION, 723 spin_lock_init(&efivars->lock);
667 EFIVARS_DATE); 724 INIT_LIST_HEAD(&efivars->list);
725 efivars->ops = ops;
668 726
669 /* For now we'll register the efi directory at /sys/firmware/efi */ 727 efivars->kset = kset_create_and_add("vars", NULL, parent_kobj);
670 efi_kobj = kobject_create_and_add("efi", firmware_kobj); 728 if (!efivars->kset) {
671 if (!efi_kobj) {
672 printk(KERN_ERR "efivars: Firmware registration failed.\n");
673 error = -ENOMEM;
674 goto out_free;
675 }
676
677 vars_kset = kset_create_and_add("vars", NULL, efi_kobj);
678 if (!vars_kset) {
679 printk(KERN_ERR "efivars: Subsystem registration failed.\n"); 729 printk(KERN_ERR "efivars: Subsystem registration failed.\n");
680 error = -ENOMEM; 730 error = -ENOMEM;
681 goto out_firmware_unregister; 731 goto out;
682 } 732 }
683 733
684 /* 734 /*
@@ -689,14 +739,15 @@ efivars_init(void)
689 do { 739 do {
690 variable_name_size = 1024; 740 variable_name_size = 1024;
691 741
692 status = efi.get_next_variable(&variable_name_size, 742 status = ops->get_next_variable(&variable_name_size,
693 variable_name, 743 variable_name,
694 &vendor_guid); 744 &vendor_guid);
695 switch (status) { 745 switch (status) {
696 case EFI_SUCCESS: 746 case EFI_SUCCESS:
697 efivar_create_sysfs_entry(variable_name_size, 747 efivar_create_sysfs_entry(efivars,
698 variable_name, 748 variable_name_size,
699 &vendor_guid); 749 variable_name,
750 &vendor_guid);
700 break; 751 break;
701 case EFI_NOT_FOUND: 752 case EFI_NOT_FOUND:
702 break; 753 break;
@@ -708,35 +759,60 @@ efivars_init(void)
708 } 759 }
709 } while (status != EFI_NOT_FOUND); 760 } while (status != EFI_NOT_FOUND);
710 761
711 /* 762 error = create_efivars_bin_attributes(efivars);
712 * Now add attributes to allow creation of new vars
713 * and deletion of existing ones...
714 */
715 error = sysfs_create_bin_file(&vars_kset->kobj,
716 &var_subsys_attr_new_var);
717 if (error)
718 printk(KERN_ERR "efivars: unable to create new_var sysfs file"
719 " due to error %d\n", error);
720 error = sysfs_create_bin_file(&vars_kset->kobj,
721 &var_subsys_attr_del_var);
722 if (error) 763 if (error)
723 printk(KERN_ERR "efivars: unable to create del_var sysfs file" 764 unregister_efivars(efivars);
724 " due to error %d\n", error);
725 765
726 /* Don't forget the systab entry */ 766out:
727 error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); 767 kfree(variable_name);
728 if (error)
729 printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error);
730 else
731 goto out_free;
732 768
733 kset_unregister(vars_kset); 769 return error;
770}
771EXPORT_SYMBOL_GPL(register_efivars);
734 772
735out_firmware_unregister: 773static struct efivars __efivars;
736 kobject_put(efi_kobj); 774static struct efivar_operations ops;
737 775
738out_free: 776/*
739 kfree(variable_name); 777 * For now we register the efi subsystem with the firmware subsystem
778 * and the vars subsystem with the efi subsystem. In the future, it
779 * might make sense to split off the efi subsystem into its own
780 * driver, but for now only efivars will register with it, so just
781 * include it here.
782 */
783
784static int __init
785efivars_init(void)
786{
787 int error = 0;
788
789 printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION,
790 EFIVARS_DATE);
791
792 if (!efi_enabled)
793 return 0;
794
795 /* For now we'll register the efi directory at /sys/firmware/efi */
796 efi_kobj = kobject_create_and_add("efi", firmware_kobj);
797 if (!efi_kobj) {
798 printk(KERN_ERR "efivars: Firmware registration failed.\n");
799 return -ENOMEM;
800 }
801
802 ops.get_variable = efi.get_variable;
803 ops.set_variable = efi.set_variable;
804 ops.get_next_variable = efi.get_next_variable;
805 error = register_efivars(&__efivars, &ops, efi_kobj);
806
807 /* Don't forget the systab entry */
808 error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group);
809 if (error) {
810 printk(KERN_ERR
811 "efivars: Sysfs attribute export failed with error %d.\n",
812 error);
813 unregister_efivars(&__efivars);
814 kobject_put(efi_kobj);
815 }
740 816
741 return error; 817 return error;
742} 818}
@@ -744,16 +820,7 @@ out_free:
744static void __exit 820static void __exit
745efivars_exit(void) 821efivars_exit(void)
746{ 822{
747 struct efivar_entry *entry, *n; 823 unregister_efivars(&__efivars);
748
749 list_for_each_entry_safe(entry, n, &efivar_list, list) {
750 spin_lock(&efivars_lock);
751 list_del(&entry->list);
752 spin_unlock(&efivars_lock);
753 efivar_unregister(entry);
754 }
755
756 kset_unregister(vars_kset);
757 kobject_put(efi_kobj); 824 kobject_put(efi_kobj);
758} 825}
759 826
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index cc8e49db45fe..b7d5ef234ac9 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -441,7 +441,7 @@ config BMP085
441 module will be called bmp085. 441 module will be called bmp085.
442 442
443config PCH_PHUB 443config PCH_PHUB
444 tristate "PCH Packet Hub of Intel Topcliff" 444 tristate "PCH Packet Hub of Intel Topcliff / OKI SEMICONDUCTOR ML7213"
445 depends on PCI 445 depends on PCI
446 help 446 help
447 This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of 447 This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of
@@ -449,6 +449,11 @@ config PCH_PHUB
449 processor. The Topcliff has MAC address and Option ROM data in SROM. 449 processor. The Topcliff has MAC address and Option ROM data in SROM.
450 This driver can access MAC address and Option ROM data in SROM. 450 This driver can access MAC address and Option ROM data in SROM.
451 451
452 This driver also can be used for OKI SEMICONDUCTOR's ML7213 which is
453 for IVI(In-Vehicle Infotainment) use.
454 ML7213 is companion chip for Intel Atom E6xx series.
455 ML7213 is completely compatible for Intel EG20T PCH.
456
452 To compile this driver as a module, choose M here: the module will 457 To compile this driver as a module, choose M here: the module will
453 be called pch_phub. 458 be called pch_phub.
454 459
diff --git a/drivers/misc/pch_phub.c b/drivers/misc/pch_phub.c
index 744b804aca15..98bffc471b17 100644
--- a/drivers/misc/pch_phub.c
+++ b/drivers/misc/pch_phub.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. 2 * Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD.
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
@@ -33,7 +33,12 @@
33#define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */ 33#define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */
34#define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */ 34#define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */
35#define PCH_PHUB_ROM_WRITE_DISABLE 0x00 /* Disabling for writing ROM */ 35#define PCH_PHUB_ROM_WRITE_DISABLE 0x00 /* Disabling for writing ROM */
36#define PCH_PHUB_ROM_START_ADDR 0x14 /* ROM data area start address offset */ 36#define PCH_PHUB_MAC_START_ADDR 0x20C /* MAC data area start address offset */
37#define PCH_PHUB_ROM_START_ADDR_EG20T 0x14 /* ROM data area start address offset
38 (Intel EG20T PCH)*/
39#define PCH_PHUB_ROM_START_ADDR_ML7213 0x400 /* ROM data area start address
40 offset(OKI SEMICONDUCTOR ML7213)
41 */
37 42
38/* MAX number of INT_REDUCE_CONTROL registers */ 43/* MAX number of INT_REDUCE_CONTROL registers */
39#define MAX_NUM_INT_REDUCE_CONTROL_REG 128 44#define MAX_NUM_INT_REDUCE_CONTROL_REG 128
@@ -42,6 +47,10 @@
42#define CLKCFG_CAN_50MHZ 0x12000000 47#define CLKCFG_CAN_50MHZ 0x12000000
43#define CLKCFG_CANCLK_MASK 0xFF000000 48#define CLKCFG_CANCLK_MASK 0xFF000000
44 49
50/* Macros for ML7213 */
51#define PCI_VENDOR_ID_ROHM 0x10db
52#define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A
53
45/* SROM ACCESS Macro */ 54/* SROM ACCESS Macro */
46#define PCH_WORD_ADDR_MASK (~((1 << 2) - 1)) 55#define PCH_WORD_ADDR_MASK (~((1 << 2) - 1))
47 56
@@ -298,7 +307,7 @@ static void pch_phub_read_serial_rom_val(struct pch_phub_reg *chip,
298{ 307{
299 unsigned int mem_addr; 308 unsigned int mem_addr;
300 309
301 mem_addr = PCH_PHUB_ROM_START_ADDR + 310 mem_addr = PCH_PHUB_ROM_START_ADDR_EG20T +
302 pch_phub_mac_offset[offset_address]; 311 pch_phub_mac_offset[offset_address];
303 312
304 pch_phub_read_serial_rom(chip, mem_addr, data); 313 pch_phub_read_serial_rom(chip, mem_addr, data);
@@ -315,7 +324,7 @@ static int pch_phub_write_serial_rom_val(struct pch_phub_reg *chip,
315 int retval; 324 int retval;
316 unsigned int mem_addr; 325 unsigned int mem_addr;
317 326
318 mem_addr = PCH_PHUB_ROM_START_ADDR + 327 mem_addr = PCH_PHUB_ROM_START_ADDR_EG20T +
319 pch_phub_mac_offset[offset_address]; 328 pch_phub_mac_offset[offset_address];
320 329
321 retval = pch_phub_write_serial_rom(chip, mem_addr, data); 330 retval = pch_phub_write_serial_rom(chip, mem_addr, data);
@@ -594,23 +603,38 @@ static int __devinit pch_phub_probe(struct pci_dev *pdev,
594 "pch_phub_extrom_base_address variable is %p\n", __func__, 603 "pch_phub_extrom_base_address variable is %p\n", __func__,
595 chip->pch_phub_extrom_base_address); 604 chip->pch_phub_extrom_base_address);
596 605
597 pci_set_drvdata(pdev, chip); 606 if (id->driver_data == 1) {
598 607 retval = sysfs_create_file(&pdev->dev.kobj,
599 retval = sysfs_create_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); 608 &dev_attr_pch_mac.attr);
600 if (retval) 609 if (retval)
601 goto err_sysfs_create; 610 goto err_sysfs_create;
602
603 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
604 if (retval)
605 goto exit_bin_attr;
606
607 pch_phub_read_modify_write_reg(chip, (unsigned int)CLKCFG_REG_OFFSET,
608 CLKCFG_CAN_50MHZ, CLKCFG_CANCLK_MASK);
609 611
610 /* set the prefech value */ 612 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
611 iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14); 613 if (retval)
612 /* set the interrupt delay value */ 614 goto exit_bin_attr;
613 iowrite32(0x25, chip->pch_phub_base_address + 0x44); 615
616 pch_phub_read_modify_write_reg(chip,
617 (unsigned int)CLKCFG_REG_OFFSET,
618 CLKCFG_CAN_50MHZ,
619 CLKCFG_CANCLK_MASK);
620
621 /* set the prefech value */
622 iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14);
623 /* set the interrupt delay value */
624 iowrite32(0x25, chip->pch_phub_base_address + 0x44);
625 } else if (id->driver_data == 2) {
626 retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr);
627 if (retval)
628 goto err_sysfs_create;
629 /* set the prefech value
630 * Device2(USB OHCI #1/ USB EHCI #1/ USB Device):a
631 * Device4(SDIO #0,1,2):f
632 * Device6(SATA 2):f
633 * Device8(USB OHCI #0/ USB EHCI #0):a
634 */
635 iowrite32(0x000affa0, chip->pch_phub_base_address + 0x14);
636 }
637 pci_set_drvdata(pdev, chip);
614 638
615 return 0; 639 return 0;
616exit_bin_attr: 640exit_bin_attr:
@@ -687,8 +711,9 @@ static int pch_phub_resume(struct pci_dev *pdev)
687#endif /* CONFIG_PM */ 711#endif /* CONFIG_PM */
688 712
689static struct pci_device_id pch_phub_pcidev_id[] = { 713static struct pci_device_id pch_phub_pcidev_id[] = {
690 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PCH1_PHUB)}, 714 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH1_PHUB), 1, },
691 {0,} 715 { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, },
716 { }
692}; 717};
693 718
694static struct pci_driver pch_phub_driver = { 719static struct pci_driver pch_phub_driver = {
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
index f9aad06d1ae5..486117f72c9f 100644
--- a/drivers/misc/ti-st/st_core.c
+++ b/drivers/misc/ti-st/st_core.c
@@ -25,10 +25,9 @@
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/tty.h> 26#include <linux/tty.h>
27 27
28/* understand BT, FM and GPS for now */ 28#include <linux/seq_file.h>
29#include <net/bluetooth/bluetooth.h> 29#include <linux/skbuff.h>
30#include <net/bluetooth/hci_core.h> 30
31#include <net/bluetooth/hci.h>
32#include <linux/ti_wilink_st.h> 31#include <linux/ti_wilink_st.h>
33 32
34/* function pointer pointing to either, 33/* function pointer pointing to either,
@@ -38,21 +37,38 @@
38void (*st_recv) (void*, const unsigned char*, long); 37void (*st_recv) (void*, const unsigned char*, long);
39 38
40/********************************************************************/ 39/********************************************************************/
41#if 0 40static void add_channel_to_table(struct st_data_s *st_gdata,
42/* internal misc functions */ 41 struct st_proto_s *new_proto)
43bool is_protocol_list_empty(void)
44{ 42{
45 unsigned char i = 0; 43 pr_info("%s: id %d\n", __func__, new_proto->chnl_id);
46 pr_debug(" %s ", __func__); 44 /* list now has the channel id as index itself */
47 for (i = 0; i < ST_MAX; i++) { 45 st_gdata->list[new_proto->chnl_id] = new_proto;
48 if (st_gdata->list[i] != NULL) 46}
49 return ST_NOTEMPTY; 47
50 /* not empty */ 48static void remove_channel_from_table(struct st_data_s *st_gdata,
49 struct st_proto_s *proto)
50{
51 pr_info("%s: id %d\n", __func__, proto->chnl_id);
52 st_gdata->list[proto->chnl_id] = NULL;
53}
54
55/*
56 * called from KIM during firmware download.
57 *
58 * This is a wrapper function to tty->ops->write_room.
59 * It returns number of free space available in
60 * uart tx buffer.
61 */
62int st_get_uart_wr_room(struct st_data_s *st_gdata)
63{
64 struct tty_struct *tty;
65 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
66 pr_err("tty unavailable to perform write");
67 return -1;
51 } 68 }
52 /* list empty */ 69 tty = st_gdata->tty;
53 return ST_EMPTY; 70 return tty->ops->write_room(tty);
54} 71}
55#endif
56 72
57/* can be called in from 73/* can be called in from
58 * -- KIM (during fw download) 74 * -- KIM (during fw download)
@@ -67,7 +83,7 @@ int st_int_write(struct st_data_s *st_gdata,
67 struct tty_struct *tty; 83 struct tty_struct *tty;
68 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) { 84 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
69 pr_err("tty unavailable to perform write"); 85 pr_err("tty unavailable to perform write");
70 return -1; 86 return -EINVAL;
71 } 87 }
72 tty = st_gdata->tty; 88 tty = st_gdata->tty;
73#ifdef VERBOSE 89#ifdef VERBOSE
@@ -82,15 +98,15 @@ int st_int_write(struct st_data_s *st_gdata,
82 * push the skb received to relevant 98 * push the skb received to relevant
83 * protocol stacks 99 * protocol stacks
84 */ 100 */
85void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata) 101void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata)
86{ 102{
87 pr_info(" %s(prot:%d) ", __func__, protoid); 103 pr_debug(" %s(prot:%d) ", __func__, chnl_id);
88 104
89 if (unlikely 105 if (unlikely
90 (st_gdata == NULL || st_gdata->rx_skb == NULL 106 (st_gdata == NULL || st_gdata->rx_skb == NULL
91 || st_gdata->list[protoid] == NULL)) { 107 || st_gdata->list[chnl_id] == NULL)) {
92 pr_err("protocol %d not registered, no data to send?", 108 pr_err("chnl_id %d not registered, no data to send?",
93 protoid); 109 chnl_id);
94 kfree_skb(st_gdata->rx_skb); 110 kfree_skb(st_gdata->rx_skb);
95 return; 111 return;
96 } 112 }
@@ -99,17 +115,17 @@ void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata)
99 * - should be just skb_queue_tail for the 115 * - should be just skb_queue_tail for the
100 * protocol stack driver 116 * protocol stack driver
101 */ 117 */
102 if (likely(st_gdata->list[protoid]->recv != NULL)) { 118 if (likely(st_gdata->list[chnl_id]->recv != NULL)) {
103 if (unlikely 119 if (unlikely
104 (st_gdata->list[protoid]->recv 120 (st_gdata->list[chnl_id]->recv
105 (st_gdata->list[protoid]->priv_data, st_gdata->rx_skb) 121 (st_gdata->list[chnl_id]->priv_data, st_gdata->rx_skb)
106 != 0)) { 122 != 0)) {
107 pr_err(" proto stack %d's ->recv failed", protoid); 123 pr_err(" proto stack %d's ->recv failed", chnl_id);
108 kfree_skb(st_gdata->rx_skb); 124 kfree_skb(st_gdata->rx_skb);
109 return; 125 return;
110 } 126 }
111 } else { 127 } else {
112 pr_err(" proto stack %d's ->recv null", protoid); 128 pr_err(" proto stack %d's ->recv null", chnl_id);
113 kfree_skb(st_gdata->rx_skb); 129 kfree_skb(st_gdata->rx_skb);
114 } 130 }
115 return; 131 return;
@@ -124,16 +140,22 @@ void st_reg_complete(struct st_data_s *st_gdata, char err)
124{ 140{
125 unsigned char i = 0; 141 unsigned char i = 0;
126 pr_info(" %s ", __func__); 142 pr_info(" %s ", __func__);
127 for (i = 0; i < ST_MAX; i++) { 143 for (i = 0; i < ST_MAX_CHANNELS; i++) {
128 if (likely(st_gdata != NULL && st_gdata->list[i] != NULL && 144 if (likely(st_gdata != NULL && st_gdata->list[i] != NULL &&
129 st_gdata->list[i]->reg_complete_cb != NULL)) 145 st_gdata->list[i]->reg_complete_cb != NULL)) {
130 st_gdata->list[i]->reg_complete_cb 146 st_gdata->list[i]->reg_complete_cb
131 (st_gdata->list[i]->priv_data, err); 147 (st_gdata->list[i]->priv_data, err);
148 pr_info("protocol %d's cb sent %d\n", i, err);
149 if (err) { /* cleanup registered protocol */
150 st_gdata->protos_registered--;
151 st_gdata->list[i] = NULL;
152 }
153 }
132 } 154 }
133} 155}
134 156
135static inline int st_check_data_len(struct st_data_s *st_gdata, 157static inline int st_check_data_len(struct st_data_s *st_gdata,
136 int protoid, int len) 158 unsigned char chnl_id, int len)
137{ 159{
138 int room = skb_tailroom(st_gdata->rx_skb); 160 int room = skb_tailroom(st_gdata->rx_skb);
139 161
@@ -144,7 +166,7 @@ static inline int st_check_data_len(struct st_data_s *st_gdata,
144 * has zero length payload. So, ask ST CORE to 166 * has zero length payload. So, ask ST CORE to
145 * forward the packet to protocol driver (BT/FM/GPS) 167 * forward the packet to protocol driver (BT/FM/GPS)
146 */ 168 */
147 st_send_frame(protoid, st_gdata); 169 st_send_frame(chnl_id, st_gdata);
148 170
149 } else if (len > room) { 171 } else if (len > room) {
150 /* Received packet's payload length is larger. 172 /* Received packet's payload length is larger.
@@ -157,7 +179,7 @@ static inline int st_check_data_len(struct st_data_s *st_gdata,
157 /* Packet header has non-zero payload length and 179 /* Packet header has non-zero payload length and
158 * we have enough space in created skb. Lets read 180 * we have enough space in created skb. Lets read
159 * payload data */ 181 * payload data */
160 st_gdata->rx_state = ST_BT_W4_DATA; 182 st_gdata->rx_state = ST_W4_DATA;
161 st_gdata->rx_count = len; 183 st_gdata->rx_count = len;
162 return len; 184 return len;
163 } 185 }
@@ -167,6 +189,7 @@ static inline int st_check_data_len(struct st_data_s *st_gdata,
167 st_gdata->rx_state = ST_W4_PACKET_TYPE; 189 st_gdata->rx_state = ST_W4_PACKET_TYPE;
168 st_gdata->rx_skb = NULL; 190 st_gdata->rx_skb = NULL;
169 st_gdata->rx_count = 0; 191 st_gdata->rx_count = 0;
192 st_gdata->rx_chnl = 0;
170 193
171 return 0; 194 return 0;
172} 195}
@@ -208,14 +231,12 @@ void st_int_recv(void *disc_data,
208 const unsigned char *data, long count) 231 const unsigned char *data, long count)
209{ 232{
210 char *ptr; 233 char *ptr;
211 struct hci_event_hdr *eh; 234 struct st_proto_s *proto;
212 struct hci_acl_hdr *ah; 235 unsigned short payload_len = 0;
213 struct hci_sco_hdr *sh; 236 int len = 0, type = 0;
214 struct fm_event_hdr *fm; 237 unsigned char *plen;
215 struct gps_event_hdr *gps;
216 int len = 0, type = 0, dlen = 0;
217 static enum proto_type protoid = ST_MAX;
218 struct st_data_s *st_gdata = (struct st_data_s *)disc_data; 238 struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
239 unsigned long flags;
219 240
220 ptr = (char *)data; 241 ptr = (char *)data;
221 /* tty_receive sent null ? */ 242 /* tty_receive sent null ? */
@@ -224,10 +245,11 @@ void st_int_recv(void *disc_data,
224 return; 245 return;
225 } 246 }
226 247
227 pr_info("count %ld rx_state %ld" 248 pr_debug("count %ld rx_state %ld"
228 "rx_count %ld", count, st_gdata->rx_state, 249 "rx_count %ld", count, st_gdata->rx_state,
229 st_gdata->rx_count); 250 st_gdata->rx_count);
230 251
252 spin_lock_irqsave(&st_gdata->lock, flags);
231 /* Decode received bytes here */ 253 /* Decode received bytes here */
232 while (count) { 254 while (count) {
233 if (st_gdata->rx_count) { 255 if (st_gdata->rx_count) {
@@ -242,64 +264,36 @@ void st_int_recv(void *disc_data,
242 264
243 /* Check ST RX state machine , where are we? */ 265 /* Check ST RX state machine , where are we? */
244 switch (st_gdata->rx_state) { 266 switch (st_gdata->rx_state) {
245 267 /* Waiting for complete packet ? */
246 /* Waiting for complete packet ? */ 268 case ST_W4_DATA:
247 case ST_BT_W4_DATA:
248 pr_debug("Complete pkt received"); 269 pr_debug("Complete pkt received");
249
250 /* Ask ST CORE to forward 270 /* Ask ST CORE to forward
251 * the packet to protocol driver */ 271 * the packet to protocol driver */
252 st_send_frame(protoid, st_gdata); 272 st_send_frame(st_gdata->rx_chnl, st_gdata);
253 273
254 st_gdata->rx_state = ST_W4_PACKET_TYPE; 274 st_gdata->rx_state = ST_W4_PACKET_TYPE;
255 st_gdata->rx_skb = NULL; 275 st_gdata->rx_skb = NULL;
256 protoid = ST_MAX; /* is this required ? */
257 continue; 276 continue;
258 277 /* parse the header to know details */
259 /* Waiting for Bluetooth event header ? */ 278 case ST_W4_HEADER:
260 case ST_BT_W4_EVENT_HDR: 279 proto = st_gdata->list[st_gdata->rx_chnl];
261 eh = (struct hci_event_hdr *)st_gdata->rx_skb-> 280 plen =
262 data; 281 &st_gdata->rx_skb->data
263 282 [proto->offset_len_in_hdr];
264 pr_debug("Event header: evt 0x%2.2x" 283 pr_debug("plen pointing to %x\n", *plen);
265 "plen %d", eh->evt, eh->plen); 284 if (proto->len_size == 1)/* 1 byte len field */
266 285 payload_len = *(unsigned char *)plen;
267 st_check_data_len(st_gdata, protoid, eh->plen); 286 else if (proto->len_size == 2)
268 continue; 287 payload_len =
269 288 __le16_to_cpu(*(unsigned short *)plen);
270 /* Waiting for Bluetooth acl header ? */ 289 else
271 case ST_BT_W4_ACL_HDR: 290 pr_info("%s: invalid length "
272 ah = (struct hci_acl_hdr *)st_gdata->rx_skb-> 291 "for id %d\n",
273 data; 292 __func__, proto->chnl_id);
274 dlen = __le16_to_cpu(ah->dlen); 293 st_check_data_len(st_gdata, proto->chnl_id,
275 294 payload_len);
276 pr_info("ACL header: dlen %d", dlen); 295 pr_debug("off %d, pay len %d\n",
277 296 proto->offset_len_in_hdr, payload_len);
278 st_check_data_len(st_gdata, protoid, dlen);
279 continue;
280
281 /* Waiting for Bluetooth sco header ? */
282 case ST_BT_W4_SCO_HDR:
283 sh = (struct hci_sco_hdr *)st_gdata->rx_skb->
284 data;
285
286 pr_info("SCO header: dlen %d", sh->dlen);
287
288 st_check_data_len(st_gdata, protoid, sh->dlen);
289 continue;
290 case ST_FM_W4_EVENT_HDR:
291 fm = (struct fm_event_hdr *)st_gdata->rx_skb->
292 data;
293 pr_info("FM Header: ");
294 st_check_data_len(st_gdata, ST_FM, fm->plen);
295 continue;
296 /* TODO : Add GPS packet machine logic here */
297 case ST_GPS_W4_EVENT_HDR:
298 /* [0x09 pkt hdr][R/W byte][2 byte len] */
299 gps = (struct gps_event_hdr *)st_gdata->rx_skb->
300 data;
301 pr_info("GPS Header: ");
302 st_check_data_len(st_gdata, ST_GPS, gps->plen);
303 continue; 297 continue;
304 } /* end of switch rx_state */ 298 } /* end of switch rx_state */
305 } 299 }
@@ -308,123 +302,56 @@ void st_int_recv(void *disc_data,
308 /* Check first byte of packet and identify module 302 /* Check first byte of packet and identify module
309 * owner (BT/FM/GPS) */ 303 * owner (BT/FM/GPS) */
310 switch (*ptr) { 304 switch (*ptr) {
311
312 /* Bluetooth event packet? */
313 case HCI_EVENT_PKT:
314 pr_info("Event packet");
315 st_gdata->rx_state = ST_BT_W4_EVENT_HDR;
316 st_gdata->rx_count = HCI_EVENT_HDR_SIZE;
317 type = HCI_EVENT_PKT;
318 protoid = ST_BT;
319 break;
320
321 /* Bluetooth acl packet? */
322 case HCI_ACLDATA_PKT:
323 pr_info("ACL packet");
324 st_gdata->rx_state = ST_BT_W4_ACL_HDR;
325 st_gdata->rx_count = HCI_ACL_HDR_SIZE;
326 type = HCI_ACLDATA_PKT;
327 protoid = ST_BT;
328 break;
329
330 /* Bluetooth sco packet? */
331 case HCI_SCODATA_PKT:
332 pr_info("SCO packet");
333 st_gdata->rx_state = ST_BT_W4_SCO_HDR;
334 st_gdata->rx_count = HCI_SCO_HDR_SIZE;
335 type = HCI_SCODATA_PKT;
336 protoid = ST_BT;
337 break;
338
339 /* Channel 8(FM) packet? */
340 case ST_FM_CH8_PKT:
341 pr_info("FM CH8 packet");
342 type = ST_FM_CH8_PKT;
343 st_gdata->rx_state = ST_FM_W4_EVENT_HDR;
344 st_gdata->rx_count = FM_EVENT_HDR_SIZE;
345 protoid = ST_FM;
346 break;
347
348 /* Channel 9(GPS) packet? */
349 case 0x9: /*ST_LL_GPS_CH9_PKT */
350 pr_info("GPS CH9 packet");
351 type = 0x9; /* ST_LL_GPS_CH9_PKT; */
352 protoid = ST_GPS;
353 st_gdata->rx_state = ST_GPS_W4_EVENT_HDR;
354 st_gdata->rx_count = 3; /* GPS_EVENT_HDR_SIZE -1*/
355 break;
356 case LL_SLEEP_IND: 305 case LL_SLEEP_IND:
357 case LL_SLEEP_ACK: 306 case LL_SLEEP_ACK:
358 case LL_WAKE_UP_IND: 307 case LL_WAKE_UP_IND:
359 pr_info("PM packet"); 308 pr_debug("PM packet");
360 /* this takes appropriate action based on 309 /* this takes appropriate action based on
361 * sleep state received -- 310 * sleep state received --
362 */ 311 */
363 st_ll_sleep_state(st_gdata, *ptr); 312 st_ll_sleep_state(st_gdata, *ptr);
313 /* if WAKEUP_IND collides copy from waitq to txq
314 * and assume chip awake
315 */
316 spin_unlock_irqrestore(&st_gdata->lock, flags);
317 if (st_ll_getstate(st_gdata) == ST_LL_AWAKE)
318 st_wakeup_ack(st_gdata, LL_WAKE_UP_ACK);
319 spin_lock_irqsave(&st_gdata->lock, flags);
320
364 ptr++; 321 ptr++;
365 count--; 322 count--;
366 continue; 323 continue;
367 case LL_WAKE_UP_ACK: 324 case LL_WAKE_UP_ACK:
368 pr_info("PM packet"); 325 pr_debug("PM packet");
326
327 spin_unlock_irqrestore(&st_gdata->lock, flags);
369 /* wake up ack received */ 328 /* wake up ack received */
370 st_wakeup_ack(st_gdata, *ptr); 329 st_wakeup_ack(st_gdata, *ptr);
330 spin_lock_irqsave(&st_gdata->lock, flags);
331
371 ptr++; 332 ptr++;
372 count--; 333 count--;
373 continue; 334 continue;
374 /* Unknow packet? */ 335 /* Unknow packet? */
375 default: 336 default:
376 pr_err("Unknown packet type %2.2x", (__u8) *ptr); 337 type = *ptr;
377 ptr++; 338 st_gdata->rx_skb = alloc_skb(
378 count--; 339 st_gdata->list[type]->max_frame_size,
379 continue; 340 GFP_ATOMIC);
341 skb_reserve(st_gdata->rx_skb,
342 st_gdata->list[type]->reserve);
343 /* next 2 required for BT only */
344 st_gdata->rx_skb->cb[0] = type; /*pkt_type*/
345 st_gdata->rx_skb->cb[1] = 0; /*incoming*/
346 st_gdata->rx_chnl = *ptr;
347 st_gdata->rx_state = ST_W4_HEADER;
348 st_gdata->rx_count = st_gdata->list[type]->hdr_len;
349 pr_debug("rx_count %ld\n", st_gdata->rx_count);
380 }; 350 };
381 ptr++; 351 ptr++;
382 count--; 352 count--;
383
384 switch (protoid) {
385 case ST_BT:
386 /* Allocate new packet to hold received data */
387 st_gdata->rx_skb =
388 bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
389 if (!st_gdata->rx_skb) {
390 pr_err("Can't allocate mem for new packet");
391 st_gdata->rx_state = ST_W4_PACKET_TYPE;
392 st_gdata->rx_count = 0;
393 return;
394 }
395 bt_cb(st_gdata->rx_skb)->pkt_type = type;
396 break;
397 case ST_FM: /* for FM */
398 st_gdata->rx_skb =
399 alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC);
400 if (!st_gdata->rx_skb) {
401 pr_err("Can't allocate mem for new packet");
402 st_gdata->rx_state = ST_W4_PACKET_TYPE;
403 st_gdata->rx_count = 0;
404 return;
405 }
406 /* place holder 0x08 */
407 skb_reserve(st_gdata->rx_skb, 1);
408 st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT;
409 break;
410 case ST_GPS:
411 /* for GPS */
412 st_gdata->rx_skb =
413 alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ , GFP_ATOMIC);
414 if (!st_gdata->rx_skb) {
415 pr_err("Can't allocate mem for new packet");
416 st_gdata->rx_state = ST_W4_PACKET_TYPE;
417 st_gdata->rx_count = 0;
418 return;
419 }
420 /* place holder 0x09 */
421 skb_reserve(st_gdata->rx_skb, 1);
422 st_gdata->rx_skb->cb[0] = 0x09; /*ST_GPS_CH9_PKT; */
423 break;
424 case ST_MAX:
425 break;
426 }
427 } 353 }
354 spin_unlock_irqrestore(&st_gdata->lock, flags);
428 pr_debug("done %s", __func__); 355 pr_debug("done %s", __func__);
429 return; 356 return;
430} 357}
@@ -466,7 +393,7 @@ void st_int_enqueue(struct st_data_s *st_gdata, struct sk_buff *skb)
466 393
467 switch (st_ll_getstate(st_gdata)) { 394 switch (st_ll_getstate(st_gdata)) {
468 case ST_LL_AWAKE: 395 case ST_LL_AWAKE:
469 pr_info("ST LL is AWAKE, sending normally"); 396 pr_debug("ST LL is AWAKE, sending normally");
470 skb_queue_tail(&st_gdata->txq, skb); 397 skb_queue_tail(&st_gdata->txq, skb);
471 break; 398 break;
472 case ST_LL_ASLEEP_TO_AWAKE: 399 case ST_LL_ASLEEP_TO_AWAKE:
@@ -506,7 +433,7 @@ void st_tx_wakeup(struct st_data_s *st_data)
506 pr_debug("%s", __func__); 433 pr_debug("%s", __func__);
507 /* check for sending & set flag sending here */ 434 /* check for sending & set flag sending here */
508 if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) { 435 if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) {
509 pr_info("ST already sending"); 436 pr_debug("ST already sending");
510 /* keep sending */ 437 /* keep sending */
511 set_bit(ST_TX_WAKEUP, &st_data->tx_state); 438 set_bit(ST_TX_WAKEUP, &st_data->tx_state);
512 return; 439 return;
@@ -548,9 +475,9 @@ void kim_st_list_protocols(struct st_data_s *st_gdata, void *buf)
548{ 475{
549 seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n", 476 seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n",
550 st_gdata->protos_registered, 477 st_gdata->protos_registered,
551 st_gdata->list[ST_BT] != NULL ? 'R' : 'U', 478 st_gdata->list[0x04] != NULL ? 'R' : 'U',
552 st_gdata->list[ST_FM] != NULL ? 'R' : 'U', 479 st_gdata->list[0x08] != NULL ? 'R' : 'U',
553 st_gdata->list[ST_GPS] != NULL ? 'R' : 'U'); 480 st_gdata->list[0x09] != NULL ? 'R' : 'U');
554} 481}
555 482
556/********************************************************************/ 483/********************************************************************/
@@ -565,20 +492,20 @@ long st_register(struct st_proto_s *new_proto)
565 unsigned long flags = 0; 492 unsigned long flags = 0;
566 493
567 st_kim_ref(&st_gdata, 0); 494 st_kim_ref(&st_gdata, 0);
568 pr_info("%s(%d) ", __func__, new_proto->type); 495 pr_info("%s(%d) ", __func__, new_proto->chnl_id);
569 if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL 496 if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
570 || new_proto->reg_complete_cb == NULL) { 497 || new_proto->reg_complete_cb == NULL) {
571 pr_err("gdata/new_proto/recv or reg_complete_cb not ready"); 498 pr_err("gdata/new_proto/recv or reg_complete_cb not ready");
572 return -1; 499 return -EINVAL;
573 } 500 }
574 501
575 if (new_proto->type < ST_BT || new_proto->type >= ST_MAX) { 502 if (new_proto->chnl_id >= ST_MAX_CHANNELS) {
576 pr_err("protocol %d not supported", new_proto->type); 503 pr_err("chnl_id %d not supported", new_proto->chnl_id);
577 return -EPROTONOSUPPORT; 504 return -EPROTONOSUPPORT;
578 } 505 }
579 506
580 if (st_gdata->list[new_proto->type] != NULL) { 507 if (st_gdata->list[new_proto->chnl_id] != NULL) {
581 pr_err("protocol %d already registered", new_proto->type); 508 pr_err("chnl_id %d already registered", new_proto->chnl_id);
582 return -EALREADY; 509 return -EALREADY;
583 } 510 }
584 511
@@ -586,11 +513,10 @@ long st_register(struct st_proto_s *new_proto)
586 spin_lock_irqsave(&st_gdata->lock, flags); 513 spin_lock_irqsave(&st_gdata->lock, flags);
587 514
588 if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) { 515 if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) {
589 pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->type); 516 pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->chnl_id);
590 /* fw download in progress */ 517 /* fw download in progress */
591 st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
592 518
593 st_gdata->list[new_proto->type] = new_proto; 519 add_channel_to_table(st_gdata, new_proto);
594 st_gdata->protos_registered++; 520 st_gdata->protos_registered++;
595 new_proto->write = st_write; 521 new_proto->write = st_write;
596 522
@@ -598,7 +524,7 @@ long st_register(struct st_proto_s *new_proto)
598 spin_unlock_irqrestore(&st_gdata->lock, flags); 524 spin_unlock_irqrestore(&st_gdata->lock, flags);
599 return -EINPROGRESS; 525 return -EINPROGRESS;
600 } else if (st_gdata->protos_registered == ST_EMPTY) { 526 } else if (st_gdata->protos_registered == ST_EMPTY) {
601 pr_info(" protocol list empty :%d ", new_proto->type); 527 pr_info(" chnl_id list empty :%d ", new_proto->chnl_id);
602 set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); 528 set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
603 st_recv = st_kim_recv; 529 st_recv = st_kim_recv;
604 530
@@ -616,16 +542,11 @@ long st_register(struct st_proto_s *new_proto)
616 if ((st_gdata->protos_registered != ST_EMPTY) && 542 if ((st_gdata->protos_registered != ST_EMPTY) &&
617 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) { 543 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
618 pr_err(" KIM failure complete callback "); 544 pr_err(" KIM failure complete callback ");
619 st_reg_complete(st_gdata, -1); 545 st_reg_complete(st_gdata, err);
620 } 546 }
621 547 return -EINVAL;
622 return -1;
623 } 548 }
624 549
625 /* the protocol might require other gpios to be toggled
626 */
627 st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
628
629 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); 550 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
630 st_recv = st_int_recv; 551 st_recv = st_int_recv;
631 552
@@ -642,14 +563,14 @@ long st_register(struct st_proto_s *new_proto)
642 /* check for already registered once more, 563 /* check for already registered once more,
643 * since the above check is old 564 * since the above check is old
644 */ 565 */
645 if (st_gdata->list[new_proto->type] != NULL) { 566 if (st_gdata->list[new_proto->chnl_id] != NULL) {
646 pr_err(" proto %d already registered ", 567 pr_err(" proto %d already registered ",
647 new_proto->type); 568 new_proto->chnl_id);
648 return -EALREADY; 569 return -EALREADY;
649 } 570 }
650 571
651 spin_lock_irqsave(&st_gdata->lock, flags); 572 spin_lock_irqsave(&st_gdata->lock, flags);
652 st_gdata->list[new_proto->type] = new_proto; 573 add_channel_to_table(st_gdata, new_proto);
653 st_gdata->protos_registered++; 574 st_gdata->protos_registered++;
654 new_proto->write = st_write; 575 new_proto->write = st_write;
655 spin_unlock_irqrestore(&st_gdata->lock, flags); 576 spin_unlock_irqrestore(&st_gdata->lock, flags);
@@ -657,22 +578,7 @@ long st_register(struct st_proto_s *new_proto)
657 } 578 }
658 /* if fw is already downloaded & new stack registers protocol */ 579 /* if fw is already downloaded & new stack registers protocol */
659 else { 580 else {
660 switch (new_proto->type) { 581 add_channel_to_table(st_gdata, new_proto);
661 case ST_BT:
662 /* do nothing */
663 break;
664 case ST_FM:
665 case ST_GPS:
666 st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
667 break;
668 case ST_MAX:
669 default:
670 pr_err("%d protocol not supported",
671 new_proto->type);
672 spin_unlock_irqrestore(&st_gdata->lock, flags);
673 return -EPROTONOSUPPORT;
674 }
675 st_gdata->list[new_proto->type] = new_proto;
676 st_gdata->protos_registered++; 582 st_gdata->protos_registered++;
677 new_proto->write = st_write; 583 new_proto->write = st_write;
678 584
@@ -680,48 +586,42 @@ long st_register(struct st_proto_s *new_proto)
680 spin_unlock_irqrestore(&st_gdata->lock, flags); 586 spin_unlock_irqrestore(&st_gdata->lock, flags);
681 return err; 587 return err;
682 } 588 }
683 pr_debug("done %s(%d) ", __func__, new_proto->type); 589 pr_debug("done %s(%d) ", __func__, new_proto->chnl_id);
684} 590}
685EXPORT_SYMBOL_GPL(st_register); 591EXPORT_SYMBOL_GPL(st_register);
686 592
687/* to unregister a protocol - 593/* to unregister a protocol -
688 * to be called from protocol stack driver 594 * to be called from protocol stack driver
689 */ 595 */
690long st_unregister(enum proto_type type) 596long st_unregister(struct st_proto_s *proto)
691{ 597{
692 long err = 0; 598 long err = 0;
693 unsigned long flags = 0; 599 unsigned long flags = 0;
694 struct st_data_s *st_gdata; 600 struct st_data_s *st_gdata;
695 601
696 pr_debug("%s: %d ", __func__, type); 602 pr_debug("%s: %d ", __func__, proto->chnl_id);
697 603
698 st_kim_ref(&st_gdata, 0); 604 st_kim_ref(&st_gdata, 0);
699 if (type < ST_BT || type >= ST_MAX) { 605 if (proto->chnl_id >= ST_MAX_CHANNELS) {
700 pr_err(" protocol %d not supported", type); 606 pr_err(" chnl_id %d not supported", proto->chnl_id);
701 return -EPROTONOSUPPORT; 607 return -EPROTONOSUPPORT;
702 } 608 }
703 609
704 spin_lock_irqsave(&st_gdata->lock, flags); 610 spin_lock_irqsave(&st_gdata->lock, flags);
705 611
706 if (st_gdata->list[type] == NULL) { 612 if (st_gdata->list[proto->chnl_id] == NULL) {
707 pr_err(" protocol %d not registered", type); 613 pr_err(" chnl_id %d not registered", proto->chnl_id);
708 spin_unlock_irqrestore(&st_gdata->lock, flags); 614 spin_unlock_irqrestore(&st_gdata->lock, flags);
709 return -EPROTONOSUPPORT; 615 return -EPROTONOSUPPORT;
710 } 616 }
711 617
712 st_gdata->protos_registered--; 618 st_gdata->protos_registered--;
713 st_gdata->list[type] = NULL; 619 remove_channel_from_table(st_gdata, proto);
714
715 /* kim ignores BT in the below function
716 * and handles the rest, BT is toggled
717 * only in kim_start and kim_stop
718 */
719 st_kim_chip_toggle(type, KIM_GPIO_INACTIVE);
720 spin_unlock_irqrestore(&st_gdata->lock, flags); 620 spin_unlock_irqrestore(&st_gdata->lock, flags);
721 621
722 if ((st_gdata->protos_registered == ST_EMPTY) && 622 if ((st_gdata->protos_registered == ST_EMPTY) &&
723 (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) { 623 (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
724 pr_info(" all protocols unregistered "); 624 pr_info(" all chnl_ids unregistered ");
725 625
726 /* stop traffic on tty */ 626 /* stop traffic on tty */
727 if (st_gdata->tty) { 627 if (st_gdata->tty) {
@@ -729,7 +629,7 @@ long st_unregister(enum proto_type type)
729 stop_tty(st_gdata->tty); 629 stop_tty(st_gdata->tty);
730 } 630 }
731 631
732 /* all protocols now unregistered */ 632 /* all chnl_ids now unregistered */
733 st_kim_stop(st_gdata->kim_data); 633 st_kim_stop(st_gdata->kim_data);
734 /* disable ST LL */ 634 /* disable ST LL */
735 st_ll_disable(st_gdata); 635 st_ll_disable(st_gdata);
@@ -744,37 +644,15 @@ long st_unregister(enum proto_type type)
744long st_write(struct sk_buff *skb) 644long st_write(struct sk_buff *skb)
745{ 645{
746 struct st_data_s *st_gdata; 646 struct st_data_s *st_gdata;
747#ifdef DEBUG
748 enum proto_type protoid = ST_MAX;
749#endif
750 long len; 647 long len;
751 648
752 st_kim_ref(&st_gdata, 0); 649 st_kim_ref(&st_gdata, 0);
753 if (unlikely(skb == NULL || st_gdata == NULL 650 if (unlikely(skb == NULL || st_gdata == NULL
754 || st_gdata->tty == NULL)) { 651 || st_gdata->tty == NULL)) {
755 pr_err("data/tty unavailable to perform write"); 652 pr_err("data/tty unavailable to perform write");
756 return -1; 653 return -EINVAL;
757 } 654 }
758#ifdef DEBUG /* open-up skb to read the 1st byte */ 655
759 switch (skb->data[0]) {
760 case HCI_COMMAND_PKT:
761 case HCI_ACLDATA_PKT:
762 case HCI_SCODATA_PKT:
763 protoid = ST_BT;
764 break;
765 case ST_FM_CH8_PKT:
766 protoid = ST_FM;
767 break;
768 case 0x09:
769 protoid = ST_GPS;
770 break;
771 }
772 if (unlikely(st_gdata->list[protoid] == NULL)) {
773 pr_err(" protocol %d not registered, and writing? ",
774 protoid);
775 return -1;
776 }
777#endif
778 pr_debug("%d to be written", skb->len); 656 pr_debug("%d to be written", skb->len);
779 len = skb->len; 657 len = skb->len;
780 658
@@ -824,7 +702,7 @@ static int st_tty_open(struct tty_struct *tty)
824 702
825static void st_tty_close(struct tty_struct *tty) 703static void st_tty_close(struct tty_struct *tty)
826{ 704{
827 unsigned char i = ST_MAX; 705 unsigned char i = ST_MAX_CHANNELS;
828 unsigned long flags = 0; 706 unsigned long flags = 0;
829 struct st_data_s *st_gdata = tty->disc_data; 707 struct st_data_s *st_gdata = tty->disc_data;
830 708
@@ -835,7 +713,7 @@ static void st_tty_close(struct tty_struct *tty)
835 * un-installed for some reason - what should be done ? 713 * un-installed for some reason - what should be done ?
836 */ 714 */
837 spin_lock_irqsave(&st_gdata->lock, flags); 715 spin_lock_irqsave(&st_gdata->lock, flags);
838 for (i = ST_BT; i < ST_MAX; i++) { 716 for (i = ST_BT; i < ST_MAX_CHANNELS; i++) {
839 if (st_gdata->list[i] != NULL) 717 if (st_gdata->list[i] != NULL)
840 pr_err("%d not un-registered", i); 718 pr_err("%d not un-registered", i);
841 st_gdata->list[i] = NULL; 719 st_gdata->list[i] = NULL;
@@ -869,7 +747,6 @@ static void st_tty_close(struct tty_struct *tty)
869static void st_tty_receive(struct tty_struct *tty, const unsigned char *data, 747static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
870 char *tty_flags, int count) 748 char *tty_flags, int count)
871{ 749{
872
873#ifdef VERBOSE 750#ifdef VERBOSE
874 print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE, 751 print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE,
875 16, 1, data, count, 0); 752 16, 1, data, count, 0);
@@ -960,7 +837,7 @@ int st_core_init(struct st_data_s **core_data)
960 err = tty_unregister_ldisc(N_TI_WL); 837 err = tty_unregister_ldisc(N_TI_WL);
961 if (err) 838 if (err)
962 pr_err("unable to un-register ldisc"); 839 pr_err("unable to un-register ldisc");
963 return -1; 840 return err;
964 } 841 }
965 *core_data = st_gdata; 842 *core_data = st_gdata;
966 return 0; 843 return 0;
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index 73b6c8b0e869..9ee4c788aa69 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -30,50 +30,12 @@
30#include <linux/debugfs.h> 30#include <linux/debugfs.h>
31#include <linux/seq_file.h> 31#include <linux/seq_file.h>
32#include <linux/sched.h> 32#include <linux/sched.h>
33#include <linux/rfkill.h> 33#include <linux/tty.h>
34
35/* understand BT events for fw response */
36#include <net/bluetooth/bluetooth.h>
37#include <net/bluetooth/hci_core.h>
38#include <net/bluetooth/hci.h>
39 34
35#include <linux/skbuff.h>
40#include <linux/ti_wilink_st.h> 36#include <linux/ti_wilink_st.h>
41 37
42 38
43static int kim_probe(struct platform_device *pdev);
44static int kim_remove(struct platform_device *pdev);
45
46/* KIM platform device driver structure */
47static struct platform_driver kim_platform_driver = {
48 .probe = kim_probe,
49 .remove = kim_remove,
50 /* TODO: ST driver power management during suspend/resume ?
51 */
52#if 0
53 .suspend = kim_suspend,
54 .resume = kim_resume,
55#endif
56 .driver = {
57 .name = "kim",
58 .owner = THIS_MODULE,
59 },
60};
61
62static int kim_toggle_radio(void*, bool);
63static const struct rfkill_ops kim_rfkill_ops = {
64 .set_block = kim_toggle_radio,
65};
66
67/* strings to be used for rfkill entries and by
68 * ST Core to be used for sysfs debug entry
69 */
70#define PROTO_ENTRY(type, name) name
71const unsigned char *protocol_names[] = {
72 PROTO_ENTRY(ST_BT, "Bluetooth"),
73 PROTO_ENTRY(ST_FM, "FM"),
74 PROTO_ENTRY(ST_GPS, "GPS"),
75};
76
77#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ 39#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */
78static struct platform_device *st_kim_devices[MAX_ST_DEVICES]; 40static struct platform_device *st_kim_devices[MAX_ST_DEVICES];
79 41
@@ -134,7 +96,7 @@ static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len)
134 /* Packet header has non-zero payload length and 96 /* Packet header has non-zero payload length and
135 * we have enough space in created skb. Lets read 97 * we have enough space in created skb. Lets read
136 * payload data */ 98 * payload data */
137 kim_gdata->rx_state = ST_BT_W4_DATA; 99 kim_gdata->rx_state = ST_W4_DATA;
138 kim_gdata->rx_count = len; 100 kim_gdata->rx_count = len;
139 return len; 101 return len;
140 } 102 }
@@ -158,8 +120,8 @@ void kim_int_recv(struct kim_data_s *kim_gdata,
158 const unsigned char *data, long count) 120 const unsigned char *data, long count)
159{ 121{
160 const unsigned char *ptr; 122 const unsigned char *ptr;
161 struct hci_event_hdr *eh;
162 int len = 0, type = 0; 123 int len = 0, type = 0;
124 unsigned char *plen;
163 125
164 pr_debug("%s", __func__); 126 pr_debug("%s", __func__);
165 /* Decode received bytes here */ 127 /* Decode received bytes here */
@@ -183,29 +145,27 @@ void kim_int_recv(struct kim_data_s *kim_gdata,
183 /* Check ST RX state machine , where are we? */ 145 /* Check ST RX state machine , where are we? */
184 switch (kim_gdata->rx_state) { 146 switch (kim_gdata->rx_state) {
185 /* Waiting for complete packet ? */ 147 /* Waiting for complete packet ? */
186 case ST_BT_W4_DATA: 148 case ST_W4_DATA:
187 pr_debug("Complete pkt received"); 149 pr_debug("Complete pkt received");
188 validate_firmware_response(kim_gdata); 150 validate_firmware_response(kim_gdata);
189 kim_gdata->rx_state = ST_W4_PACKET_TYPE; 151 kim_gdata->rx_state = ST_W4_PACKET_TYPE;
190 kim_gdata->rx_skb = NULL; 152 kim_gdata->rx_skb = NULL;
191 continue; 153 continue;
192 /* Waiting for Bluetooth event header ? */ 154 /* Waiting for Bluetooth event header ? */
193 case ST_BT_W4_EVENT_HDR: 155 case ST_W4_HEADER:
194 eh = (struct hci_event_hdr *)kim_gdata-> 156 plen =
195 rx_skb->data; 157 (unsigned char *)&kim_gdata->rx_skb->data[1];
196 pr_debug("Event header: evt 0x%2.2x" 158 pr_debug("event hdr: plen 0x%02x\n", *plen);
197 "plen %d", eh->evt, eh->plen); 159 kim_check_data_len(kim_gdata, *plen);
198 kim_check_data_len(kim_gdata, eh->plen);
199 continue; 160 continue;
200 } /* end of switch */ 161 } /* end of switch */
201 } /* end of if rx_state */ 162 } /* end of if rx_state */
202 switch (*ptr) { 163 switch (*ptr) {
203 /* Bluetooth event packet? */ 164 /* Bluetooth event packet? */
204 case HCI_EVENT_PKT: 165 case 0x04:
205 pr_info("Event packet"); 166 kim_gdata->rx_state = ST_W4_HEADER;
206 kim_gdata->rx_state = ST_BT_W4_EVENT_HDR; 167 kim_gdata->rx_count = 2;
207 kim_gdata->rx_count = HCI_EVENT_HDR_SIZE; 168 type = *ptr;
208 type = HCI_EVENT_PKT;
209 break; 169 break;
210 default: 170 default:
211 pr_info("unknown packet"); 171 pr_info("unknown packet");
@@ -216,16 +176,18 @@ void kim_int_recv(struct kim_data_s *kim_gdata,
216 ptr++; 176 ptr++;
217 count--; 177 count--;
218 kim_gdata->rx_skb = 178 kim_gdata->rx_skb =
219 bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); 179 alloc_skb(1024+8, GFP_ATOMIC);
220 if (!kim_gdata->rx_skb) { 180 if (!kim_gdata->rx_skb) {
221 pr_err("can't allocate mem for new packet"); 181 pr_err("can't allocate mem for new packet");
222 kim_gdata->rx_state = ST_W4_PACKET_TYPE; 182 kim_gdata->rx_state = ST_W4_PACKET_TYPE;
223 kim_gdata->rx_count = 0; 183 kim_gdata->rx_count = 0;
224 return; 184 return;
225 } 185 }
226 bt_cb(kim_gdata->rx_skb)->pkt_type = type; 186 skb_reserve(kim_gdata->rx_skb, 8);
187 kim_gdata->rx_skb->cb[0] = 4;
188 kim_gdata->rx_skb->cb[1] = 0;
189
227 } 190 }
228 pr_info("done %s", __func__);
229 return; 191 return;
230} 192}
231 193
@@ -239,13 +201,13 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
239 INIT_COMPLETION(kim_gdata->kim_rcvd); 201 INIT_COMPLETION(kim_gdata->kim_rcvd);
240 if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) { 202 if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) {
241 pr_err("kim: couldn't write 4 bytes"); 203 pr_err("kim: couldn't write 4 bytes");
242 return -1; 204 return -EIO;
243 } 205 }
244 206
245 if (!wait_for_completion_timeout 207 if (!wait_for_completion_timeout
246 (&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) { 208 (&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) {
247 pr_err(" waiting for ver info- timed out "); 209 pr_err(" waiting for ver info- timed out ");
248 return -1; 210 return -ETIMEDOUT;
249 } 211 }
250 212
251 version = 213 version =
@@ -270,6 +232,26 @@ static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
270 return 0; 232 return 0;
271} 233}
272 234
235void skip_change_remote_baud(unsigned char **ptr, long *len)
236{
237 unsigned char *nxt_action, *cur_action;
238 cur_action = *ptr;
239
240 nxt_action = cur_action + sizeof(struct bts_action) +
241 ((struct bts_action *) cur_action)->size;
242
243 if (((struct bts_action *) nxt_action)->type != ACTION_WAIT_EVENT) {
244 pr_err("invalid action after change remote baud command");
245 } else {
246 *ptr = *ptr + sizeof(struct bts_action) +
247 ((struct bts_action *)nxt_action)->size;
248 *len = *len - (sizeof(struct bts_action) +
249 ((struct bts_action *)nxt_action)->size);
250 /* warn user on not commenting these in firmware */
251 pr_warn("skipping the wait event of change remote baud");
252 }
253}
254
273/** 255/**
274 * download_firmware - 256 * download_firmware -
275 * internal function which parses through the .bts firmware 257 * internal function which parses through the .bts firmware
@@ -282,6 +264,9 @@ static long download_firmware(struct kim_data_s *kim_gdata)
282 unsigned char *ptr = NULL; 264 unsigned char *ptr = NULL;
283 unsigned char *action_ptr = NULL; 265 unsigned char *action_ptr = NULL;
284 unsigned char bts_scr_name[30] = { 0 }; /* 30 char long bts scr name? */ 266 unsigned char bts_scr_name[30] = { 0 }; /* 30 char long bts scr name? */
267 int wr_room_space;
268 int cmd_size;
269 unsigned long timeout;
285 270
286 err = read_local_version(kim_gdata, bts_scr_name); 271 err = read_local_version(kim_gdata, bts_scr_name);
287 if (err != 0) { 272 if (err != 0) {
@@ -295,7 +280,7 @@ static long download_firmware(struct kim_data_s *kim_gdata)
295 (kim_gdata->fw_entry->size == 0))) { 280 (kim_gdata->fw_entry->size == 0))) {
296 pr_err(" request_firmware failed(errno %ld) for %s", err, 281 pr_err(" request_firmware failed(errno %ld) for %s", err,
297 bts_scr_name); 282 bts_scr_name);
298 return -1; 283 return -EINVAL;
299 } 284 }
300 ptr = (void *)kim_gdata->fw_entry->data; 285 ptr = (void *)kim_gdata->fw_entry->data;
301 len = kim_gdata->fw_entry->size; 286 len = kim_gdata->fw_entry->size;
@@ -318,29 +303,72 @@ static long download_firmware(struct kim_data_s *kim_gdata)
318 0xFF36)) { 303 0xFF36)) {
319 /* ignore remote change 304 /* ignore remote change
320 * baud rate HCI VS command */ 305 * baud rate HCI VS command */
321 pr_err 306 pr_warn("change remote baud"
322 (" change remote baud"
323 " rate command in firmware"); 307 " rate command in firmware");
308 skip_change_remote_baud(&ptr, &len);
324 break; 309 break;
325 } 310 }
311 /*
312 * Make sure we have enough free space in uart
313 * tx buffer to write current firmware command
314 */
315 cmd_size = ((struct bts_action *)ptr)->size;
316 timeout = jiffies + msecs_to_jiffies(CMD_WR_TIME);
317 do {
318 wr_room_space =
319 st_get_uart_wr_room(kim_gdata->core_data);
320 if (wr_room_space < 0) {
321 pr_err("Unable to get free "
322 "space info from uart tx buffer");
323 release_firmware(kim_gdata->fw_entry);
324 return wr_room_space;
325 }
326 mdelay(1); /* wait 1ms before checking room */
327 } while ((wr_room_space < cmd_size) &&
328 time_before(jiffies, timeout));
329
330 /* Timeout happened ? */
331 if (time_after_eq(jiffies, timeout)) {
332 pr_err("Timeout while waiting for free "
333 "free space in uart tx buffer");
334 release_firmware(kim_gdata->fw_entry);
335 return -ETIMEDOUT;
336 }
326 337
327 INIT_COMPLETION(kim_gdata->kim_rcvd); 338 /*
339 * Free space found in uart buffer, call st_int_write
340 * to send current firmware command to the uart tx
341 * buffer.
342 */
328 err = st_int_write(kim_gdata->core_data, 343 err = st_int_write(kim_gdata->core_data,
329 ((struct bts_action_send *)action_ptr)->data, 344 ((struct bts_action_send *)action_ptr)->data,
330 ((struct bts_action *)ptr)->size); 345 ((struct bts_action *)ptr)->size);
331 if (unlikely(err < 0)) { 346 if (unlikely(err < 0)) {
332 release_firmware(kim_gdata->fw_entry); 347 release_firmware(kim_gdata->fw_entry);
333 return -1; 348 return err;
334 } 349 }
350 /*
351 * Check number of bytes written to the uart tx buffer
352 * and requested command write size
353 */
354 if (err != cmd_size) {
355 pr_err("Number of bytes written to uart "
356 "tx buffer are not matching with "
357 "requested cmd write size");
358 release_firmware(kim_gdata->fw_entry);
359 return -EIO;
360 }
361 break;
362 case ACTION_WAIT_EVENT: /* wait */
335 if (!wait_for_completion_timeout 363 if (!wait_for_completion_timeout
336 (&kim_gdata->kim_rcvd, 364 (&kim_gdata->kim_rcvd,
337 msecs_to_jiffies(CMD_RESP_TIME))) { 365 msecs_to_jiffies(CMD_RESP_TIME))) {
338 pr_err 366 pr_err("response timeout during fw download ");
339 (" response timeout during fw download ");
340 /* timed out */ 367 /* timed out */
341 release_firmware(kim_gdata->fw_entry); 368 release_firmware(kim_gdata->fw_entry);
342 return -1; 369 return -ETIMEDOUT;
343 } 370 }
371 INIT_COMPLETION(kim_gdata->kim_rcvd);
344 break; 372 break;
345 case ACTION_DELAY: /* sleep */ 373 case ACTION_DELAY: /* sleep */
346 pr_info("sleep command in scr"); 374 pr_info("sleep command in scr");
@@ -362,50 +390,6 @@ static long download_firmware(struct kim_data_s *kim_gdata)
362 390
363/**********************************************************************/ 391/**********************************************************************/
364/* functions called from ST core */ 392/* functions called from ST core */
365/* function to toggle the GPIO
366 * needs to know whether the GPIO is active high or active low
367 */
368void st_kim_chip_toggle(enum proto_type type, enum kim_gpio_state state)
369{
370 struct platform_device *kim_pdev;
371 struct kim_data_s *kim_gdata;
372 pr_info(" %s ", __func__);
373
374 kim_pdev = st_get_plat_device(0);
375 kim_gdata = dev_get_drvdata(&kim_pdev->dev);
376
377 if (kim_gdata->gpios[type] == -1) {
378 pr_info(" gpio not requested for protocol %s",
379 protocol_names[type]);
380 return;
381 }
382 switch (type) {
383 case ST_BT:
384 /*Do Nothing */
385 break;
386
387 case ST_FM:
388 if (state == KIM_GPIO_ACTIVE)
389 gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_LOW);
390 else
391 gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_HIGH);
392 break;
393
394 case ST_GPS:
395 if (state == KIM_GPIO_ACTIVE)
396 gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_HIGH);
397 else
398 gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_LOW);
399 break;
400
401 case ST_MAX:
402 default:
403 break;
404 }
405
406 return;
407}
408
409/* called from ST Core, when REG_IN_PROGRESS (registration in progress) 393/* called from ST Core, when REG_IN_PROGRESS (registration in progress)
410 * can be because of 394 * can be because of
411 * 1. response to read local version 395 * 1. response to read local version
@@ -416,7 +400,6 @@ void st_kim_recv(void *disc_data, const unsigned char *data, long count)
416 struct st_data_s *st_gdata = (struct st_data_s *)disc_data; 400 struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
417 struct kim_data_s *kim_gdata = st_gdata->kim_data; 401 struct kim_data_s *kim_gdata = st_gdata->kim_data;
418 402
419 pr_info(" %s ", __func__);
420 /* copy to local buffer */ 403 /* copy to local buffer */
421 if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) { 404 if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) {
422 /* must be the read_ver_cmd */ 405 /* must be the read_ver_cmd */
@@ -455,35 +438,28 @@ long st_kim_start(void *kim_data)
455 pr_info(" %s", __func__); 438 pr_info(" %s", __func__);
456 439
457 do { 440 do {
458 /* TODO: this is only because rfkill sub-system
459 * doesn't send events to user-space if the state
460 * isn't changed
461 */
462 rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1);
463 /* Configure BT nShutdown to HIGH state */ 441 /* Configure BT nShutdown to HIGH state */
464 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); 442 gpio_set_value(kim_gdata->nshutdown, GPIO_LOW);
465 mdelay(5); /* FIXME: a proper toggle */ 443 mdelay(5); /* FIXME: a proper toggle */
466 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH); 444 gpio_set_value(kim_gdata->nshutdown, GPIO_HIGH);
467 mdelay(100); 445 mdelay(100);
468 /* re-initialize the completion */ 446 /* re-initialize the completion */
469 INIT_COMPLETION(kim_gdata->ldisc_installed); 447 INIT_COMPLETION(kim_gdata->ldisc_installed);
470#if 0 /* older way of signalling user-space UIM */ 448 /* send notification to UIM */
471 /* send signal to UIM */ 449 kim_gdata->ldisc_install = 1;
472 err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 0); 450 pr_info("ldisc_install = 1");
473 if (err != 0) { 451 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj,
474 pr_info(" sending SIGUSR2 to uim failed %ld", err); 452 NULL, "install");
475 err = -1;
476 continue;
477 }
478#endif
479 /* unblock and send event to UIM via /dev/rfkill */
480 rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 0);
481 /* wait for ldisc to be installed */ 453 /* wait for ldisc to be installed */
482 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, 454 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed,
483 msecs_to_jiffies(LDISC_TIME)); 455 msecs_to_jiffies(LDISC_TIME));
484 if (!err) { /* timeout */ 456 if (!err) { /* timeout */
485 pr_err("line disc installation timed out "); 457 pr_err("line disc installation timed out ");
486 err = -1; 458 kim_gdata->ldisc_install = 0;
459 pr_info("ldisc_install = 0");
460 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj,
461 NULL, "install");
462 err = -ETIMEDOUT;
487 continue; 463 continue;
488 } else { 464 } else {
489 /* ldisc installed now */ 465 /* ldisc installed now */
@@ -491,6 +467,10 @@ long st_kim_start(void *kim_data)
491 err = download_firmware(kim_gdata); 467 err = download_firmware(kim_gdata);
492 if (err != 0) { 468 if (err != 0) {
493 pr_err("download firmware failed"); 469 pr_err("download firmware failed");
470 kim_gdata->ldisc_install = 0;
471 pr_info("ldisc_install = 0");
472 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj,
473 NULL, "install");
494 continue; 474 continue;
495 } else { /* on success don't retry */ 475 } else { /* on success don't retry */
496 break; 476 break;
@@ -510,31 +490,30 @@ long st_kim_stop(void *kim_data)
510 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 490 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
511 491
512 INIT_COMPLETION(kim_gdata->ldisc_installed); 492 INIT_COMPLETION(kim_gdata->ldisc_installed);
513#if 0 /* older way of signalling user-space UIM */ 493
514 /* send signal to UIM */ 494 /* Flush any pending characters in the driver and discipline. */
515 err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 1); 495 tty_ldisc_flush(kim_gdata->core_data->tty);
516 if (err != 0) { 496 tty_driver_flush_buffer(kim_gdata->core_data->tty);
517 pr_err("sending SIGUSR2 to uim failed %ld", err); 497
518 return -1; 498 /* send uninstall notification to UIM */
519 } 499 pr_info("ldisc_install = 0");
520#endif 500 kim_gdata->ldisc_install = 0;
521 /* set BT rfkill to be blocked */ 501 sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, NULL, "install");
522 err = rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1);
523 502
524 /* wait for ldisc to be un-installed */ 503 /* wait for ldisc to be un-installed */
525 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, 504 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed,
526 msecs_to_jiffies(LDISC_TIME)); 505 msecs_to_jiffies(LDISC_TIME));
527 if (!err) { /* timeout */ 506 if (!err) { /* timeout */
528 pr_err(" timed out waiting for ldisc to be un-installed"); 507 pr_err(" timed out waiting for ldisc to be un-installed");
529 return -1; 508 return -ETIMEDOUT;
530 } 509 }
531 510
532 /* By default configure BT nShutdown to LOW state */ 511 /* By default configure BT nShutdown to LOW state */
533 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); 512 gpio_set_value(kim_gdata->nshutdown, GPIO_LOW);
534 mdelay(1); 513 mdelay(1);
535 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH); 514 gpio_set_value(kim_gdata->nshutdown, GPIO_HIGH);
536 mdelay(1); 515 mdelay(1);
537 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); 516 gpio_set_value(kim_gdata->nshutdown, GPIO_LOW);
538 return err; 517 return err;
539} 518}
540 519
@@ -558,33 +537,59 @@ static int show_list(struct seq_file *s, void *unused)
558 return 0; 537 return 0;
559} 538}
560 539
561/* function called from rfkill subsystem, when someone from 540static ssize_t show_install(struct device *dev,
562 * user space would write 0/1 on the sysfs entry 541 struct device_attribute *attr, char *buf)
563 * /sys/class/rfkill/rfkill0,1,3/state
564 */
565static int kim_toggle_radio(void *data, bool blocked)
566{ 542{
567 enum proto_type type = *((enum proto_type *)data); 543 struct kim_data_s *kim_data = dev_get_drvdata(dev);
568 pr_debug(" %s: %d ", __func__, type); 544 return sprintf(buf, "%d\n", kim_data->ldisc_install);
569
570 switch (type) {
571 case ST_BT:
572 /* do nothing */
573 break;
574 case ST_FM:
575 case ST_GPS:
576 if (blocked)
577 st_kim_chip_toggle(type, KIM_GPIO_INACTIVE);
578 else
579 st_kim_chip_toggle(type, KIM_GPIO_ACTIVE);
580 break;
581 case ST_MAX:
582 pr_err(" wrong proto type ");
583 break;
584 }
585 return 0;
586} 545}
587 546
547static ssize_t show_dev_name(struct device *dev,
548 struct device_attribute *attr, char *buf)
549{
550 struct kim_data_s *kim_data = dev_get_drvdata(dev);
551 return sprintf(buf, "%s\n", kim_data->dev_name);
552}
553
554static ssize_t show_baud_rate(struct device *dev,
555 struct device_attribute *attr, char *buf)
556{
557 struct kim_data_s *kim_data = dev_get_drvdata(dev);
558 return sprintf(buf, "%ld\n", kim_data->baud_rate);
559}
560
561static ssize_t show_flow_cntrl(struct device *dev,
562 struct device_attribute *attr, char *buf)
563{
564 struct kim_data_s *kim_data = dev_get_drvdata(dev);
565 return sprintf(buf, "%d\n", kim_data->flow_cntrl);
566}
567
568/* structures specific for sysfs entries */
569static struct kobj_attribute ldisc_install =
570__ATTR(install, 0444, (void *)show_install, NULL);
571
572static struct kobj_attribute uart_dev_name =
573__ATTR(dev_name, 0444, (void *)show_dev_name, NULL);
574
575static struct kobj_attribute uart_baud_rate =
576__ATTR(baud_rate, 0444, (void *)show_baud_rate, NULL);
577
578static struct kobj_attribute uart_flow_cntrl =
579__ATTR(flow_cntrl, 0444, (void *)show_flow_cntrl, NULL);
580
581static struct attribute *uim_attrs[] = {
582 &ldisc_install.attr,
583 &uart_dev_name.attr,
584 &uart_baud_rate.attr,
585 &uart_flow_cntrl.attr,
586 NULL,
587};
588
589static struct attribute_group uim_attr_grp = {
590 .attrs = uim_attrs,
591};
592
588/** 593/**
589 * st_kim_ref - reference the core's data 594 * st_kim_ref - reference the core's data
590 * This references the per-ST platform device in the arch/xx/ 595 * This references the per-ST platform device in the arch/xx/
@@ -637,9 +642,8 @@ struct dentry *kim_debugfs_dir;
637static int kim_probe(struct platform_device *pdev) 642static int kim_probe(struct platform_device *pdev)
638{ 643{
639 long status; 644 long status;
640 long proto;
641 long *gpios = pdev->dev.platform_data;
642 struct kim_data_s *kim_gdata; 645 struct kim_data_s *kim_gdata;
646 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
643 647
644 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) { 648 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) {
645 /* multiple devices could exist */ 649 /* multiple devices could exist */
@@ -659,44 +663,24 @@ static int kim_probe(struct platform_device *pdev)
659 status = st_core_init(&kim_gdata->core_data); 663 status = st_core_init(&kim_gdata->core_data);
660 if (status != 0) { 664 if (status != 0) {
661 pr_err(" ST core init failed"); 665 pr_err(" ST core init failed");
662 return -1; 666 return -EIO;
663 } 667 }
664 /* refer to itself */ 668 /* refer to itself */
665 kim_gdata->core_data->kim_data = kim_gdata; 669 kim_gdata->core_data->kim_data = kim_gdata;
666 670
667 for (proto = 0; proto < ST_MAX; proto++) { 671 /* Claim the chip enable nShutdown gpio from the system */
668 kim_gdata->gpios[proto] = gpios[proto]; 672 kim_gdata->nshutdown = pdata->nshutdown_gpio;
669 pr_info(" %ld gpio to be requested", gpios[proto]); 673 status = gpio_request(kim_gdata->nshutdown, "kim");
674 if (unlikely(status)) {
675 pr_err(" gpio %ld request failed ", kim_gdata->nshutdown);
676 return status;
670 } 677 }
671 678
672 for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { 679 /* Configure nShutdown GPIO as output=0 */
673 /* Claim the Bluetooth/FM/GPIO 680 status = gpio_direction_output(kim_gdata->nshutdown, 0);
674 * nShutdown gpio from the system 681 if (unlikely(status)) {
675 */ 682 pr_err(" unable to configure gpio %ld", kim_gdata->nshutdown);
676 status = gpio_request(gpios[proto], "kim"); 683 return status;
677 if (unlikely(status)) {
678 pr_err(" gpio %ld request failed ", gpios[proto]);
679 proto -= 1;
680 while (proto >= 0) {
681 if (gpios[proto] != -1)
682 gpio_free(gpios[proto]);
683 }
684 return status;
685 }
686
687 /* Configure nShutdown GPIO as output=0 */
688 status =
689 gpio_direction_output(gpios[proto], 0);
690 if (unlikely(status)) {
691 pr_err(" unable to configure gpio %ld",
692 gpios[proto]);
693 proto -= 1;
694 while (proto >= 0) {
695 if (gpios[proto] != -1)
696 gpio_free(gpios[proto]);
697 }
698 return status;
699 }
700 } 684 }
701 /* get reference of pdev for request_firmware 685 /* get reference of pdev for request_firmware
702 */ 686 */
@@ -704,34 +688,23 @@ static int kim_probe(struct platform_device *pdev)
704 init_completion(&kim_gdata->kim_rcvd); 688 init_completion(&kim_gdata->kim_rcvd);
705 init_completion(&kim_gdata->ldisc_installed); 689 init_completion(&kim_gdata->ldisc_installed);
706 690
707 for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { 691 status = sysfs_create_group(&pdev->dev.kobj, &uim_attr_grp);
708 /* TODO: should all types be rfkill_type_bt ? */ 692 if (status) {
709 kim_gdata->rf_protos[proto] = proto; 693 pr_err("failed to create sysfs entries");
710 kim_gdata->rfkill[proto] = rfkill_alloc(protocol_names[proto], 694 return status;
711 &pdev->dev, RFKILL_TYPE_BLUETOOTH,
712 &kim_rfkill_ops, &kim_gdata->rf_protos[proto]);
713 if (kim_gdata->rfkill[proto] == NULL) {
714 pr_err("cannot create rfkill entry for gpio %ld",
715 gpios[proto]);
716 continue;
717 }
718 /* block upon creation */
719 rfkill_init_sw_state(kim_gdata->rfkill[proto], 1);
720 status = rfkill_register(kim_gdata->rfkill[proto]);
721 if (unlikely(status)) {
722 pr_err("rfkill registration failed for gpio %ld",
723 gpios[proto]);
724 rfkill_unregister(kim_gdata->rfkill[proto]);
725 continue;
726 }
727 pr_info("rfkill entry created for %ld", gpios[proto]);
728 } 695 }
729 696
697 /* copying platform data */
698 strncpy(kim_gdata->dev_name, pdata->dev_name, UART_DEV_NAME_LEN);
699 kim_gdata->flow_cntrl = pdata->flow_cntrl;
700 kim_gdata->baud_rate = pdata->baud_rate;
701 pr_info("sysfs entries created\n");
702
730 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL); 703 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL);
731 if (IS_ERR(kim_debugfs_dir)) { 704 if (IS_ERR(kim_debugfs_dir)) {
732 pr_err(" debugfs entries creation failed "); 705 pr_err(" debugfs entries creation failed ");
733 kim_debugfs_dir = NULL; 706 kim_debugfs_dir = NULL;
734 return -1; 707 return -EIO;
735 } 708 }
736 709
737 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir, 710 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir,
@@ -744,25 +717,22 @@ static int kim_probe(struct platform_device *pdev)
744 717
745static int kim_remove(struct platform_device *pdev) 718static int kim_remove(struct platform_device *pdev)
746{ 719{
747 /* free the GPIOs requested 720 /* free the GPIOs requested */
748 */ 721 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
749 long *gpios = pdev->dev.platform_data;
750 long proto;
751 struct kim_data_s *kim_gdata; 722 struct kim_data_s *kim_gdata;
752 723
753 kim_gdata = dev_get_drvdata(&pdev->dev); 724 kim_gdata = dev_get_drvdata(&pdev->dev);
754 725
755 for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { 726 /* Free the Bluetooth/FM/GPIO
756 /* Claim the Bluetooth/FM/GPIO 727 * nShutdown gpio from the system
757 * nShutdown gpio from the system 728 */
758 */ 729 gpio_free(pdata->nshutdown_gpio);
759 gpio_free(gpios[proto]); 730 pr_info("nshutdown GPIO Freed");
760 rfkill_unregister(kim_gdata->rfkill[proto]); 731
761 rfkill_destroy(kim_gdata->rfkill[proto]);
762 kim_gdata->rfkill[proto] = NULL;
763 }
764 pr_info("kim: GPIO Freed");
765 debugfs_remove_recursive(kim_debugfs_dir); 732 debugfs_remove_recursive(kim_debugfs_dir);
733 sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp);
734 pr_info("sysfs entries removed");
735
766 kim_gdata->kim_pdev = NULL; 736 kim_gdata->kim_pdev = NULL;
767 st_core_exit(kim_gdata->core_data); 737 st_core_exit(kim_gdata->core_data);
768 738
@@ -771,23 +741,46 @@ static int kim_remove(struct platform_device *pdev)
771 return 0; 741 return 0;
772} 742}
773 743
744int kim_suspend(struct platform_device *pdev, pm_message_t state)
745{
746 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
747
748 if (pdata->suspend)
749 return pdata->suspend(pdev, state);
750
751 return -EOPNOTSUPP;
752}
753
754int kim_resume(struct platform_device *pdev)
755{
756 struct ti_st_plat_data *pdata = pdev->dev.platform_data;
757
758 if (pdata->resume)
759 return pdata->resume(pdev);
760
761 return -EOPNOTSUPP;
762}
763
774/**********************************************************************/ 764/**********************************************************************/
775/* entry point for ST KIM module, called in from ST Core */ 765/* entry point for ST KIM module, called in from ST Core */
766static struct platform_driver kim_platform_driver = {
767 .probe = kim_probe,
768 .remove = kim_remove,
769 .suspend = kim_suspend,
770 .resume = kim_resume,
771 .driver = {
772 .name = "kim",
773 .owner = THIS_MODULE,
774 },
775};
776 776
777static int __init st_kim_init(void) 777static int __init st_kim_init(void)
778{ 778{
779 long ret = 0; 779 return platform_driver_register(&kim_platform_driver);
780 ret = platform_driver_register(&kim_platform_driver);
781 if (ret != 0) {
782 pr_err("platform drv registration failed");
783 return -1;
784 }
785 return 0;
786} 780}
787 781
788static void __exit st_kim_deinit(void) 782static void __exit st_kim_deinit(void)
789{ 783{
790 /* the following returns void */
791 platform_driver_unregister(&kim_platform_driver); 784 platform_driver_unregister(&kim_platform_driver);
792} 785}
793 786
diff --git a/drivers/misc/ti-st/st_ll.c b/drivers/misc/ti-st/st_ll.c
index 2bda8dea15b0..3f2495138855 100644
--- a/drivers/misc/ti-st/st_ll.c
+++ b/drivers/misc/ti-st/st_ll.c
@@ -30,7 +30,7 @@ static void send_ll_cmd(struct st_data_s *st_data,
30 unsigned char cmd) 30 unsigned char cmd)
31{ 31{
32 32
33 pr_info("%s: writing %x", __func__, cmd); 33 pr_debug("%s: writing %x", __func__, cmd);
34 st_int_write(st_data, &cmd, 1); 34 st_int_write(st_data, &cmd, 1);
35 return; 35 return;
36} 36}
@@ -114,23 +114,23 @@ unsigned long st_ll_sleep_state(struct st_data_s *st_data,
114{ 114{
115 switch (cmd) { 115 switch (cmd) {
116 case LL_SLEEP_IND: /* sleep ind */ 116 case LL_SLEEP_IND: /* sleep ind */
117 pr_info("sleep indication recvd"); 117 pr_debug("sleep indication recvd");
118 ll_device_want_to_sleep(st_data); 118 ll_device_want_to_sleep(st_data);
119 break; 119 break;
120 case LL_SLEEP_ACK: /* sleep ack */ 120 case LL_SLEEP_ACK: /* sleep ack */
121 pr_err("sleep ack rcvd: host shouldn't"); 121 pr_err("sleep ack rcvd: host shouldn't");
122 break; 122 break;
123 case LL_WAKE_UP_IND: /* wake ind */ 123 case LL_WAKE_UP_IND: /* wake ind */
124 pr_info("wake indication recvd"); 124 pr_debug("wake indication recvd");
125 ll_device_want_to_wakeup(st_data); 125 ll_device_want_to_wakeup(st_data);
126 break; 126 break;
127 case LL_WAKE_UP_ACK: /* wake ack */ 127 case LL_WAKE_UP_ACK: /* wake ack */
128 pr_info("wake ack rcvd"); 128 pr_debug("wake ack rcvd");
129 st_data->ll_state = ST_LL_AWAKE; 129 st_data->ll_state = ST_LL_AWAKE;
130 break; 130 break;
131 default: 131 default:
132 pr_err(" unknown input/state "); 132 pr_err(" unknown input/state ");
133 return -1; 133 return -EINVAL;
134 } 134 }
135 return 0; 135 return 0;
136} 136}
diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
index bb440792a1b7..6f3ea9bbc818 100644
--- a/drivers/uio/Kconfig
+++ b/drivers/uio/Kconfig
@@ -94,4 +94,21 @@ config UIO_NETX
94 To compile this driver as a module, choose M here; the module 94 To compile this driver as a module, choose M here; the module
95 will be called uio_netx. 95 will be called uio_netx.
96 96
97config UIO_PRUSS
98 tristate "Texas Instruments PRUSS driver"
99 depends on ARCH_DAVINCI_DA850
100 help
101 PRUSS driver for OMAPL138/DA850/AM18XX devices
102 PRUSS driver requires user space components, examples and user space
103 driver is available from below SVN repo - you may use anonymous login
104
105 https://gforge.ti.com/gf/project/pru_sw/
106
107 More info on API is available at below wiki
108
109 http://processors.wiki.ti.com/index.php/PRU_Linux_Application_Loader
110
111 To compile this driver as a module, choose M here: the module
112 will be called uio_pruss.
113
97endif 114endif
diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile
index 18fd818c5b97..d4dd9a5552f8 100644
--- a/drivers/uio/Makefile
+++ b/drivers/uio/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_UIO_AEC) += uio_aec.o
6obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o 6obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o
7obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o 7obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o
8obj-$(CONFIG_UIO_NETX) += uio_netx.o 8obj-$(CONFIG_UIO_NETX) += uio_netx.o
9obj-$(CONFIG_UIO_PRUSS) += uio_pruss.o
diff --git a/drivers/uio/uio_pruss.c b/drivers/uio/uio_pruss.c
new file mode 100644
index 000000000000..daf6e77de2b1
--- /dev/null
+++ b/drivers/uio/uio_pruss.c
@@ -0,0 +1,247 @@
1/*
2 * Programmable Real-Time Unit Sub System (PRUSS) UIO driver (uio_pruss)
3 *
4 * This driver exports PRUSS host event out interrupts and PRUSS, L3 RAM,
5 * and DDR RAM to user space for applications interacting with PRUSS firmware
6 *
7 * Copyright (C) 2010-11 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation version 2.
12 *
13 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
14 * kind, whether express or implied; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18#include <linux/device.h>
19#include <linux/module.h>
20#include <linux/moduleparam.h>
21#include <linux/platform_device.h>
22#include <linux/uio_driver.h>
23#include <linux/platform_data/uio_pruss.h>
24#include <linux/io.h>
25#include <linux/clk.h>
26#include <linux/dma-mapping.h>
27#include <linux/slab.h>
28#include <mach/sram.h>
29
30#define DRV_NAME "pruss_uio"
31#define DRV_VERSION "1.0"
32
33static int sram_pool_sz = SZ_16K;
34module_param(sram_pool_sz, int, 0);
35MODULE_PARM_DESC(sram_pool_sz, "sram pool size to allocate ");
36
37static int extram_pool_sz = SZ_256K;
38module_param(extram_pool_sz, int, 0);
39MODULE_PARM_DESC(extram_pool_sz, "external ram pool size to allocate");
40
41/*
42 * Host event IRQ numbers from PRUSS - PRUSS can generate upto 8 interrupt
43 * events to AINTC of ARM host processor - which can be used for IPC b/w PRUSS
44 * firmware and user space application, async notification from PRU firmware
45 * to user space application
46 * 3 PRU_EVTOUT0
47 * 4 PRU_EVTOUT1
48 * 5 PRU_EVTOUT2
49 * 6 PRU_EVTOUT3
50 * 7 PRU_EVTOUT4
51 * 8 PRU_EVTOUT5
52 * 9 PRU_EVTOUT6
53 * 10 PRU_EVTOUT7
54*/
55#define MAX_PRUSS_EVT 8
56
57#define PINTC_HIDISR 0x0038
58#define PINTC_HIPIR 0x0900
59#define HIPIR_NOPEND 0x80000000
60#define PINTC_HIER 0x1500
61
62struct uio_pruss_dev {
63 struct uio_info *info;
64 struct clk *pruss_clk;
65 dma_addr_t sram_paddr;
66 dma_addr_t ddr_paddr;
67 void __iomem *prussio_vaddr;
68 void *sram_vaddr;
69 void *ddr_vaddr;
70 unsigned int hostirq_start;
71 unsigned int pintc_base;
72};
73
74static irqreturn_t pruss_handler(int irq, struct uio_info *info)
75{
76 struct uio_pruss_dev *gdev = info->priv;
77 int intr_bit = (irq - gdev->hostirq_start + 2);
78 int val, intr_mask = (1 << intr_bit);
79 void __iomem *base = gdev->prussio_vaddr + gdev->pintc_base;
80 void __iomem *intren_reg = base + PINTC_HIER;
81 void __iomem *intrdis_reg = base + PINTC_HIDISR;
82 void __iomem *intrstat_reg = base + PINTC_HIPIR + (intr_bit << 2);
83
84 val = ioread32(intren_reg);
85 /* Is interrupt enabled and active ? */
86 if (!(val & intr_mask) && (ioread32(intrstat_reg) & HIPIR_NOPEND))
87 return IRQ_NONE;
88 /* Disable interrupt */
89 iowrite32(intr_bit, intrdis_reg);
90 return IRQ_HANDLED;
91}
92
93static void pruss_cleanup(struct platform_device *dev,
94 struct uio_pruss_dev *gdev)
95{
96 int cnt;
97 struct uio_info *p = gdev->info;
98
99 for (cnt = 0; cnt < MAX_PRUSS_EVT; cnt++, p++) {
100 uio_unregister_device(p);
101 kfree(p->name);
102 }
103 iounmap(gdev->prussio_vaddr);
104 if (gdev->ddr_vaddr) {
105 dma_free_coherent(&dev->dev, extram_pool_sz, gdev->ddr_vaddr,
106 gdev->ddr_paddr);
107 }
108 if (gdev->sram_vaddr)
109 sram_free(gdev->sram_vaddr, sram_pool_sz);
110 kfree(gdev->info);
111 clk_put(gdev->pruss_clk);
112 kfree(gdev);
113}
114
115static int __devinit pruss_probe(struct platform_device *dev)
116{
117 struct uio_info *p;
118 struct uio_pruss_dev *gdev;
119 struct resource *regs_prussio;
120 int ret = -ENODEV, cnt = 0, len;
121 struct uio_pruss_pdata *pdata = dev->dev.platform_data;
122
123 gdev = kzalloc(sizeof(struct uio_pruss_dev), GFP_KERNEL);
124 if (!gdev)
125 return -ENOMEM;
126
127 gdev->info = kzalloc(sizeof(*p) * MAX_PRUSS_EVT, GFP_KERNEL);
128 if (!gdev->info) {
129 kfree(gdev);
130 return -ENOMEM;
131 }
132 /* Power on PRU in case its not done as part of boot-loader */
133 gdev->pruss_clk = clk_get(&dev->dev, "pruss");
134 if (IS_ERR(gdev->pruss_clk)) {
135 dev_err(&dev->dev, "Failed to get clock\n");
136 kfree(gdev->info);
137 kfree(gdev);
138 ret = PTR_ERR(gdev->pruss_clk);
139 return ret;
140 } else {
141 clk_enable(gdev->pruss_clk);
142 }
143
144 regs_prussio = platform_get_resource(dev, IORESOURCE_MEM, 0);
145 if (!regs_prussio) {
146 dev_err(&dev->dev, "No PRUSS I/O resource specified\n");
147 goto out_free;
148 }
149
150 if (!regs_prussio->start) {
151 dev_err(&dev->dev, "Invalid memory resource\n");
152 goto out_free;
153 }
154
155 gdev->sram_vaddr = sram_alloc(sram_pool_sz, &(gdev->sram_paddr));
156 if (!gdev->sram_vaddr) {
157 dev_err(&dev->dev, "Could not allocate SRAM pool\n");
158 goto out_free;
159 }
160
161 gdev->ddr_vaddr = dma_alloc_coherent(&dev->dev, extram_pool_sz,
162 &(gdev->ddr_paddr), GFP_KERNEL | GFP_DMA);
163 if (!gdev->ddr_vaddr) {
164 dev_err(&dev->dev, "Could not allocate external memory\n");
165 goto out_free;
166 }
167
168 len = resource_size(regs_prussio);
169 gdev->prussio_vaddr = ioremap(regs_prussio->start, len);
170 if (!gdev->prussio_vaddr) {
171 dev_err(&dev->dev, "Can't remap PRUSS I/O address range\n");
172 goto out_free;
173 }
174
175 gdev->pintc_base = pdata->pintc_base;
176 gdev->hostirq_start = platform_get_irq(dev, 0);
177
178 for (cnt = 0, p = gdev->info; cnt < MAX_PRUSS_EVT; cnt++, p++) {
179 p->mem[0].addr = regs_prussio->start;
180 p->mem[0].size = resource_size(regs_prussio);
181 p->mem[0].memtype = UIO_MEM_PHYS;
182
183 p->mem[1].addr = gdev->sram_paddr;
184 p->mem[1].size = sram_pool_sz;
185 p->mem[1].memtype = UIO_MEM_PHYS;
186
187 p->mem[2].addr = gdev->ddr_paddr;
188 p->mem[2].size = extram_pool_sz;
189 p->mem[2].memtype = UIO_MEM_PHYS;
190
191 p->name = kasprintf(GFP_KERNEL, "pruss_evt%d", cnt);
192 p->version = DRV_VERSION;
193
194 /* Register PRUSS IRQ lines */
195 p->irq = gdev->hostirq_start + cnt;
196 p->handler = pruss_handler;
197 p->priv = gdev;
198
199 ret = uio_register_device(&dev->dev, p);
200 if (ret < 0)
201 goto out_free;
202 }
203
204 platform_set_drvdata(dev, gdev);
205 return 0;
206
207out_free:
208 pruss_cleanup(dev, gdev);
209 return ret;
210}
211
212static int __devexit pruss_remove(struct platform_device *dev)
213{
214 struct uio_pruss_dev *gdev = platform_get_drvdata(dev);
215
216 pruss_cleanup(dev, gdev);
217 platform_set_drvdata(dev, NULL);
218 return 0;
219}
220
221static struct platform_driver pruss_driver = {
222 .probe = pruss_probe,
223 .remove = __devexit_p(pruss_remove),
224 .driver = {
225 .name = DRV_NAME,
226 .owner = THIS_MODULE,
227 },
228};
229
230static int __init pruss_init_module(void)
231{
232 return platform_driver_register(&pruss_driver);
233}
234
235module_init(pruss_init_module);
236
237static void __exit pruss_exit_module(void)
238{
239 platform_driver_unregister(&pruss_driver);
240}
241
242module_exit(pruss_exit_module);
243
244MODULE_LICENSE("GPL v2");
245MODULE_VERSION(DRV_VERSION);
246MODULE_AUTHOR("Amit Chatterjee <amit.chatterjee@ti.com>");
247MODULE_AUTHOR("Pratheesh Gangadhar <pratheesh@ti.com>");
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
index 37a8ca7c1222..e7a7a2f07324 100644
--- a/fs/debugfs/inode.c
+++ b/fs/debugfs/inode.c
@@ -13,9 +13,6 @@
13 * 13 *
14 */ 14 */
15 15
16/* uncomment to get debug messages from the debug filesystem, ah the irony. */
17/* #define DEBUG */
18
19#include <linux/module.h> 16#include <linux/module.h>
20#include <linux/fs.h> 17#include <linux/fs.h>
21#include <linux/mount.h> 18#include <linux/mount.h>
@@ -310,7 +307,7 @@ struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
310} 307}
311EXPORT_SYMBOL_GPL(debugfs_create_symlink); 308EXPORT_SYMBOL_GPL(debugfs_create_symlink);
312 309
313static void __debugfs_remove(struct dentry *dentry, struct dentry *parent) 310static int __debugfs_remove(struct dentry *dentry, struct dentry *parent)
314{ 311{
315 int ret = 0; 312 int ret = 0;
316 313
@@ -333,6 +330,7 @@ static void __debugfs_remove(struct dentry *dentry, struct dentry *parent)
333 dput(dentry); 330 dput(dentry);
334 } 331 }
335 } 332 }
333 return ret;
336} 334}
337 335
338/** 336/**
@@ -351,7 +349,8 @@ static void __debugfs_remove(struct dentry *dentry, struct dentry *parent)
351void debugfs_remove(struct dentry *dentry) 349void debugfs_remove(struct dentry *dentry)
352{ 350{
353 struct dentry *parent; 351 struct dentry *parent;
354 352 int ret;
353
355 if (!dentry) 354 if (!dentry)
356 return; 355 return;
357 356
@@ -360,9 +359,10 @@ void debugfs_remove(struct dentry *dentry)
360 return; 359 return;
361 360
362 mutex_lock(&parent->d_inode->i_mutex); 361 mutex_lock(&parent->d_inode->i_mutex);
363 __debugfs_remove(dentry, parent); 362 ret = __debugfs_remove(dentry, parent);
364 mutex_unlock(&parent->d_inode->i_mutex); 363 mutex_unlock(&parent->d_inode->i_mutex);
365 simple_release_fs(&debugfs_mount, &debugfs_mount_count); 364 if (!ret)
365 simple_release_fs(&debugfs_mount, &debugfs_mount_count);
366} 366}
367EXPORT_SYMBOL_GPL(debugfs_remove); 367EXPORT_SYMBOL_GPL(debugfs_remove);
368 368
@@ -540,17 +540,5 @@ static int __init debugfs_init(void)
540 540
541 return retval; 541 return retval;
542} 542}
543
544static void __exit debugfs_exit(void)
545{
546 debugfs_registered = false;
547
548 simple_release_fs(&debugfs_mount, &debugfs_mount_count);
549 unregister_filesystem(&debug_fs_type);
550 kobject_put(debug_kobj);
551}
552
553core_initcall(debugfs_init); 543core_initcall(debugfs_init);
554module_exit(debugfs_exit);
555MODULE_LICENSE("GPL");
556 544
diff --git a/include/linux/dmi.h b/include/linux/dmi.h
index 90e087f8d951..f156cca25ad0 100644
--- a/include/linux/dmi.h
+++ b/include/linux/dmi.h
@@ -23,6 +23,53 @@ enum dmi_device_type {
23 DMI_DEV_TYPE_DEV_ONBOARD = -3, 23 DMI_DEV_TYPE_DEV_ONBOARD = -3,
24}; 24};
25 25
26enum dmi_entry_type {
27 DMI_ENTRY_BIOS = 0,
28 DMI_ENTRY_SYSTEM,
29 DMI_ENTRY_BASEBOARD,
30 DMI_ENTRY_CHASSIS,
31 DMI_ENTRY_PROCESSOR,
32 DMI_ENTRY_MEM_CONTROLLER,
33 DMI_ENTRY_MEM_MODULE,
34 DMI_ENTRY_CACHE,
35 DMI_ENTRY_PORT_CONNECTOR,
36 DMI_ENTRY_SYSTEM_SLOT,
37 DMI_ENTRY_ONBOARD_DEVICE,
38 DMI_ENTRY_OEMSTRINGS,
39 DMI_ENTRY_SYSCONF,
40 DMI_ENTRY_BIOS_LANG,
41 DMI_ENTRY_GROUP_ASSOC,
42 DMI_ENTRY_SYSTEM_EVENT_LOG,
43 DMI_ENTRY_PHYS_MEM_ARRAY,
44 DMI_ENTRY_MEM_DEVICE,
45 DMI_ENTRY_32_MEM_ERROR,
46 DMI_ENTRY_MEM_ARRAY_MAPPED_ADDR,
47 DMI_ENTRY_MEM_DEV_MAPPED_ADDR,
48 DMI_ENTRY_BUILTIN_POINTING_DEV,
49 DMI_ENTRY_PORTABLE_BATTERY,
50 DMI_ENTRY_SYSTEM_RESET,
51 DMI_ENTRY_HW_SECURITY,
52 DMI_ENTRY_SYSTEM_POWER_CONTROLS,
53 DMI_ENTRY_VOLTAGE_PROBE,
54 DMI_ENTRY_COOLING_DEV,
55 DMI_ENTRY_TEMP_PROBE,
56 DMI_ENTRY_ELECTRICAL_CURRENT_PROBE,
57 DMI_ENTRY_OOB_REMOTE_ACCESS,
58 DMI_ENTRY_BIS_ENTRY,
59 DMI_ENTRY_SYSTEM_BOOT,
60 DMI_ENTRY_MGMT_DEV,
61 DMI_ENTRY_MGMT_DEV_COMPONENT,
62 DMI_ENTRY_MGMT_DEV_THRES,
63 DMI_ENTRY_MEM_CHANNEL,
64 DMI_ENTRY_IPMI_DEV,
65 DMI_ENTRY_SYS_POWER_SUPPLY,
66 DMI_ENTRY_ADDITIONAL,
67 DMI_ENTRY_ONBOARD_DEV_EXT,
68 DMI_ENTRY_MGMT_CONTROLLER_HOST,
69 DMI_ENTRY_INACTIVE = 126,
70 DMI_ENTRY_END_OF_TABLE = 127,
71};
72
26struct dmi_header { 73struct dmi_header {
27 u8 type; 74 u8 type;
28 u8 length; 75 u8 length;
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 1c70028f81f9..0c9653f11c18 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -31,6 +31,10 @@ struct _ddebug {
31 * writes commands to <debugfs>/dynamic_debug/control 31 * writes commands to <debugfs>/dynamic_debug/control
32 */ 32 */
33#define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */ 33#define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */
34#define _DPRINTK_FLAGS_INCL_MODNAME (1<<1)
35#define _DPRINTK_FLAGS_INCL_FUNCNAME (1<<2)
36#define _DPRINTK_FLAGS_INCL_LINENO (1<<3)
37#define _DPRINTK_FLAGS_INCL_TID (1<<4)
34#define _DPRINTK_FLAGS_DEFAULT 0 38#define _DPRINTK_FLAGS_DEFAULT 0
35 unsigned int flags:8; 39 unsigned int flags:8;
36 char enabled; 40 char enabled;
@@ -42,6 +46,8 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
42 46
43#if defined(CONFIG_DYNAMIC_DEBUG) 47#if defined(CONFIG_DYNAMIC_DEBUG)
44extern int ddebug_remove_module(const char *mod_name); 48extern int ddebug_remove_module(const char *mod_name);
49extern int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
50 __attribute__ ((format (printf, 2, 3)));
45 51
46#define dynamic_pr_debug(fmt, ...) do { \ 52#define dynamic_pr_debug(fmt, ...) do { \
47 static struct _ddebug descriptor \ 53 static struct _ddebug descriptor \
@@ -50,7 +56,7 @@ extern int ddebug_remove_module(const char *mod_name);
50 { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \ 56 { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \
51 _DPRINTK_FLAGS_DEFAULT }; \ 57 _DPRINTK_FLAGS_DEFAULT }; \
52 if (unlikely(descriptor.enabled)) \ 58 if (unlikely(descriptor.enabled)) \
53 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \ 59 __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \
54 } while (0) 60 } while (0)
55 61
56 62
diff --git a/include/linux/efi.h b/include/linux/efi.h
index fb737bc19a8c..33fa1203024e 100644
--- a/include/linux/efi.h
+++ b/include/linux/efi.h
@@ -397,4 +397,41 @@ static inline void memrange_efi_to_native(u64 *addr, u64 *npages)
397 *addr &= PAGE_MASK; 397 *addr &= PAGE_MASK;
398} 398}
399 399
400#if defined(CONFIG_EFI_VARS) || defined(CONFIG_EFI_VARS_MODULE)
401/*
402 * EFI Variable support.
403 *
404 * Different firmware drivers can expose their EFI-like variables using
405 * the following.
406 */
407
408struct efivar_operations {
409 efi_get_variable_t *get_variable;
410 efi_get_next_variable_t *get_next_variable;
411 efi_set_variable_t *set_variable;
412};
413
414struct efivars {
415 /*
416 * ->lock protects two things:
417 * 1) ->list - adds, removals, reads, writes
418 * 2) ops.[gs]et_variable() calls.
419 * It must not be held when creating sysfs entries or calling kmalloc.
420 * ops.get_next_variable() is only called from register_efivars(),
421 * which is protected by the BKL, so that path is safe.
422 */
423 spinlock_t lock;
424 struct list_head list;
425 struct kset *kset;
426 struct bin_attribute *new_var, *del_var;
427 const struct efivar_operations *ops;
428};
429
430int register_efivars(struct efivars *efivars,
431 const struct efivar_operations *ops,
432 struct kobject *parent_kobj);
433void unregister_efivars(struct efivars *efivars);
434
435#endif /* CONFIG_EFI_VARS */
436
400#endif /* _LINUX_EFI_H */ 437#endif /* _LINUX_EFI_H */
diff --git a/include/linux/firmware.h b/include/linux/firmware.h
index 53d1e6c4f848..21b3e7588abd 100644
--- a/include/linux/firmware.h
+++ b/include/linux/firmware.h
@@ -39,7 +39,7 @@ struct builtin_fw {
39int request_firmware(const struct firmware **fw, const char *name, 39int request_firmware(const struct firmware **fw, const char *name,
40 struct device *device); 40 struct device *device);
41int request_firmware_nowait( 41int request_firmware_nowait(
42 struct module *module, int uevent, 42 struct module *module, bool uevent,
43 const char *name, struct device *device, gfp_t gfp, void *context, 43 const char *name, struct device *device, gfp_t gfp, void *context,
44 void (*cont)(const struct firmware *fw, void *context)); 44 void (*cont)(const struct firmware *fw, void *context));
45 45
@@ -52,7 +52,7 @@ static inline int request_firmware(const struct firmware **fw,
52 return -EINVAL; 52 return -EINVAL;
53} 53}
54static inline int request_firmware_nowait( 54static inline int request_firmware_nowait(
55 struct module *module, int uevent, 55 struct module *module, bool uevent,
56 const char *name, struct device *device, gfp_t gfp, void *context, 56 const char *name, struct device *device, gfp_t gfp, void *context,
57 void (*cont)(const struct firmware *fw, void *context)) 57 void (*cont)(const struct firmware *fw, void *context))
58{ 58{
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 8f6d12151048..9229b64ee3aa 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -85,11 +85,13 @@ static inline const char *kobject_name(const struct kobject *kobj)
85extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype); 85extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
86extern int __must_check kobject_add(struct kobject *kobj, 86extern int __must_check kobject_add(struct kobject *kobj,
87 struct kobject *parent, 87 struct kobject *parent,
88 const char *fmt, ...); 88 const char *fmt, ...)
89 __attribute__((format(printf, 3, 4)));
89extern int __must_check kobject_init_and_add(struct kobject *kobj, 90extern int __must_check kobject_init_and_add(struct kobject *kobj,
90 struct kobj_type *ktype, 91 struct kobj_type *ktype,
91 struct kobject *parent, 92 struct kobject *parent,
92 const char *fmt, ...); 93 const char *fmt, ...)
94 __attribute__((format(printf, 4, 5)));
93 95
94extern void kobject_del(struct kobject *kobj); 96extern void kobject_del(struct kobject *kobj);
95 97
@@ -224,8 +226,8 @@ static inline int kobject_uevent_env(struct kobject *kobj,
224 char *envp[]) 226 char *envp[])
225{ return 0; } 227{ return 0; }
226 228
227static inline int add_uevent_var(struct kobj_uevent_env *env, 229static inline __attribute__((format(printf, 2, 3)))
228 const char *format, ...) 230int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
229{ return 0; } 231{ return 0; }
230 232
231static inline int kobject_action_type(const char *buf, size_t count, 233static inline int kobject_action_type(const char *buf, size_t count,
diff --git a/include/linux/memory.h b/include/linux/memory.h
index 06c1fa0a5c7b..e1e3b2b84f85 100644
--- a/include/linux/memory.h
+++ b/include/linux/memory.h
@@ -21,7 +21,8 @@
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22 22
23struct memory_block { 23struct memory_block {
24 unsigned long phys_index; 24 unsigned long start_section_nr;
25 unsigned long end_section_nr;
25 unsigned long state; 26 unsigned long state;
26 int section_count; 27 int section_count;
27 28
diff --git a/include/linux/node.h b/include/linux/node.h
index 1466945cc9ef..92370e22343c 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -39,7 +39,8 @@ extern int register_cpu_under_node(unsigned int cpu, unsigned int nid);
39extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); 39extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid);
40extern int register_mem_sect_under_node(struct memory_block *mem_blk, 40extern int register_mem_sect_under_node(struct memory_block *mem_blk,
41 int nid); 41 int nid);
42extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk); 42extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
43 unsigned long phys_index);
43 44
44#ifdef CONFIG_HUGETLBFS 45#ifdef CONFIG_HUGETLBFS
45extern void register_hugetlbfs_with_node(node_registration_func_t doregister, 46extern void register_hugetlbfs_with_node(node_registration_func_t doregister,
@@ -67,7 +68,8 @@ static inline int register_mem_sect_under_node(struct memory_block *mem_blk,
67{ 68{
68 return 0; 69 return 0;
69} 70}
70static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk) 71static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk,
72 unsigned long phys_index)
71{ 73{
72 return 0; 74 return 0;
73} 75}
diff --git a/include/linux/platform_data/uio_pruss.h b/include/linux/platform_data/uio_pruss.h
new file mode 100644
index 000000000000..f39140aabc6f
--- /dev/null
+++ b/include/linux/platform_data/uio_pruss.h
@@ -0,0 +1,25 @@
1/*
2 * include/linux/platform_data/uio_pruss.h
3 *
4 * Platform data for uio_pruss driver
5 *
6 * Copyright (C) 2010-11 Texas Instruments Incorporated - http://www.ti.com/
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation version 2.
11 *
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#ifndef _UIO_PRUSS_H_
19#define _UIO_PRUSS_H_
20
21/* To configure the PRUSS INTC base offset for UIO driver */
22struct uio_pruss_pdata {
23 u32 pintc_base;
24};
25#endif /* _UIO_PRUSS_H_ */
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 2e700ec0601f..d96db9825708 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -130,8 +130,15 @@ extern void platform_driver_unregister(struct platform_driver *);
130extern int platform_driver_probe(struct platform_driver *driver, 130extern int platform_driver_probe(struct platform_driver *driver,
131 int (*probe)(struct platform_device *)); 131 int (*probe)(struct platform_device *));
132 132
133#define platform_get_drvdata(_dev) dev_get_drvdata(&(_dev)->dev) 133static inline void *platform_get_drvdata(const struct platform_device *pdev)
134#define platform_set_drvdata(_dev,data) dev_set_drvdata(&(_dev)->dev, (data)) 134{
135 return dev_get_drvdata(&pdev->dev);
136}
137
138static inline void platform_set_drvdata(struct platform_device *pdev, void *data)
139{
140 dev_set_drvdata(&pdev->dev, data);
141}
135 142
136extern struct platform_device *platform_create_bundle(struct platform_driver *driver, 143extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
137 int (*probe)(struct platform_device *), 144 int (*probe)(struct platform_device *),
diff --git a/include/linux/ti_wilink_st.h b/include/linux/ti_wilink_st.h
index 4c7be2263011..7071ec5d0118 100644
--- a/include/linux/ti_wilink_st.h
+++ b/include/linux/ti_wilink_st.h
@@ -26,15 +26,6 @@
26#define TI_WILINK_ST_H 26#define TI_WILINK_ST_H
27 27
28/** 28/**
29 * enum kim_gpio_state - Few protocols such as FM have ACTIVE LOW
30 * gpio states for their chip/core enable gpios
31 */
32enum kim_gpio_state {
33 KIM_GPIO_INACTIVE,
34 KIM_GPIO_ACTIVE,
35};
36
37/**
38 * enum proto-type - The protocol on WiLink chips which share a 29 * enum proto-type - The protocol on WiLink chips which share a
39 * common physical interface like UART. 30 * common physical interface like UART.
40 */ 31 */
@@ -42,7 +33,7 @@ enum proto_type {
42 ST_BT, 33 ST_BT,
43 ST_FM, 34 ST_FM,
44 ST_GPS, 35 ST_GPS,
45 ST_MAX, 36 ST_MAX_CHANNELS = 16,
46}; 37};
47 38
48/** 39/**
@@ -62,6 +53,17 @@ enum proto_type {
62 * @priv_data: privdate data holder for the protocol drivers, sent 53 * @priv_data: privdate data holder for the protocol drivers, sent
63 * from the protocol drivers during registration, and sent back on 54 * from the protocol drivers during registration, and sent back on
64 * reg_complete_cb and recv. 55 * reg_complete_cb and recv.
56 * @chnl_id: channel id the protocol driver is interested in, the channel
57 * id is nothing but the 1st byte of the packet in UART frame.
58 * @max_frame_size: size of the largest frame the protocol can receive.
59 * @hdr_len: length of the header structure of the protocol.
60 * @offset_len_in_hdr: this provides the offset of the length field in the
61 * header structure of the protocol header, to assist ST to know
62 * how much to receive, if the data is split across UART frames.
63 * @len_size: whether the length field inside the header is 2 bytes
64 * or 1 byte.
65 * @reserve: the number of bytes ST needs to reserve in the skb being
66 * prepared for the protocol driver.
65 */ 67 */
66struct st_proto_s { 68struct st_proto_s {
67 enum proto_type type; 69 enum proto_type type;
@@ -70,10 +72,17 @@ struct st_proto_s {
70 void (*reg_complete_cb) (void *, char data); 72 void (*reg_complete_cb) (void *, char data);
71 long (*write) (struct sk_buff *skb); 73 long (*write) (struct sk_buff *skb);
72 void *priv_data; 74 void *priv_data;
75
76 unsigned char chnl_id;
77 unsigned short max_frame_size;
78 unsigned char hdr_len;
79 unsigned char offset_len_in_hdr;
80 unsigned char len_size;
81 unsigned char reserve;
73}; 82};
74 83
75extern long st_register(struct st_proto_s *); 84extern long st_register(struct st_proto_s *);
76extern long st_unregister(enum proto_type); 85extern long st_unregister(struct st_proto_s *);
77 86
78 87
79/* 88/*
@@ -114,6 +123,7 @@ extern long st_unregister(enum proto_type);
114 * @rx_skb: the skb where all data for a protocol gets accumulated, 123 * @rx_skb: the skb where all data for a protocol gets accumulated,
115 * since tty might not call receive when a complete event packet 124 * since tty might not call receive when a complete event packet
116 * is received, the states, count and the skb needs to be maintained. 125 * is received, the states, count and the skb needs to be maintained.
126 * @rx_chnl: the channel ID for which the data is getting accumalated for.
117 * @txq: the list of skbs which needs to be sent onto the TTY. 127 * @txq: the list of skbs which needs to be sent onto the TTY.
118 * @tx_waitq: if the chip is not in AWAKE state, the skbs needs to be queued 128 * @tx_waitq: if the chip is not in AWAKE state, the skbs needs to be queued
119 * up in here, PM(WAKEUP_IND) data needs to be sent and then the skbs 129 * up in here, PM(WAKEUP_IND) data needs to be sent and then the skbs
@@ -135,10 +145,11 @@ struct st_data_s {
135#define ST_TX_SENDING 1 145#define ST_TX_SENDING 1
136#define ST_TX_WAKEUP 2 146#define ST_TX_WAKEUP 2
137 unsigned long tx_state; 147 unsigned long tx_state;
138 struct st_proto_s *list[ST_MAX]; 148 struct st_proto_s *list[ST_MAX_CHANNELS];
139 unsigned long rx_state; 149 unsigned long rx_state;
140 unsigned long rx_count; 150 unsigned long rx_count;
141 struct sk_buff *rx_skb; 151 struct sk_buff *rx_skb;
152 unsigned char rx_chnl;
142 struct sk_buff_head txq, tx_waitq; 153 struct sk_buff_head txq, tx_waitq;
143 spinlock_t lock; 154 spinlock_t lock;
144 unsigned char protos_registered; 155 unsigned char protos_registered;
@@ -146,6 +157,11 @@ struct st_data_s {
146 void *kim_data; 157 void *kim_data;
147}; 158};
148 159
160/*
161 * wrapper around tty->ops->write_room to check
162 * availability during firmware download
163 */
164int st_get_uart_wr_room(struct st_data_s *st_gdata);
149/** 165/**
150 * st_int_write - 166 * st_int_write -
151 * point this to tty->driver->write or tty->ops->write 167 * point this to tty->driver->write or tty->ops->write
@@ -186,8 +202,9 @@ void gps_chrdrv_stub_init(void);
186/* time in msec to wait for 202/* time in msec to wait for
187 * line discipline to be installed 203 * line discipline to be installed
188 */ 204 */
189#define LDISC_TIME 500 205#define LDISC_TIME 1000
190#define CMD_RESP_TIME 500 206#define CMD_RESP_TIME 800
207#define CMD_WR_TIME 5000
191#define MAKEWORD(a, b) ((unsigned short)(((unsigned char)(a)) \ 208#define MAKEWORD(a, b) ((unsigned short)(((unsigned char)(a)) \
192 | ((unsigned short)((unsigned char)(b))) << 8)) 209 | ((unsigned short)((unsigned char)(b))) << 8))
193 210
@@ -210,6 +227,7 @@ struct chip_version {
210 unsigned short maj_ver; 227 unsigned short maj_ver;
211}; 228};
212 229
230#define UART_DEV_NAME_LEN 32
213/** 231/**
214 * struct kim_data_s - the KIM internal data, embedded as the 232 * struct kim_data_s - the KIM internal data, embedded as the
215 * platform's drv data. One for each ST device in the system. 233 * platform's drv data. One for each ST device in the system.
@@ -225,14 +243,11 @@ struct chip_version {
225 * the ldisc was properly installed. 243 * the ldisc was properly installed.
226 * @resp_buffer: data buffer for the .bts fw file name. 244 * @resp_buffer: data buffer for the .bts fw file name.
227 * @fw_entry: firmware class struct to request/release the fw. 245 * @fw_entry: firmware class struct to request/release the fw.
228 * @gpios: the list of core/chip enable gpios for BT, FM and GPS cores.
229 * @rx_state: the rx state for kim's receive func during fw download. 246 * @rx_state: the rx state for kim's receive func during fw download.
230 * @rx_count: the rx count for the kim's receive func during fw download. 247 * @rx_count: the rx count for the kim's receive func during fw download.
231 * @rx_skb: all of fw data might not come at once, and hence data storage for 248 * @rx_skb: all of fw data might not come at once, and hence data storage for
232 * whole of the fw response, only HCI_EVENTs and hence diff from ST's 249 * whole of the fw response, only HCI_EVENTs and hence diff from ST's
233 * response. 250 * response.
234 * @rfkill: rfkill data for each of the cores to be registered with rfkill.
235 * @rf_protos: proto types of the data registered with rfkill sub-system.
236 * @core_data: ST core's data, which mainly is the tty's disc_data 251 * @core_data: ST core's data, which mainly is the tty's disc_data
237 * @version: chip version available via a sysfs entry. 252 * @version: chip version available via a sysfs entry.
238 * 253 *
@@ -243,14 +258,16 @@ struct kim_data_s {
243 struct completion kim_rcvd, ldisc_installed; 258 struct completion kim_rcvd, ldisc_installed;
244 char resp_buffer[30]; 259 char resp_buffer[30];
245 const struct firmware *fw_entry; 260 const struct firmware *fw_entry;
246 long gpios[ST_MAX]; 261 long nshutdown;
247 unsigned long rx_state; 262 unsigned long rx_state;
248 unsigned long rx_count; 263 unsigned long rx_count;
249 struct sk_buff *rx_skb; 264 struct sk_buff *rx_skb;
250 struct rfkill *rfkill[ST_MAX];
251 enum proto_type rf_protos[ST_MAX];
252 struct st_data_s *core_data; 265 struct st_data_s *core_data;
253 struct chip_version version; 266 struct chip_version version;
267 unsigned char ldisc_install;
268 unsigned char dev_name[UART_DEV_NAME_LEN];
269 unsigned char flow_cntrl;
270 unsigned long baud_rate;
254}; 271};
255 272
256/** 273/**
@@ -262,7 +279,6 @@ long st_kim_start(void *);
262long st_kim_stop(void *); 279long st_kim_stop(void *);
263 280
264void st_kim_recv(void *, const unsigned char *, long count); 281void st_kim_recv(void *, const unsigned char *, long count);
265void st_kim_chip_toggle(enum proto_type, enum kim_gpio_state);
266void st_kim_complete(void *); 282void st_kim_complete(void *);
267void kim_st_list_protocols(struct st_data_s *, void *); 283void kim_st_list_protocols(struct st_data_s *, void *);
268 284
@@ -338,12 +354,8 @@ struct hci_command {
338 354
339/* ST LL receiver states */ 355/* ST LL receiver states */
340#define ST_W4_PACKET_TYPE 0 356#define ST_W4_PACKET_TYPE 0
341#define ST_BT_W4_EVENT_HDR 1 357#define ST_W4_HEADER 1
342#define ST_BT_W4_ACL_HDR 2 358#define ST_W4_DATA 2
343#define ST_BT_W4_SCO_HDR 3
344#define ST_BT_W4_DATA 4
345#define ST_FM_W4_EVENT_HDR 5
346#define ST_GPS_W4_EVENT_HDR 6
347 359
348/* ST LL state machines */ 360/* ST LL state machines */
349#define ST_LL_ASLEEP 0 361#define ST_LL_ASLEEP 0
@@ -397,4 +409,14 @@ struct gps_event_hdr {
397 u16 plen; 409 u16 plen;
398} __attribute__ ((packed)); 410} __attribute__ ((packed));
399 411
412/* platform data */
413struct ti_st_plat_data {
414 long nshutdown_gpio;
415 unsigned char dev_name[UART_DEV_NAME_LEN]; /* uart name */
416 unsigned char flow_cntrl; /* flow control flag */
417 unsigned long baud_rate;
418 int (*suspend)(struct platform_device *, pm_message_t);
419 int (*resume)(struct platform_device *);
420};
421
400#endif /* TI_WILINK_ST_H */ 422#endif /* TI_WILINK_ST_H */
diff --git a/init/Kconfig b/init/Kconfig
index 5721d27af626..6f49ceb25710 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -836,7 +836,7 @@ config MM_OWNER
836 bool 836 bool
837 837
838config SYSFS_DEPRECATED 838config SYSFS_DEPRECATED
839 bool "enable deprecated sysfs features to support old userspace tools" 839 bool "Enable deprecated sysfs features to support old userspace tools"
840 depends on SYSFS 840 depends on SYSFS
841 default n 841 default n
842 help 842 help
@@ -859,7 +859,7 @@ config SYSFS_DEPRECATED
859 need to say Y here. 859 need to say Y here.
860 860
861config SYSFS_DEPRECATED_V2 861config SYSFS_DEPRECATED_V2
862 bool "enabled deprecated sysfs features by default" 862 bool "Enable deprecated sysfs features by default"
863 default n 863 default n
864 depends on SYSFS 864 depends on SYSFS
865 depends on SYSFS_DEPRECATED 865 depends on SYSFS_DEPRECATED
diff --git a/kernel/printk.c b/kernel/printk.c
index 36231525e22f..33284adb2189 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -515,6 +515,71 @@ static void _call_console_drivers(unsigned start,
515} 515}
516 516
517/* 517/*
518 * Parse the syslog header <[0-9]*>. The decimal value represents 32bit, the
519 * lower 3 bit are the log level, the rest are the log facility. In case
520 * userspace passes usual userspace syslog messages to /dev/kmsg or
521 * /dev/ttyprintk, the log prefix might contain the facility. Printk needs
522 * to extract the correct log level for in-kernel processing, and not mangle
523 * the original value.
524 *
525 * If a prefix is found, the length of the prefix is returned. If 'level' is
526 * passed, it will be filled in with the log level without a possible facility
527 * value. If 'special' is passed, the special printk prefix chars are accepted
528 * and returned. If no valid header is found, 0 is returned and the passed
529 * variables are not touched.
530 */
531static size_t log_prefix(const char *p, unsigned int *level, char *special)
532{
533 unsigned int lev = 0;
534 char sp = '\0';
535 size_t len;
536
537 if (p[0] != '<' || !p[1])
538 return 0;
539 if (p[2] == '>') {
540 /* usual single digit level number or special char */
541 switch (p[1]) {
542 case '0' ... '7':
543 lev = p[1] - '0';
544 break;
545 case 'c': /* KERN_CONT */
546 case 'd': /* KERN_DEFAULT */
547 sp = p[1];
548 break;
549 default:
550 return 0;
551 }
552 len = 3;
553 } else {
554 /* multi digit including the level and facility number */
555 char *endp = NULL;
556
557 if (p[1] < '0' && p[1] > '9')
558 return 0;
559
560 lev = (simple_strtoul(&p[1], &endp, 10) & 7);
561 if (endp == NULL || endp[0] != '>')
562 return 0;
563 len = (endp + 1) - p;
564 }
565
566 /* do not accept special char if not asked for */
567 if (sp && !special)
568 return 0;
569
570 if (special) {
571 *special = sp;
572 /* return special char, do not touch level */
573 if (sp)
574 return len;
575 }
576
577 if (level)
578 *level = lev;
579 return len;
580}
581
582/*
518 * Call the console drivers, asking them to write out 583 * Call the console drivers, asking them to write out
519 * log_buf[start] to log_buf[end - 1]. 584 * log_buf[start] to log_buf[end - 1].
520 * The console_lock must be held. 585 * The console_lock must be held.
@@ -529,13 +594,9 @@ static void call_console_drivers(unsigned start, unsigned end)
529 cur_index = start; 594 cur_index = start;
530 start_print = start; 595 start_print = start;
531 while (cur_index != end) { 596 while (cur_index != end) {
532 if (msg_level < 0 && ((end - cur_index) > 2) && 597 if (msg_level < 0 && ((end - cur_index) > 2)) {
533 LOG_BUF(cur_index + 0) == '<' && 598 /* strip log prefix */
534 LOG_BUF(cur_index + 1) >= '0' && 599 cur_index += log_prefix(&LOG_BUF(cur_index), &msg_level, NULL);
535 LOG_BUF(cur_index + 1) <= '7' &&
536 LOG_BUF(cur_index + 2) == '>') {
537 msg_level = LOG_BUF(cur_index + 1) - '0';
538 cur_index += 3;
539 start_print = cur_index; 600 start_print = cur_index;
540 } 601 }
541 while (cur_index != end) { 602 while (cur_index != end) {
@@ -733,6 +794,8 @@ asmlinkage int vprintk(const char *fmt, va_list args)
733 unsigned long flags; 794 unsigned long flags;
734 int this_cpu; 795 int this_cpu;
735 char *p; 796 char *p;
797 size_t plen;
798 char special;
736 799
737 boot_delay_msec(); 800 boot_delay_msec();
738 printk_delay(); 801 printk_delay();
@@ -773,45 +836,52 @@ asmlinkage int vprintk(const char *fmt, va_list args)
773 printed_len += vscnprintf(printk_buf + printed_len, 836 printed_len += vscnprintf(printk_buf + printed_len,
774 sizeof(printk_buf) - printed_len, fmt, args); 837 sizeof(printk_buf) - printed_len, fmt, args);
775 838
776
777 p = printk_buf; 839 p = printk_buf;
778 840
779 /* Do we have a loglevel in the string? */ 841 /* Read log level and handle special printk prefix */
780 if (p[0] == '<') { 842 plen = log_prefix(p, &current_log_level, &special);
781 unsigned char c = p[1]; 843 if (plen) {
782 if (c && p[2] == '>') { 844 p += plen;
783 switch (c) { 845
784 case '0' ... '7': /* loglevel */ 846 switch (special) {
785 current_log_level = c - '0'; 847 case 'c': /* Strip <c> KERN_CONT, continue line */
786 /* Fallthrough - make sure we're on a new line */ 848 plen = 0;
787 case 'd': /* KERN_DEFAULT */ 849 break;
788 if (!new_text_line) { 850 case 'd': /* Strip <d> KERN_DEFAULT, start new line */
789 emit_log_char('\n'); 851 plen = 0;
790 new_text_line = 1; 852 default:
791 } 853 if (!new_text_line) {
792 /* Fallthrough - skip the loglevel */ 854 emit_log_char('\n');
793 case 'c': /* KERN_CONT */ 855 new_text_line = 1;
794 p += 3;
795 break;
796 } 856 }
797 } 857 }
798 } 858 }
799 859
800 /* 860 /*
801 * Copy the output into log_buf. If the caller didn't provide 861 * Copy the output into log_buf. If the caller didn't provide
802 * appropriate log level tags, we insert them here 862 * the appropriate log prefix, we insert them here
803 */ 863 */
804 for ( ; *p; p++) { 864 for (; *p; p++) {
805 if (new_text_line) { 865 if (new_text_line) {
806 /* Always output the token */
807 emit_log_char('<');
808 emit_log_char(current_log_level + '0');
809 emit_log_char('>');
810 printed_len += 3;
811 new_text_line = 0; 866 new_text_line = 0;
812 867
868 if (plen) {
869 /* Copy original log prefix */
870 int i;
871
872 for (i = 0; i < plen; i++)
873 emit_log_char(printk_buf[i]);
874 printed_len += plen;
875 } else {
876 /* Add log prefix */
877 emit_log_char('<');
878 emit_log_char(current_log_level + '0');
879 emit_log_char('>');
880 printed_len += 3;
881 }
882
813 if (printk_time) { 883 if (printk_time) {
814 /* Follow the token with the time */ 884 /* Add the current time stamp */
815 char tbuf[50], *tp; 885 char tbuf[50], *tp;
816 unsigned tlen; 886 unsigned tlen;
817 unsigned long long t; 887 unsigned long long t;
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index b335acb43be2..75ca78f3a8c9 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -7,6 +7,7 @@
7 * Copyright (C) 2008 Jason Baron <jbaron@redhat.com> 7 * Copyright (C) 2008 Jason Baron <jbaron@redhat.com>
8 * By Greg Banks <gnb@melbourne.sgi.com> 8 * By Greg Banks <gnb@melbourne.sgi.com>
9 * Copyright (c) 2008 Silicon Graphics Inc. All Rights Reserved. 9 * Copyright (c) 2008 Silicon Graphics Inc. All Rights Reserved.
10 * Copyright (C) 2011 Bart Van Assche. All Rights Reserved.
10 */ 11 */
11 12
12#include <linux/kernel.h> 13#include <linux/kernel.h>
@@ -27,6 +28,8 @@
27#include <linux/debugfs.h> 28#include <linux/debugfs.h>
28#include <linux/slab.h> 29#include <linux/slab.h>
29#include <linux/jump_label.h> 30#include <linux/jump_label.h>
31#include <linux/hardirq.h>
32#include <linux/sched.h>
30 33
31extern struct _ddebug __start___verbose[]; 34extern struct _ddebug __start___verbose[];
32extern struct _ddebug __stop___verbose[]; 35extern struct _ddebug __stop___verbose[];
@@ -63,15 +66,25 @@ static inline const char *basename(const char *path)
63 return tail ? tail+1 : path; 66 return tail ? tail+1 : path;
64} 67}
65 68
69static struct { unsigned flag:8; char opt_char; } opt_array[] = {
70 { _DPRINTK_FLAGS_PRINT, 'p' },
71 { _DPRINTK_FLAGS_INCL_MODNAME, 'm' },
72 { _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' },
73 { _DPRINTK_FLAGS_INCL_LINENO, 'l' },
74 { _DPRINTK_FLAGS_INCL_TID, 't' },
75};
76
66/* format a string into buf[] which describes the _ddebug's flags */ 77/* format a string into buf[] which describes the _ddebug's flags */
67static char *ddebug_describe_flags(struct _ddebug *dp, char *buf, 78static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
68 size_t maxlen) 79 size_t maxlen)
69{ 80{
70 char *p = buf; 81 char *p = buf;
82 int i;
71 83
72 BUG_ON(maxlen < 4); 84 BUG_ON(maxlen < 4);
73 if (dp->flags & _DPRINTK_FLAGS_PRINT) 85 for (i = 0; i < ARRAY_SIZE(opt_array); ++i)
74 *p++ = 'p'; 86 if (dp->flags & opt_array[i].flag)
87 *p++ = opt_array[i].opt_char;
75 if (p == buf) 88 if (p == buf)
76 *p++ = '-'; 89 *p++ = '-';
77 *p = '\0'; 90 *p = '\0';
@@ -343,7 +356,7 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
343 unsigned int *maskp) 356 unsigned int *maskp)
344{ 357{
345 unsigned flags = 0; 358 unsigned flags = 0;
346 int op = '='; 359 int op = '=', i;
347 360
348 switch (*str) { 361 switch (*str) {
349 case '+': 362 case '+':
@@ -358,13 +371,14 @@ static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
358 printk(KERN_INFO "%s: op='%c'\n", __func__, op); 371 printk(KERN_INFO "%s: op='%c'\n", __func__, op);
359 372
360 for ( ; *str ; ++str) { 373 for ( ; *str ; ++str) {
361 switch (*str) { 374 for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) {
362 case 'p': 375 if (*str == opt_array[i].opt_char) {
363 flags |= _DPRINTK_FLAGS_PRINT; 376 flags |= opt_array[i].flag;
364 break; 377 break;
365 default: 378 }
366 return -EINVAL;
367 } 379 }
380 if (i < 0)
381 return -EINVAL;
368 } 382 }
369 if (flags == 0) 383 if (flags == 0)
370 return -EINVAL; 384 return -EINVAL;
@@ -413,6 +427,35 @@ static int ddebug_exec_query(char *query_string)
413 return 0; 427 return 0;
414} 428}
415 429
430int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...)
431{
432 va_list args;
433 int res;
434
435 BUG_ON(!descriptor);
436 BUG_ON(!fmt);
437
438 va_start(args, fmt);
439 res = printk(KERN_DEBUG);
440 if (descriptor->flags & _DPRINTK_FLAGS_INCL_TID) {
441 if (in_interrupt())
442 res += printk(KERN_CONT "<intr> ");
443 else
444 res += printk(KERN_CONT "[%d] ", task_pid_vnr(current));
445 }
446 if (descriptor->flags & _DPRINTK_FLAGS_INCL_MODNAME)
447 res += printk(KERN_CONT "%s:", descriptor->modname);
448 if (descriptor->flags & _DPRINTK_FLAGS_INCL_FUNCNAME)
449 res += printk(KERN_CONT "%s:", descriptor->function);
450 if (descriptor->flags & _DPRINTK_FLAGS_INCL_LINENO)
451 res += printk(KERN_CONT "%d ", descriptor->lineno);
452 res += vprintk(fmt, args);
453 va_end(args);
454
455 return res;
456}
457EXPORT_SYMBOL(__dynamic_pr_debug);
458
416static __initdata char ddebug_setup_string[1024]; 459static __initdata char ddebug_setup_string[1024];
417static __init int ddebug_setup_query(char *str) 460static __init int ddebug_setup_query(char *str)
418{ 461{