16aec1278SMax Laier /*-
2*b61a5730SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3f0cfa1b1SPedro F. Giffuni *
46aec1278SMax Laier * Copyright (c) 2006, Max Laier <mlaier@FreeBSD.org>
56aec1278SMax Laier * All rights reserved.
66aec1278SMax Laier *
76aec1278SMax Laier * Redistribution and use in source and binary forms, with or without
86aec1278SMax Laier * modification, are permitted provided that the following conditions
96aec1278SMax Laier * are met:
106aec1278SMax Laier * 1. Redistributions of source code must retain the above copyright
116aec1278SMax Laier * notice unmodified, this list of conditions, and the following
126aec1278SMax Laier * disclaimer.
136aec1278SMax Laier * 2. Redistributions in binary form must reproduce the above copyright
146aec1278SMax Laier * notice, this list of conditions and the following disclaimer in the
156aec1278SMax Laier * documentation and/or other materials provided with the distribution.
166aec1278SMax Laier *
176aec1278SMax Laier * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
186aec1278SMax Laier * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
196aec1278SMax Laier * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
206aec1278SMax Laier * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
216aec1278SMax Laier * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
226aec1278SMax Laier * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236aec1278SMax Laier * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246aec1278SMax Laier * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256aec1278SMax Laier * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
266aec1278SMax Laier * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276aec1278SMax Laier */
286aec1278SMax Laier
296aec1278SMax Laier #include <sys/param.h>
306aec1278SMax Laier #include <sys/kernel.h>
316aec1278SMax Laier #include <sys/errno.h>
326aec1278SMax Laier #include <sys/systm.h>
336aec1278SMax Laier #include <sys/linker.h>
346aec1278SMax Laier #include <sys/firmware.h>
356aec1278SMax Laier #include <sys/proc.h>
366aec1278SMax Laier #include <sys/module.h>
376aec1278SMax Laier
38539f7d3aSWojciech A. Koszek static const struct firmware *fp;
396aec1278SMax Laier
406aec1278SMax Laier static int
fw_consumer_modevent(module_t mod,int type,void * unused)416aec1278SMax Laier fw_consumer_modevent(module_t mod, int type, void *unused)
426aec1278SMax Laier {
436aec1278SMax Laier switch (type) {
446aec1278SMax Laier case MOD_LOAD:
456aec1278SMax Laier fp = firmware_get("beastie");
466aec1278SMax Laier
476aec1278SMax Laier if (fp == NULL)
486aec1278SMax Laier return (ENOENT);
496aec1278SMax Laier
506aec1278SMax Laier if (((const char *)fp->data)[fp->datasize - 1] != '\0') {
516aec1278SMax Laier firmware_put(fp, FIRMWARE_UNLOAD);
526aec1278SMax Laier return (EINVAL);
536aec1278SMax Laier }
546aec1278SMax Laier printf("%s", (const char *)fp->data);
556aec1278SMax Laier
566aec1278SMax Laier return (0);
576aec1278SMax Laier case MOD_UNLOAD:
586aec1278SMax Laier printf("Bye!\n");
596aec1278SMax Laier
606aec1278SMax Laier if (fp != NULL) {
616aec1278SMax Laier printf("%s", (const char *)fp->data);
626aec1278SMax Laier firmware_put(fp, FIRMWARE_UNLOAD);
636aec1278SMax Laier }
646aec1278SMax Laier
656aec1278SMax Laier return (0);
666aec1278SMax Laier }
676aec1278SMax Laier return (EINVAL);
686aec1278SMax Laier }
696aec1278SMax Laier
706aec1278SMax Laier static moduledata_t fw_consumer_mod = {
716aec1278SMax Laier "fw_consumer",
726aec1278SMax Laier fw_consumer_modevent,
739823d527SKevin Lo 0
746aec1278SMax Laier };
756aec1278SMax Laier DECLARE_MODULE(fw_consumer, fw_consumer_mod, SI_SUB_DRIVERS, SI_ORDER_ANY);
766aec1278SMax Laier MODULE_VERSION(fw_consumer, 1);
776aec1278SMax Laier MODULE_DEPEND(fw_consumer, firmware, 1, 1, 1);
78