zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

platformvar.h (3696B) - Raw


      1 /*-
      2  * Copyright (c) 2005 Peter Grehan
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     24  * SUCH DAMAGE.
     25  */
     26 
     27 #ifndef _MACHINE_PLATFORMVAR_H_
     28 #define _MACHINE_PLATFORMVAR_H_
     29 
     30 /*
     31  * An ARM platform implementation is declared with a kernel object and
     32  * an associated method table, similar to a device driver.
     33  *
     34  * e.g.
     35  *
     36  * static platform_method_t bcm2835_methods[] = {
     37  *	PLATFORMMETHOD(platform_probe,		bcm2835_probe),
     38  *  ...
     39  *	PLATFORMMETHOD_END
     40  * };
     41  *
     42  * static platform_def_t bcm3835_platform = {
     43  * 	"bcm2835",
     44  *	bcm2835_methods,
     45  *	sizeof(bcm2835_platform_softc),	// or 0 if no softc
     46  * };
     47  *
     48  * PLATFORM_DEF(bcm2835_platform);
     49  */
     50 
     51 #include <sys/kobj.h>
     52 #include <sys/linker_set.h>
     53 
     54 struct platform_class {
     55 	KOBJ_CLASS_FIELDS;
     56 
     57 	/* How many times to loop to delay approximately 1us */
     58 	int delay_count;
     59 };
     60 
     61 struct platform_kobj {
     62 	/*
     63 	 * A platform instance is a kernel object
     64 	 */
     65 	KOBJ_FIELDS;
     66 
     67 	/* Platform class, for access to class specific data */
     68 	struct platform_class *cls;
     69 };
     70 
     71 typedef struct platform_kobj	*platform_t;
     72 typedef struct platform_class	platform_def_t;
     73 #define platform_method_t	kobj_method_t
     74 
     75 #define PLATFORMMETHOD		KOBJMETHOD
     76 #define	PLATFORMMETHOD_END	KOBJMETHOD_END
     77 
     78 #define PLATFORM_DEF(name)	DATA_SET(platform_set, name)
     79 
     80 #ifdef FDT
     81 struct fdt_platform_class {
     82 	KOBJ_CLASS_FIELDS;
     83 
     84 	const char *fdt_compatible;
     85 };
     86 
     87 typedef struct fdt_platform_class fdt_platform_def_t;
     88 
     89 extern platform_method_t fdt_platform_methods[];
     90 
     91 #define FDT_PLATFORM_DEF2(NAME, VAR_NAME, NAME_STR, _size, _compatible,	\
     92     _delay)								\
     93 CTASSERT(_delay > 0);							\
     94 static fdt_platform_def_t VAR_NAME ## _fdt_platform = {			\
     95 	.name = NAME_STR,						\
     96 	.methods = fdt_platform_methods,				\
     97 	.fdt_compatible = _compatible,					\
     98 };									\
     99 static kobj_class_t VAR_NAME ## _baseclasses[] =			\
    100 	{ (kobj_class_t)&VAR_NAME ## _fdt_platform, NULL };		\
    101 static platform_def_t VAR_NAME ## _platform = {				\
    102 	.name = NAME_STR,						\
    103 	.methods = NAME ## _methods,					\
    104 	.size = _size,							\
    105 	.baseclasses = VAR_NAME ## _baseclasses,			\
    106 	.delay_count = _delay,						\
    107 };									\
    108 DATA_SET(platform_set, VAR_NAME ## _platform)
    109 
    110 #define	FDT_PLATFORM_DEF(NAME, NAME_STR, size, compatible, delay)	\
    111     FDT_PLATFORM_DEF2(NAME, NAME, NAME_STR, size, compatible, delay)
    112 
    113 #endif
    114 
    115 /*
    116  * Helper to get the platform object
    117  */
    118 platform_t platform_obj(void);
    119 
    120 bool arm_tmr_timed_wait(platform_t, int);
    121 
    122 #endif /* _MACHINE_PLATFORMVAR_H_ */