require '_h2ph_pre.ph';

if(defined( &__NetBSD__) || defined( &__OpenBSD__)) {
    eval 'sub DMAADDR {
        local($dma) = @_;
	    eval q((($dma)-> ($block->{map}->{dm_segs[0]}->{ds_addr}) + ($dma)-> &offs));
    }' unless defined(&DMAADDR);
    eval 'sub KERNADDR {
        local($dma) = @_;
	    eval q(((($dma)-> ($block->{kaddr}) + ($dma)-> &offs)));
    }' unless defined(&KERNADDR);
}
 elsif(defined( &__FreeBSD__)) {
    require 'sys/param.ph';
    require 'sys/systm.ph';
    require 'sys/queue.ph';
    require 'sys/proc.ph';
    require 'sys/buf.ph';
    require 'sys/malloc.ph';
    require 'sys/kernel.ph';
    require 'vm/vm.ph';
    eval 'sub usb_allocmem {
        local($t,$s,$a,$p) = @_;
	    eval q((*($p) =  &malloc($s,  &M_USB,  &M_NOWAIT), (*($p) ==  &NULL?  &USBD_NOMEM:  &USBD_NORMAL_COMPLETION)));
    }' unless defined(&usb_allocmem);
    eval 'sub usb_freemem {
        local($t,$p) = @_;
	    eval q(( &free(*($p),  &M_USB)));
    }' unless defined(&usb_freemem);
    if(defined(&__alpha__)) {
	eval 'sub DMAADDR {
	    local($dma) = @_;
    	    eval q(( &alpha_XXX_dmamap(( &vm_offset_t) *($dma))));
	}' unless defined(&DMAADDR);
    } else {
	eval 'sub DMAADDR {
	    local($dma) = @_;
    	    eval q(( &vtophys(*($dma))));
	}' unless defined(&DMAADDR);
    }
    eval 'sub KERNADDR {
        local($dma) = @_;
	    eval q((( &void *) *($dma)));
    }' unless defined(&KERNADDR);
}
1;
