aboutsummaryrefslogtreecommitdiffstats
path: root/meta-seattle/recipes-kernel/linux/files/412-1-styx-linux-tracking.git-2a3f98071e81b66033f6272f6c632023d1dcb1d2.patch
blob: 1f392a48ba78b1d1a40a72ce32d105325351c0a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
From 2f12ab9f8409067cd3a977994659c1a0e8f3088b Mon Sep 17 00:00:00 2001
From: Adrian Calianu <adrian.calianu@enea.com>
Date: Mon, 10 Aug 2015 17:19:12 +0200
Subject: [PATCH] Subject: [PATCH] ACPI / scan: Add support for ACPI _CLS
 device matching

Device drivers typically use ACPI _HIDs/_CIDs listed in struct device_driver
acpi_match_table to match devices. However, for generic drivers, we do not
want to list _HID for all supported devices. Also, certain classes of devices
do not have _CID (e.g. SATA, USB). Instead, we can leverage ACPI _CLS,
which specifies PCI-defined class code (i.e. base-class, subclass and
programming interface). This patch adds support for matching ACPI devices using
the _CLS method.

To support loadable module, current design uses _HID or _CID to match device's
modalias. With the new way of matching with _CLS this would requires modification
to the current ACPI modalias key to include _CLS. This patch appends PCI-defined
class-code to the existing ACPI modalias as following.

    acpi:<HID>:<CID1>:<CID2>:..:<CIDn>:<bbsspp>:
E.g:
    # cat /sys/devices/platform/AMDI0600:00/modalias
    acpi:AMDI0600:010601:

where bb is th base-class code, ss is te sub-class code, and pp is the
programming interface code

Since there would not be _HID/_CID in the ACPI matching table of the driver,
this patch adds a field to acpi_device_id to specify the matching _CLS.

    static const struct acpi_device_id ahci_acpi_match[] = {
        { "", 0, PCI_CLASS_STORAGE_SATA_AHCI },
        {},
    };

In this case, the corresponded entry in modules.alias file would be:

    alias acpi*:010601:* ahci_platform

Signed-off-by: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>

Upstream-Status: Pending

Ported from 3.19 kernel, patch provided by AMD.

Signed-off-by: Adrian Calianu <adrian.calianu@enea.com>
---
 drivers/acpi/acpica/acutils.h     |  3 ++
 drivers/acpi/acpica/nsxfname.c    | 21 ++++++++++--
 drivers/acpi/acpica/utids.c       | 71 +++++++++++++++++++++++++++++++++++++++
 drivers/acpi/scan.c               | 20 ++++++++---
 include/acpi/acnames.h            |  1 +
 include/acpi/actypes.h            |  4 ++-
 include/linux/mod_devicetable.h   |  1 +
 scripts/mod/devicetable-offsets.c |  1 +
 scripts/mod/file2alias.c          | 14 ++++++--
 9 files changed, 126 insertions(+), 10 deletions(-)

diff --git a/drivers/acpi/acpica/acutils.h b/drivers/acpi/acpica/acutils.h
index 2b3c5bd..218ddfd 100644
--- a/drivers/acpi/acpica/acutils.h
+++ b/drivers/acpi/acpica/acutils.h
@@ -430,6 +430,9 @@ acpi_status
 acpi_ut_execute_CID(struct acpi_namespace_node *device_node,
 		    struct acpi_pnp_device_id_list ** return_cid_list);
 
+acpi_status
+acpi_ut_execute_CLS(struct acpi_namespace_node *device_node,
+           struct acpi_pnp_device_id **return_id);
 /*
  * utlock - reader/writer locks
  */
