Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'driver-core-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6

* 'driver-core-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6: (50 commits)
printk: do not mangle valid userspace syslog prefixes
efivars: Add Documentation
efivars: Expose efivars functionality to external drivers.
efivars: Parameterize operations.
efivars: Split out variable registration
efivars: parameterize efivars
efivars: Make efivars bin_attributes dynamic
efivars: move efivars globals into struct efivars
drivers:misc: ti-st: fix debugging code
kref: Fix typo in kref documentation
UIO: add PRUSS UIO driver support
Fix spelling mistakes in Documentation/zh_CN/SubmittingPatches
firmware: Fix unaligned memory accesses in dmi-sysfs
firmware: Add documentation for /sys/firmware/dmi
firmware: Expose DMI type 15 System Event Log
firmware: Break out system_event_log in dmi-sysfs
firmware: Basic dmi-sysfs support
firmware: Add DMI entry types to the headers
Driver core: convert platform_{get,set}_drvdata to static inline functions
Translate linux-2.6/Documentation/magic-number.txt into Chinese
...

+2892 -915
+75
Documentation/ABI/stable/sysfs-firmware-efi-vars
··· 1 + What: /sys/firmware/efi/vars 2 + Date: April 2004 3 + Contact: Matt Domsch <Matt_Domsch@dell.com> 4 + Description: 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.
+110
Documentation/ABI/testing/sysfs-firmware-dmi
··· 1 + What: /sys/firmware/dmi/ 2 + Date: February 2011 3 + Contact: Mike Waychison <mikew@google.com> 4 + Description: 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.
+48
Documentation/ABI/testing/sysfs-platform-kim
··· 1 + What: /sys/devices/platform/kim/dev_name 2 + Date: January 2010 3 + KernelVersion: 2.6.38 4 + Contact: "Pavan Savoy" <pavan_savoy@ti.com> 5 + Description: 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 + 13 + What: /sys/devices/platform/kim/baud_rate 14 + Date: January 2010 15 + KernelVersion: 2.6.38 16 + Contact: "Pavan Savoy" <pavan_savoy@ti.com> 17 + Description: 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 + 25 + What: /sys/devices/platform/kim/flow_cntrl 26 + Date: January 2010 27 + KernelVersion: 2.6.38 28 + Contact: "Pavan Savoy" <pavan_savoy@ti.com> 29 + Description: 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 + 35 + What: /sys/devices/platform/kim/install 36 + Date: January 2010 37 + KernelVersion: 2.6.38 38 + Contact: "Pavan Savoy" <pavan_savoy@ti.com> 39 + Description: 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.
+10 -2
Documentation/dynamic-debug-howto.txt
··· 205 205 206 206 The flags are: 207 207 208 + f 209 + Include the function name in the printed message 210 + l 211 + Include line number in the printed message 212 + m 213 + Include module name in the printed message 208 214 p 209 215 Causes a printk() message to be emitted to dmesg 216 + t 217 + Include thread ID in messages not generated from interrupt context 210 218 211 - Note the regexp ^[-+=][scp]+$ matches a flags specification. 219 + Note the regexp ^[-+=][flmpt]+$ matches a flags specification. 212 220 Note also that there is no convenient syntax to remove all 213 - the flags at once, you need to use "-psc". 221 + the flags at once, you need to use "-flmpt". 214 222 215 223 216 224 Debug messages during boot process
+9 -7
Documentation/filesystems/sysfs.txt
··· 39 39 ancestors of object hierarchies; i.e. the subsystems the objects 40 40 belong to. 41 41 42 - Sysfs internally stores the kobject that owns the directory in the 43 - ->d_fsdata pointer of the directory's dentry. This allows sysfs to do 44 - reference counting directly on the kobject when the file is opened and 45 - closed. 42 + Sysfs internally stores a pointer to the kobject that implements a 43 + directory in the sysfs_dirent object associated with the directory. In 44 + the past this kobject pointer has been used by sysfs to do reference 45 + counting directly on the kobject whenever the file is opened or closed. 46 + With the current sysfs implementation the kobject reference count is 47 + only modified directly by the function sysfs_schedule_callback(). 46 48 47 49 48 50 Attributes ··· 210 208 is 4096. 211 209 212 210 - show() methods should return the number of bytes printed into the 213 - buffer. This is the return value of snprintf(). 211 + buffer. This is the return value of scnprintf(). 214 212 215 - - show() should always use snprintf(). 213 + - show() should always use scnprintf(). 216 214 217 215 - store() should return the number of bytes used from the buffer. If the 218 216 entire buffer has been used, just return the count argument. ··· 231 229 static ssize_t show_name(struct device *dev, struct device_attribute *attr, 232 230 char *buf) 233 231 { 234 - return snprintf(buf, PAGE_SIZE, "%s\n", dev->name); 232 + return scnprintf(buf, PAGE_SIZE, "%s\n", dev->name); 235 233 } 236 234 237 235 static ssize_t store_name(struct device *dev, struct device_attribute *attr,
+1 -1
Documentation/kref.txt
··· 156 156 struct my_data *entry = NULL; 157 157 mutex_lock(&mutex); 158 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 160 kref_get(&entry->refcount); 161 161 } 162 162 mutex_unlock(&mutex);
+31 -16
Documentation/memory-hotplug.txt
··· 126 126 -------------------------------- 127 127 4 sysfs files for memory hotplug 128 128 -------------------------------- 129 - All sections have their device information under /sys/devices/system/memory as 129 + All sections have their device information in sysfs. Each section is part of 130 + a memory block under /sys/devices/system/memory as 130 131 131 132 /sys/devices/system/memory/memoryXXX 132 - (XXX is section id.) 133 + (XXX is the section id.) 133 134 134 - Now, XXX is defined as start_address_of_section / section_size. 135 + Now, XXX is defined as (start_address_of_section / section_size) of the first 136 + section 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 138 + for the memory block covered by the sysfs directory. It is expected that all 139 + memory sections in this range are present and no memory holes exist in the 140 + range. Currently there is no way to determine if there is a memory hole, but 141 + the existence of one should not affect the hotplug capabilities of the memory 142 + block. 135 143 136 144 For example, assume 1GiB section size. A device for a memory starting at 137 145 0x100000000 is /sys/device/system/memory/memory4 138 146 (0x100000000 / 1Gib = 4) 139 147 This device covers address range [0x100000000 ... 0x140000000) 140 148 141 - Under each section, you can see 4 files. 149 + Under each section, you can see 4 or 5 files, the end_phys_index file being 150 + a 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 154 /sys/devices/system/memory/memoryXXX/phys_device 145 155 /sys/devices/system/memory/memoryXXX/state 146 156 /sys/devices/system/memory/memoryXXX/removable 147 157 148 - 'phys_index' : read-only and contains section id, same as XXX. 149 - 'state' : read-write 150 - at read: contains online/offline state of memory. 151 - at write: user can specify "online", "offline" command 152 - 'phys_device': read-only: designed to show the name of physical memory device. 153 - This is not well implemented now. 154 - 'removable' : read-only: contains an integer value indicating 155 - whether the memory section is removable or not 156 - removable. A value of 1 indicates that the memory 157 - section is removable and a value of 0 indicates that 158 - it is not removable. 158 + 'phys_index' : read-only and contains section id of the first section 159 + in the memory block, same as XXX. 160 + 'end_phys_index' : read-only and contains section id of the last section 161 + in the memory block. 162 + 'state' : read-write 163 + at read: contains online/offline state of memory. 164 + at write: user can specify "online", "offline" command 165 + which will be performed on al sections in the block. 166 + 'phys_device' : read-only: designed to show the name of physical memory 167 + device. This is not well implemented now. 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 160 175 NOTE: 161 176 These directories/files appear after physical memory hotplug phase.
+50
Documentation/zh_CN/SecurityBugs
··· 1 + Chinese translated version of Documentation/SecurityBugs 2 + 3 + If you have any comment or update to the content, please contact the 4 + original document maintainer directly. However, if you have a problem 5 + communicating in English you can also ask the Chinese maintainer for 6 + help. Contact the Chinese maintainer if this translation is outdated 7 + or if there is a problem with the translation. 8 + 9 + Chinese maintainer: Harry Wei <harryxiyou@gmail.com> 10 + --------------------------------------------------------------------- 11 + Documentation/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 + --------------------------------------------------------------------- 24 + Linux内核开发者认为安全非常重要。因此,我们想要知道当一个有关于 25 + 安全的漏洞被发现的时候,并且它可能会被尽快的修复或者公开。请把这个安全 26 + 漏洞报告给Linux内核安全团队。 27 + 28 + 1) 联系 29 + 30 + linux内核安全团队可以通过email<security@kernel.org>来联系。这是 31 + 一组独立的安全工作人员,可以帮助改善漏洞报告并且公布和取消一个修复。安 32 + 全团队有可能会从部分的维护者那里引进额外的帮助来了解并且修复安全漏洞。 33 + 当遇到任何漏洞,所能提供的信息越多就越能诊断和修复。如果你不清楚什么 34 + 是有帮助的信息,那就请重温一下REPORTING-BUGS文件中的概述过程。任 35 + 何攻击性的代码都是非常有用的,未经报告者的同意不会被取消,除非它已经 36 + 被公布于众。 37 + 38 + 2) 公开 39 + 40 + Linux内核安全团队的宗旨就是和漏洞提交者一起处理漏洞的解决方案直 41 + 到公开。我们喜欢尽快地完全公开漏洞。当一个漏洞或者修复还没有被完全地理 42 + 解,解决方案没有通过测试或者供应商协调,可以合理地延迟公开。然而,我们 43 + 期望这些延迟尽可能的短些,是可数的几天,而不是几个星期或者几个月。公开 44 + 日期是通过安全团队和漏洞提供者以及供应商洽谈后的结果。公开时间表是从很 45 + 短(特殊的,它已经被公众所知道)到几个星期。作为一个基本的默认政策,我 46 + 们所期望通知公众的日期是7天的安排。 47 + 48 + 3) 保密协议 49 + 50 + Linux内核安全团队不是一个正式的团体,因此不能加入任何的保密协议。
+109
Documentation/zh_CN/SubmitChecklist
··· 1 + Chinese translated version of Documentation/SubmitChecklist 2 + 3 + If you have any comment or update to the content, please contact the 4 + original document maintainer directly. However, if you have a problem 5 + communicating in English you can also ask the Chinese maintainer for 6 + help. Contact the Chinese maintainer if this translation is outdated 7 + or if there is a problem with the translation. 8 + 9 + Chinese maintainer: Harry Wei <harryxiyou@gmail.com> 10 + --------------------------------------------------------------------- 11 + Documentation/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 + --------------------------------------------------------------------- 24 + Linux�ں��ύ�嵥 25 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 26 + 27 + ������һЩ�ں˿�����Ӧ�����Ļ������飬��������뿴���Լ����ں˲����ύ 28 + �����ܵĸ��졣 29 + 30 + ��Щ���dz���Documentation/SubmittingPatches�ĵ������ṩ���Լ����� 31 + �����ύLinux�ں˲�����˵���� 32 + 33 + 1�������ʹ����һ��������ô��#include����/�����Ǹ����ܵ��Ǹ��ļ��� 34 + ��Ҫ��������������붨��/�����Ǹ����ܵ�ͷ�ļ��� 35 + 36 + 2������������û��߸���CONFIGѡ�� =y��=m������=n�� 37 + ��Ҫ�б��뾯��/���� ��Ҫ�����Ӿ���/���� 38 + 39 + 2b��ͨ�� allnoconfig, allmodconfig 40 + 41 + 2c����ʹ�� 0=builddir �ɹ��ع��� 42 + 43 + 3��ͨ��ʹ�ñ��ؽ�����빤�߻�������һЩ�����������ڶ�CPU����Ϲ����� 44 + 45 + 4��ppc64 ��һ���ܺõļ�齻�����Ŀ�ܣ���Ϊ�������ѡ�unsigned long�� 46 + ��64λֵ��ʹ�á� 47 + 48 + 5������Documentation/CodingStyle�ļ������ϸ����������㲹���������� 49 + ʹ�ò�������������Υ��(scripts/checkpatch.pl)�����Ա�����ύ�� 50 + ��Ӧ�õ����������㲹���е�����Υ�档 51 + 52 + 6���κθ��»��߸Ķ�CONFIGѡ����ܴ������ò˵��� 53 + 54 + 7�����е�Kconfigѡ����¶�Ҫ��˵�����֡� 55 + 56 + 8���Ѿ�������ܽ�����ص�Kconfig��ϡ����Ǻ���ͨ���������õ�--�����������½��� 57 + 58 + 9�������м���ԡ� 59 + 60 + 10��ʹ��'make checkstack'��'make namespacecheck'��飬Ȼ���޸����ҵ������⡣ 61 + ע�⣺��ջ��鲻����ȷ�س������⣬�����κε�һ�������ڶ�ջ��ʹ�ö���512�ֽ� 62 + ��Ҫ׼���޸ġ� 63 + 64 + 11������kernel-doc��ȫ���ں�APIs�ļ�������Ҫ��̬�ĺ��������ǰ���Ҳ����ν���� 65 + ʹ��'make htmldocs'����'make mandocs'�����kernel-doc��Ȼ���޸��κ� 66 + ���ֵ����⡣ 67 + 68 + 12���Ѿ�ͨ��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 + 73 + 13���Ѿ�����������ʹ�û��߲�ʹ�� CONFIG_SMP �� CONFIG_PREEMPT����ִ��ʱ�䡣 74 + 75 + 14���������Ӱ��IO/Disk���ȵȣ��Ѿ�ͨ��ʹ�û��߲�ʹ�� CONFIG_LBDAF ���ԡ� 76 + 77 + 15�����е�codepaths�Ѿ���ʹ����lockdep���ù��ܡ� 78 + 79 + 16�����е�/proc��¼���¶�Ҫ�����ļ�����Documentation/Ŀ¼�¡� 80 + 81 + 17�����е��ں������������¶�����¼��Documentation/kernel-parameters.txt�ļ��С� 82 + 83 + 18�����е�ģ��������¶���MODULE_PARM_DESC()��¼�� 84 + 85 + 19�����е��û��ռ�ӿڸ��¶�����¼��Documentation/ABI/���鿴Documentation/ABI/README 86 + ���Ի�ø������Ϣ���ı��û��ռ�ӿڵIJ���Ӧ�ñ��ʼ����͸�linux-api@vger.kernel.org�� 87 + 88 + 20��������Dz��Ƕ�ͨ��`make headers_check'�� 89 + 90 + 21���Ѿ�ͨ����������slab��page-allocationʧ�ܼ�顣�鿴Documentation/fault-injection/�� 91 + 92 + 22���¼����Դ���Ѿ�ͨ��`gcc -W'��ʹ��"make EXTRA_CFLAGS=-W"�����롣�����������ܶෳ�գ� 93 + ���Ƕ���Ѱ��©�������洦������:"warning: comparison between signed and unsigned"�� 94 + 95 + 23���������ϲ���-mm���������ٲ��ԣ�����ȷ�����Ƿ񻹺Ͳ��������е���������һ�����Լ���VM��VFS 96 + ��������ϵͳ�и����仯�� 97 + 98 + 24�����е��ڴ�����{e.g., barrier(), rmb(), wmb()}��Ҫ��Դ�����е�һ��ע�����������Ƕ��Ǹ�ʲô�� 99 + �Լ�ԭ�� 100 + 101 + 25��������κ�����������ƵIJ��������ӣ�ҲҪ����Documentation/ioctl/ioctl-number.txt�� 102 + 103 + 26�������ĸ��Ĵ�����������ʹ���κε��ں�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)
+2 -2
Documentation/zh_CN/SubmittingPatches
··· 100 100 101 101 将改动拆分,逻辑类似的放到同一个补丁文件里。 102 102 103 - 例如,如果你的改动里同时有bug修正和性能优化,那么把这些改动才分到两个或 103 + 例如,如果你的改动里同时有bug修正和性能优化,那么把这些改动拆分到两个或 104 104 者更多的补丁文件中。如果你的改动包含对API的修改,并且修改了驱动程序来适 105 105 应这些新的API,那么把这些修改分成两个补丁。 106 106 ··· 230 230 些原因,修正错误,重新提交更新后的改动,是你自己的工作。 231 231 232 232 Linus不给出任何评论就“丢弃”你的补丁是常见的事情。在系统中这样的事情很 233 - 平常。如果他没有接受你的补丁,也许是由于以下原本: 233 + 平常。如果他没有接受你的补丁,也许是由于以下原因: 234 234 * 你的补丁不能在最新版本的内核上干净的打上。 235 235 * 你的补丁在 linux-kernel 邮件列表中没有得到充分的讨论。 236 236 * 风格问题(参照第2小节)
+167
Documentation/zh_CN/magic-number.txt
··· 1 + Chinese translated version of Documentation/magic-number.txt 2 + 3 + If you have any comment or update to the content, please post to LKML directly. 4 + However, if you have problem communicating in English you can also ask the 5 + Chinese maintainer for help. Contact the Chinese maintainer, if this 6 + translation is outdated or there is problem with translation. 7 + 8 + Chinese maintainer: Jia Wei Wei <harryxiyou@gmail.com> 9 + --------------------------------------------------------------------- 10 + Documentation/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 + 27 + struct 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 + =========================================================================== 63 + PG_MAGIC 'P' pg_{read,write}_hdr include/linux/pg.h 64 + CMAGIC 0x0111 user include/linux/a.out.h 65 + MKISS_DRIVER_MAGIC 0x04bf mkiss_channel drivers/net/mkiss.h 66 + RISCOM8_MAGIC 0x0907 riscom_port drivers/char/riscom8.h 67 + SPECIALIX_MAGIC 0x0907 specialix_port drivers/char/specialix_io8.h 68 + HDLC_MAGIC 0x239e n_hdlc drivers/char/n_hdlc.c 69 + APM_BIOS_MAGIC 0x4101 apm_user arch/i386/kernel/apm.c 70 + CYCLADES_MAGIC 0x4359 cyclades_port include/linux/cyclades.h 71 + DB_MAGIC 0x4442 fc_info drivers/net/iph5526_novram.c 72 + DL_MAGIC 0x444d fc_info drivers/net/iph5526_novram.c 73 + FASYNC_MAGIC 0x4601 fasync_struct include/linux/fs.h 74 + FF_MAGIC 0x4646 fc_info drivers/net/iph5526_novram.c 75 + ISICOM_MAGIC 0x4d54 isi_port include/linux/isicom.h 76 + PTY_MAGIC 0x5001 drivers/char/pty.c 77 + PPP_MAGIC 0x5002 ppp include/linux/if_pppvar.h 78 + SERIAL_MAGIC 0x5301 async_struct include/linux/serial.h 79 + SSTATE_MAGIC 0x5302 serial_state include/linux/serial.h 80 + SLIP_MAGIC 0x5302 slip drivers/net/slip.h 81 + STRIP_MAGIC 0x5303 strip drivers/net/strip.c 82 + X25_ASY_MAGIC 0x5303 x25_asy drivers/net/x25_asy.h 83 + SIXPACK_MAGIC 0x5304 sixpack drivers/net/hamradio/6pack.h 84 + AX25_MAGIC 0x5316 ax_disp drivers/net/mkiss.h 85 + ESP_MAGIC 0x53ee esp_struct drivers/char/esp.h 86 + TTY_MAGIC 0x5401 tty_struct include/linux/tty.h 87 + MGSL_MAGIC 0x5401 mgsl_info drivers/char/synclink.c 88 + TTY_DRIVER_MAGIC 0x5402 tty_driver include/linux/tty_driver.h 89 + MGSLPC_MAGIC 0x5402 mgslpc_info drivers/char/pcmcia/synclink_cs.c 90 + TTY_LDISC_MAGIC 0x5403 tty_ldisc include/linux/tty_ldisc.h 91 + USB_SERIAL_MAGIC 0x6702 usb_serial drivers/usb/serial/usb-serial.h 92 + FULL_DUPLEX_MAGIC 0x6969 drivers/net/tulip/de2104x.c 93 + USB_BLUETOOTH_MAGIC 0x6d02 usb_bluetooth drivers/usb/class/bluetty.c 94 + RFCOMM_TTY_MAGIC 0x6d02 net/bluetooth/rfcomm/tty.c 95 + USB_SERIAL_PORT_MAGIC 0x7301 usb_serial_port drivers/usb/serial/usb-serial.h 96 + CG_MAGIC 0x00090255 ufs_cylinder_group include/linux/ufs_fs.h 97 + A2232_MAGIC 0x000a2232 gs_port drivers/char/ser_a2232.h 98 + RPORT_MAGIC 0x00525001 r_port drivers/char/rocket_int.h 99 + LSEMAGIC 0x05091998 lse drivers/fc4/fc.c 100 + GDTIOCTL_MAGIC 0x06030f07 gdth_iowr_str drivers/scsi/gdth_ioctl.h 101 + RIEBL_MAGIC 0x09051990 drivers/net/atarilance.c 102 + RIO_MAGIC 0x12345678 gs_port drivers/char/rio/rio_linux.c 103 + SX_MAGIC 0x12345678 gs_port drivers/char/sx.h 104 + NBD_REQUEST_MAGIC 0x12560953 nbd_request include/linux/nbd.h 105 + RED_MAGIC2 0x170fc2a5 (any) mm/slab.c 106 + BAYCOM_MAGIC 0x19730510 baycom_state drivers/net/baycom_epp.c 107 + ISDN_X25IFACE_MAGIC 0x1e75a2b9 isdn_x25iface_proto_data 108 + drivers/isdn/isdn_x25iface.h 109 + ECP_MAGIC 0x21504345 cdkecpsig include/linux/cdk.h 110 + LSOMAGIC 0x27091997 lso drivers/fc4/fc.c 111 + LSMAGIC 0x2a3b4d2a ls drivers/fc4/fc.c 112 + WANPIPE_MAGIC 0x414C4453 sdla_{dump,exec} include/linux/wanpipe.h 113 + CS_CARD_MAGIC 0x43525553 cs_card sound/oss/cs46xx.c 114 + LABELCL_MAGIC 0x4857434c labelcl_info_s include/asm/ia64/sn/labelcl.h 115 + ISDN_ASYNC_MAGIC 0x49344C01 modem_info include/linux/isdn.h 116 + CTC_ASYNC_MAGIC 0x49344C01 ctc_tty_info drivers/s390/net/ctctty.c 117 + ISDN_NET_MAGIC 0x49344C02 isdn_net_local_s drivers/isdn/i4l/isdn_net_lib.h 118 + SAVEKMSG_MAGIC2 0x4B4D5347 savekmsg arch/*/amiga/config.c 119 + STLI_BOARDMAGIC 0x4bc6c825 stlibrd include/linux/istallion.h 120 + CS_STATE_MAGIC 0x4c4f4749 cs_state sound/oss/cs46xx.c 121 + SLAB_C_MAGIC 0x4f17a36d kmem_cache mm/slab.c 122 + COW_MAGIC 0x4f4f4f4d cow_header_v1 arch/um/drivers/ubd_user.c 123 + I810_CARD_MAGIC 0x5072696E i810_card sound/oss/i810_audio.c 124 + TRIDENT_CARD_MAGIC 0x5072696E trident_card sound/oss/trident.c 125 + ROUTER_MAGIC 0x524d4157 wan_device include/linux/wanrouter.h 126 + SCC_MAGIC 0x52696368 gs_port drivers/char/scc.h 127 + SAVEKMSG_MAGIC1 0x53415645 savekmsg arch/*/amiga/config.c 128 + GDA_MAGIC 0x58464552 gda arch/mips/include/asm/sn/gda.h 129 + RED_MAGIC1 0x5a2cf071 (any) mm/slab.c 130 + STL_PORTMAGIC 0x5a7182c9 stlport include/linux/stallion.h 131 + EEPROM_MAGIC_VALUE 0x5ab478d2 lanai_dev drivers/atm/lanai.c 132 + HDLCDRV_MAGIC 0x5ac6e778 hdlcdrv_state include/linux/hdlcdrv.h 133 + EPCA_MAGIC 0x5c6df104 channel include/linux/epca.h 134 + PCXX_MAGIC 0x5c6df104 channel drivers/char/pcxx.h 135 + KV_MAGIC 0x5f4b565f kernel_vars_s arch/mips/include/asm/sn/klkernvars.h 136 + I810_STATE_MAGIC 0x63657373 i810_state sound/oss/i810_audio.c 137 + TRIDENT_STATE_MAGIC 0x63657373 trient_state sound/oss/trident.c 138 + M3_CARD_MAGIC 0x646e6f50 m3_card sound/oss/maestro3.c 139 + FW_HEADER_MAGIC 0x65726F66 fw_header drivers/atm/fore200e.h 140 + SLOT_MAGIC 0x67267321 slot drivers/hotplug/cpqphp.h 141 + SLOT_MAGIC 0x67267322 slot drivers/hotplug/acpiphp.h 142 + LO_MAGIC 0x68797548 nbd_device include/linux/nbd.h 143 + OPROFILE_MAGIC 0x6f70726f super_block drivers/oprofile/oprofilefs.h 144 + M3_STATE_MAGIC 0x734d724d m3_state sound/oss/maestro3.c 145 + STL_PANELMAGIC 0x7ef621a1 stlpanel include/linux/stallion.h 146 + VMALLOC_MAGIC 0x87654320 snd_alloc_track sound/core/memory.c 147 + KMALLOC_MAGIC 0x87654321 snd_alloc_track sound/core/memory.c 148 + PWC_MAGIC 0x89DC10AB pwc_device drivers/usb/media/pwc.h 149 + NBD_REPLY_MAGIC 0x96744668 nbd_reply include/linux/nbd.h 150 + STL_BOARDMAGIC 0xa2267f52 stlbrd include/linux/stallion.h 151 + ENI155_MAGIC 0xa54b872d midway_eprom drivers/atm/eni.h 152 + SCI_MAGIC 0xbabeface gs_port drivers/char/sh-sci.h 153 + CODA_MAGIC 0xC0DAC0DA coda_file_info include/linux/coda_fs_i.h 154 + DPMEM_MAGIC 0xc0ffee11 gdt_pci_sram drivers/scsi/gdth.h 155 + STLI_PORTMAGIC 0xe671c7a1 stliport include/linux/istallion.h 156 + YAM_MAGIC 0xF10A7654 yam_port drivers/net/hamradio/yam.c 157 + CCB_MAGIC 0xf2691ad2 ccb drivers/scsi/ncr53c8xx.c 158 + QUEUE_MAGIC_FREE 0xf7e1c9a3 queue_entry drivers/scsi/arm/queue.c 159 + QUEUE_MAGIC_USED 0xf7e1cc33 queue_entry drivers/scsi/arm/queue.c 160 + HTB_CMAGIC 0xFEFAFEF1 htb_class net/sched/sch_htb.c 161 + NMI_MAGIC 0x48414d4d455201 nmi_s arch/mips/include/asm/sn/nmi.h 162 + 163 + 请注意,在声音记忆管理中仍然有每一些被定义的驱动魔术值。查看include/sound/sndmagic.h来获取他们完整的列表信息。很多OSS声音驱动拥有自己从声卡PCI ID构建的魔术值-他们也没有被列在这里。 164 + 165 + IrDA子系统也使用了大量的自己的魔术值,查看include/net/irda/irda.h来获取他们完整的信息。 166 + 167 + HFS是另外一个比较大的使用魔术值的文件系统-你可以在fs/hfs/hfs.h中找到他们。
+53 -13
arch/powerpc/platforms/pseries/hotplug-memory.c
··· 17 17 #include <asm/pSeries_reconfig.h> 18 18 #include <asm/sparsemem.h> 19 19 20 + static 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 + 63 + unsigned long memory_block_size_bytes(void) 64 + { 65 + return get_memblock_size(); 66 + } 67 + 20 68 static int pseries_remove_memblock(unsigned long base, unsigned int memblock_size) 21 69 { 22 70 unsigned long start, start_pfn; ··· 175 127 176 128 static int pseries_drconf_memory(unsigned long *base, unsigned int action) 177 129 { 178 - struct device_node *np; 179 - const unsigned long *lmb_size; 130 + unsigned long memblock_size; 180 131 int rc; 181 132 182 - np = of_find_node_by_path("/ibm,dynamic-reconfiguration-memory"); 183 - if (!np) 133 + memblock_size = get_memblock_size(); 134 + if (!memblock_size) 184 135 return -EINVAL; 185 - 186 - lmb_size = of_get_property(np, "ibm,lmb-size", NULL); 187 - if (!lmb_size) { 188 - of_node_put(np); 189 - return -EINVAL; 190 - } 191 136 192 137 if (action == PSERIES_DRCONF_MEM_ADD) { 193 - rc = memblock_add(*base, *lmb_size); 138 + rc = memblock_add(*base, memblock_size); 194 139 rc = (rc < 0) ? -EINVAL : 0; 195 140 } else if (action == PSERIES_DRCONF_MEM_REMOVE) { 196 - rc = pseries_remove_memblock(*base, *lmb_size); 141 + rc = pseries_remove_memblock(*base, memblock_size); 197 142 } else { 198 143 rc = -EINVAL; 199 144 } 200 145 201 - of_node_put(np); 202 146 return rc; 203 147 } 204 148
+14
arch/x86/mm/init_64.c
··· 51 51 #include <asm/numa.h> 52 52 #include <asm/cacheflush.h> 53 53 #include <asm/init.h> 54 + #include <asm/uv/uv.h> 54 55 55 56 static int __init parse_direct_gbpages_off(char *arg) 56 57 { ··· 898 897 return "[vsyscall]"; 899 898 return NULL; 900 899 } 900 + 901 + #ifdef CONFIG_X86_UV 902 + #define MIN_MEMORY_BLOCK_SIZE (1 << SECTION_SIZE_BITS) 903 + 904 + unsigned long memory_block_size_bytes(void) 905 + { 906 + if (is_uv_system()) { 907 + printk(KERN_INFO "UV: memory block size 2GB\n"); 908 + return 2UL * 1024 * 1024 * 1024; 909 + } 910 + return MIN_MEMORY_BLOCK_SIZE; 911 + } 912 + #endif 901 913 902 914 #ifdef CONFIG_SPARSEMEM_VMEMMAP 903 915 /*
+32 -2
drivers/base/core.c
··· 1320 1320 struct module *owner; 1321 1321 }; 1322 1322 1323 - #define to_root_device(dev) container_of(dev, struct root_device, dev) 1323 + inline struct root_device *to_root_device(struct device *d) 1324 + { 1325 + return container_of(d, struct root_device, dev); 1326 + } 1324 1327 1325 1328 static void root_device_release(struct device *dev) 1326 1329 { ··· 1554 1551 * on the same device to ensure that new_name is valid and 1555 1552 * won't conflict with other devices. 1556 1553 * 1557 - * "Never use this function, bad things will happen" - gregkh 1554 + * Note: Don't call this function. Currently, the networking layer calls this 1555 + * function, but that will change. The following text from Kay Sievers offers 1556 + * some insight: 1557 + * 1558 + * Renaming devices is racy at many levels, symlinks and other stuff are not 1559 + * replaced atomically, and you get a "move" uevent, but it's not easy to 1560 + * connect the event to the old and new device. Device nodes are not renamed at 1561 + * all, there isn't even support for that in the kernel now. 1562 + * 1563 + * In the meantime, during renaming, your target name might be taken by another 1564 + * driver, creating conflicts. Or the old name is taken directly after you 1565 + * renamed it -- then you get events for the same DEVPATH, before you even see 1566 + * the "move" event. It's just a mess, and nothing new should ever rely on 1567 + * kernel device renaming. Besides that, it's not even implemented now for 1568 + * other things than (driver-core wise very simple) network devices. 1569 + * 1570 + * We are currently about to change network renaming in udev to completely 1571 + * disallow renaming of devices in the same namespace as the kernel uses, 1572 + * because we can't solve the problems properly, that arise with swapping names 1573 + * of multiple interfaces without races. Means, renaming of eth[0-9]* will only 1574 + * be allowed to some other name than eth[0-9]*, for the aforementioned 1575 + * reasons. 1576 + * 1577 + * Make up a "real" name in the driver before you register anything, or add 1578 + * some other attributes for userspace to find the device, or use udev to add 1579 + * symlinks -- but never rename kernel devices later, it's a complete mess. We 1580 + * don't even want to get into that and try to implement the missing pieces in 1581 + * the core. We really have other pieces to fix in the driver core mess. :) 1558 1582 */ 1559 1583 int device_rename(struct device *dev, const char *new_name) 1560 1584 {
+3 -4
drivers/base/firmware_class.c
··· 593 593 request_firmware(const struct firmware **firmware_p, const char *name, 594 594 struct device *device) 595 595 { 596 - int uevent = 1; 597 - return _request_firmware(firmware_p, name, device, uevent, false); 596 + return _request_firmware(firmware_p, name, device, true, false); 598 597 } 599 598 600 599 /** ··· 617 618 struct device *device; 618 619 void *context; 619 620 void (*cont)(const struct firmware *fw, void *context); 620 - int uevent; 621 + bool uevent; 621 622 }; 622 623 623 624 static int request_firmware_work_func(void *arg) ··· 660 661 **/ 661 662 int 662 663 request_firmware_nowait( 663 - struct module *module, int uevent, 664 + struct module *module, bool uevent, 664 665 const char *name, struct device *device, gfp_t gfp, void *context, 665 666 void (*cont)(const struct firmware *fw, void *context)) 666 667 {
+143 -54
drivers/base/memory.c
··· 30 30 static DEFINE_MUTEX(mem_sysfs_mutex); 31 31 32 32 #define MEMORY_CLASS_NAME "memory" 33 + #define MIN_MEMORY_BLOCK_SIZE (1 << SECTION_SIZE_BITS) 34 + 35 + static int sections_per_block; 36 + 37 + static inline int base_memory_block_id(int section_nr) 38 + { 39 + return section_nr / sections_per_block; 40 + } 33 41 34 42 static struct sysdev_class memory_sysdev_class = { 35 43 .name = MEMORY_CLASS_NAME, ··· 92 84 * register_memory - Setup a sysfs device for a memory block 93 85 */ 94 86 static 95 - int register_memory(struct memory_block *memory, struct mem_section *section) 87 + int register_memory(struct memory_block *memory) 96 88 { 97 89 int error; 98 90 99 91 memory->sysdev.cls = &memory_sysdev_class; 100 - memory->sysdev.id = __section_nr(section); 92 + memory->sysdev.id = memory->start_section_nr / sections_per_block; 101 93 102 94 error = sysdev_register(&memory->sysdev); 103 95 return error; 104 96 } 105 97 106 98 static void 107 - unregister_memory(struct memory_block *memory, struct mem_section *section) 99 + unregister_memory(struct memory_block *memory) 108 100 { 109 101 BUG_ON(memory->sysdev.cls != &memory_sysdev_class); 110 - BUG_ON(memory->sysdev.id != __section_nr(section)); 111 102 112 103 /* drop the ref. we got in remove_memory_block() */ 113 104 kobject_put(&memory->sysdev.kobj); 114 105 sysdev_unregister(&memory->sysdev); 106 + } 107 + 108 + unsigned long __weak memory_block_size_bytes(void) 109 + { 110 + return MIN_MEMORY_BLOCK_SIZE; 111 + } 112 + 113 + static unsigned long get_memory_block_size(void) 114 + { 115 + unsigned long block_sz; 116 + 117 + block_sz = memory_block_size_bytes(); 118 + 119 + /* Validate blk_sz is a power of 2 and not less than section size */ 120 + if ((block_sz & (block_sz - 1)) || (block_sz < MIN_MEMORY_BLOCK_SIZE)) { 121 + WARN_ON(1); 122 + block_sz = MIN_MEMORY_BLOCK_SIZE; 123 + } 124 + 125 + return block_sz; 115 126 } 116 127 117 128 /* ··· 138 111 * uses. 139 112 */ 140 113 141 - static ssize_t show_mem_phys_index(struct sys_device *dev, 114 + static ssize_t show_mem_start_phys_index(struct sys_device *dev, 142 115 struct sysdev_attribute *attr, char *buf) 143 116 { 144 117 struct memory_block *mem = 145 118 container_of(dev, struct memory_block, sysdev); 146 - return sprintf(buf, "%08lx\n", mem->phys_index); 119 + unsigned long phys_index; 120 + 121 + phys_index = mem->start_section_nr / sections_per_block; 122 + return sprintf(buf, "%08lx\n", phys_index); 123 + } 124 + 125 + static ssize_t show_mem_end_phys_index(struct sys_device *dev, 126 + struct sysdev_attribute *attr, char *buf) 127 + { 128 + struct memory_block *mem = 129 + container_of(dev, struct memory_block, sysdev); 130 + unsigned long phys_index; 131 + 132 + phys_index = mem->end_section_nr / sections_per_block; 133 + return sprintf(buf, "%08lx\n", phys_index); 147 134 } 148 135 149 136 /* ··· 166 125 static ssize_t show_mem_removable(struct sys_device *dev, 167 126 struct sysdev_attribute *attr, char *buf) 168 127 { 169 - unsigned long start_pfn; 170 - int ret; 128 + unsigned long i, pfn; 129 + int ret = 1; 171 130 struct memory_block *mem = 172 131 container_of(dev, struct memory_block, sysdev); 173 132 174 - start_pfn = section_nr_to_pfn(mem->phys_index); 175 - ret = is_mem_section_removable(start_pfn, PAGES_PER_SECTION); 133 + for (i = 0; i < sections_per_block; i++) { 134 + pfn = section_nr_to_pfn(mem->start_section_nr + i); 135 + ret &= is_mem_section_removable(pfn, PAGES_PER_SECTION); 136 + } 137 + 176 138 return sprintf(buf, "%d\n", ret); 177 139 } 178 140 ··· 228 184 * OK to have direct references to sparsemem variables in here. 229 185 */ 230 186 static int 231 - memory_block_action(struct memory_block *mem, unsigned long action) 187 + memory_section_action(unsigned long phys_index, unsigned long action) 232 188 { 233 189 int i; 234 - unsigned long psection; 235 190 unsigned long start_pfn, start_paddr; 236 191 struct page *first_page; 237 192 int ret; 238 - int old_state = mem->state; 239 193 240 - psection = mem->phys_index; 241 - first_page = pfn_to_page(psection << PFN_SECTION_SHIFT); 194 + first_page = pfn_to_page(phys_index << PFN_SECTION_SHIFT); 242 195 243 196 /* 244 197 * The probe routines leave the pages reserved, just ··· 248 207 continue; 249 208 250 209 printk(KERN_WARNING "section number %ld page number %d " 251 - "not reserved, was it already online? \n", 252 - psection, i); 210 + "not reserved, was it already online?\n", 211 + phys_index, i); 253 212 return -EBUSY; 254 213 } 255 214 } ··· 260 219 ret = online_pages(start_pfn, PAGES_PER_SECTION); 261 220 break; 262 221 case MEM_OFFLINE: 263 - mem->state = MEM_GOING_OFFLINE; 264 222 start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; 265 223 ret = remove_memory(start_paddr, 266 224 PAGES_PER_SECTION << PAGE_SHIFT); 267 - if (ret) { 268 - mem->state = old_state; 269 - break; 270 - } 271 225 break; 272 226 default: 273 - WARN(1, KERN_WARNING "%s(%p, %ld) unknown action: %ld\n", 274 - __func__, mem, action, action); 227 + WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " 228 + "%ld\n", __func__, phys_index, action, action); 275 229 ret = -EINVAL; 276 230 } 277 231 ··· 276 240 static int memory_block_change_state(struct memory_block *mem, 277 241 unsigned long to_state, unsigned long from_state_req) 278 242 { 279 - int ret = 0; 243 + int i, ret = 0; 244 + 280 245 mutex_lock(&mem->state_mutex); 281 246 282 247 if (mem->state != from_state_req) { ··· 285 248 goto out; 286 249 } 287 250 288 - ret = memory_block_action(mem, to_state); 289 - if (!ret) 251 + if (to_state == MEM_OFFLINE) 252 + mem->state = MEM_GOING_OFFLINE; 253 + 254 + for (i = 0; i < sections_per_block; i++) { 255 + ret = memory_section_action(mem->start_section_nr + i, 256 + to_state); 257 + if (ret) 258 + break; 259 + } 260 + 261 + if (ret) { 262 + for (i = 0; i < sections_per_block; i++) 263 + memory_section_action(mem->start_section_nr + i, 264 + from_state_req); 265 + 266 + mem->state = from_state_req; 267 + } else 290 268 mem->state = to_state; 291 269 292 270 out: ··· 314 262 struct sysdev_attribute *attr, const char *buf, size_t count) 315 263 { 316 264 struct memory_block *mem; 317 - unsigned int phys_section_nr; 318 265 int ret = -EINVAL; 319 266 320 267 mem = container_of(dev, struct memory_block, sysdev); 321 - phys_section_nr = mem->phys_index; 322 - 323 - if (!present_section_nr(phys_section_nr)) 324 - goto out; 325 268 326 269 if (!strncmp(buf, "online", min((int)count, 6))) 327 270 ret = memory_block_change_state(mem, MEM_ONLINE, MEM_OFFLINE); 328 271 else if(!strncmp(buf, "offline", min((int)count, 7))) 329 272 ret = memory_block_change_state(mem, MEM_OFFLINE, MEM_ONLINE); 330 - out: 273 + 331 274 if (ret) 332 275 return ret; 333 276 return count; ··· 345 298 return sprintf(buf, "%d\n", mem->phys_device); 346 299 } 347 300 348 - static SYSDEV_ATTR(phys_index, 0444, show_mem_phys_index, NULL); 301 + static SYSDEV_ATTR(phys_index, 0444, show_mem_start_phys_index, NULL); 302 + static SYSDEV_ATTR(end_phys_index, 0444, show_mem_end_phys_index, NULL); 349 303 static SYSDEV_ATTR(state, 0644, show_mem_state, store_mem_state); 350 304 static SYSDEV_ATTR(phys_device, 0444, show_phys_device, NULL); 351 305 static SYSDEV_ATTR(removable, 0444, show_mem_removable, NULL); ··· 363 315 print_block_size(struct sysdev_class *class, struct sysdev_class_attribute *attr, 364 316 char *buf) 365 317 { 366 - return sprintf(buf, "%lx\n", (unsigned long)PAGES_PER_SECTION * PAGE_SIZE); 318 + return sprintf(buf, "%lx\n", get_memory_block_size()); 367 319 } 368 320 369 321 static SYSDEV_CLASS_ATTR(block_size_bytes, 0444, print_block_size, NULL); ··· 387 339 { 388 340 u64 phys_addr; 389 341 int nid; 390 - int ret; 342 + int i, ret; 391 343 392 344 phys_addr = simple_strtoull(buf, NULL, 0); 393 345 394 - nid = memory_add_physaddr_to_nid(phys_addr); 395 - ret = add_memory(nid, phys_addr, PAGES_PER_SECTION << PAGE_SHIFT); 346 + for (i = 0; i < sections_per_block; i++) { 347 + nid = memory_add_physaddr_to_nid(phys_addr); 348 + ret = add_memory(nid, phys_addr, 349 + PAGES_PER_SECTION << PAGE_SHIFT); 350 + if (ret) 351 + break; 352 + 353 + phys_addr += MIN_MEMORY_BLOCK_SIZE; 354 + } 396 355 397 356 if (ret) 398 357 count = ret; ··· 499 444 struct sys_device *sysdev; 500 445 struct memory_block *mem; 501 446 char name[sizeof(MEMORY_CLASS_NAME) + 9 + 1]; 447 + int block_id = base_memory_block_id(__section_nr(section)); 502 448 503 449 kobj = hint ? &hint->sysdev.kobj : NULL; 504 450 ··· 507 451 * This only works because we know that section == sysdev->id 508 452 * slightly redundant with sysdev_register() 509 453 */ 510 - sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, __section_nr(section)); 454 + sprintf(&name[0], "%s%d", MEMORY_CLASS_NAME, block_id); 511 455 512 456 kobj = kset_find_obj_hinted(&memory_sysdev_class.kset, name, kobj); 513 457 if (!kobj) ··· 532 476 return find_memory_block_hinted(section, NULL); 533 477 } 534 478 535 - static int add_memory_block(int nid, struct mem_section *section, 536 - unsigned long state, enum mem_add_context context) 479 + static int init_memory_block(struct memory_block **memory, 480 + struct mem_section *section, unsigned long state) 537 481 { 538 - struct memory_block *mem = kzalloc(sizeof(*mem), GFP_KERNEL); 482 + struct memory_block *mem; 539 483 unsigned long start_pfn; 484 + int scn_nr; 540 485 int ret = 0; 541 486 487 + mem = kzalloc(sizeof(*mem), GFP_KERNEL); 542 488 if (!mem) 543 489 return -ENOMEM; 544 490 545 - mutex_lock(&mem_sysfs_mutex); 546 - 547 - mem->phys_index = __section_nr(section); 491 + scn_nr = __section_nr(section); 492 + mem->start_section_nr = 493 + base_memory_block_id(scn_nr) * sections_per_block; 494 + mem->end_section_nr = mem->start_section_nr + sections_per_block - 1; 548 495 mem->state = state; 549 496 mem->section_count++; 550 497 mutex_init(&mem->state_mutex); 551 - start_pfn = section_nr_to_pfn(mem->phys_index); 498 + start_pfn = section_nr_to_pfn(mem->start_section_nr); 552 499 mem->phys_device = arch_get_memory_phys_device(start_pfn); 553 500 554 - ret = register_memory(mem, section); 501 + ret = register_memory(mem); 555 502 if (!ret) 556 503 ret = mem_create_simple_file(mem, phys_index); 504 + if (!ret) 505 + ret = mem_create_simple_file(mem, end_phys_index); 557 506 if (!ret) 558 507 ret = mem_create_simple_file(mem, state); 559 508 if (!ret) 560 509 ret = mem_create_simple_file(mem, phys_device); 561 510 if (!ret) 562 511 ret = mem_create_simple_file(mem, removable); 512 + 513 + *memory = mem; 514 + return ret; 515 + } 516 + 517 + static int add_memory_section(int nid, struct mem_section *section, 518 + unsigned long state, enum mem_add_context context) 519 + { 520 + struct memory_block *mem; 521 + int ret = 0; 522 + 523 + mutex_lock(&mem_sysfs_mutex); 524 + 525 + mem = find_memory_block(section); 526 + if (mem) { 527 + mem->section_count++; 528 + kobject_put(&mem->sysdev.kobj); 529 + } else 530 + ret = init_memory_block(&mem, section, state); 531 + 563 532 if (!ret) { 564 - if (context == HOTPLUG) 533 + if (context == HOTPLUG && 534 + mem->section_count == sections_per_block) 565 535 ret = register_mem_sect_under_node(mem, nid); 566 536 } 567 537 ··· 602 520 603 521 mutex_lock(&mem_sysfs_mutex); 604 522 mem = find_memory_block(section); 523 + unregister_mem_sect_under_nodes(mem, __section_nr(section)); 605 524 606 525 mem->section_count--; 607 526 if (mem->section_count == 0) { 608 - unregister_mem_sect_under_nodes(mem); 609 527 mem_remove_simple_file(mem, phys_index); 528 + mem_remove_simple_file(mem, end_phys_index); 610 529 mem_remove_simple_file(mem, state); 611 530 mem_remove_simple_file(mem, phys_device); 612 531 mem_remove_simple_file(mem, removable); 613 - unregister_memory(mem, section); 614 - } 532 + unregister_memory(mem); 533 + kfree(mem); 534 + } else 535 + kobject_put(&mem->sysdev.kobj); 615 536 616 537 mutex_unlock(&mem_sysfs_mutex); 617 538 return 0; ··· 626 541 */ 627 542 int register_new_memory(int nid, struct mem_section *section) 628 543 { 629 - return add_memory_block(nid, section, MEM_OFFLINE, HOTPLUG); 544 + return add_memory_section(nid, section, MEM_OFFLINE, HOTPLUG); 630 545 } 631 546 632 547 int unregister_memory_section(struct mem_section *section) ··· 645 560 unsigned int i; 646 561 int ret; 647 562 int err; 563 + unsigned long block_sz; 648 564 649 565 memory_sysdev_class.kset.uevent_ops = &memory_uevent_ops; 650 566 ret = sysdev_class_register(&memory_sysdev_class); 651 567 if (ret) 652 568 goto out; 569 + 570 + block_sz = get_memory_block_size(); 571 + sections_per_block = block_sz / MIN_MEMORY_BLOCK_SIZE; 653 572 654 573 /* 655 574 * Create entries for memory sections that were found ··· 662 573 for (i = 0; i < NR_MEM_SECTIONS; i++) { 663 574 if (!present_section_nr(i)) 664 575 continue; 665 - err = add_memory_block(0, __nr_to_section(i), MEM_ONLINE, 666 - BOOT); 576 + err = add_memory_section(0, __nr_to_section(i), MEM_ONLINE, 577 + BOOT); 667 578 if (!ret) 668 579 ret = err; 669 580 }
+8 -4
drivers/base/node.c
··· 375 375 return -EFAULT; 376 376 if (!node_online(nid)) 377 377 return 0; 378 - sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index); 379 - sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; 378 + 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 382 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { 381 383 int page_nid; 382 384 ··· 402 400 } 403 401 404 402 /* unregister memory section under all nodes that it spans */ 405 - int unregister_mem_sect_under_nodes(struct memory_block *mem_blk) 403 + int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, 404 + unsigned long phys_index) 406 405 { 407 406 NODEMASK_ALLOC(nodemask_t, unlinked_nodes, GFP_KERNEL); 408 407 unsigned long pfn, sect_start_pfn, sect_end_pfn; ··· 415 412 if (!unlinked_nodes) 416 413 return -ENOMEM; 417 414 nodes_clear(*unlinked_nodes); 418 - sect_start_pfn = section_nr_to_pfn(mem_blk->phys_index); 415 + 416 + sect_start_pfn = section_nr_to_pfn(phys_index); 419 417 sect_end_pfn = sect_start_pfn + PAGES_PER_SECTION - 1; 420 418 for (pfn = sect_start_pfn; pfn <= sect_end_pfn; pfn++) { 421 419 int nid;
+46 -19
drivers/base/sys.c
··· 166 166 167 167 static 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 + */ 174 + static 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 + 195 + kset_put: 196 + kset_put(&cls->kset); 197 + } 198 + 169 199 /** 170 200 * sysdev_driver_register - Register auxillary driver 171 201 * @cls: Device class driver belongs to. ··· 205 175 * called on each operation on devices of that class. The refcount 206 176 * of @cls is incremented. 207 177 */ 208 - 209 178 int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) 210 179 { 180 + struct sys_device *dev = NULL; 211 181 int err = 0; 212 182 213 183 if (!cls) { 214 - WARN(1, KERN_WARNING "sysdev: invalid class passed to " 215 - "sysdev_driver_register!\n"); 184 + WARN(1, KERN_WARNING "sysdev: invalid class passed to %s!\n", 185 + __func__); 216 186 return -EINVAL; 217 187 } 218 188 ··· 228 198 229 199 /* If devices of this class already exist, tell the driver */ 230 200 if (drv->add) { 231 - struct sys_device *dev; 232 - list_for_each_entry(dev, &cls->kset.list, kobj.entry) 233 - drv->add(dev); 201 + list_for_each_entry(dev, &cls->kset.list, kobj.entry) { 202 + err = drv->add(dev); 203 + if (err) 204 + goto unwind; 205 + } 234 206 } 235 207 } else { 236 208 err = -EINVAL; 237 209 WARN(1, KERN_ERR "%s: invalid device class\n", __func__); 238 210 } 211 + 212 + goto unlock; 213 + 214 + unwind: 215 + __sysdev_driver_remove(cls, drv, dev); 216 + 217 + unlock: 239 218 mutex_unlock(&sysdev_drivers_lock); 240 219 return err; 241 220 } 242 - 243 221 244 222 /** 245 223 * sysdev_driver_unregister - Remove an auxillary driver. ··· 258 220 struct sysdev_driver *drv) 259 221 { 260 222 mutex_lock(&sysdev_drivers_lock); 261 - list_del_init(&drv->entry); 262 - if (cls) { 263 - if (drv->remove) { 264 - struct sys_device *dev; 265 - list_for_each_entry(dev, &cls->kset.list, kobj.entry) 266 - drv->remove(dev); 267 - } 268 - kset_put(&cls->kset); 269 - } 223 + __sysdev_driver_remove(cls, drv, NULL); 270 224 mutex_unlock(&sysdev_drivers_lock); 271 225 } 272 - 273 226 EXPORT_SYMBOL_GPL(sysdev_driver_register); 274 227 EXPORT_SYMBOL_GPL(sysdev_driver_unregister); 275 - 276 - 277 228 278 229 /** 279 230 * sysdev_register - add a system device to the tree
+11
drivers/firmware/Kconfig
··· 113 113 information from userspace through /sys/class/dmi/id/ or if you want 114 114 DMI-based module auto-loading. 115 115 116 + config 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 + 116 127 config ISCSI_IBFT_FIND 117 128 bool "iSCSI Boot Firmware Table Attributes" 118 129 depends on X86
+1
drivers/firmware/Makefile
··· 2 2 # Makefile for the linux kernel. 3 3 # 4 4 obj-$(CONFIG_DMI) += dmi_scan.o 5 + obj-$(CONFIG_DMI_SYSFS) += dmi-sysfs.o 5 6 obj-$(CONFIG_EDD) += edd.o 6 7 obj-$(CONFIG_EFI_VARS) += efivars.o 7 8 obj-$(CONFIG_EFI_PCDP) += pcdp.o
+696
drivers/firmware/dmi-sysfs.c
··· 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 + 32 + struct 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 + */ 46 + static LIST_HEAD(entry_list); 47 + static DEFINE_SPINLOCK(entry_list_lock); 48 + 49 + /* dmi_sysfs_attribute - Top level attribute. used by all entries. */ 50 + struct 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) \ 56 + struct 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 + */ 65 + struct 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) \ 73 + struct 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 + *************************************************/ 81 + static void dmi_entry_free(struct kobject *kobj) 82 + { 83 + kfree(kobj); 84 + } 85 + 86 + static struct dmi_sysfs_entry *to_entry(struct kobject *kobj) 87 + { 88 + return container_of(kobj, struct dmi_sysfs_entry, kobj); 89 + } 90 + 91 + static struct dmi_sysfs_attribute *to_attr(struct attribute *attr) 92 + { 93 + return container_of(attr, struct dmi_sysfs_attribute, attr); 94 + } 95 + 96 + static 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 + 109 + static const struct sysfs_ops dmi_sysfs_attr_ops = { 110 + .show = dmi_sysfs_attr_show, 111 + }; 112 + 113 + typedef ssize_t (*dmi_callback)(struct dmi_sysfs_entry *, 114 + const struct dmi_header *dh, void *); 115 + 116 + struct 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 + 124 + static 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() */ 151 + struct dmi_read_state { 152 + char *buf; 153 + loff_t pos; 154 + size_t count; 155 + }; 156 + 157 + static 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 + */ 181 + static 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 + *************************************************/ 196 + struct dmi_entry_attr_show_data { 197 + struct attribute *attr; 198 + char *buf; 199 + }; 200 + 201 + static 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 + 213 + static 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 + 227 + static 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 + 243 + struct 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) \ 267 + static 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 + } \ 277 + static DMI_SYSFS_MAPPED_ATTR(sel, _field) 278 + 279 + DMI_SYSFS_SEL_FIELD(area_length); 280 + DMI_SYSFS_SEL_FIELD(header_start_offset); 281 + DMI_SYSFS_SEL_FIELD(data_start_offset); 282 + DMI_SYSFS_SEL_FIELD(access_method); 283 + DMI_SYSFS_SEL_FIELD(status); 284 + DMI_SYSFS_SEL_FIELD(change_token); 285 + DMI_SYSFS_SEL_FIELD(access_method_address); 286 + DMI_SYSFS_SEL_FIELD(header_format); 287 + DMI_SYSFS_SEL_FIELD(type_descriptors_supported_count); 288 + DMI_SYSFS_SEL_FIELD(per_log_type_descriptor_length); 289 + 290 + static 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 + 305 + static 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 + 311 + typedef u8 (*sel_io_reader)(const struct dmi_system_event_log *sel, 312 + loff_t offset); 313 + 314 + static DEFINE_MUTEX(io_port_lock); 315 + 316 + static 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 + 328 + static 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 + 341 + static 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 + 353 + static 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 + 359 + static 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 + 376 + static 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 + 397 + static 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 + 428 + static 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 + 442 + static struct bin_attribute dmi_sel_raw_attr = { 443 + .attr = {.name = "raw_event_log", .mode = 0400}, 444 + .read = dmi_sel_raw_read, 445 + }; 446 + 447 + static 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 + 467 + out_del: 468 + kobject_del(entry->child); 469 + out_free: 470 + kfree(entry->child); 471 + return ret; 472 + } 473 + 474 + /************************************************* 475 + * Generic DMI entry support. 476 + *************************************************/ 477 + 478 + static 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 + 483 + static 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 + 488 + static 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 + 493 + static 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 + 499 + static 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 + 505 + static DMI_SYSFS_ATTR(entry, length); 506 + static DMI_SYSFS_ATTR(entry, handle); 507 + static DMI_SYSFS_ATTR(entry, type); 508 + static DMI_SYSFS_ATTR(entry, instance); 509 + static DMI_SYSFS_ATTR(entry, position); 510 + 511 + static 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 + 520 + static 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 + 533 + static 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 + 548 + static const struct bin_attribute dmi_entry_raw_attr = { 549 + .attr = {.name = "raw", .mode = 0400}, 550 + .read = dmi_entry_raw_read, 551 + }; 552 + 553 + static 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 + 563 + static 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 + 569 + static struct kobject *dmi_kobj; 570 + static struct kset *dmi_kset; 571 + 572 + /* Global count of all instances seen. Only for setup */ 573 + static int __initdata instance_counts[MAX_ENTRY_TYPE + 1]; 574 + 575 + /* Global positional count of all entries seen. Only for setup */ 576 + static int __initdata position_count; 577 + 578 + static 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; 632 + out_err: 633 + kobject_put(entry->child); 634 + kobject_put(&entry->kobj); 635 + return; 636 + } 637 + 638 + static 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 + 649 + static 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; 675 + err: 676 + cleanup_entry_list(); 677 + kset_unregister(dmi_kset); 678 + kobject_put(dmi_kobj); 679 + return error; 680 + } 681 + 682 + /* clean up everything. */ 683 + static 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 + 691 + module_init(dmi_sysfs_init); 692 + module_exit(dmi_sysfs_exit); 693 + 694 + MODULE_AUTHOR("Mike Waychison <mikew@google.com>"); 695 + MODULE_DESCRIPTION("DMI sysfs support"); 696 + MODULE_LICENSE("GPL");
+206 -139
drivers/firmware/efivars.c
··· 90 90 MODULE_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 - */ 100 - static DEFINE_SPINLOCK(efivars_lock); 101 - static LIST_HEAD(efivar_list); 102 - 103 - /* 104 93 * The maximum size of VariableName + Data = 1024 105 94 * Therefore, it's reasonable to save that much 106 95 * space in each part of the structure, ··· 107 118 108 119 109 120 struct efivar_entry { 121 + struct efivars *efivars; 110 122 struct efi_variable var; 111 123 struct list_head list; 112 124 struct kobject kobj; ··· 134 144 * Prototype for sysfs creation function 135 145 */ 136 146 static int 137 - efivar_create_sysfs_entry(unsigned long variable_name_size, 138 - efi_char16_t *variable_name, 139 - efi_guid_t *vendor_guid); 147 + efivar_create_sysfs_entry(struct efivars *efivars, 148 + unsigned long variable_name_size, 149 + efi_char16_t *variable_name, 150 + efi_guid_t *vendor_guid); 140 151 141 152 /* Return the number of unicode characters in data */ 142 153 static unsigned long ··· 161 170 } 162 171 163 172 static efi_status_t 164 - get_var_data(struct efi_variable *var) 173 + get_var_data(struct efivars *efivars, struct efi_variable *var) 165 174 { 166 175 efi_status_t status; 167 176 168 - spin_lock(&efivars_lock); 177 + spin_lock(&efivars->lock); 169 178 var->DataSize = 1024; 170 - status = efi.get_variable(var->VariableName, 171 - &var->VendorGuid, 172 - &var->Attributes, 173 - &var->DataSize, 174 - var->Data); 175 - spin_unlock(&efivars_lock); 179 + status = efivars->ops->get_variable(var->VariableName, 180 + &var->VendorGuid, 181 + &var->Attributes, 182 + &var->DataSize, 183 + var->Data); 184 + spin_unlock(&efivars->lock); 176 185 if (status != EFI_SUCCESS) { 177 186 printk(KERN_WARNING "efivars: get_variable() failed 0x%lx!\n", 178 187 status); ··· 206 215 if (!entry || !buf) 207 216 return -EINVAL; 208 217 209 - status = get_var_data(var); 218 + status = get_var_data(entry->efivars, var); 210 219 if (status != EFI_SUCCESS) 211 220 return -EIO; 212 221 ··· 229 238 if (!entry || !buf) 230 239 return -EINVAL; 231 240 232 - status = get_var_data(var); 241 + status = get_var_data(entry->efivars, var); 233 242 if (status != EFI_SUCCESS) 234 243 return -EIO; 235 244 ··· 246 255 if (!entry || !buf) 247 256 return -EINVAL; 248 257 249 - status = get_var_data(var); 258 + status = get_var_data(entry->efivars, var); 250 259 if (status != EFI_SUCCESS) 251 260 return -EIO; 252 261 ··· 261 270 efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count) 262 271 { 263 272 struct efi_variable *new_var, *var = &entry->var; 273 + struct efivars *efivars = entry->efivars; 264 274 efi_status_t status = EFI_NOT_FOUND; 265 275 266 276 if (count != sizeof(struct efi_variable)) ··· 283 291 return -EINVAL; 284 292 } 285 293 286 - spin_lock(&efivars_lock); 287 - status = efi.set_variable(new_var->VariableName, 288 - &new_var->VendorGuid, 289 - new_var->Attributes, 290 - new_var->DataSize, 291 - new_var->Data); 294 + spin_lock(&efivars->lock); 295 + status = efivars->ops->set_variable(new_var->VariableName, 296 + &new_var->VendorGuid, 297 + new_var->Attributes, 298 + new_var->DataSize, 299 + new_var->Data); 292 300 293 - spin_unlock(&efivars_lock); 301 + spin_unlock(&efivars->lock); 294 302 295 303 if (status != EFI_SUCCESS) { 296 304 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", ··· 311 319 if (!entry || !buf) 312 320 return 0; 313 321 314 - status = get_var_data(var); 322 + status = get_var_data(entry->efivars, var); 315 323 if (status != EFI_SUCCESS) 316 324 return -EIO; 317 325 ··· 399 407 char *buf, loff_t pos, size_t count) 400 408 { 401 409 struct efi_variable *new_var = (struct efi_variable *)buf; 410 + struct efivars *efivars = bin_attr->private; 402 411 struct efivar_entry *search_efivar, *n; 403 412 unsigned long strsize1, strsize2; 404 413 efi_status_t status = EFI_NOT_FOUND; ··· 408 415 if (!capable(CAP_SYS_ADMIN)) 409 416 return -EACCES; 410 417 411 - spin_lock(&efivars_lock); 418 + spin_lock(&efivars->lock); 412 419 413 420 /* 414 421 * Does this variable already exist? 415 422 */ 416 - list_for_each_entry_safe(search_efivar, n, &efivar_list, list) { 423 + list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { 417 424 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); 418 425 strsize2 = utf8_strsize(new_var->VariableName, 1024); 419 426 if (strsize1 == strsize2 && ··· 426 433 } 427 434 } 428 435 if (found) { 429 - spin_unlock(&efivars_lock); 436 + spin_unlock(&efivars->lock); 430 437 return -EINVAL; 431 438 } 432 439 433 440 /* now *really* create the variable via EFI */ 434 - status = efi.set_variable(new_var->VariableName, 435 - &new_var->VendorGuid, 436 - new_var->Attributes, 437 - new_var->DataSize, 438 - new_var->Data); 441 + status = efivars->ops->set_variable(new_var->VariableName, 442 + &new_var->VendorGuid, 443 + new_var->Attributes, 444 + new_var->DataSize, 445 + new_var->Data); 439 446 440 447 if (status != EFI_SUCCESS) { 441 448 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", 442 449 status); 443 - spin_unlock(&efivars_lock); 450 + spin_unlock(&efivars->lock); 444 451 return -EIO; 445 452 } 446 - spin_unlock(&efivars_lock); 453 + spin_unlock(&efivars->lock); 447 454 448 455 /* Create the entry in sysfs. Locking is not required here */ 449 - status = efivar_create_sysfs_entry(utf8_strsize(new_var->VariableName, 450 - 1024), new_var->VariableName, &new_var->VendorGuid); 456 + status = efivar_create_sysfs_entry(efivars, 457 + utf8_strsize(new_var->VariableName, 458 + 1024), 459 + new_var->VariableName, 460 + &new_var->VendorGuid); 451 461 if (status) { 452 462 printk(KERN_WARNING "efivars: variable created, but sysfs entry wasn't.\n"); 453 463 } ··· 462 466 char *buf, loff_t pos, size_t count) 463 467 { 464 468 struct efi_variable *del_var = (struct efi_variable *)buf; 469 + struct efivars *efivars = bin_attr->private; 465 470 struct efivar_entry *search_efivar, *n; 466 471 unsigned long strsize1, strsize2; 467 472 efi_status_t status = EFI_NOT_FOUND; ··· 471 474 if (!capable(CAP_SYS_ADMIN)) 472 475 return -EACCES; 473 476 474 - spin_lock(&efivars_lock); 477 + spin_lock(&efivars->lock); 475 478 476 479 /* 477 480 * Does this variable already exist? 478 481 */ 479 - list_for_each_entry_safe(search_efivar, n, &efivar_list, list) { 482 + list_for_each_entry_safe(search_efivar, n, &efivars->list, list) { 480 483 strsize1 = utf8_strsize(search_efivar->var.VariableName, 1024); 481 484 strsize2 = utf8_strsize(del_var->VariableName, 1024); 482 485 if (strsize1 == strsize2 && ··· 489 492 } 490 493 } 491 494 if (!found) { 492 - spin_unlock(&efivars_lock); 495 + spin_unlock(&efivars->lock); 493 496 return -EINVAL; 494 497 } 495 498 /* force the Attributes/DataSize to 0 to ensure deletion */ 496 499 del_var->Attributes = 0; 497 500 del_var->DataSize = 0; 498 501 499 - status = efi.set_variable(del_var->VariableName, 500 - &del_var->VendorGuid, 501 - del_var->Attributes, 502 - del_var->DataSize, 503 - del_var->Data); 502 + status = efivars->ops->set_variable(del_var->VariableName, 503 + &del_var->VendorGuid, 504 + del_var->Attributes, 505 + del_var->DataSize, 506 + del_var->Data); 504 507 505 508 if (status != EFI_SUCCESS) { 506 509 printk(KERN_WARNING "efivars: set_variable() failed: status=%lx\n", 507 510 status); 508 - spin_unlock(&efivars_lock); 511 + spin_unlock(&efivars->lock); 509 512 return -EIO; 510 513 } 511 514 list_del(&search_efivar->list); 512 515 /* We need to release this lock before unregistering. */ 513 - spin_unlock(&efivars_lock); 516 + spin_unlock(&efivars->lock); 514 517 efivar_unregister(search_efivar); 515 518 516 519 /* It's dead Jim.... */ 517 520 return count; 518 521 } 519 - 520 - static struct bin_attribute var_subsys_attr_new_var = { 521 - .attr = {.name = "new_var", .mode = 0200}, 522 - .write = efivar_create, 523 - }; 524 - 525 - static struct bin_attribute var_subsys_attr_del_var = { 526 - .attr = {.name = "del_var", .mode = 0200}, 527 - .write = efivar_delete, 528 - }; 529 522 530 523 /* 531 524 * Let's not leave out systab information that snuck into ··· 559 572 .attrs = efi_subsys_attrs, 560 573 }; 561 574 562 - 563 - static struct kset *vars_kset; 564 575 static struct kobject *efi_kobj; 565 576 566 577 /* ··· 567 582 * variable_name_size = number of bytes required to hold 568 583 * variable_name (not counting the NULL 569 584 * character at the end. 570 - * efivars_lock is not held on entry or exit. 585 + * efivars->lock is not held on entry or exit. 571 586 * Returns 1 on failure, 0 on success 572 587 */ 573 588 static int 574 - efivar_create_sysfs_entry(unsigned long variable_name_size, 575 - efi_char16_t *variable_name, 576 - efi_guid_t *vendor_guid) 589 + efivar_create_sysfs_entry(struct efivars *efivars, 590 + unsigned long variable_name_size, 591 + efi_char16_t *variable_name, 592 + efi_guid_t *vendor_guid) 577 593 { 578 594 int i, short_name_size = variable_name_size / sizeof(efi_char16_t) + 38; 579 595 char *short_name; ··· 589 603 return 1; 590 604 } 591 605 606 + new_efivar->efivars = efivars; 592 607 memcpy(new_efivar->var.VariableName, variable_name, 593 608 variable_name_size); 594 609 memcpy(&(new_efivar->var.VendorGuid), vendor_guid, sizeof(efi_guid_t)); ··· 605 618 *(short_name + strlen(short_name)) = '-'; 606 619 efi_guid_unparse(vendor_guid, short_name + strlen(short_name)); 607 620 608 - new_efivar->kobj.kset = vars_kset; 621 + new_efivar->kobj.kset = efivars->kset; 609 622 i = kobject_init_and_add(&new_efivar->kobj, &efivar_ktype, NULL, 610 623 "%s", short_name); 611 624 if (i) { ··· 618 631 kfree(short_name); 619 632 short_name = NULL; 620 633 621 - spin_lock(&efivars_lock); 622 - list_add(&new_efivar->list, &efivar_list); 623 - spin_unlock(&efivars_lock); 634 + spin_lock(&efivars->lock); 635 + list_add(&new_efivar->list, &efivars->list); 636 + spin_unlock(&efivars->lock); 624 637 625 638 return 0; 626 639 } 627 - /* 628 - * For now we register the efi subsystem with the firmware subsystem 629 - * and the vars subsystem with the efi subsystem. In the future, it 630 - * might make sense to split off the efi subsystem into its own 631 - * driver, but for now only efivars will register with it, so just 632 - * include it here. 633 - */ 634 640 635 - static int __init 636 - efivars_init(void) 641 + static int 642 + create_efivars_bin_attributes(struct efivars *efivars) 643 + { 644 + struct bin_attribute *attr; 645 + int error; 646 + 647 + /* new_var */ 648 + attr = kzalloc(sizeof(*attr), GFP_KERNEL); 649 + if (!attr) 650 + return -ENOMEM; 651 + 652 + attr->attr.name = "new_var"; 653 + attr->attr.mode = 0200; 654 + attr->write = efivar_create; 655 + attr->private = efivars; 656 + efivars->new_var = attr; 657 + 658 + /* del_var */ 659 + attr = kzalloc(sizeof(*attr), GFP_KERNEL); 660 + if (!attr) { 661 + error = -ENOMEM; 662 + goto out_free; 663 + } 664 + attr->attr.name = "del_var"; 665 + attr->attr.mode = 0200; 666 + attr->write = efivar_delete; 667 + attr->private = efivars; 668 + efivars->del_var = attr; 669 + 670 + sysfs_bin_attr_init(efivars->new_var); 671 + sysfs_bin_attr_init(efivars->del_var); 672 + 673 + /* Register */ 674 + error = sysfs_create_bin_file(&efivars->kset->kobj, 675 + efivars->new_var); 676 + if (error) { 677 + printk(KERN_ERR "efivars: unable to create new_var sysfs file" 678 + " due to error %d\n", error); 679 + goto out_free; 680 + } 681 + error = sysfs_create_bin_file(&efivars->kset->kobj, 682 + efivars->del_var); 683 + if (error) { 684 + printk(KERN_ERR "efivars: unable to create del_var sysfs file" 685 + " due to error %d\n", error); 686 + sysfs_remove_bin_file(&efivars->kset->kobj, 687 + efivars->new_var); 688 + goto out_free; 689 + } 690 + 691 + return 0; 692 + out_free: 693 + kfree(efivars->new_var); 694 + efivars->new_var = NULL; 695 + kfree(efivars->new_var); 696 + efivars->new_var = NULL; 697 + return error; 698 + } 699 + 700 + void unregister_efivars(struct efivars *efivars) 701 + { 702 + struct efivar_entry *entry, *n; 703 + 704 + list_for_each_entry_safe(entry, n, &efivars->list, list) { 705 + spin_lock(&efivars->lock); 706 + list_del(&entry->list); 707 + spin_unlock(&efivars->lock); 708 + efivar_unregister(entry); 709 + } 710 + if (efivars->new_var) 711 + sysfs_remove_bin_file(&efivars->kset->kobj, efivars->new_var); 712 + if (efivars->del_var) 713 + sysfs_remove_bin_file(&efivars->kset->kobj, efivars->del_var); 714 + kfree(efivars->new_var); 715 + kfree(efivars->del_var); 716 + kset_unregister(efivars->kset); 717 + } 718 + EXPORT_SYMBOL_GPL(unregister_efivars); 719 + 720 + int register_efivars(struct efivars *efivars, 721 + const struct efivar_operations *ops, 722 + struct kobject *parent_kobj) 637 723 { 638 724 efi_status_t status = EFI_NOT_FOUND; 639 725 efi_guid_t vendor_guid; ··· 714 654 unsigned long variable_name_size = 1024; 715 655 int error = 0; 716 656 717 - if (!efi_enabled) 718 - return -ENODEV; 719 - 720 657 variable_name = kzalloc(variable_name_size, GFP_KERNEL); 721 658 if (!variable_name) { 722 659 printk(KERN_ERR "efivars: Memory allocation failed.\n"); 723 660 return -ENOMEM; 724 661 } 725 662 726 - printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION, 727 - EFIVARS_DATE); 663 + spin_lock_init(&efivars->lock); 664 + INIT_LIST_HEAD(&efivars->list); 665 + efivars->ops = ops; 728 666 729 - /* For now we'll register the efi directory at /sys/firmware/efi */ 730 - efi_kobj = kobject_create_and_add("efi", firmware_kobj); 731 - if (!efi_kobj) { 732 - printk(KERN_ERR "efivars: Firmware registration failed.\n"); 733 - error = -ENOMEM; 734 - goto out_free; 735 - } 736 - 737 - vars_kset = kset_create_and_add("vars", NULL, efi_kobj); 738 - if (!vars_kset) { 667 + efivars->kset = kset_create_and_add("vars", NULL, parent_kobj); 668 + if (!efivars->kset) { 739 669 printk(KERN_ERR "efivars: Subsystem registration failed.\n"); 740 670 error = -ENOMEM; 741 - goto out_firmware_unregister; 671 + goto out; 742 672 } 743 673 744 674 /* ··· 739 689 do { 740 690 variable_name_size = 1024; 741 691 742 - status = efi.get_next_variable(&variable_name_size, 692 + status = ops->get_next_variable(&variable_name_size, 743 693 variable_name, 744 694 &vendor_guid); 745 695 switch (status) { 746 696 case EFI_SUCCESS: 747 - efivar_create_sysfs_entry(variable_name_size, 748 - variable_name, 749 - &vendor_guid); 697 + efivar_create_sysfs_entry(efivars, 698 + variable_name_size, 699 + variable_name, 700 + &vendor_guid); 750 701 break; 751 702 case EFI_NOT_FOUND: 752 703 break; ··· 759 708 } 760 709 } while (status != EFI_NOT_FOUND); 761 710 762 - /* 763 - * Now add attributes to allow creation of new vars 764 - * and deletion of existing ones... 765 - */ 766 - error = sysfs_create_bin_file(&vars_kset->kobj, 767 - &var_subsys_attr_new_var); 711 + error = create_efivars_bin_attributes(efivars); 768 712 if (error) 769 - printk(KERN_ERR "efivars: unable to create new_var sysfs file" 770 - " due to error %d\n", error); 771 - error = sysfs_create_bin_file(&vars_kset->kobj, 772 - &var_subsys_attr_del_var); 773 - if (error) 774 - printk(KERN_ERR "efivars: unable to create del_var sysfs file" 775 - " due to error %d\n", error); 713 + unregister_efivars(efivars); 714 + 715 + out: 716 + kfree(variable_name); 717 + 718 + return error; 719 + } 720 + EXPORT_SYMBOL_GPL(register_efivars); 721 + 722 + static struct efivars __efivars; 723 + static struct efivar_operations ops; 724 + 725 + /* 726 + * For now we register the efi subsystem with the firmware subsystem 727 + * and the vars subsystem with the efi subsystem. In the future, it 728 + * might make sense to split off the efi subsystem into its own 729 + * driver, but for now only efivars will register with it, so just 730 + * include it here. 731 + */ 732 + 733 + static int __init 734 + efivars_init(void) 735 + { 736 + int error = 0; 737 + 738 + printk(KERN_INFO "EFI Variables Facility v%s %s\n", EFIVARS_VERSION, 739 + EFIVARS_DATE); 740 + 741 + if (!efi_enabled) 742 + return 0; 743 + 744 + /* For now we'll register the efi directory at /sys/firmware/efi */ 745 + efi_kobj = kobject_create_and_add("efi", firmware_kobj); 746 + if (!efi_kobj) { 747 + printk(KERN_ERR "efivars: Firmware registration failed.\n"); 748 + return -ENOMEM; 749 + } 750 + 751 + ops.get_variable = efi.get_variable; 752 + ops.set_variable = efi.set_variable; 753 + ops.get_next_variable = efi.get_next_variable; 754 + error = register_efivars(&__efivars, &ops, efi_kobj); 776 755 777 756 /* Don't forget the systab entry */ 778 757 error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); 779 - if (error) 780 - printk(KERN_ERR "efivars: Sysfs attribute export failed with error %d.\n", error); 781 - else 782 - goto out_free; 783 - 784 - kset_unregister(vars_kset); 785 - 786 - out_firmware_unregister: 787 - kobject_put(efi_kobj); 788 - 789 - out_free: 790 - kfree(variable_name); 758 + if (error) { 759 + printk(KERN_ERR 760 + "efivars: Sysfs attribute export failed with error %d.\n", 761 + error); 762 + unregister_efivars(&__efivars); 763 + kobject_put(efi_kobj); 764 + } 791 765 792 766 return error; 793 767 } ··· 820 744 static void __exit 821 745 efivars_exit(void) 822 746 { 823 - struct efivar_entry *entry, *n; 824 - 825 - list_for_each_entry_safe(entry, n, &efivar_list, list) { 826 - spin_lock(&efivars_lock); 827 - list_del(&entry->list); 828 - spin_unlock(&efivars_lock); 829 - efivar_unregister(entry); 830 - } 831 - 832 - kset_unregister(vars_kset); 747 + unregister_efivars(&__efivars); 833 748 kobject_put(efi_kobj); 834 749 } 835 750
+6 -1
drivers/misc/Kconfig
··· 441 441 module will be called bmp085. 442 442 443 443 config PCH_PHUB 444 - tristate "PCH Packet Hub of Intel Topcliff" 444 + tristate "PCH Packet Hub of Intel Topcliff / OKI SEMICONDUCTOR ML7213" 445 445 depends on PCI 446 446 help 447 447 This driver is for PCH(Platform controller Hub) PHUB(Packet Hub) of 448 448 Intel Topcliff which is an IOH(Input/Output Hub) for x86 embedded 449 449 processor. The Topcliff has MAC address and Option ROM data in SROM. 450 450 This driver can access MAC address and Option ROM data in SROM. 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. 451 456 452 457 To compile this driver as a module, choose M here: the module will 453 458 be called pch_phub.
+47 -22
drivers/misc/pch_phub.c
··· 1 1 /* 2 - * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. 2 + * Copyright (C) 2010 OKI SEMICONDUCTOR CO., LTD. 3 3 * 4 4 * This program is free software; you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by ··· 33 33 #define PHUB_TIMEOUT 0x05 /* Time out value for Status Register */ 34 34 #define PCH_PHUB_ROM_WRITE_ENABLE 0x01 /* Enabling for writing ROM */ 35 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 43 /* MAX number of INT_REDUCE_CONTROL registers */ 39 44 #define MAX_NUM_INT_REDUCE_CONTROL_REG 128 ··· 46 41 #define PCH_MINOR_NOS 1 47 42 #define CLKCFG_CAN_50MHZ 0x12000000 48 43 #define CLKCFG_CANCLK_MASK 0xFF000000 44 + 45 + /* Macros for ML7213 */ 46 + #define PCI_VENDOR_ID_ROHM 0x10db 47 + #define PCI_DEVICE_ID_ROHM_ML7213_PHUB 0x801A 49 48 50 49 /* SROM ACCESS Macro */ 51 50 #define PCH_WORD_ADDR_MASK (~((1 << 2) - 1)) ··· 307 298 { 308 299 unsigned int mem_addr; 309 300 310 - mem_addr = PCH_PHUB_ROM_START_ADDR + 301 + mem_addr = PCH_PHUB_ROM_START_ADDR_EG20T + 311 302 pch_phub_mac_offset[offset_address]; 312 303 313 304 pch_phub_read_serial_rom(chip, mem_addr, data); ··· 324 315 int retval; 325 316 unsigned int mem_addr; 326 317 327 - mem_addr = PCH_PHUB_ROM_START_ADDR + 318 + mem_addr = PCH_PHUB_ROM_START_ADDR_EG20T + 328 319 pch_phub_mac_offset[offset_address]; 329 320 330 321 retval = pch_phub_write_serial_rom(chip, mem_addr, data); ··· 603 594 "pch_phub_extrom_base_address variable is %p\n", __func__, 604 595 chip->pch_phub_extrom_base_address); 605 596 597 + if (id->driver_data == 1) { 598 + retval = sysfs_create_file(&pdev->dev.kobj, 599 + &dev_attr_pch_mac.attr); 600 + if (retval) 601 + 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, 608 + (unsigned int)CLKCFG_REG_OFFSET, 609 + CLKCFG_CAN_50MHZ, 610 + CLKCFG_CANCLK_MASK); 611 + 612 + /* set the prefech value */ 613 + iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14); 614 + /* set the interrupt delay value */ 615 + iowrite32(0x25, chip->pch_phub_base_address + 0x44); 616 + } else if (id->driver_data == 2) { 617 + retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 618 + if (retval) 619 + goto err_sysfs_create; 620 + /* set the prefech value 621 + * Device2(USB OHCI #1/ USB EHCI #1/ USB Device):a 622 + * Device4(SDIO #0,1,2):f 623 + * Device6(SATA 2):f 624 + * Device8(USB OHCI #0/ USB EHCI #0):a 625 + */ 626 + iowrite32(0x000affa0, chip->pch_phub_base_address + 0x14); 627 + } 606 628 pci_set_drvdata(pdev, chip); 607 - 608 - retval = sysfs_create_file(&pdev->dev.kobj, &dev_attr_pch_mac.attr); 609 - if (retval) 610 - goto err_sysfs_create; 611 - 612 - retval = sysfs_create_bin_file(&pdev->dev.kobj, &pch_bin_attr); 613 - if (retval) 614 - goto exit_bin_attr; 615 - 616 - pch_phub_read_modify_write_reg(chip, (unsigned int)CLKCFG_REG_OFFSET, 617 - CLKCFG_CAN_50MHZ, CLKCFG_CANCLK_MASK); 618 - 619 - /* set the prefech value */ 620 - iowrite32(0x000affaa, chip->pch_phub_base_address + 0x14); 621 - /* set the interrupt delay value */ 622 - iowrite32(0x25, chip->pch_phub_base_address + 0x44); 623 629 624 630 return 0; 625 631 exit_bin_attr: ··· 711 687 #endif /* CONFIG_PM */ 712 688 713 689 static struct pci_device_id pch_phub_pcidev_id[] = { 714 - {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PCH1_PHUB)}, 715 - {0,} 690 + { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH1_PHUB), 1, }, 691 + { PCI_VDEVICE(ROHM, PCI_DEVICE_ID_ROHM_ML7213_PHUB), 2, }, 692 + { } 716 693 }; 717 694 718 695 static struct pci_driver pch_phub_driver = {
+149 -272
drivers/misc/ti-st/st_core.c
··· 25 25 #include <linux/init.h> 26 26 #include <linux/tty.h> 27 27 28 - /* understand BT, FM and GPS for now */ 29 - #include <net/bluetooth/bluetooth.h> 30 - #include <net/bluetooth/hci_core.h> 31 - #include <net/bluetooth/hci.h> 28 + #include <linux/seq_file.h> 29 + #include <linux/skbuff.h> 30 + 32 31 #include <linux/ti_wilink_st.h> 33 32 34 33 /* function pointer pointing to either, ··· 37 38 void (*st_recv) (void*, const unsigned char*, long); 38 39 39 40 /********************************************************************/ 40 - #if 0 41 - /* internal misc functions */ 42 - bool is_protocol_list_empty(void) 41 + static void add_channel_to_table(struct st_data_s *st_gdata, 42 + struct st_proto_s *new_proto) 43 43 { 44 - unsigned char i = 0; 45 - pr_debug(" %s ", __func__); 46 - for (i = 0; i < ST_MAX; i++) { 47 - if (st_gdata->list[i] != NULL) 48 - return ST_NOTEMPTY; 49 - /* not empty */ 50 - } 51 - /* list empty */ 52 - return ST_EMPTY; 44 + pr_info("%s: id %d\n", __func__, new_proto->chnl_id); 45 + /* list now has the channel id as index itself */ 46 + st_gdata->list[new_proto->chnl_id] = new_proto; 53 47 } 54 - #endif 48 + 49 + static void remove_channel_from_table(struct st_data_s *st_gdata, 50 + struct st_proto_s *proto) 51 + { 52 + pr_info("%s: id %d\n", __func__, proto->chnl_id); 53 + st_gdata->list[proto->chnl_id] = NULL; 54 + } 55 + 56 + /* 57 + * called from KIM during firmware download. 58 + * 59 + * This is a wrapper function to tty->ops->write_room. 60 + * It returns number of free space available in 61 + * uart tx buffer. 62 + */ 63 + int st_get_uart_wr_room(struct st_data_s *st_gdata) 64 + { 65 + struct tty_struct *tty; 66 + if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) { 67 + pr_err("tty unavailable to perform write"); 68 + return -1; 69 + } 70 + tty = st_gdata->tty; 71 + return tty->ops->write_room(tty); 72 + } 55 73 56 74 /* can be called in from 57 75 * -- KIM (during fw download) ··· 83 67 struct tty_struct *tty; 84 68 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) { 85 69 pr_err("tty unavailable to perform write"); 86 - return -1; 70 + return -EINVAL; 87 71 } 88 72 tty = st_gdata->tty; 89 73 #ifdef VERBOSE ··· 98 82 * push the skb received to relevant 99 83 * protocol stacks 100 84 */ 101 - void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata) 85 + void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata) 102 86 { 103 - pr_info(" %s(prot:%d) ", __func__, protoid); 87 + pr_debug(" %s(prot:%d) ", __func__, chnl_id); 104 88 105 89 if (unlikely 106 90 (st_gdata == NULL || st_gdata->rx_skb == NULL 107 - || st_gdata->list[protoid] == NULL)) { 108 - pr_err("protocol %d not registered, no data to send?", 109 - protoid); 91 + || st_gdata->list[chnl_id] == NULL)) { 92 + pr_err("chnl_id %d not registered, no data to send?", 93 + chnl_id); 110 94 kfree_skb(st_gdata->rx_skb); 111 95 return; 112 96 } ··· 115 99 * - should be just skb_queue_tail for the 116 100 * protocol stack driver 117 101 */ 118 - if (likely(st_gdata->list[protoid]->recv != NULL)) { 102 + if (likely(st_gdata->list[chnl_id]->recv != NULL)) { 119 103 if (unlikely 120 - (st_gdata->list[protoid]->recv 121 - (st_gdata->list[protoid]->priv_data, st_gdata->rx_skb) 104 + (st_gdata->list[chnl_id]->recv 105 + (st_gdata->list[chnl_id]->priv_data, st_gdata->rx_skb) 122 106 != 0)) { 123 - pr_err(" proto stack %d's ->recv failed", protoid); 107 + pr_err(" proto stack %d's ->recv failed", chnl_id); 124 108 kfree_skb(st_gdata->rx_skb); 125 109 return; 126 110 } 127 111 } else { 128 - pr_err(" proto stack %d's ->recv null", protoid); 112 + pr_err(" proto stack %d's ->recv null", chnl_id); 129 113 kfree_skb(st_gdata->rx_skb); 130 114 } 131 115 return; ··· 140 124 { 141 125 unsigned char i = 0; 142 126 pr_info(" %s ", __func__); 143 - for (i = 0; i < ST_MAX; i++) { 127 + for (i = 0; i < ST_MAX_CHANNELS; i++) { 144 128 if (likely(st_gdata != NULL && st_gdata->list[i] != NULL && 145 - st_gdata->list[i]->reg_complete_cb != NULL)) 129 + st_gdata->list[i]->reg_complete_cb != NULL)) { 146 130 st_gdata->list[i]->reg_complete_cb 147 131 (st_gdata->list[i]->priv_data, err); 132 + pr_info("protocol %d's cb sent %d\n", i, err); 133 + if (err) { /* cleanup registered protocol */ 134 + st_gdata->protos_registered--; 135 + st_gdata->list[i] = NULL; 136 + } 137 + } 148 138 } 149 139 } 150 140 151 141 static inline int st_check_data_len(struct st_data_s *st_gdata, 152 - int protoid, int len) 142 + unsigned char chnl_id, int len) 153 143 { 154 144 int room = skb_tailroom(st_gdata->rx_skb); 155 145 ··· 166 144 * has zero length payload. So, ask ST CORE to 167 145 * forward the packet to protocol driver (BT/FM/GPS) 168 146 */ 169 - st_send_frame(protoid, st_gdata); 147 + st_send_frame(chnl_id, st_gdata); 170 148 171 149 } else if (len > room) { 172 150 /* Received packet's payload length is larger. ··· 179 157 /* Packet header has non-zero payload length and 180 158 * we have enough space in created skb. Lets read 181 159 * payload data */ 182 - st_gdata->rx_state = ST_BT_W4_DATA; 160 + st_gdata->rx_state = ST_W4_DATA; 183 161 st_gdata->rx_count = len; 184 162 return len; 185 163 } ··· 189 167 st_gdata->rx_state = ST_W4_PACKET_TYPE; 190 168 st_gdata->rx_skb = NULL; 191 169 st_gdata->rx_count = 0; 170 + st_gdata->rx_chnl = 0; 192 171 193 172 return 0; 194 173 } ··· 231 208 const unsigned char *data, long count) 232 209 { 233 210 char *ptr; 234 - struct hci_event_hdr *eh; 235 - struct hci_acl_hdr *ah; 236 - struct hci_sco_hdr *sh; 237 - struct fm_event_hdr *fm; 238 - struct gps_event_hdr *gps; 239 - int len = 0, type = 0, dlen = 0; 240 - static enum proto_type protoid = ST_MAX; 211 + struct st_proto_s *proto; 212 + unsigned short payload_len = 0; 213 + int len = 0, type = 0; 214 + unsigned char *plen; 241 215 struct st_data_s *st_gdata = (struct st_data_s *)disc_data; 216 + unsigned long flags; 242 217 243 218 ptr = (char *)data; 244 219 /* tty_receive sent null ? */ ··· 245 224 return; 246 225 } 247 226 248 - pr_info("count %ld rx_state %ld" 227 + pr_debug("count %ld rx_state %ld" 249 228 "rx_count %ld", count, st_gdata->rx_state, 250 229 st_gdata->rx_count); 251 230 231 + spin_lock_irqsave(&st_gdata->lock, flags); 252 232 /* Decode received bytes here */ 253 233 while (count) { 254 234 if (st_gdata->rx_count) { ··· 264 242 265 243 /* Check ST RX state machine , where are we? */ 266 244 switch (st_gdata->rx_state) { 267 - 268 - /* Waiting for complete packet ? */ 269 - case ST_BT_W4_DATA: 245 + /* Waiting for complete packet ? */ 246 + case ST_W4_DATA: 270 247 pr_debug("Complete pkt received"); 271 - 272 248 /* Ask ST CORE to forward 273 249 * the packet to protocol driver */ 274 - st_send_frame(protoid, st_gdata); 250 + st_send_frame(st_gdata->rx_chnl, st_gdata); 275 251 276 252 st_gdata->rx_state = ST_W4_PACKET_TYPE; 277 253 st_gdata->rx_skb = NULL; 278 - protoid = ST_MAX; /* is this required ? */ 279 254 continue; 280 - 281 - /* Waiting for Bluetooth event header ? */ 282 - case ST_BT_W4_EVENT_HDR: 283 - eh = (struct hci_event_hdr *)st_gdata->rx_skb-> 284 - data; 285 - 286 - pr_debug("Event header: evt 0x%2.2x" 287 - "plen %d", eh->evt, eh->plen); 288 - 289 - st_check_data_len(st_gdata, protoid, eh->plen); 290 - continue; 291 - 292 - /* Waiting for Bluetooth acl header ? */ 293 - case ST_BT_W4_ACL_HDR: 294 - ah = (struct hci_acl_hdr *)st_gdata->rx_skb-> 295 - data; 296 - dlen = __le16_to_cpu(ah->dlen); 297 - 298 - pr_info("ACL header: dlen %d", dlen); 299 - 300 - st_check_data_len(st_gdata, protoid, dlen); 301 - continue; 302 - 303 - /* Waiting for Bluetooth sco header ? */ 304 - case ST_BT_W4_SCO_HDR: 305 - sh = (struct hci_sco_hdr *)st_gdata->rx_skb-> 306 - data; 307 - 308 - pr_info("SCO header: dlen %d", sh->dlen); 309 - 310 - st_check_data_len(st_gdata, protoid, sh->dlen); 311 - continue; 312 - case ST_FM_W4_EVENT_HDR: 313 - fm = (struct fm_event_hdr *)st_gdata->rx_skb-> 314 - data; 315 - pr_info("FM Header: "); 316 - st_check_data_len(st_gdata, ST_FM, fm->plen); 317 - continue; 318 - /* TODO : Add GPS packet machine logic here */ 319 - case ST_GPS_W4_EVENT_HDR: 320 - /* [0x09 pkt hdr][R/W byte][2 byte len] */ 321 - gps = (struct gps_event_hdr *)st_gdata->rx_skb-> 322 - data; 323 - pr_info("GPS Header: "); 324 - st_check_data_len(st_gdata, ST_GPS, gps->plen); 255 + /* parse the header to know details */ 256 + case ST_W4_HEADER: 257 + proto = st_gdata->list[st_gdata->rx_chnl]; 258 + plen = 259 + &st_gdata->rx_skb->data 260 + [proto->offset_len_in_hdr]; 261 + pr_debug("plen pointing to %x\n", *plen); 262 + if (proto->len_size == 1)/* 1 byte len field */ 263 + payload_len = *(unsigned char *)plen; 264 + else if (proto->len_size == 2) 265 + payload_len = 266 + __le16_to_cpu(*(unsigned short *)plen); 267 + else 268 + pr_info("%s: invalid length " 269 + "for id %d\n", 270 + __func__, proto->chnl_id); 271 + st_check_data_len(st_gdata, proto->chnl_id, 272 + payload_len); 273 + pr_debug("off %d, pay len %d\n", 274 + proto->offset_len_in_hdr, payload_len); 325 275 continue; 326 276 } /* end of switch rx_state */ 327 277 } ··· 302 308 /* Check first byte of packet and identify module 303 309 * owner (BT/FM/GPS) */ 304 310 switch (*ptr) { 305 - 306 - /* Bluetooth event packet? */ 307 - case HCI_EVENT_PKT: 308 - pr_info("Event packet"); 309 - st_gdata->rx_state = ST_BT_W4_EVENT_HDR; 310 - st_gdata->rx_count = HCI_EVENT_HDR_SIZE; 311 - type = HCI_EVENT_PKT; 312 - protoid = ST_BT; 313 - break; 314 - 315 - /* Bluetooth acl packet? */ 316 - case HCI_ACLDATA_PKT: 317 - pr_info("ACL packet"); 318 - st_gdata->rx_state = ST_BT_W4_ACL_HDR; 319 - st_gdata->rx_count = HCI_ACL_HDR_SIZE; 320 - type = HCI_ACLDATA_PKT; 321 - protoid = ST_BT; 322 - break; 323 - 324 - /* Bluetooth sco packet? */ 325 - case HCI_SCODATA_PKT: 326 - pr_info("SCO packet"); 327 - st_gdata->rx_state = ST_BT_W4_SCO_HDR; 328 - st_gdata->rx_count = HCI_SCO_HDR_SIZE; 329 - type = HCI_SCODATA_PKT; 330 - protoid = ST_BT; 331 - break; 332 - 333 - /* Channel 8(FM) packet? */ 334 - case ST_FM_CH8_PKT: 335 - pr_info("FM CH8 packet"); 336 - type = ST_FM_CH8_PKT; 337 - st_gdata->rx_state = ST_FM_W4_EVENT_HDR; 338 - st_gdata->rx_count = FM_EVENT_HDR_SIZE; 339 - protoid = ST_FM; 340 - break; 341 - 342 - /* Channel 9(GPS) packet? */ 343 - case 0x9: /*ST_LL_GPS_CH9_PKT */ 344 - pr_info("GPS CH9 packet"); 345 - type = 0x9; /* ST_LL_GPS_CH9_PKT; */ 346 - protoid = ST_GPS; 347 - st_gdata->rx_state = ST_GPS_W4_EVENT_HDR; 348 - st_gdata->rx_count = 3; /* GPS_EVENT_HDR_SIZE -1*/ 349 - break; 350 311 case LL_SLEEP_IND: 351 312 case LL_SLEEP_ACK: 352 313 case LL_WAKE_UP_IND: 353 - pr_info("PM packet"); 314 + pr_debug("PM packet"); 354 315 /* this takes appropriate action based on 355 316 * sleep state received -- 356 317 */ 357 318 st_ll_sleep_state(st_gdata, *ptr); 319 + /* if WAKEUP_IND collides copy from waitq to txq 320 + * and assume chip awake 321 + */ 322 + spin_unlock_irqrestore(&st_gdata->lock, flags); 323 + if (st_ll_getstate(st_gdata) == ST_LL_AWAKE) 324 + st_wakeup_ack(st_gdata, LL_WAKE_UP_ACK); 325 + spin_lock_irqsave(&st_gdata->lock, flags); 326 + 358 327 ptr++; 359 328 count--; 360 329 continue; 361 330 case LL_WAKE_UP_ACK: 362 - pr_info("PM packet"); 331 + pr_debug("PM packet"); 332 + 333 + spin_unlock_irqrestore(&st_gdata->lock, flags); 363 334 /* wake up ack received */ 364 335 st_wakeup_ack(st_gdata, *ptr); 336 + spin_lock_irqsave(&st_gdata->lock, flags); 337 + 365 338 ptr++; 366 339 count--; 367 340 continue; 368 341 /* Unknow packet? */ 369 342 default: 370 - pr_err("Unknown packet type %2.2x", (__u8) *ptr); 371 - ptr++; 372 - count--; 373 - continue; 343 + type = *ptr; 344 + st_gdata->rx_skb = alloc_skb( 345 + st_gdata->list[type]->max_frame_size, 346 + GFP_ATOMIC); 347 + skb_reserve(st_gdata->rx_skb, 348 + st_gdata->list[type]->reserve); 349 + /* next 2 required for BT only */ 350 + st_gdata->rx_skb->cb[0] = type; /*pkt_type*/ 351 + st_gdata->rx_skb->cb[1] = 0; /*incoming*/ 352 + st_gdata->rx_chnl = *ptr; 353 + st_gdata->rx_state = ST_W4_HEADER; 354 + st_gdata->rx_count = st_gdata->list[type]->hdr_len; 355 + pr_debug("rx_count %ld\n", st_gdata->rx_count); 374 356 }; 375 357 ptr++; 376 358 count--; 377 - 378 - switch (protoid) { 379 - case ST_BT: 380 - /* Allocate new packet to hold received data */ 381 - st_gdata->rx_skb = 382 - bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); 383 - if (!st_gdata->rx_skb) { 384 - pr_err("Can't allocate mem for new packet"); 385 - st_gdata->rx_state = ST_W4_PACKET_TYPE; 386 - st_gdata->rx_count = 0; 387 - return; 388 - } 389 - bt_cb(st_gdata->rx_skb)->pkt_type = type; 390 - break; 391 - case ST_FM: /* for FM */ 392 - st_gdata->rx_skb = 393 - alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC); 394 - if (!st_gdata->rx_skb) { 395 - pr_err("Can't allocate mem for new packet"); 396 - st_gdata->rx_state = ST_W4_PACKET_TYPE; 397 - st_gdata->rx_count = 0; 398 - return; 399 - } 400 - /* place holder 0x08 */ 401 - skb_reserve(st_gdata->rx_skb, 1); 402 - st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT; 403 - break; 404 - case ST_GPS: 405 - /* for GPS */ 406 - st_gdata->rx_skb = 407 - alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ , GFP_ATOMIC); 408 - if (!st_gdata->rx_skb) { 409 - pr_err("Can't allocate mem for new packet"); 410 - st_gdata->rx_state = ST_W4_PACKET_TYPE; 411 - st_gdata->rx_count = 0; 412 - return; 413 - } 414 - /* place holder 0x09 */ 415 - skb_reserve(st_gdata->rx_skb, 1); 416 - st_gdata->rx_skb->cb[0] = 0x09; /*ST_GPS_CH9_PKT; */ 417 - break; 418 - case ST_MAX: 419 - break; 420 - } 421 359 } 360 + spin_unlock_irqrestore(&st_gdata->lock, flags); 422 361 pr_debug("done %s", __func__); 423 362 return; 424 363 } ··· 393 466 394 467 switch (st_ll_getstate(st_gdata)) { 395 468 case ST_LL_AWAKE: 396 - pr_info("ST LL is AWAKE, sending normally"); 469 + pr_debug("ST LL is AWAKE, sending normally"); 397 470 skb_queue_tail(&st_gdata->txq, skb); 398 471 break; 399 472 case ST_LL_ASLEEP_TO_AWAKE: ··· 433 506 pr_debug("%s", __func__); 434 507 /* check for sending & set flag sending here */ 435 508 if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) { 436 - pr_info("ST already sending"); 509 + pr_debug("ST already sending"); 437 510 /* keep sending */ 438 511 set_bit(ST_TX_WAKEUP, &st_data->tx_state); 439 512 return; ··· 475 548 { 476 549 seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n", 477 550 st_gdata->protos_registered, 478 - st_gdata->list[ST_BT] != NULL ? 'R' : 'U', 479 - st_gdata->list[ST_FM] != NULL ? 'R' : 'U', 480 - st_gdata->list[ST_GPS] != NULL ? 'R' : 'U'); 551 + st_gdata->list[0x04] != NULL ? 'R' : 'U', 552 + st_gdata->list[0x08] != NULL ? 'R' : 'U', 553 + st_gdata->list[0x09] != NULL ? 'R' : 'U'); 481 554 } 482 555 483 556 /********************************************************************/ ··· 492 565 unsigned long flags = 0; 493 566 494 567 st_kim_ref(&st_gdata, 0); 495 - pr_info("%s(%d) ", __func__, new_proto->type); 568 + pr_info("%s(%d) ", __func__, new_proto->chnl_id); 496 569 if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL 497 570 || new_proto->reg_complete_cb == NULL) { 498 571 pr_err("gdata/new_proto/recv or reg_complete_cb not ready"); 499 - return -1; 572 + return -EINVAL; 500 573 } 501 574 502 - if (new_proto->type < ST_BT || new_proto->type >= ST_MAX) { 503 - pr_err("protocol %d not supported", new_proto->type); 575 + if (new_proto->chnl_id >= ST_MAX_CHANNELS) { 576 + pr_err("chnl_id %d not supported", new_proto->chnl_id); 504 577 return -EPROTONOSUPPORT; 505 578 } 506 579 507 - if (st_gdata->list[new_proto->type] != NULL) { 508 - pr_err("protocol %d already registered", new_proto->type); 580 + if (st_gdata->list[new_proto->chnl_id] != NULL) { 581 + pr_err("chnl_id %d already registered", new_proto->chnl_id); 509 582 return -EALREADY; 510 583 } 511 584 ··· 513 586 spin_lock_irqsave(&st_gdata->lock, flags); 514 587 515 588 if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) { 516 - pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->type); 589 + pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->chnl_id); 517 590 /* fw download in progress */ 518 - st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE); 519 591 520 - st_gdata->list[new_proto->type] = new_proto; 592 + add_channel_to_table(st_gdata, new_proto); 521 593 st_gdata->protos_registered++; 522 594 new_proto->write = st_write; 523 595 ··· 524 598 spin_unlock_irqrestore(&st_gdata->lock, flags); 525 599 return -EINPROGRESS; 526 600 } else if (st_gdata->protos_registered == ST_EMPTY) { 527 - pr_info(" protocol list empty :%d ", new_proto->type); 601 + pr_info(" chnl_id list empty :%d ", new_proto->chnl_id); 528 602 set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); 529 603 st_recv = st_kim_recv; 530 604 ··· 542 616 if ((st_gdata->protos_registered != ST_EMPTY) && 543 617 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) { 544 618 pr_err(" KIM failure complete callback "); 545 - st_reg_complete(st_gdata, -1); 619 + st_reg_complete(st_gdata, err); 546 620 } 547 - 548 - return -1; 621 + return -EINVAL; 549 622 } 550 - 551 - /* the protocol might require other gpios to be toggled 552 - */ 553 - st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE); 554 623 555 624 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); 556 625 st_recv = st_int_recv; ··· 563 642 /* check for already registered once more, 564 643 * since the above check is old 565 644 */ 566 - if (st_gdata->list[new_proto->type] != NULL) { 645 + if (st_gdata->list[new_proto->chnl_id] != NULL) { 567 646 pr_err(" proto %d already registered ", 568 - new_proto->type); 647 + new_proto->chnl_id); 569 648 return -EALREADY; 570 649 } 571 650 572 651 spin_lock_irqsave(&st_gdata->lock, flags); 573 - st_gdata->list[new_proto->type] = new_proto; 652 + add_channel_to_table(st_gdata, new_proto); 574 653 st_gdata->protos_registered++; 575 654 new_proto->write = st_write; 576 655 spin_unlock_irqrestore(&st_gdata->lock, flags); ··· 578 657 } 579 658 /* if fw is already downloaded & new stack registers protocol */ 580 659 else { 581 - switch (new_proto->type) { 582 - case ST_BT: 583 - /* do nothing */ 584 - break; 585 - case ST_FM: 586 - case ST_GPS: 587 - st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE); 588 - break; 589 - case ST_MAX: 590 - default: 591 - pr_err("%d protocol not supported", 592 - new_proto->type); 593 - spin_unlock_irqrestore(&st_gdata->lock, flags); 594 - return -EPROTONOSUPPORT; 595 - } 596 - st_gdata->list[new_proto->type] = new_proto; 660 + add_channel_to_table(st_gdata, new_proto); 597 661 st_gdata->protos_registered++; 598 662 new_proto->write = st_write; 599 663 ··· 586 680 spin_unlock_irqrestore(&st_gdata->lock, flags); 587 681 return err; 588 682 } 589 - pr_debug("done %s(%d) ", __func__, new_proto->type); 683 + pr_debug("done %s(%d) ", __func__, new_proto->chnl_id); 590 684 } 591 685 EXPORT_SYMBOL_GPL(st_register); 592 686 593 687 /* to unregister a protocol - 594 688 * to be called from protocol stack driver 595 689 */ 596 - long st_unregister(enum proto_type type) 690 + long st_unregister(struct st_proto_s *proto) 597 691 { 598 692 long err = 0; 599 693 unsigned long flags = 0; 600 694 struct st_data_s *st_gdata; 601 695 602 - pr_debug("%s: %d ", __func__, type); 696 + pr_debug("%s: %d ", __func__, proto->chnl_id); 603 697 604 698 st_kim_ref(&st_gdata, 0); 605 - if (type < ST_BT || type >= ST_MAX) { 606 - pr_err(" protocol %d not supported", type); 699 + if (proto->chnl_id >= ST_MAX_CHANNELS) { 700 + pr_err(" chnl_id %d not supported", proto->chnl_id); 607 701 return -EPROTONOSUPPORT; 608 702 } 609 703 610 704 spin_lock_irqsave(&st_gdata->lock, flags); 611 705 612 - if (st_gdata->list[type] == NULL) { 613 - pr_err(" protocol %d not registered", type); 706 + if (st_gdata->list[proto->chnl_id] == NULL) { 707 + pr_err(" chnl_id %d not registered", proto->chnl_id); 614 708 spin_unlock_irqrestore(&st_gdata->lock, flags); 615 709 return -EPROTONOSUPPORT; 616 710 } 617 711 618 712 st_gdata->protos_registered--; 619 - st_gdata->list[type] = NULL; 620 - 621 - /* kim ignores BT in the below function 622 - * and handles the rest, BT is toggled 623 - * only in kim_start and kim_stop 624 - */ 625 - st_kim_chip_toggle(type, KIM_GPIO_INACTIVE); 713 + remove_channel_from_table(st_gdata, proto); 626 714 spin_unlock_irqrestore(&st_gdata->lock, flags); 627 715 628 716 if ((st_gdata->protos_registered == ST_EMPTY) && 629 717 (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) { 630 - pr_info(" all protocols unregistered "); 718 + pr_info(" all chnl_ids unregistered "); 631 719 632 720 /* stop traffic on tty */ 633 721 if (st_gdata->tty) { ··· 629 729 stop_tty(st_gdata->tty); 630 730 } 631 731 632 - /* all protocols now unregistered */ 732 + /* all chnl_ids now unregistered */ 633 733 st_kim_stop(st_gdata->kim_data); 634 734 /* disable ST LL */ 635 735 st_ll_disable(st_gdata); ··· 644 744 long st_write(struct sk_buff *skb) 645 745 { 646 746 struct st_data_s *st_gdata; 647 - #ifdef DEBUG 648 - enum proto_type protoid = ST_MAX; 649 - #endif 650 747 long len; 651 748 652 749 st_kim_ref(&st_gdata, 0); 653 750 if (unlikely(skb == NULL || st_gdata == NULL 654 751 || st_gdata->tty == NULL)) { 655 752 pr_err("data/tty unavailable to perform write"); 656 - return -1; 753 + return -EINVAL; 657 754 } 658 - #ifdef DEBUG /* open-up skb to read the 1st byte */ 659 - switch (skb->data[0]) { 660 - case HCI_COMMAND_PKT: 661 - case HCI_ACLDATA_PKT: 662 - case HCI_SCODATA_PKT: 663 - protoid = ST_BT; 664 - break; 665 - case ST_FM_CH8_PKT: 666 - protoid = ST_FM; 667 - break; 668 - case 0x09: 669 - protoid = ST_GPS; 670 - break; 671 - } 672 - if (unlikely(st_gdata->list[protoid] == NULL)) { 673 - pr_err(" protocol %d not registered, and writing? ", 674 - protoid); 675 - return -1; 676 - } 677 - #endif 755 + 678 756 pr_debug("%d to be written", skb->len); 679 757 len = skb->len; 680 758 ··· 702 824 703 825 static void st_tty_close(struct tty_struct *tty) 704 826 { 705 - unsigned char i = ST_MAX; 827 + unsigned char i = ST_MAX_CHANNELS; 706 828 unsigned long flags = 0; 707 829 struct st_data_s *st_gdata = tty->disc_data; 708 830 ··· 713 835 * un-installed for some reason - what should be done ? 714 836 */ 715 837 spin_lock_irqsave(&st_gdata->lock, flags); 716 - for (i = ST_BT; i < ST_MAX; i++) { 838 + for (i = ST_BT; i < ST_MAX_CHANNELS; i++) { 717 839 if (st_gdata->list[i] != NULL) 718 840 pr_err("%d not un-registered", i); 719 841 st_gdata->list[i] = NULL; ··· 747 869 static void st_tty_receive(struct tty_struct *tty, const unsigned char *data, 748 870 char *tty_flags, int count) 749 871 { 750 - 751 872 #ifdef VERBOSE 752 873 print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE, 753 874 16, 1, data, count, 0); ··· 837 960 err = tty_unregister_ldisc(N_TI_WL); 838 961 if (err) 839 962 pr_err("unable to un-register ldisc"); 840 - return -1; 963 + return err; 841 964 } 842 965 *core_data = st_gdata; 843 966 return 0;
+242 -249
drivers/misc/ti-st/st_kim.c
··· 30 30 #include <linux/debugfs.h> 31 31 #include <linux/seq_file.h> 32 32 #include <linux/sched.h> 33 - #include <linux/rfkill.h> 33 + #include <linux/tty.h> 34 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 - 35 + #include <linux/skbuff.h> 40 36 #include <linux/ti_wilink_st.h> 41 37 42 - 43 - static int kim_probe(struct platform_device *pdev); 44 - static int kim_remove(struct platform_device *pdev); 45 - 46 - /* KIM platform device driver structure */ 47 - static 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 - 62 - static int kim_toggle_radio(void*, bool); 63 - static 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 71 - const unsigned char *protocol_names[] = { 72 - PROTO_ENTRY(ST_BT, "Bluetooth"), 73 - PROTO_ENTRY(ST_FM, "FM"), 74 - PROTO_ENTRY(ST_GPS, "GPS"), 75 - }; 76 38 77 39 #define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ 78 40 static struct platform_device *st_kim_devices[MAX_ST_DEVICES]; ··· 96 134 /* Packet header has non-zero payload length and 97 135 * we have enough space in created skb. Lets read 98 136 * payload data */ 99 - kim_gdata->rx_state = ST_BT_W4_DATA; 137 + kim_gdata->rx_state = ST_W4_DATA; 100 138 kim_gdata->rx_count = len; 101 139 return len; 102 140 } ··· 120 158 const unsigned char *data, long count) 121 159 { 122 160 const unsigned char *ptr; 123 - struct hci_event_hdr *eh; 124 161 int len = 0, type = 0; 162 + unsigned char *plen; 125 163 126 164 pr_debug("%s", __func__); 127 165 /* Decode received bytes here */ ··· 145 183 /* Check ST RX state machine , where are we? */ 146 184 switch (kim_gdata->rx_state) { 147 185 /* Waiting for complete packet ? */ 148 - case ST_BT_W4_DATA: 186 + case ST_W4_DATA: 149 187 pr_debug("Complete pkt received"); 150 188 validate_firmware_response(kim_gdata); 151 189 kim_gdata->rx_state = ST_W4_PACKET_TYPE; 152 190 kim_gdata->rx_skb = NULL; 153 191 continue; 154 192 /* Waiting for Bluetooth event header ? */ 155 - case ST_BT_W4_EVENT_HDR: 156 - eh = (struct hci_event_hdr *)kim_gdata-> 157 - rx_skb->data; 158 - pr_debug("Event header: evt 0x%2.2x" 159 - "plen %d", eh->evt, eh->plen); 160 - kim_check_data_len(kim_gdata, eh->plen); 193 + case ST_W4_HEADER: 194 + plen = 195 + (unsigned char *)&kim_gdata->rx_skb->data[1]; 196 + pr_debug("event hdr: plen 0x%02x\n", *plen); 197 + kim_check_data_len(kim_gdata, *plen); 161 198 continue; 162 199 } /* end of switch */ 163 200 } /* end of if rx_state */ 164 201 switch (*ptr) { 165 202 /* Bluetooth event packet? */ 166 - case HCI_EVENT_PKT: 167 - pr_info("Event packet"); 168 - kim_gdata->rx_state = ST_BT_W4_EVENT_HDR; 169 - kim_gdata->rx_count = HCI_EVENT_HDR_SIZE; 170 - type = HCI_EVENT_PKT; 203 + case 0x04: 204 + kim_gdata->rx_state = ST_W4_HEADER; 205 + kim_gdata->rx_count = 2; 206 + type = *ptr; 171 207 break; 172 208 default: 173 209 pr_info("unknown packet"); ··· 176 216 ptr++; 177 217 count--; 178 218 kim_gdata->rx_skb = 179 - bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); 219 + alloc_skb(1024+8, GFP_ATOMIC); 180 220 if (!kim_gdata->rx_skb) { 181 221 pr_err("can't allocate mem for new packet"); 182 222 kim_gdata->rx_state = ST_W4_PACKET_TYPE; 183 223 kim_gdata->rx_count = 0; 184 224 return; 185 225 } 186 - bt_cb(kim_gdata->rx_skb)->pkt_type = type; 226 + skb_reserve(kim_gdata->rx_skb, 8); 227 + kim_gdata->rx_skb->cb[0] = 4; 228 + kim_gdata->rx_skb->cb[1] = 0; 229 + 187 230 } 188 - pr_info("done %s", __func__); 189 231 return; 190 232 } 191 233 ··· 201 239 INIT_COMPLETION(kim_gdata->kim_rcvd); 202 240 if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) { 203 241 pr_err("kim: couldn't write 4 bytes"); 204 - return -1; 242 + return -EIO; 205 243 } 206 244 207 245 if (!wait_for_completion_timeout 208 246 (&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) { 209 247 pr_err(" waiting for ver info- timed out "); 210 - return -1; 248 + return -ETIMEDOUT; 211 249 } 212 250 213 251 version = ··· 232 270 return 0; 233 271 } 234 272 273 + void skip_change_remote_baud(unsigned char **ptr, long *len) 274 + { 275 + unsigned char *nxt_action, *cur_action; 276 + cur_action = *ptr; 277 + 278 + nxt_action = cur_action + sizeof(struct bts_action) + 279 + ((struct bts_action *) cur_action)->size; 280 + 281 + if (((struct bts_action *) nxt_action)->type != ACTION_WAIT_EVENT) { 282 + pr_err("invalid action after change remote baud command"); 283 + } else { 284 + *ptr = *ptr + sizeof(struct bts_action) + 285 + ((struct bts_action *)nxt_action)->size; 286 + *len = *len - (sizeof(struct bts_action) + 287 + ((struct bts_action *)nxt_action)->size); 288 + /* warn user on not commenting these in firmware */ 289 + pr_warn("skipping the wait event of change remote baud"); 290 + } 291 + } 292 + 235 293 /** 236 294 * download_firmware - 237 295 * internal function which parses through the .bts firmware ··· 264 282 unsigned char *ptr = NULL; 265 283 unsigned char *action_ptr = NULL; 266 284 unsigned char bts_scr_name[30] = { 0 }; /* 30 char long bts scr name? */ 285 + int wr_room_space; 286 + int cmd_size; 287 + unsigned long timeout; 267 288 268 289 err = read_local_version(kim_gdata, bts_scr_name); 269 290 if (err != 0) { ··· 280 295 (kim_gdata->fw_entry->size == 0))) { 281 296 pr_err(" request_firmware failed(errno %ld) for %s", err, 282 297 bts_scr_name); 283 - return -1; 298 + return -EINVAL; 284 299 } 285 300 ptr = (void *)kim_gdata->fw_entry->data; 286 301 len = kim_gdata->fw_entry->size; ··· 303 318 0xFF36)) { 304 319 /* ignore remote change 305 320 * baud rate HCI VS command */ 306 - pr_err 307 - (" change remote baud" 321 + pr_warn("change remote baud" 308 322 " rate command in firmware"); 323 + skip_change_remote_baud(&ptr, &len); 309 324 break; 310 325 } 326 + /* 327 + * Make sure we have enough free space in uart 328 + * tx buffer to write current firmware command 329 + */ 330 + cmd_size = ((struct bts_action *)ptr)->size; 331 + timeout = jiffies + msecs_to_jiffies(CMD_WR_TIME); 332 + do { 333 + wr_room_space = 334 + st_get_uart_wr_room(kim_gdata->core_data); 335 + if (wr_room_space < 0) { 336 + pr_err("Unable to get free " 337 + "space info from uart tx buffer"); 338 + release_firmware(kim_gdata->fw_entry); 339 + return wr_room_space; 340 + } 341 + mdelay(1); /* wait 1ms before checking room */ 342 + } while ((wr_room_space < cmd_size) && 343 + time_before(jiffies, timeout)); 311 344 312 - INIT_COMPLETION(kim_gdata->kim_rcvd); 345 + /* Timeout happened ? */ 346 + if (time_after_eq(jiffies, timeout)) { 347 + pr_err("Timeout while waiting for free " 348 + "free space in uart tx buffer"); 349 + release_firmware(kim_gdata->fw_entry); 350 + return -ETIMEDOUT; 351 + } 352 + 353 + /* 354 + * Free space found in uart buffer, call st_int_write 355 + * to send current firmware command to the uart tx 356 + * buffer. 357 + */ 313 358 err = st_int_write(kim_gdata->core_data, 314 359 ((struct bts_action_send *)action_ptr)->data, 315 360 ((struct bts_action *)ptr)->size); 316 361 if (unlikely(err < 0)) { 317 362 release_firmware(kim_gdata->fw_entry); 318 - return -1; 363 + return err; 319 364 } 365 + /* 366 + * Check number of bytes written to the uart tx buffer 367 + * and requested command write size 368 + */ 369 + if (err != cmd_size) { 370 + pr_err("Number of bytes written to uart " 371 + "tx buffer are not matching with " 372 + "requested cmd write size"); 373 + release_firmware(kim_gdata->fw_entry); 374 + return -EIO; 375 + } 376 + break; 377 + case ACTION_WAIT_EVENT: /* wait */ 320 378 if (!wait_for_completion_timeout 321 - (&kim_gdata->kim_rcvd, 322 - msecs_to_jiffies(CMD_RESP_TIME))) { 323 - pr_err 324 - (" response timeout during fw download "); 379 + (&kim_gdata->kim_rcvd, 380 + msecs_to_jiffies(CMD_RESP_TIME))) { 381 + pr_err("response timeout during fw download "); 325 382 /* timed out */ 326 383 release_firmware(kim_gdata->fw_entry); 327 - return -1; 384 + return -ETIMEDOUT; 328 385 } 386 + INIT_COMPLETION(kim_gdata->kim_rcvd); 329 387 break; 330 388 case ACTION_DELAY: /* sleep */ 331 389 pr_info("sleep command in scr"); ··· 390 362 391 363 /**********************************************************************/ 392 364 /* functions called from ST core */ 393 - /* function to toggle the GPIO 394 - * needs to know whether the GPIO is active high or active low 395 - */ 396 - void st_kim_chip_toggle(enum proto_type type, enum kim_gpio_state state) 397 - { 398 - struct platform_device *kim_pdev; 399 - struct kim_data_s *kim_gdata; 400 - pr_info(" %s ", __func__); 401 - 402 - kim_pdev = st_get_plat_device(0); 403 - kim_gdata = dev_get_drvdata(&kim_pdev->dev); 404 - 405 - if (kim_gdata->gpios[type] == -1) { 406 - pr_info(" gpio not requested for protocol %s", 407 - protocol_names[type]); 408 - return; 409 - } 410 - switch (type) { 411 - case ST_BT: 412 - /*Do Nothing */ 413 - break; 414 - 415 - case ST_FM: 416 - if (state == KIM_GPIO_ACTIVE) 417 - gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_LOW); 418 - else 419 - gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_HIGH); 420 - break; 421 - 422 - case ST_GPS: 423 - if (state == KIM_GPIO_ACTIVE) 424 - gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_HIGH); 425 - else 426 - gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_LOW); 427 - break; 428 - 429 - case ST_MAX: 430 - default: 431 - break; 432 - } 433 - 434 - return; 435 - } 436 - 437 365 /* called from ST Core, when REG_IN_PROGRESS (registration in progress) 438 366 * can be because of 439 367 * 1. response to read local version ··· 400 416 struct st_data_s *st_gdata = (struct st_data_s *)disc_data; 401 417 struct kim_data_s *kim_gdata = st_gdata->kim_data; 402 418 403 - pr_info(" %s ", __func__); 404 419 /* copy to local buffer */ 405 420 if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) { 406 421 /* must be the read_ver_cmd */ ··· 438 455 pr_info(" %s", __func__); 439 456 440 457 do { 441 - /* TODO: this is only because rfkill sub-system 442 - * doesn't send events to user-space if the state 443 - * isn't changed 444 - */ 445 - rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1); 446 458 /* Configure BT nShutdown to HIGH state */ 447 - gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); 459 + gpio_set_value(kim_gdata->nshutdown, GPIO_LOW); 448 460 mdelay(5); /* FIXME: a proper toggle */ 449 - gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH); 461 + gpio_set_value(kim_gdata->nshutdown, GPIO_HIGH); 450 462 mdelay(100); 451 463 /* re-initialize the completion */ 452 464 INIT_COMPLETION(kim_gdata->ldisc_installed); 453 - #if 0 /* older way of signalling user-space UIM */ 454 - /* send signal to UIM */ 455 - err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 0); 456 - if (err != 0) { 457 - pr_info(" sending SIGUSR2 to uim failed %ld", err); 458 - err = -1; 459 - continue; 460 - } 461 - #endif 462 - /* unblock and send event to UIM via /dev/rfkill */ 463 - rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 0); 465 + /* send notification to UIM */ 466 + kim_gdata->ldisc_install = 1; 467 + pr_info("ldisc_install = 1"); 468 + sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, 469 + NULL, "install"); 464 470 /* wait for ldisc to be installed */ 465 471 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, 466 472 msecs_to_jiffies(LDISC_TIME)); 467 473 if (!err) { /* timeout */ 468 474 pr_err("line disc installation timed out "); 469 - err = -1; 475 + kim_gdata->ldisc_install = 0; 476 + pr_info("ldisc_install = 0"); 477 + sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, 478 + NULL, "install"); 479 + err = -ETIMEDOUT; 470 480 continue; 471 481 } else { 472 482 /* ldisc installed now */ ··· 467 491 err = download_firmware(kim_gdata); 468 492 if (err != 0) { 469 493 pr_err("download firmware failed"); 494 + kim_gdata->ldisc_install = 0; 495 + pr_info("ldisc_install = 0"); 496 + sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, 497 + NULL, "install"); 470 498 continue; 471 499 } else { /* on success don't retry */ 472 500 break; ··· 490 510 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 491 511 492 512 INIT_COMPLETION(kim_gdata->ldisc_installed); 493 - #if 0 /* older way of signalling user-space UIM */ 494 - /* send signal to UIM */ 495 - err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 1); 496 - if (err != 0) { 497 - pr_err("sending SIGUSR2 to uim failed %ld", err); 498 - return -1; 499 - } 500 - #endif 501 - /* set BT rfkill to be blocked */ 502 - err = rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1); 513 + 514 + /* Flush any pending characters in the driver and discipline. */ 515 + tty_ldisc_flush(kim_gdata->core_data->tty); 516 + tty_driver_flush_buffer(kim_gdata->core_data->tty); 517 + 518 + /* send uninstall notification to UIM */ 519 + pr_info("ldisc_install = 0"); 520 + kim_gdata->ldisc_install = 0; 521 + sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, NULL, "install"); 503 522 504 523 /* wait for ldisc to be un-installed */ 505 524 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed, 506 525 msecs_to_jiffies(LDISC_TIME)); 507 526 if (!err) { /* timeout */ 508 527 pr_err(" timed out waiting for ldisc to be un-installed"); 509 - return -1; 528 + return -ETIMEDOUT; 510 529 } 511 530 512 531 /* By default configure BT nShutdown to LOW state */ 513 - gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); 532 + gpio_set_value(kim_gdata->nshutdown, GPIO_LOW); 514 533 mdelay(1); 515 - gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH); 534 + gpio_set_value(kim_gdata->nshutdown, GPIO_HIGH); 516 535 mdelay(1); 517 - gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW); 536 + gpio_set_value(kim_gdata->nshutdown, GPIO_LOW); 518 537 return err; 519 538 } 520 539 ··· 537 558 return 0; 538 559 } 539 560 540 - /* function called from rfkill subsystem, when someone from 541 - * user space would write 0/1 on the sysfs entry 542 - * /sys/class/rfkill/rfkill0,1,3/state 543 - */ 544 - static int kim_toggle_radio(void *data, bool blocked) 561 + static ssize_t show_install(struct device *dev, 562 + struct device_attribute *attr, char *buf) 545 563 { 546 - enum proto_type type = *((enum proto_type *)data); 547 - pr_debug(" %s: %d ", __func__, type); 548 - 549 - switch (type) { 550 - case ST_BT: 551 - /* do nothing */ 552 - break; 553 - case ST_FM: 554 - case ST_GPS: 555 - if (blocked) 556 - st_kim_chip_toggle(type, KIM_GPIO_INACTIVE); 557 - else 558 - st_kim_chip_toggle(type, KIM_GPIO_ACTIVE); 559 - break; 560 - case ST_MAX: 561 - pr_err(" wrong proto type "); 562 - break; 563 - } 564 - return 0; 564 + struct kim_data_s *kim_data = dev_get_drvdata(dev); 565 + return sprintf(buf, "%d\n", kim_data->ldisc_install); 565 566 } 567 + 568 + static ssize_t show_dev_name(struct device *dev, 569 + struct device_attribute *attr, char *buf) 570 + { 571 + struct kim_data_s *kim_data = dev_get_drvdata(dev); 572 + return sprintf(buf, "%s\n", kim_data->dev_name); 573 + } 574 + 575 + static ssize_t show_baud_rate(struct device *dev, 576 + struct device_attribute *attr, char *buf) 577 + { 578 + struct kim_data_s *kim_data = dev_get_drvdata(dev); 579 + return sprintf(buf, "%ld\n", kim_data->baud_rate); 580 + } 581 + 582 + static ssize_t show_flow_cntrl(struct device *dev, 583 + struct device_attribute *attr, char *buf) 584 + { 585 + struct kim_data_s *kim_data = dev_get_drvdata(dev); 586 + return sprintf(buf, "%d\n", kim_data->flow_cntrl); 587 + } 588 + 589 + /* structures specific for sysfs entries */ 590 + static struct kobj_attribute ldisc_install = 591 + __ATTR(install, 0444, (void *)show_install, NULL); 592 + 593 + static struct kobj_attribute uart_dev_name = 594 + __ATTR(dev_name, 0444, (void *)show_dev_name, NULL); 595 + 596 + static struct kobj_attribute uart_baud_rate = 597 + __ATTR(baud_rate, 0444, (void *)show_baud_rate, NULL); 598 + 599 + static struct kobj_attribute uart_flow_cntrl = 600 + __ATTR(flow_cntrl, 0444, (void *)show_flow_cntrl, NULL); 601 + 602 + static struct attribute *uim_attrs[] = { 603 + &ldisc_install.attr, 604 + &uart_dev_name.attr, 605 + &uart_baud_rate.attr, 606 + &uart_flow_cntrl.attr, 607 + NULL, 608 + }; 609 + 610 + static struct attribute_group uim_attr_grp = { 611 + .attrs = uim_attrs, 612 + }; 566 613 567 614 /** 568 615 * st_kim_ref - reference the core's data ··· 642 637 static int kim_probe(struct platform_device *pdev) 643 638 { 644 639 long status; 645 - long proto; 646 - long *gpios = pdev->dev.platform_data; 647 640 struct kim_data_s *kim_gdata; 641 + struct ti_st_plat_data *pdata = pdev->dev.platform_data; 648 642 649 643 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) { 650 644 /* multiple devices could exist */ ··· 663 659 status = st_core_init(&kim_gdata->core_data); 664 660 if (status != 0) { 665 661 pr_err(" ST core init failed"); 666 - return -1; 662 + return -EIO; 667 663 } 668 664 /* refer to itself */ 669 665 kim_gdata->core_data->kim_data = kim_gdata; 670 666 671 - for (proto = 0; proto < ST_MAX; proto++) { 672 - kim_gdata->gpios[proto] = gpios[proto]; 673 - pr_info(" %ld gpio to be requested", gpios[proto]); 667 + /* Claim the chip enable nShutdown gpio from the system */ 668 + kim_gdata->nshutdown = pdata->nshutdown_gpio; 669 + status = gpio_request(kim_gdata->nshutdown, "kim"); 670 + if (unlikely(status)) { 671 + pr_err(" gpio %ld request failed ", kim_gdata->nshutdown); 672 + return status; 674 673 } 675 674 676 - for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { 677 - /* Claim the Bluetooth/FM/GPIO 678 - * nShutdown gpio from the system 679 - */ 680 - status = gpio_request(gpios[proto], "kim"); 681 - if (unlikely(status)) { 682 - pr_err(" gpio %ld request failed ", gpios[proto]); 683 - proto -= 1; 684 - while (proto >= 0) { 685 - if (gpios[proto] != -1) 686 - gpio_free(gpios[proto]); 687 - } 688 - return status; 689 - } 690 - 691 - /* Configure nShutdown GPIO as output=0 */ 692 - status = 693 - gpio_direction_output(gpios[proto], 0); 694 - if (unlikely(status)) { 695 - pr_err(" unable to configure gpio %ld", 696 - gpios[proto]); 697 - proto -= 1; 698 - while (proto >= 0) { 699 - if (gpios[proto] != -1) 700 - gpio_free(gpios[proto]); 701 - } 702 - return status; 703 - } 675 + /* Configure nShutdown GPIO as output=0 */ 676 + status = gpio_direction_output(kim_gdata->nshutdown, 0); 677 + if (unlikely(status)) { 678 + pr_err(" unable to configure gpio %ld", kim_gdata->nshutdown); 679 + return status; 704 680 } 705 681 /* get reference of pdev for request_firmware 706 682 */ ··· 688 704 init_completion(&kim_gdata->kim_rcvd); 689 705 init_completion(&kim_gdata->ldisc_installed); 690 706 691 - for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { 692 - /* TODO: should all types be rfkill_type_bt ? */ 693 - kim_gdata->rf_protos[proto] = proto; 694 - kim_gdata->rfkill[proto] = rfkill_alloc(protocol_names[proto], 695 - &pdev->dev, RFKILL_TYPE_BLUETOOTH, 696 - &kim_rfkill_ops, &kim_gdata->rf_protos[proto]); 697 - if (kim_gdata->rfkill[proto] == NULL) { 698 - pr_err("cannot create rfkill entry for gpio %ld", 699 - gpios[proto]); 700 - continue; 701 - } 702 - /* block upon creation */ 703 - rfkill_init_sw_state(kim_gdata->rfkill[proto], 1); 704 - status = rfkill_register(kim_gdata->rfkill[proto]); 705 - if (unlikely(status)) { 706 - pr_err("rfkill registration failed for gpio %ld", 707 - gpios[proto]); 708 - rfkill_unregister(kim_gdata->rfkill[proto]); 709 - continue; 710 - } 711 - pr_info("rfkill entry created for %ld", gpios[proto]); 707 + status = sysfs_create_group(&pdev->dev.kobj, &uim_attr_grp); 708 + if (status) { 709 + pr_err("failed to create sysfs entries"); 710 + return status; 712 711 } 712 + 713 + /* copying platform data */ 714 + strncpy(kim_gdata->dev_name, pdata->dev_name, UART_DEV_NAME_LEN); 715 + kim_gdata->flow_cntrl = pdata->flow_cntrl; 716 + kim_gdata->baud_rate = pdata->baud_rate; 717 + pr_info("sysfs entries created\n"); 713 718 714 719 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL); 715 720 if (IS_ERR(kim_debugfs_dir)) { 716 721 pr_err(" debugfs entries creation failed "); 717 722 kim_debugfs_dir = NULL; 718 - return -1; 723 + return -EIO; 719 724 } 720 725 721 726 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir, ··· 717 744 718 745 static int kim_remove(struct platform_device *pdev) 719 746 { 720 - /* free the GPIOs requested 721 - */ 722 - long *gpios = pdev->dev.platform_data; 723 - long proto; 747 + /* free the GPIOs requested */ 748 + struct ti_st_plat_data *pdata = pdev->dev.platform_data; 724 749 struct kim_data_s *kim_gdata; 725 750 726 751 kim_gdata = dev_get_drvdata(&pdev->dev); 727 752 728 - for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { 729 - /* Claim the Bluetooth/FM/GPIO 730 - * nShutdown gpio from the system 731 - */ 732 - gpio_free(gpios[proto]); 733 - rfkill_unregister(kim_gdata->rfkill[proto]); 734 - rfkill_destroy(kim_gdata->rfkill[proto]); 735 - kim_gdata->rfkill[proto] = NULL; 736 - } 737 - pr_info("kim: GPIO Freed"); 753 + /* Free the Bluetooth/FM/GPIO 754 + * nShutdown gpio from the system 755 + */ 756 + gpio_free(pdata->nshutdown_gpio); 757 + pr_info("nshutdown GPIO Freed"); 758 + 738 759 debugfs_remove_recursive(kim_debugfs_dir); 760 + sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp); 761 + pr_info("sysfs entries removed"); 762 + 739 763 kim_gdata->kim_pdev = NULL; 740 764 st_core_exit(kim_gdata->core_data); 741 765 ··· 741 771 return 0; 742 772 } 743 773 774 + int kim_suspend(struct platform_device *pdev, pm_message_t state) 775 + { 776 + struct ti_st_plat_data *pdata = pdev->dev.platform_data; 777 + 778 + if (pdata->suspend) 779 + return pdata->suspend(pdev, state); 780 + 781 + return -EOPNOTSUPP; 782 + } 783 + 784 + int kim_resume(struct platform_device *pdev) 785 + { 786 + struct ti_st_plat_data *pdata = pdev->dev.platform_data; 787 + 788 + if (pdata->resume) 789 + return pdata->resume(pdev); 790 + 791 + return -EOPNOTSUPP; 792 + } 793 + 744 794 /**********************************************************************/ 745 795 /* entry point for ST KIM module, called in from ST Core */ 796 + static struct platform_driver kim_platform_driver = { 797 + .probe = kim_probe, 798 + .remove = kim_remove, 799 + .suspend = kim_suspend, 800 + .resume = kim_resume, 801 + .driver = { 802 + .name = "kim", 803 + .owner = THIS_MODULE, 804 + }, 805 + }; 746 806 747 807 static int __init st_kim_init(void) 748 808 { 749 - long ret = 0; 750 - ret = platform_driver_register(&kim_platform_driver); 751 - if (ret != 0) { 752 - pr_err("platform drv registration failed"); 753 - return -1; 754 - } 755 - return 0; 809 + return platform_driver_register(&kim_platform_driver); 756 810 } 757 811 758 812 static void __exit st_kim_deinit(void) 759 813 { 760 - /* the following returns void */ 761 814 platform_driver_unregister(&kim_platform_driver); 762 815 } 763 816
+5 -5
drivers/misc/ti-st/st_ll.c
··· 30 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 34 st_int_write(st_data, &cmd, 1); 35 35 return; 36 36 } ··· 114 114 { 115 115 switch (cmd) { 116 116 case LL_SLEEP_IND: /* sleep ind */ 117 - pr_info("sleep indication recvd"); 117 + pr_debug("sleep indication recvd"); 118 118 ll_device_want_to_sleep(st_data); 119 119 break; 120 120 case LL_SLEEP_ACK: /* sleep ack */ 121 121 pr_err("sleep ack rcvd: host shouldn't"); 122 122 break; 123 123 case LL_WAKE_UP_IND: /* wake ind */ 124 - pr_info("wake indication recvd"); 124 + pr_debug("wake indication recvd"); 125 125 ll_device_want_to_wakeup(st_data); 126 126 break; 127 127 case LL_WAKE_UP_ACK: /* wake ack */ 128 - pr_info("wake ack rcvd"); 128 + pr_debug("wake ack rcvd"); 129 129 st_data->ll_state = ST_LL_AWAKE; 130 130 break; 131 131 default: 132 132 pr_err(" unknown input/state "); 133 - return -1; 133 + return -EINVAL; 134 134 } 135 135 return 0; 136 136 }
+17
drivers/uio/Kconfig
··· 94 94 To compile this driver as a module, choose M here; the module 95 95 will be called uio_netx. 96 96 97 + config 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 + 97 114 endif
+1
drivers/uio/Makefile
··· 6 6 obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o 7 7 obj-$(CONFIG_UIO_PCI_GENERIC) += uio_pci_generic.o 8 8 obj-$(CONFIG_UIO_NETX) += uio_netx.o 9 + obj-$(CONFIG_UIO_PRUSS) += uio_pruss.o
+247
drivers/uio/uio_pruss.c
··· 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 + 33 + static int sram_pool_sz = SZ_16K; 34 + module_param(sram_pool_sz, int, 0); 35 + MODULE_PARM_DESC(sram_pool_sz, "sram pool size to allocate "); 36 + 37 + static int extram_pool_sz = SZ_256K; 38 + module_param(extram_pool_sz, int, 0); 39 + MODULE_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 + 62 + struct 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 + 74 + static 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 + 93 + static 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 + 115 + static 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 + 207 + out_free: 208 + pruss_cleanup(dev, gdev); 209 + return ret; 210 + } 211 + 212 + static 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 + 221 + static 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 + 230 + static int __init pruss_init_module(void) 231 + { 232 + return platform_driver_register(&pruss_driver); 233 + } 234 + 235 + module_init(pruss_init_module); 236 + 237 + static void __exit pruss_exit_module(void) 238 + { 239 + platform_driver_unregister(&pruss_driver); 240 + } 241 + 242 + module_exit(pruss_exit_module); 243 + 244 + MODULE_LICENSE("GPL v2"); 245 + MODULE_VERSION(DRV_VERSION); 246 + MODULE_AUTHOR("Amit Chatterjee <amit.chatterjee@ti.com>"); 247 + MODULE_AUTHOR("Pratheesh Gangadhar <pratheesh@ti.com>");
+7 -19
fs/debugfs/inode.c
··· 13 13 * 14 14 */ 15 15 16 - /* uncomment to get debug messages from the debug filesystem, ah the irony. */ 17 - /* #define DEBUG */ 18 - 19 16 #include <linux/module.h> 20 17 #include <linux/fs.h> 21 18 #include <linux/mount.h> ··· 307 310 } 308 311 EXPORT_SYMBOL_GPL(debugfs_create_symlink); 309 312 310 - static void __debugfs_remove(struct dentry *dentry, struct dentry *parent) 313 + static int __debugfs_remove(struct dentry *dentry, struct dentry *parent) 311 314 { 312 315 int ret = 0; 313 316 ··· 330 333 dput(dentry); 331 334 } 332 335 } 336 + return ret; 333 337 } 334 338 335 339 /** ··· 349 351 void debugfs_remove(struct dentry *dentry) 350 352 { 351 353 struct dentry *parent; 352 - 354 + int ret; 355 + 353 356 if (!dentry) 354 357 return; 355 358 ··· 359 360 return; 360 361 361 362 mutex_lock(&parent->d_inode->i_mutex); 362 - __debugfs_remove(dentry, parent); 363 + ret = __debugfs_remove(dentry, parent); 363 364 mutex_unlock(&parent->d_inode->i_mutex); 364 - simple_release_fs(&debugfs_mount, &debugfs_mount_count); 365 + if (!ret) 366 + simple_release_fs(&debugfs_mount, &debugfs_mount_count); 365 367 } 366 368 EXPORT_SYMBOL_GPL(debugfs_remove); 367 369 ··· 540 540 541 541 return retval; 542 542 } 543 - 544 - static 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 - 553 543 core_initcall(debugfs_init); 554 - module_exit(debugfs_exit); 555 - MODULE_LICENSE("GPL"); 556 544
+47
include/linux/dmi.h
··· 23 23 DMI_DEV_TYPE_DEV_ONBOARD = -3, 24 24 }; 25 25 26 + enum 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 + 26 73 struct dmi_header { 27 74 u8 type; 28 75 u8 length;
+7 -1
include/linux/dynamic_debug.h
··· 31 31 * writes commands to <debugfs>/dynamic_debug/control 32 32 */ 33 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 38 #define _DPRINTK_FLAGS_DEFAULT 0 35 39 unsigned int flags:8; 36 40 char enabled; ··· 46 42 47 43 #if defined(CONFIG_DYNAMIC_DEBUG) 48 44 extern int ddebug_remove_module(const char *mod_name); 45 + extern int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...) 46 + __attribute__ ((format (printf, 2, 3))); 49 47 50 48 #define dynamic_pr_debug(fmt, ...) do { \ 51 49 static struct _ddebug descriptor \ ··· 56 50 { KBUILD_MODNAME, __func__, __FILE__, fmt, __LINE__, \ 57 51 _DPRINTK_FLAGS_DEFAULT }; \ 58 52 if (unlikely(descriptor.enabled)) \ 59 - printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \ 53 + __dynamic_pr_debug(&descriptor, pr_fmt(fmt), ##__VA_ARGS__); \ 60 54 } while (0) 61 55 62 56
+37
include/linux/efi.h
··· 397 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 + 408 + struct 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 + 414 + struct 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 + 430 + int register_efivars(struct efivars *efivars, 431 + const struct efivar_operations *ops, 432 + struct kobject *parent_kobj); 433 + void unregister_efivars(struct efivars *efivars); 434 + 435 + #endif /* CONFIG_EFI_VARS */ 436 + 400 437 #endif /* _LINUX_EFI_H */
+2 -2
include/linux/firmware.h
··· 39 39 int request_firmware(const struct firmware **fw, const char *name, 40 40 struct device *device); 41 41 int request_firmware_nowait( 42 - struct module *module, int uevent, 42 + struct module *module, bool uevent, 43 43 const char *name, struct device *device, gfp_t gfp, void *context, 44 44 void (*cont)(const struct firmware *fw, void *context)); 45 45 ··· 52 52 return -EINVAL; 53 53 } 54 54 static inline int request_firmware_nowait( 55 - struct module *module, int uevent, 55 + struct module *module, bool uevent, 56 56 const char *name, struct device *device, gfp_t gfp, void *context, 57 57 void (*cont)(const struct firmware *fw, void *context)) 58 58 {
+6 -4
include/linux/kobject.h
··· 85 85 extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype); 86 86 extern int __must_check kobject_add(struct kobject *kobj, 87 87 struct kobject *parent, 88 - const char *fmt, ...); 88 + const char *fmt, ...) 89 + __attribute__((format(printf, 3, 4))); 89 90 extern int __must_check kobject_init_and_add(struct kobject *kobj, 90 91 struct kobj_type *ktype, 91 92 struct kobject *parent, 92 - const char *fmt, ...); 93 + const char *fmt, ...) 94 + __attribute__((format(printf, 4, 5))); 93 95 94 96 extern void kobject_del(struct kobject *kobj); 95 97 ··· 226 224 char *envp[]) 227 225 { return 0; } 228 226 229 - static inline int add_uevent_var(struct kobj_uevent_env *env, 230 - const char *format, ...) 227 + static inline __attribute__((format(printf, 2, 3))) 228 + int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...) 231 229 { return 0; } 232 230 233 231 static inline int kobject_action_type(const char *buf, size_t count,
+2 -1
include/linux/memory.h
··· 21 21 #include <linux/mutex.h> 22 22 23 23 struct memory_block { 24 - unsigned long phys_index; 24 + unsigned long start_section_nr; 25 + unsigned long end_section_nr; 25 26 unsigned long state; 26 27 int section_count; 27 28
+4 -2
include/linux/node.h
··· 39 39 extern int unregister_cpu_under_node(unsigned int cpu, unsigned int nid); 40 40 extern int register_mem_sect_under_node(struct memory_block *mem_blk, 41 41 int nid); 42 - extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk); 42 + extern int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, 43 + unsigned long phys_index); 43 44 44 45 #ifdef CONFIG_HUGETLBFS 45 46 extern void register_hugetlbfs_with_node(node_registration_func_t doregister, ··· 68 67 { 69 68 return 0; 70 69 } 71 - static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk) 70 + static inline int unregister_mem_sect_under_nodes(struct memory_block *mem_blk, 71 + unsigned long phys_index) 72 72 { 73 73 return 0; 74 74 }
+25
include/linux/platform_data/uio_pruss.h
··· 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 */ 22 + struct uio_pruss_pdata { 23 + u32 pintc_base; 24 + }; 25 + #endif /* _UIO_PRUSS_H_ */
+9 -2
include/linux/platform_device.h
··· 130 130 extern int platform_driver_probe(struct platform_driver *driver, 131 131 int (*probe)(struct platform_device *)); 132 132 133 - #define platform_get_drvdata(_dev) dev_get_drvdata(&(_dev)->dev) 134 - #define platform_set_drvdata(_dev,data) dev_set_drvdata(&(_dev)->dev, (data)) 133 + static inline void *platform_get_drvdata(const struct platform_device *pdev) 134 + { 135 + return dev_get_drvdata(&pdev->dev); 136 + } 137 + 138 + static inline void platform_set_drvdata(struct platform_device *pdev, void *data) 139 + { 140 + dev_set_drvdata(&pdev->dev, data); 141 + } 135 142 136 143 extern struct platform_device *platform_create_bundle(struct platform_driver *driver, 137 144 int (*probe)(struct platform_device *),
+2 -2
init/Kconfig
··· 836 836 bool 837 837 838 838 config 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 840 depends on SYSFS 841 841 default n 842 842 help ··· 859 859 need to say Y here. 860 860 861 861 config SYSFS_DEPRECATED_V2 862 - bool "enabled deprecated sysfs features by default" 862 + bool "Enable deprecated sysfs features by default" 863 863 default n 864 864 depends on SYSFS 865 865 depends on SYSFS_DEPRECATED
+104 -34
kernel/printk.c
··· 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 + */ 531 + static 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 583 * Call the console drivers, asking them to write out 519 584 * log_buf[start] to log_buf[end - 1]. 520 585 * The console_lock must be held. ··· 594 529 cur_index = start; 595 530 start_print = start; 596 531 while (cur_index != end) { 597 - if (msg_level < 0 && ((end - cur_index) > 2) && 598 - LOG_BUF(cur_index + 0) == '<' && 599 - LOG_BUF(cur_index + 1) >= '0' && 600 - LOG_BUF(cur_index + 1) <= '7' && 601 - LOG_BUF(cur_index + 2) == '>') { 602 - msg_level = LOG_BUF(cur_index + 1) - '0'; 603 - cur_index += 3; 532 + if (msg_level < 0 && ((end - cur_index) > 2)) { 533 + /* strip log prefix */ 534 + cur_index += log_prefix(&LOG_BUF(cur_index), &msg_level, NULL); 604 535 start_print = cur_index; 605 536 } 606 537 while (cur_index != end) { ··· 794 733 unsigned long flags; 795 734 int this_cpu; 796 735 char *p; 736 + size_t plen; 737 + char special; 797 738 798 739 boot_delay_msec(); 799 740 printk_delay(); ··· 836 773 printed_len += vscnprintf(printk_buf + printed_len, 837 774 sizeof(printk_buf) - printed_len, fmt, args); 838 775 839 - 840 776 p = printk_buf; 841 777 842 - /* Do we have a loglevel in the string? */ 843 - if (p[0] == '<') { 844 - unsigned char c = p[1]; 845 - if (c && p[2] == '>') { 846 - switch (c) { 847 - case '0' ... '7': /* loglevel */ 848 - current_log_level = c - '0'; 849 - /* Fallthrough - make sure we're on a new line */ 850 - case 'd': /* KERN_DEFAULT */ 851 - if (!new_text_line) { 852 - emit_log_char('\n'); 853 - new_text_line = 1; 854 - } 855 - /* Fallthrough - skip the loglevel */ 856 - case 'c': /* KERN_CONT */ 857 - p += 3; 858 - break; 778 + /* Read log level and handle special printk prefix */ 779 + plen = log_prefix(p, &current_log_level, &special); 780 + if (plen) { 781 + p += plen; 782 + 783 + switch (special) { 784 + case 'c': /* Strip <c> KERN_CONT, continue line */ 785 + plen = 0; 786 + break; 787 + case 'd': /* Strip <d> KERN_DEFAULT, start new line */ 788 + plen = 0; 789 + default: 790 + if (!new_text_line) { 791 + emit_log_char('\n'); 792 + new_text_line = 1; 859 793 } 860 794 } 861 795 } 862 796 863 797 /* 864 - * Copy the output into log_buf. If the caller didn't provide 865 - * appropriate log level tags, we insert them here 798 + * Copy the output into log_buf. If the caller didn't provide 799 + * the appropriate log prefix, we insert them here 866 800 */ 867 - for ( ; *p; p++) { 801 + for (; *p; p++) { 868 802 if (new_text_line) { 869 - /* Always output the token */ 870 - emit_log_char('<'); 871 - emit_log_char(current_log_level + '0'); 872 - emit_log_char('>'); 873 - printed_len += 3; 874 803 new_text_line = 0; 875 804 805 + if (plen) { 806 + /* Copy original log prefix */ 807 + int i; 808 + 809 + for (i = 0; i < plen; i++) 810 + emit_log_char(printk_buf[i]); 811 + printed_len += plen; 812 + } else { 813 + /* Add log prefix */ 814 + emit_log_char('<'); 815 + emit_log_char(current_log_level + '0'); 816 + emit_log_char('>'); 817 + printed_len += 3; 818 + } 819 + 876 820 if (printk_time) { 877 - /* Follow the token with the time */ 821 + /* Add the current time stamp */ 878 822 char tbuf[50], *tp; 879 823 unsigned tlen; 880 824 unsigned long long t;
+52 -9
lib/dynamic_debug.c
··· 7 7 * Copyright (C) 2008 Jason Baron <jbaron@redhat.com> 8 8 * By Greg Banks <gnb@melbourne.sgi.com> 9 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 13 #include <linux/kernel.h> ··· 28 27 #include <linux/debugfs.h> 29 28 #include <linux/slab.h> 30 29 #include <linux/jump_label.h> 30 + #include <linux/hardirq.h> 31 + #include <linux/sched.h> 31 32 32 33 extern struct _ddebug __start___verbose[]; 33 34 extern struct _ddebug __stop___verbose[]; ··· 66 63 return tail ? tail+1 : path; 67 64 } 68 65 66 + static struct { unsigned flag:8; char opt_char; } opt_array[] = { 67 + { _DPRINTK_FLAGS_PRINT, 'p' }, 68 + { _DPRINTK_FLAGS_INCL_MODNAME, 'm' }, 69 + { _DPRINTK_FLAGS_INCL_FUNCNAME, 'f' }, 70 + { _DPRINTK_FLAGS_INCL_LINENO, 'l' }, 71 + { _DPRINTK_FLAGS_INCL_TID, 't' }, 72 + }; 73 + 69 74 /* format a string into buf[] which describes the _ddebug's flags */ 70 75 static char *ddebug_describe_flags(struct _ddebug *dp, char *buf, 71 76 size_t maxlen) 72 77 { 73 78 char *p = buf; 79 + int i; 74 80 75 81 BUG_ON(maxlen < 4); 76 - if (dp->flags & _DPRINTK_FLAGS_PRINT) 77 - *p++ = 'p'; 82 + for (i = 0; i < ARRAY_SIZE(opt_array); ++i) 83 + if (dp->flags & opt_array[i].flag) 84 + *p++ = opt_array[i].opt_char; 78 85 if (p == buf) 79 86 *p++ = '-'; 80 87 *p = '\0'; ··· 356 343 unsigned int *maskp) 357 344 { 358 345 unsigned flags = 0; 359 - int op = '='; 346 + int op = '=', i; 360 347 361 348 switch (*str) { 362 349 case '+': ··· 371 358 printk(KERN_INFO "%s: op='%c'\n", __func__, op); 372 359 373 360 for ( ; *str ; ++str) { 374 - switch (*str) { 375 - case 'p': 376 - flags |= _DPRINTK_FLAGS_PRINT; 377 - break; 378 - default: 379 - return -EINVAL; 361 + for (i = ARRAY_SIZE(opt_array) - 1; i >= 0; i--) { 362 + if (*str == opt_array[i].opt_char) { 363 + flags |= opt_array[i].flag; 364 + break; 365 + } 380 366 } 367 + if (i < 0) 368 + return -EINVAL; 381 369 } 382 370 if (flags == 0) 383 371 return -EINVAL; ··· 426 412 ddebug_change(&query, flags, mask); 427 413 return 0; 428 414 } 415 + 416 + int __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...) 417 + { 418 + va_list args; 419 + int res; 420 + 421 + BUG_ON(!descriptor); 422 + BUG_ON(!fmt); 423 + 424 + va_start(args, fmt); 425 + res = printk(KERN_DEBUG); 426 + if (descriptor->flags & _DPRINTK_FLAGS_INCL_TID) { 427 + if (in_interrupt()) 428 + res += printk(KERN_CONT "<intr> "); 429 + else 430 + res += printk(KERN_CONT "[%d] ", task_pid_vnr(current)); 431 + } 432 + if (descriptor->flags & _DPRINTK_FLAGS_INCL_MODNAME) 433 + res += printk(KERN_CONT "%s:", descriptor->modname); 434 + if (descriptor->flags & _DPRINTK_FLAGS_INCL_FUNCNAME) 435 + res += printk(KERN_CONT "%s:", descriptor->function); 436 + if (descriptor->flags & _DPRINTK_FLAGS_INCL_LINENO) 437 + res += printk(KERN_CONT "%d ", descriptor->lineno); 438 + res += vprintk(fmt, args); 439 + va_end(args); 440 + 441 + return res; 442 + } 443 + EXPORT_SYMBOL(__dynamic_pr_debug); 429 444 430 445 static __initdata char ddebug_setup_string[1024]; 431 446 static __init int ddebug_setup_query(char *str)