Home | History | Annotate | Line # | Download | only in pv
pvbus.c revision 1.1
      1 /* $NetBSD: pvbus.c,v 1.1 2025/01/02 10:34:33 imil Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2024 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Emile 'iMil' Heitor.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #include <sys/param.h>
     34 #include <sys/bus.h>
     35 #include <sys/device.h>
     36 #include <sys/kernel.h>
     37 #include <sys/systm.h>
     38 
     39 #include <machine/bus_private.h>
     40 
     41 #include <arch/x86/pv/pvvar.h>
     42 
     43 static int _pv_dma_may_bounce(bus_dma_tag_t, bus_dmamap_t, int, int *);
     44 static int pv_match(device_t, cfdata_t, void *);
     45 static void pv_attach(device_t, device_t, void *);
     46 static int pv_submatch(device_t, cfdata_t, const int *, void *);
     47 
     48 struct x86_bus_dma_tag pvbus_bus_dma_tag = {
     49 	._tag_needs_free	= 0,
     50 	._bounce_thresh		= 0,
     51 	._bounce_alloc_lo	= 0,
     52 	._bounce_alloc_hi	= 0,
     53 	._may_bounce		= _pv_dma_may_bounce,
     54 };
     55 
     56 CFATTACH_DECL_NEW(pv, sizeof(struct pv_softc),
     57 		  pv_match, pv_attach, NULL, NULL);
     58 
     59 static int
     60 _pv_dma_may_bounce(bus_dma_tag_t t, bus_dmamap_t map, int flags,
     61 	int *cookieflagsp)
     62 {
     63 	if ((map->_dm_size / PAGE_SIZE) > map->_dm_segcnt)
     64 		*cookieflagsp |= X86_DMA_MIGHT_NEED_BOUNCE;
     65 
     66 	return 0;
     67 }
     68 
     69 
     70 static int
     71 pv_match(device_t parent, cfdata_t match, void *aux)
     72 {
     73 	return 1;
     74 }
     75 
     76 static void
     77 pv_attach(device_t parent, device_t self, void *aux)
     78 {
     79 	struct pv_attach_args pvaa;
     80 
     81 	pvaa.pvaa_memt = x86_bus_space_mem;
     82 	pvaa.pvaa_dmat = &pvbus_bus_dma_tag;
     83 
     84 	aprint_naive("\n");
     85 	aprint_normal("\n");
     86 
     87 	config_found(self, &pvaa, NULL, CFARGS(.search = pv_submatch));
     88 }
     89 
     90 static int
     91 pv_submatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
     92 {
     93 	struct pv_attach_args *pvaa = aux;
     94 
     95 	if (config_probe(parent, cf, pvaa)) {
     96 		config_attach(parent, cf, pvaa, NULL, CFARGS_NONE);
     97 		return 0;
     98 	}
     99 	return 0;
    100 }
    101