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