Skip to content

Commit e647b53

Browse files
Marc Zyngierrafaeljw
authored andcommitted
ACPI: Add early device probing infrastructure
IRQ controllers and timers are the two types of device the kernel requires before being able to use the device driver model. ACPI so far lacks a proper probing infrastructure similar to the one we have with DT, where we're able to declare IRQ chips and clocksources inside the driver code, and let the core code pick it up and call us back on a match. This leads to all kind of really ugly hacks all over the arm64 code and even in the ACPI layer. In order to allow some basic probing based on the ACPI tables, introduce "struct acpi_probe_entry" which contains just enough data and callbacks to match a table, an optional subtable, and call a probe function. A driver can, at build time, register itself and expect being called if the right entry exists in the ACPI table. A acpi_probe_device_table() is provided, taking an identifier for a set of acpi_prove_entries, and iterating over the registered entries. Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Reviewed-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Reviewed-by: Hanjun Guo <hanjun.guo@linaro.org> Acked-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Hanjun Guo <hanjun.guo@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 2337824 commit e647b53

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

drivers/acpi/scan.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,3 +1913,42 @@ int __init acpi_scan_init(void)
19131913
mutex_unlock(&acpi_scan_lock);
19141914
return result;
19151915
}
1916+
1917+
static struct acpi_probe_entry *ape;
1918+
static int acpi_probe_count;
1919+
static DEFINE_SPINLOCK(acpi_probe_lock);
1920+
1921+
static int __init acpi_match_madt(struct acpi_subtable_header *header,
1922+
const unsigned long end)
1923+
{
1924+
if (!ape->subtable_valid || ape->subtable_valid(header, ape))
1925+
if (!ape->probe_subtbl(header, end))
1926+
acpi_probe_count++;
1927+
1928+
return 0;
1929+
}
1930+
1931+
int __init __acpi_probe_device_table(struct acpi_probe_entry *ap_head, int nr)
1932+
{
1933+
int count = 0;
1934+
1935+
if (acpi_disabled)
1936+
return 0;
1937+
1938+
spin_lock(&acpi_probe_lock);
1939+
for (ape = ap_head; nr; ape++, nr--) {
1940+
if (ACPI_COMPARE_NAME(ACPI_SIG_MADT, ape->id)) {
1941+
acpi_probe_count = 0;
1942+
acpi_table_parse_madt(ape->type, acpi_match_madt, 0);
1943+
count += acpi_probe_count;
1944+
} else {
1945+
int res;
1946+
res = acpi_table_parse(ape->id, ape->probe_table);
1947+
if (!res)
1948+
count++;
1949+
}
1950+
}
1951+
spin_unlock(&acpi_probe_lock);
1952+
1953+
return count;
1954+
}

include/asm-generic/vmlinux.lds.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,16 @@
181181
#define CPUIDLE_METHOD_OF_TABLES() OF_TABLE(CONFIG_CPU_IDLE, cpuidle_method)
182182
#define EARLYCON_OF_TABLES() OF_TABLE(CONFIG_SERIAL_EARLYCON, earlycon)
183183

184+
#ifdef CONFIG_ACPI
185+
#define ACPI_PROBE_TABLE(name) \
186+
. = ALIGN(8); \
187+
VMLINUX_SYMBOL(__##name##_acpi_probe_table) = .; \
188+
*(__##name##_acpi_probe_table) \
189+
VMLINUX_SYMBOL(__##name##_acpi_probe_table_end) = .;
190+
#else
191+
#define ACPI_PROBE_TABLE(name)
192+
#endif
193+
184194
#define KERNEL_DTB() \
185195
STRUCT_ALIGN(); \
186196
VMLINUX_SYMBOL(__dtb_start) = .; \

include/linux/acpi.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,61 @@ int acpi_dev_prop_read(struct acpi_device *adev, const char *propname,
773773

774774
struct fwnode_handle *acpi_get_next_subnode(struct device *dev,
775775
struct fwnode_handle *subnode);
776+
777+
struct acpi_probe_entry;
778+
typedef bool (*acpi_probe_entry_validate_subtbl)(struct acpi_subtable_header *,
779+
struct acpi_probe_entry *);
780+
781+
#define ACPI_TABLE_ID_LEN 5
782+
783+
/**
784+
* struct acpi_probe_entry - boot-time probing entry
785+
* @id: ACPI table name
786+
* @type: Optional subtable type to match
787+
* (if @id contains subtables)
788+
* @subtable_valid: Optional callback to check the validity of
789+
* the subtable
790+
* @probe_table: Callback to the driver being probed when table
791+
* match is successful
792+
* @probe_subtbl: Callback to the driver being probed when table and
793+
* subtable match (and optional callback is successful)
794+
* @driver_data: Sideband data provided back to the driver
795+
*/
796+
struct acpi_probe_entry {
797+
__u8 id[ACPI_TABLE_ID_LEN];
798+
__u8 type;
799+
acpi_probe_entry_validate_subtbl subtable_valid;
800+
union {
801+
acpi_tbl_table_handler probe_table;
802+
acpi_tbl_entry_handler probe_subtbl;
803+
};
804+
kernel_ulong_t driver_data;
805+
};
806+
807+
#define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, subtable, valid, data, fn) \
808+
static const struct acpi_probe_entry __acpi_probe_##name \
809+
__used __section(__##table##_acpi_probe_table) \
810+
= { \
811+
.id = table_id, \
812+
.type = subtable, \
813+
.subtable_valid = valid, \
814+
.probe_table = (acpi_tbl_table_handler)fn, \
815+
.driver_data = data, \
816+
}
817+
818+
#define ACPI_PROBE_TABLE(name) __##name##_acpi_probe_table
819+
#define ACPI_PROBE_TABLE_END(name) __##name##_acpi_probe_table_end
820+
821+
int __acpi_probe_device_table(struct acpi_probe_entry *start, int nr);
822+
823+
#define acpi_probe_device_table(t) \
824+
({ \
825+
extern struct acpi_probe_entry ACPI_PROBE_TABLE(t), \
826+
ACPI_PROBE_TABLE_END(t); \
827+
__acpi_probe_device_table(&ACPI_PROBE_TABLE(t), \
828+
(&ACPI_PROBE_TABLE_END(t) - \
829+
&ACPI_PROBE_TABLE(t))); \
830+
})
776831
#else
777832
static inline int acpi_dev_get_property(struct acpi_device *adev,
778833
const char *name, acpi_object_type type,
@@ -831,6 +886,17 @@ static inline struct fwnode_handle *acpi_get_next_subnode(struct device *dev,
831886
{
832887
return NULL;
833888
}
889+
890+
#define ACPI_DECLARE_PROBE_ENTRY(table, name, table_id, subtable, validate, data, fn) \
891+
static const void * __acpi_table_##name[] \
892+
__attribute__((unused)) \
893+
= { (void *) table_id, \
894+
(void *) subtable, \
895+
(void *) valid, \
896+
(void *) fn, \
897+
(void *) data }
898+
899+
#define acpi_probe_device_table(t) ({ int __r = 0; __r;})
834900
#endif
835901

836902
#endif /*_LINUX_ACPI_H*/

0 commit comments

Comments
 (0)