aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/fwnode.h
blob: c28ccdf4c86b721da0d3c5d1b7a7d9c00c186d54 (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
/*
 * fwnode.h - Firmware device node object handle type definition.
 *
 * Copyright (C) 2015, Intel Corporation
 * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef _LINUX_FWNODE_H_
#define _LINUX_FWNODE_H_

#include <linux/device.h>

enum fwnode_type {
	FWNODE_INVALID = 0,
	FWNODE_OF,
	FWNODE_ACPI,
	FWNODE_ACPI_DATA,
	FWNODE_PDATA,
};

struct fwnode_handle {
	enum fwnode_type type;
	struct fwnode_handle *secondary;
};

/*
 * Prior to this code being introduced, device_rh was allocated in
 * device_add().  This seemed correct as there were no users of the elements of
 * device_rh prior to the device_add.  This is no longer true with the addition
 * of the fwnode code.  The functions below will check and WARN loudly on
 * uses of device_rh prior to it being initialized.  These warnings are
 * Red Hat bugs and should be filed against RHEL7.
 */
static inline struct fwnode_handle *get_rh_dev_fwnode(struct device *device)
{
	if (!device->device_rh) {
		WARN(1, "device_rh is not allocated on get ... fixing\n");
		device_rh_alloc(device);
	}
	return device->device_rh->fwnode;
}

static inline void set_rh_dev_fwnode(struct device *device,
				     struct fwnode_handle *fwnode)
{
	if (!device->device_rh) {
		WARN(1, "device_rh is not allocated on set ... fixing\n");
		device_rh_alloc(device);
	}
	device->device_rh->fwnode = fwnode;
}
#endif