1 1.2 riastrad /* $NetBSD: pvbus.c,v 1.2 2025/01/14 08:03:40 riastradh 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/param.h> 33 1.2 riastrad 34 1.1 imil #include <sys/bus.h> 35 1.2 riastrad #include <sys/cdefs.h> 36 1.1 imil #include <sys/device.h> 37 1.1 imil #include <sys/kernel.h> 38 1.1 imil #include <sys/systm.h> 39 1.1 imil 40 1.1 imil #include <machine/bus_private.h> 41 1.1 imil 42 1.1 imil #include <arch/x86/pv/pvvar.h> 43 1.1 imil 44 1.1 imil static int _pv_dma_may_bounce(bus_dma_tag_t, bus_dmamap_t, int, int *); 45 1.1 imil static int pv_match(device_t, cfdata_t, void *); 46 1.1 imil static void pv_attach(device_t, device_t, void *); 47 1.1 imil static int pv_submatch(device_t, cfdata_t, const int *, void *); 48 1.1 imil 49 1.1 imil struct x86_bus_dma_tag pvbus_bus_dma_tag = { 50 1.1 imil ._tag_needs_free = 0, 51 1.1 imil ._bounce_thresh = 0, 52 1.1 imil ._bounce_alloc_lo = 0, 53 1.1 imil ._bounce_alloc_hi = 0, 54 1.1 imil ._may_bounce = _pv_dma_may_bounce, 55 1.1 imil }; 56 1.1 imil 57 1.1 imil CFATTACH_DECL_NEW(pv, sizeof(struct pv_softc), 58 1.2 riastrad pv_match, pv_attach, NULL, NULL); 59 1.1 imil 60 1.1 imil static int 61 1.1 imil _pv_dma_may_bounce(bus_dma_tag_t t, bus_dmamap_t map, int flags, 62 1.2 riastrad int *cookieflagsp) 63 1.1 imil { 64 1.2 riastrad 65 1.1 imil if ((map->_dm_size / PAGE_SIZE) > map->_dm_segcnt) 66 1.1 imil *cookieflagsp |= X86_DMA_MIGHT_NEED_BOUNCE; 67 1.1 imil 68 1.1 imil return 0; 69 1.1 imil } 70 1.1 imil 71 1.1 imil static int 72 1.1 imil pv_match(device_t parent, cfdata_t match, void *aux) 73 1.1 imil { 74 1.2 riastrad 75 1.1 imil return 1; 76 1.1 imil } 77 1.1 imil 78 1.1 imil static void 79 1.1 imil pv_attach(device_t parent, device_t self, void *aux) 80 1.1 imil { 81 1.1 imil struct pv_attach_args pvaa; 82 1.1 imil 83 1.1 imil pvaa.pvaa_memt = x86_bus_space_mem; 84 1.1 imil pvaa.pvaa_dmat = &pvbus_bus_dma_tag; 85 1.1 imil 86 1.1 imil aprint_naive("\n"); 87 1.1 imil aprint_normal("\n"); 88 1.1 imil 89 1.1 imil config_found(self, &pvaa, NULL, CFARGS(.search = pv_submatch)); 90 1.1 imil } 91 1.1 imil 92 1.1 imil static int 93 1.1 imil pv_submatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux) 94 1.1 imil { 95 1.1 imil struct pv_attach_args *pvaa = aux; 96 1.1 imil 97 1.1 imil if (config_probe(parent, cf, pvaa)) { 98 1.1 imil config_attach(parent, cf, pvaa, NULL, CFARGS_NONE); 99 1.1 imil return 0; 100 1.1 imil } 101 1.1 imil return 0; 102 1.1 imil } 103