require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_SYS_DEVICE_H_)) {
    eval 'sub _SYS_DEVICE_H_ () {1;}' unless defined(&_SYS_DEVICE_H_);
    require 'sys/device_if.ph';
    require 'sys/evcnt.ph';
    require 'sys/queue.ph';
    if(defined(&_KERNEL) || defined(&_KMEMUSER)) {
	require 'sys/mutex.ph';
	require 'sys/condvar.ph';
	require 'sys/pmf.ph';
    }
    require 'prop/proplib.ph';
    eval("sub DV_DULL () { 0; }") unless defined(&DV_DULL);
    eval("sub DV_CPU () { 1; }") unless defined(&DV_CPU);
    eval("sub DV_DISK () { 2; }") unless defined(&DV_DISK);
    eval("sub DV_IFNET () { 3; }") unless defined(&DV_IFNET);
    eval("sub DV_TAPE () { 4; }") unless defined(&DV_TAPE);
    eval("sub DV_TTY () { 5; }") unless defined(&DV_TTY);
    eval("sub DV_AUDIODEV () { 6; }") unless defined(&DV_AUDIODEV);
    eval("sub DV_DISPLAYDEV () { 7; }") unless defined(&DV_DISPLAYDEV);
    eval("sub DV_BUS () { 8; }") unless defined(&DV_BUS);
    eval("sub DV_VIRTUAL () { 9; }") unless defined(&DV_VIRTUAL);
    eval("sub DVACT_DEACTIVATE () { 0; }") unless defined(&DVACT_DEACTIVATE);
    eval("sub DVA_SYSTEM () { 0; }") unless defined(&DVA_SYSTEM);
    eval("sub DVA_HARDWARE () { 1; }") unless defined(&DVA_HARDWARE);
    if(defined(&_KERNEL) || defined(&_KMEMUSER) || defined(&_STANDALONE)) {
    }
    if(defined(&_KERNEL) || defined(&_KMEMUSER) ) {
	eval 'sub DEVICE_COMPAT_EOL () {{ . &compat =  &NULL };}' unless defined(&DEVICE_COMPAT_EOL);
	eval("sub DEVHANDLE_TYPE_INVALID () { 0; }") unless defined(&DEVHANDLE_TYPE_INVALID);
	eval("sub DEVHANDLE_TYPE_ACPI () { 0x41435049; }") unless defined(&DEVHANDLE_TYPE_ACPI);
	eval("sub DEVHANDLE_TYPE_OF () { 0x4f504657; }") unless defined(&DEVHANDLE_TYPE_OF);
	eval("sub DEVHANDLE_TYPE_OPENBOOT () { 0x4f504254; }") unless defined(&DEVHANDLE_TYPE_OPENBOOT);
	eval("sub DEVHANDLE_TYPE_PRIVATE () { 0x50525654; }") unless defined(&DEVHANDLE_TYPE_PRIVATE);
	eval("sub DEVHANDLE_TYPE_MAX () { 0xffffffff; }") unless defined(&DEVHANDLE_TYPE_MAX);
	eval 'sub _DEVICE_CALL_REGISTER {
	    my($_g_, $_c_) = @_;
    	    eval q( &__link_set_add_rodata($_g_,  &__CONCAT($_c_, &_descriptor)););
	}' unless defined(&_DEVICE_CALL_REGISTER);
	eval 'sub DEVICE_CALL_REGISTER {
	    my($_g_, $_n_, $_c_) = @_;
    	    eval q( &static  &const \'struct device_call_descriptor\'  &__CONCAT($_c_, &_descriptor) = { . &name = ($_n_), . &call = ($_c_) };  &_DEVICE_CALL_REGISTER($_g_, $_c_));
	}' unless defined(&DEVICE_CALL_REGISTER);
	eval 'sub DEVICE_XNAME_SIZE () {16;}' unless defined(&DEVICE_XNAME_SIZE);
	eval 'sub DVF_PRIV_ALLOC () {0x2;}' unless defined(&DVF_PRIV_ALLOC);
	eval 'sub DVF_DETACH_SHUTDOWN () {0x80;}' unless defined(&DVF_DETACH_SHUTDOWN);
	if(defined(&_KERNEL)) {
	}
	eval("sub DEVITER_F_RW () { 0x1; }") unless defined(&DEVITER_F_RW);
	eval("sub DEVITER_F_SHUTDOWN () { 0x2; }") unless defined(&DEVITER_F_SHUTDOWN);
	eval("sub DEVITER_F_LEAVES_FIRST () { 0x4; }") unless defined(&DEVITER_F_LEAVES_FIRST);
	eval("sub DEVITER_F_ROOT_FIRST () { 0x8; }") unless defined(&DEVITER_F_ROOT_FIRST);
    }
    if(defined(&__GNUC__)  && (defined(&__GNUC__) ? &__GNUC__ : undef) <= 2) {
    }
    eval 'sub FSTATE_NOTFOUND () {0;}' unless defined(&FSTATE_NOTFOUND);
    eval 'sub FSTATE_FOUND () {1;}' unless defined(&FSTATE_FOUND);
    eval 'sub FSTATE_STAR () {2;}' unless defined(&FSTATE_STAR);
    eval 'sub FSTATE_DSTAR () {3;}' unless defined(&FSTATE_DSTAR);
    eval 'sub FSTATE_DNOTFOUND () {4;}' unless defined(&FSTATE_DNOTFOUND);
    if(defined(&_KERNEL)) {
    }
    eval 'sub CFATTACH_DECL3_NEW {
        my($name, $ddsize, $matfn, $attfn, $detfn, $actfn, 	$rescanfn, $chdetfn, $__flags) = @_;
	    eval q(\'struct cfattach\'  &__CONCAT($name, &_ca) = { . &ca_name =  &___STRING($name), . &ca_devsize = $ddsize, . &ca_flags = ($__flags) |  &DVF_PRIV_ALLOC, . &ca_match = $matfn, . &ca_attach = $attfn, . &ca_detach = $detfn, . &ca_activate = $actfn, . &ca_rescan = $rescanfn, . &ca_childdetached = $chdetfn, });
    }' unless defined(&CFATTACH_DECL3_NEW);
    eval 'sub CFATTACH_DECL2_NEW {
        my($name, $ddsize, $matfn, $attfn, $detfn, $actfn,		$rescanfn, $chdetfn) = @_;
	    eval q( &CFATTACH_DECL3_NEW($name, $ddsize, $matfn, $attfn, $detfn, $actfn, $rescanfn, $chdetfn, 0));
    }' unless defined(&CFATTACH_DECL2_NEW);
    eval 'sub CFATTACH_DECL_NEW {
        my($name, $ddsize, $matfn, $attfn, $detfn, $actfn) = @_;
	    eval q( &CFATTACH_DECL2_NEW($name, $ddsize, $matfn, $attfn, $detfn, $actfn,  &NULL,  &NULL));
    }' unless defined(&CFATTACH_DECL_NEW);
    eval 'sub DETACH_FORCE () {0x1;}' unless defined(&DETACH_FORCE);
    eval 'sub DETACH_QUIET () {0x2;}' unless defined(&DETACH_QUIET);
    eval 'sub DETACH_SHUTDOWN () {0x4;}' unless defined(&DETACH_SHUTDOWN);
    eval 'sub DETACH_POWEROFF () {0x8;}' unless defined(&DETACH_POWEROFF);
    eval 'sub CFDRIVER_DECL {
        my($name, $class, $attrs) = @_;
	    eval q(\'struct cfdriver\'  &__CONCAT($name, &_cd) = { . &cd_name =  &___STRING($name), . &cd_class = $class, . &cd_attrs = $attrs, });
    }' unless defined(&CFDRIVER_DECL);
    eval 'sub QUIET () {0;}' unless defined(&QUIET);
    eval 'sub UNCONF () {1;}' unless defined(&UNCONF);
    eval 'sub UNSUPP () {2;}' unless defined(&UNSUPP);
    eval 'sub DVUNIT_ANY () {-1;}' unless defined(&DVUNIT_ANY);
    if(defined(&_KERNEL) || defined(&_KMEMUSER) || defined(&_STANDALONE)) {
	eval 'sub CFARGS_VERSION () {1;}' unless defined(&CFARGS_VERSION);
	eval 'sub CFARGS_NONE () { &NULL;}' unless defined(&CFARGS_NONE);
	eval 'sub CFARGS () {(...) (( &const \'struct cfargs\'){ . &cfargs_version =  &CFARGS_VERSION,  &__VA_ARGS__ });}' unless defined(&CFARGS);
    }
    if(defined(&_KERNEL)) {
	eval 'sub device_call {
	    my($dev, $call) = @_;
    	    eval q( &device_call_generic(($dev), ($call)-> &generic));
	}' unless defined(&device_call);
    }
}
1;