diff --git a/drivers/acpi/acpica/nsxfname.c b/drivers/acpi/acpica/nsxfname.c
index d66c326..3754db5 100644
--- a/drivers/acpi/acpica/nsxfname.c
+++ b/drivers/acpi/acpica/nsxfname.c
@@ -276,11 +276,12 @@ acpi_get_object_info(acpi_handle handle,
 	struct acpi_pnp_device_id *hid = NULL;
 	struct acpi_pnp_device_id *uid = NULL;
 	struct acpi_pnp_device_id *sub = NULL;
+    struct acpi_pnp_device_id *cls = NULL;
 	char *next_id_string;
 	acpi_object_type type;
 	acpi_name name;
 	u8 param_count = 0;
-	u8 valid = 0;
+    u16 valid = 0;
 	u32 info_size;
 	u32 i;
 	acpi_status status;
@@ -320,7 +321,7 @@ acpi_get_object_info(acpi_handle handle,
 	if ((type == ACPI_TYPE_DEVICE) || (type == ACPI_TYPE_PROCESSOR)) {
 		/*
 		 * Get extra info for ACPI Device/Processor objects only:
-		 * Run the Device _HID, _UID, _SUB, and _CID methods.
+         * Run the Device _HID, _UID, _SUB, _CID and _CLS methods.
 		 *
 		 * Note: none of these methods are required, so they may or may
 		 * not be present for this device. The Info->Valid bitfield is used
@@ -351,6 +352,14 @@ acpi_get_object_info(acpi_handle handle,
 			valid |= ACPI_VALID_SUB;
 		}
 
+        /* Execute the Device._CLS method */
+
+        status = acpi_ut_execute_CLS(node, &cls);
+        if (ACPI_SUCCESS(status)) {
+            info_size += cls->length;
+            valid |= ACPI_VALID_CLS;
+        }
+
 		/* Execute the Device._CID method */
 
 		status = acpi_ut_execute_CID(node, &cid_list);
@@ -468,6 +477,11 @@ acpi_get_object_info(acpi_handle handle,
 							sub, next_id_string);
 	}
 
+    if (cls) {
+        next_id_string = acpi_ns_copy_device_id(&info->cls,
+                            cls, next_id_string);
+    }
+
 	if (cid_list) {
 		info->compatible_id_list.count = cid_list->count;
 		info->compatible_id_list.list_size = cid_list->list_size;
@@ -510,6 +524,9 @@ cleanup:
 	if (cid_list) {
 		ACPI_FREE(cid_list);
 	}
+    if (cls) {
+        ACPI_FREE(cls);
+    }
 	return (status);
 }
 
diff --git a/drivers/acpi/acpica/utids.c b/drivers/acpi/acpica/utids.c
index 27431cf..bc77122 100644
--- a/drivers/acpi/acpica/utids.c
+++ b/drivers/acpi/acpica/utids.c
@@ -416,3 +416,74 @@ cleanup:
 	acpi_ut_remove_reference(obj_desc);
 	return_ACPI_STATUS(status);
 }
+
+/*******************************************************************************
+ *
+ * FUNCTION:    acpi_ut_execute_CLS
+ *
+ * PARAMETERS:  device_node         - Node for the device
+ *              return_id           - Where the string UID is returned
+ *
+ * RETURN:      Status
+ *
+ * DESCRIPTION: Executes the _CLS control method that returns PCI-defined
+ *              class code of the device. The ACPI spec define _CLS as a
+ *              package with three integers. The returned string has format:
+ *
+ *                      "bbsspp"
+ *              where:
+ *                  bb = Base-class code
+ *                  ss = Sub-class code
+ *                  pp = Programming Interface code
+ *
+ ******************************************************************************/
+
+acpi_status
+acpi_ut_execute_CLS(struct acpi_namespace_node *device_node,
+           struct acpi_pnp_device_id **return_id)
+{
+   struct acpi_pnp_device_id *cls;
+   union acpi_operand_object *obj_desc;
+   union acpi_operand_object **cls_objects;
+   acpi_status status;
+
+   ACPI_FUNCTION_TRACE(ut_execute_CLS);
+   status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CLS,
+                    ACPI_BTYPE_PACKAGE, &obj_desc);
+   if (ACPI_FAILURE(status))
+       return_ACPI_STATUS(status);
+
+   cls_objects = obj_desc->package.elements;
+
+   if (obj_desc->common.type == ACPI_TYPE_PACKAGE &&
+       obj_desc->package.count == 3 &&
+       cls_objects[0]->common.type == ACPI_TYPE_INTEGER &&
+       cls_objects[1]->common.type == ACPI_TYPE_INTEGER &&
+       cls_objects[2]->common.type == ACPI_TYPE_INTEGER) {
+
+       /* Allocate a buffer for the CLS */
+       cls = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pnp_device_id) +
+                    (acpi_size) 7);
+       if (!cls) {
+           status = AE_NO_MEMORY;
+           goto cleanup;
+       }
+
+       cls->string =
+           ACPI_ADD_PTR(char, cls, sizeof(struct acpi_pnp_device_id));
+
+       sprintf(cls->string, "%02x%02x%02x",
+           (u8)ACPI_TO_INTEGER(cls_objects[0]->integer.value),
+           (u8)ACPI_TO_INTEGER(cls_objects[1]->integer.value),
+           (u8)ACPI_TO_INTEGER(cls_objects[2]->integer.value));
+       cls->length = 7;
+       *return_id = cls;
+   }
+
+cleanup:
+
+   /* On exit, we must delete the return object */
+
+   acpi_ut_remove_reference(obj_desc);
+   return_ACPI_STATUS(status);
+}
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index 03141aa..ca6297b1 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -1031,11 +1031,18 @@ static const struct acpi_device_id *__acpi_match_device(
 	if (!device || !device->status.present)
 		return NULL;
 
-	list_for_each_entry(hwid, &device->pnp.ids, list) {
-		/* First, check the ACPI/PNP IDs provided by the caller. */
-		for (id = ids; id->id[0]; id++)
-			if (!strcmp((char *) id->id, hwid->id))
-				return id;
+    list_for_each_entry(hwid, &device->pnp.ids, list) {
+        for (id = ids; id->id[0] || id->cls; id++) {
+            if (id->id[0] && !strcmp((char *) id->id, hwid->id)) {
+                return id;
+            } else if (id->cls) {
+                char buf[7];
+
+                sprintf(buf, "%06x", id->cls);
+                if (!strcmp(buf, hwid->id))
+                    return id;
+            }
+        }
 
 		/*
 		 * Next, check the special "PRP0001" ID and try to match the
@@ -2057,6 +2064,9 @@ static void acpi_set_pnp_ids(acpi_handle handle, struct acpi_device_pnp *pnp,
 			pnp->unique_id = kstrdup(info->unique_id.string,
 							GFP_KERNEL);
 
+       if (info->valid & ACPI_VALID_CLS)
+           acpi_add_id(pnp, info->cls.string);
+
 		kfree(info);
 
 		/*
diff --git a/include/acpi/acnames.h b/include/acpi/acnames.h
index 273de70..b52c0dc 100644
--- a/include/acpi/acnames.h
+++ b/include/acpi/acnames.h
@@ -51,6 +51,7 @@
 #define METHOD_NAME__BBN        "_BBN"
 #define METHOD_NAME__CBA        "_CBA"
 #define METHOD_NAME__CID        "_CID"
+#define METHOD_NAME__CLS        "_CLS"
 #define METHOD_NAME__CRS        "_CRS"
 #define METHOD_NAME__DDN        "_DDN"
 #define METHOD_NAME__HID        "_HID"
diff --git a/include/acpi/actypes.h b/include/acpi/actypes.h
index 1c3002e..0ad0c61 100644
--- a/include/acpi/actypes.h
+++ b/include/acpi/actypes.h
@@ -1166,7 +1166,7 @@ struct acpi_device_info {
 	u32 name;		/* ACPI object Name */
 	acpi_object_type type;	/* ACPI object Type */
 	u8 param_count;		/* If a method, required parameter count */
-	u8 valid;		/* Indicates which optional fields are valid */
+	u16 valid;		/* Indicates which optional fields are valid */
 	u8 flags;		/* Miscellaneous info */
 	u8 highest_dstates[4];	/* _sx_d values: 0xFF indicates not valid */
 	u8 lowest_dstates[5];	/* _sx_w values: 0xFF indicates not valid */
@@ -1175,6 +1175,7 @@ struct acpi_device_info {
 	struct acpi_pnp_device_id hardware_id;	/* _HID value */
 	struct acpi_pnp_device_id unique_id;	/* _UID value */
 	struct acpi_pnp_device_id subsystem_id;	/* _SUB value */
+    struct acpi_pnp_device_id cls;      /* _CLS value */
 	struct acpi_pnp_device_id_list compatible_id_list;	/* _CID list <must be last> */
 };
 
@@ -1192,6 +1193,7 @@ struct acpi_device_info {
 #define ACPI_VALID_CID                  0x20
 #define ACPI_VALID_SXDS                 0x40
 #define ACPI_VALID_SXWS                 0x80
+#define ACPI_VALID_CLS                  0x100
 
 /* Flags for _STA return value (current_status above) */
 
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index 3bfd567..8a958d1 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -35,6 +35,7 @@ struct ieee1394_device_id {
 	__u32 specifier_id;
 	__u32 version;
 	kernel_ulong_t driver_data;
+    __u32 cls;
 };
 
 
diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c
index fce36d0..aac0be3 100644
--- a/scripts/mod/devicetable-offsets.c
+++ b/scripts/mod/devicetable-offsets.c
@@ -63,6 +63,7 @@ int main(void)
 
 	DEVID(acpi_device_id);
 	DEVID_FIELD(acpi_device_id, id);
+    DEVID_FIELD(acpi_device_id, cls);
 
 	DEVID(pnp_device_id);
 	DEVID_FIELD(pnp_device_id, id);
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 78691d5..f5599ad 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -511,12 +511,22 @@ static int do_serio_entry(const char *filename,
 }
 ADD_TO_DEVTABLE("serio", serio_device_id, do_serio_entry);
 
-/* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */
+/* looks like: "acpi:ACPI0003" or "acpi:PNP0C0B"  or "acpi:LNXVIDEO" or
+ *             "acpi:bbsspp" (bb=base-class, ss=sub-class, pp=prog-if)
+ *
+ * NOTE: * Each driver should use one of the following : _HID, _CIDs or _CLS.
+ */
 static int do_acpi_entry(const char *filename,
 			void *symval, char *alias)
 {
 	DEF_FIELD_ADDR(symval, acpi_device_id, id);
-	sprintf(alias, "acpi*:%s:*", *id);
+    DEF_FIELD_ADDR(symval, acpi_device_id, cls);
+
+    if (id && strlen((const char *)*id))
+        sprintf(alias, "acpi*:%s:*", *id);
+    else if (cls)
+        sprintf(alias, "acpi*:%06x:*", *cls);
+
 	return 1;
 }
 ADD_TO_DEVTABLE("acpi", acpi_device_id, do_acpi_entry);
-- 
1.9.1