[coreboot-gerrit] New patch to review for coreboot: 50ca10d util: Add script and to extract drm_dp_helper form linux sources

Alexandru Gagniuc (mr.nuke.me@gmail.com) gerrit at coreboot.org
Tue Jan 13 21:21:45 CET 2015


Alexandru Gagniuc (mr.nuke.me at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/8210

-gerrit

commit 50ca10d60273d6c85e12d90fb786d91790c26a89
Author: Alexandru Gagniuc <mr.nuke.me at gmail.com>
Date:   Tue Jan 13 14:11:43 2015 -0600

    util: Add script and to extract drm_dp_helper form linux sources
    
    <NOTFOTMERGE>
    Feel free to edit commit msg and merge if you really want this.
    
    This gets the job mostly done. There are still some minor details to
    work out, but I wanted to publish this in case there are any
    interested parties.
    </NOTFOTMERGE>
    
    There already is a version of the drm_dp_helper in the intel gma
    driver, but that one is a severely gilded version. Most importantly,
    it's missing the I2C over AUX helpers, which we plan to use for
    radeon native init.
    
    The semantic patch introduced in this allows extracting those helpers
    without removing too much functionality. It converts include
    directives to point to files in our path, and modifies the i2c message
    structure to match the one e use in coreboot.
    
    The result is pretty close to something that compiles out-of-the box,
    tough minor manual editing may still be needed (emphasis on minor).
    
    Change-Id: Ia8c9879595528b6fd63437fed3b555e9e47ecf7f
    Signed-off-by: Alexandru Gagniuc <mr.nuke.me at gmail.com>
---
 .../drm_dp_helper/dp_helper.spatch                 | 191 +++++++++++++++++++++
 .../drm_dp_helper/extract_dp_helper.sh             |  30 ++++
 util/linux_source_extractors/drm_dp_helper/moo.h   |  16 ++
 3 files changed, 237 insertions(+)

diff --git a/util/linux_source_extractors/drm_dp_helper/dp_helper.spatch b/util/linux_source_extractors/drm_dp_helper/dp_helper.spatch
new file mode 100644
index 0000000..0a1b962
--- /dev/null
+++ b/util/linux_source_extractors/drm_dp_helper/dp_helper.spatch
@@ -0,0 +1,191 @@
+/*
+ * Convert drm_dp_helpers in linux from linux-centric to coreboot friendly.
+ *
+ * Note: You want to run the extract_dp_helper.sh script. It's much friendlier,
+ * and does almost everything for you.
+ */
+
+/* We don't use these ever */
+@ remove_bad_funcs @
+identifier func =~ "drm_dp_aux_unregister|drm_dp_aux_register|drm_dp_i2c_functionality";
+@@
+
+- func(...)
+- {
+- ...
+- }
+
+@ remove_export_symbol @
+declarer name EXPORT_SYMBOL;
+@@
+
+- EXPORT_SYMBOL(...);
+
+/* Some functions are found in coreboot headers */
+@ convert_includes_to_coreboot @
+@@
+
+(
+- #include <linux/types.h>
++ #include <stdbool.h>
++ #include <stddef.h>
++ #include <stdint.h>
++ #include <unistd.h>
+|
+- #include <linux/delay.h>
++ #include <delay.h>
+|
+- #include <drm/drm_dp_helper.h>
++ #include "drm_dp_helper.h"
+)
+
+/* The remaining linux includes, we don't give care about */
+@ kill_linux_includes @
+@@
+
+(
+- #include <linux/...>
+|
+- #include <drm/drmP.h>
+)
+
+/* Hey, what do you know! We only use u8. */
+@ convert_to_stdint @
+typedef u8;
+typedef uint8_t;
+typedef uint32_t;
+@@
+
+(
+- u8
++ uint8_t
+|
+/* A character is not an integer!!! God damn programmers */
+- unsigned char
++ uint8_t
+|
+/* How big is a long? Is it 32-bits, is it 64? Fuck that! Use a better type */
+- unsigned long
++ uint32_t
+)
+
+/* We don't use usleep_range() */
+@ usleep_to_delay @
+constant t1, t2;
+@@
+
+- usleep_range(t1, t2);
++ udelay(t1);
+
+@ remove_locks @
+expression lock;
+identifier s, memb;
+@@
+
+(
+- mutex_lock(lock);
+|
+- mutex_unlock(lock);
+|
+- mutex_init(lock);
+|
+struct s {
+...
+- struct mutex memb;
+...
+};
+)
+
+@ remove_superflous_i2c_structs @
+identifier s;
+identifier memb;
+@@
+
+struct s {
+...
+- struct i2c_adapter memb;
+...
+};
+
+/*
+ * This is bad. We might want to change this into the future, but for now,
+ * it allows us to easily integrate this helper into coreboot.
+ */
+@ change_dp_aux_context_type @
+identifier s, dev;
+@@
+
+struct s {
+...
+- struct device *dev;
++ void *parent;
+...
+};
+
+
+@ attribute_packed_fix @
+identifier s;
+//name __packed;
+@@
+
+struct s {
+...
+}
+- __packed
++ __attribute__((packed))
+;
+
+@ remove_bad_structs @
+identifier n;
+@@
+
+- static const struct i2c_algorithm n = {
+- ...
+- };
+
+@ convert_to_coreboot_i2c_struct @
+identifier func, adapter;
+identifier aux;
+@@
+
+func(...,
+- struct i2c_adapter *adapter
++ struct drm_dp_aux *aux
+,...)
+{
+...
+- struct drm_dp_aux *aux = adapter->algo_data;
+...
+}
+
+@ convert_to_coreboot_i2c_msg @
+identifier func, msgs;
+expression i;
+@@
+
+func(...,
+- struct i2c_msg *msgs
++ struct i2c_seg *msgs
+,...)
+{
+<...
+(
+- msgs[i].addr
++ msgs[i].chip
+|
+- msgs[i].flags & I2C_M_RD
++ msgs[i].read
+)
+...>
+}
+
+/* So, this rule doesn't add the prototype. hint: FIXME */
+@ make_i2c_non_static @
+identifier func =~ "drm_dp_i2c_xfer";
+@@
+
+- static
+func(...)
+{
+...
+}
diff --git a/util/linux_source_extractors/drm_dp_helper/extract_dp_helper.sh b/util/linux_source_extractors/drm_dp_helper/extract_dp_helper.sh
new file mode 100644
index 0000000..323ac07
--- /dev/null
+++ b/util/linux_source_extractors/drm_dp_helper/extract_dp_helper.sh
@@ -0,0 +1,30 @@
+#! /bin/bash
+
+#
+# Extract the drm_dp_helper.[ch] files from a linux tree
+# and convert them to a format usable in userspace or coreboot.
+#
+# Usage
+#	sh extract_dp_helper.sh <path/to/linux/sources>
+#
+# It outputs the drm_dp_helper file in the working directory.
+#
+
+DEST=$(pwd)
+HEADER=drm_dp_helper.h
+SOURCE=drm_dp_helper.c
+
+HOME=$(dirname "${BASH_SOURCE[0]}")
+
+SPATCH=spatch
+
+echo Hello
+
+cp $1/include/drm/$HEADER $DEST
+cp $1/drivers/gpu/drm/$SOURCE $DEST
+
+$SPATCH -sp_file $HOME/dp_helper.spatch \
+	--macro-file-builtins $HOME/moo.h \
+	-in_place $DEST/$SOURCE $DEST/$HEADER
+
+echo $PWD
diff --git a/util/linux_source_extractors/drm_dp_helper/moo.h b/util/linux_source_extractors/drm_dp_helper/moo.h
new file mode 100644
index 0000000..6a4b11f
--- /dev/null
+++ b/util/linux_source_extractors/drm_dp_helper/moo.h
@@ -0,0 +1,16 @@
+/*
+ * Empty macro file for our semantic patches. The default macro file is stupid.
+ * It's so stupid in fact, that it defines as nothing things we want to remove.
+ * That prevents us from renaming macros like "__packed". To make sure the
+ * semantic patch works as expected, we override the built-in macro file.
+ *
+ * The cow is here to make sure we don't provide a completely useless file.
+ */
+
+#define __MOO 			\
+	"         (__) \n"	\
+	"         (oo) \n"	\
+	"   /------\/  \n"	\
+	"  / |    ||   \n"	\
+	" *  /\---/\   \n"	\
+	"    ~~   ~~   \n"



More information about the coreboot-gerrit mailing list