From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 18/18] include: add linux/device.h wrapper around driver.h
Date: Fri, 10 Nov 2023 22:44:21 +0100 [thread overview]
Message-ID: <20231110214421.2726093-19-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20231110214421.2726093-1-a.fatoum@pengutronix.de>
We don't have device-scoped resource control and in practice memory
allocated in device functions is only freed when barebox terminates, so
let's accept the fact that most code is leaky and implement devm_
as literal leaky abstractions.
While at it provide some macros to translate Linux API into equivalent
barebox API.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
include/linux/device.h | 66 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+)
create mode 100644 include/linux/device.h
diff --git a/include/linux/device.h b/include/linux/device.h
new file mode 100644
index 000000000000..0bd61154ac30
--- /dev/null
+++ b/include/linux/device.h
@@ -0,0 +1,66 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef LINUX_DRIVER_H_
+#define LINUX_DRIVER_H_
+
+#include <driver.h>
+#include <linux/slab.h>
+#include <linux/bug.h>
+#include <mmu.h>
+
+#define device_driver driver
+
+#define __devm_wrapper(fn, dev, ...) ({ BUG_ON(!dev); fn(__VA_ARGS__); })
+
+#define devm_kmalloc(...) __devm_wrapper(kmalloc, __VA_ARGS__)
+#define devm_krealloc(...) __devm_wrapper(krealloc, __VA_ARGS__)
+#define devm_kvasprintf(...) __devm_wrapper(kvasprintf, __VA_ARGS__)
+#define devm_kasprintf(...) __devm_wrapper(kasprintf, __VA_ARGS__)
+#define devm_kzalloc(...) __devm_wrapper(kzalloc, __VA_ARGS__)
+#define devm_kmalloc_array(...) __devm_wrapper(kmalloc_array, __VA_ARGS__)
+#define devm_kcalloc(...) __devm_wrapper(kcalloc, __VA_ARGS__)
+#define devm_krealloc_array(...) __devm_wrapper(krealloc_array, __VA_ARGS__)
+#define devm_kfree(...) __devm_wrapper(kfree, __VA_ARGS__)
+#define devm_kstrdup(...) __devm_wrapper(kstrdup, __VA_ARGS__)
+#define devm_kstrdup_const(...) __devm_wrapper(kstrdup_const, __VA_ARGS__)
+#define devm_kmemdup(...) __devm_wrapper(kmemdup, __VA_ARGS__)
+#define devm_bitmap_zalloc(dev, nbits, gfp) \
+ __devm_wrapper(bitmap_zalloc, dev, nbits)
+
+#define device_register register_device
+#define device_unregister unregister_device
+
+#define driver_register register_driver
+#define driver_unregister unregister_driver
+
+static inline void __iomem *devm_ioremap(struct device *dev,
+ resource_size_t start,
+ resource_size_t size)
+{
+ if (start)
+ remap_range((void *)start, size, MAP_UNCACHED);
+
+ return IOMEM(start);
+}
+
+static inline int bus_for_each_dev(const struct bus_type *bus, struct device *start, void *data,
+ int (*fn)(struct device *dev, void *data))
+{
+ struct device *dev;
+ int ret;
+
+ bus_for_each_device(bus, dev) {
+ if (start) {
+ if (dev == start)
+ start = NULL;
+ continue;
+ }
+
+ ret = fn(dev, data);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+#endif
--
2.39.2
prev parent reply other threads:[~2023-11-10 22:05 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 21:44 [PATCH 00/18] prepare for porting OP-TEE communication support Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 01/18] include: provide linux/errno.h Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 02/18] include: add linux/refcount.h Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 03/18] bitops: split off linux/bits.h Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 04/18] include: import <linux/instruction_pointer.h> Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 05/18] asm-generic: split off typeconfused readl and friends Ahmad Fatoum
2023-11-13 12:40 ` Sascha Hauer
2023-11-10 21:44 ` [PATCH 06/18] asm-generic: migrate relaxed helpers into asm-generic/io.h Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 07/18] include: add linux/io.h with strict prototypes Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 08/18] include: import Linux word-at-a-time.h Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 09/18] string: implement strscpy Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 10/18] of: add CONFIG_OF for Linux compatibility Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 11/18] include: asm-generic/atomic.h: define atomic_cmpxchg Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 12/18] kbuild: build barebox for -std=gnu11 Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 13/18] include: linux/idr.h: implement more Linux API Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 14/18] include: implement dev_warn_once and friends Ahmad Fatoum
2023-11-13 12:38 ` Sascha Hauer
2023-11-10 21:44 ` [PATCH 15/18] include: add blocking notifier aliases Ahmad Fatoum
2023-11-13 12:39 ` Sascha Hauer
2023-11-10 21:44 ` [PATCH 16/18] include: add Linux ktime API Ahmad Fatoum
2023-11-10 21:44 ` [PATCH 17/18] of: define of_devices_ensure_probed_by_compatible Ahmad Fatoum
2023-11-13 12:47 ` Sascha Hauer
2023-11-10 21:44 ` Ahmad Fatoum [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231110214421.2726093-19-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox