summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Skeggs <bskeggs@redhat.com>2016-02-25 07:49:42 +1000
committerBen Skeggs <bskeggs@redhat.com>2016-03-14 09:53:01 +1000
commit97c2aa99f027342dde2cb480215652352a14e685 (patch)
tree5695823ea2d018756abd05e97ec78852fecd4cc2 /lib
parent547bc905af734fddb157419ec61f0b0bae92458b (diff)
downloadnouveau-97c2aa99f027342dde2cb480215652352a14e685.tar.gz
lib: support loading firmware from /lib/firmware
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile1
-rw-r--r--lib/firmware.c67
-rw-r--r--lib/include/nvif/os.h24
3 files changed, 70 insertions, 22 deletions
diff --git a/lib/Makefile b/lib/Makefile
index 11c70a27e..c72ccbe0c 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -28,6 +28,7 @@ drms := $(addprefix $(lib)/, $(nvif-y)) \
$(addprefix $(lib)/, $(nvkm-y))
srcs := $(lib)/bit.o \
$(lib)/drm.o \
+ $(lib)/firmware.o \
$(lib)/intr.o \
$(lib)/main.o \
$(lib)/null.o \
diff --git a/lib/firmware.c b/lib/firmware.c
new file mode 100644
index 000000000..fbcf0e420
--- /dev/null
+++ b/lib/firmware.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2016 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: Ben Skeggs
+ */
+#include <nvif/os.h>
+
+static int
+request_firmware_(const struct firmware **pfw, const char *prefix,
+ const char *name, struct device *dev)
+{
+ struct firmware *fw = *(void **)pfw = malloc(sizeof(*fw));
+ char *path;
+ int fd;
+
+ if (!(path = malloc(strlen(prefix) + strlen(name) + 1)))
+ return -ENOMEM;
+ sprintf(path, "%s%s", prefix, name);
+
+ fd = open(path, O_RDONLY);
+ free(path);
+ if (fd >= 0) {
+ off_t len = lseek(fd, 0, SEEK_END);
+ fw->data = malloc(len);
+ fw->size = pread(fd, fw->data, len, 0);
+ return 0;
+ }
+
+ free(fw);
+ return -EINVAL;
+}
+
+int
+request_firmware(const struct firmware **pfw, const char *name,
+ struct device *dev)
+{
+ if (!request_firmware_(pfw, "/lib/firmware/", name, dev))
+ return 0;
+ if (!request_firmware_(pfw, "", name, dev))
+ return 0;
+ return -EINVAL;
+}
+
+void
+release_firmware(const struct firmware *fw)
+{
+ free(fw->data);
+ free((void *)fw);
+}
diff --git a/lib/include/nvif/os.h b/lib/include/nvif/os.h
index 071d8d91d..3b3b46daa 100644
--- a/lib/include/nvif/os.h
+++ b/lib/include/nvif/os.h
@@ -1211,28 +1211,8 @@ struct firmware {
void *data;
};
-static inline int
-request_firmware(const struct firmware **pfw, const char *name,
- struct device *dev)
-{
- struct firmware *fw = *(void **)pfw = malloc(sizeof(*fw));
- int fd = open(name, O_RDONLY);
- if (fd >= 0) {
- off_t len = lseek(fd, 0, SEEK_END);
- fw->data = malloc(len);
- fw->size = pread(fd, fw->data, len, 0);
- return 0;
- }
- free(fw);
- return -EINVAL;
-}
-
-static inline void
-release_firmware(const struct firmware *fw)
-{
- free(fw->data);
- free((void *)fw);
-}
+int request_firmware(const struct firmware **, const char *, struct device *);
+void release_firmware(const struct firmware *);
#define MODULE_FIRMWARE(a)