1*97f8debdSpgoyette /* $NetBSD: pci_at_mainbus.c,v 1.11 2022/03/31 19:30:17 pgoyette Exp $ */
269955daeSpooka
369955daeSpooka /*
469955daeSpooka * Copyright (c) 2010 Antti Kantee. All Rights Reserved.
569955daeSpooka *
669955daeSpooka * Redistribution and use in source and binary forms, with or without
769955daeSpooka * modification, are permitted provided that the following conditions
869955daeSpooka * are met:
969955daeSpooka * 1. Redistributions of source code must retain the above copyright
1069955daeSpooka * notice, this list of conditions and the following disclaimer.
1169955daeSpooka * 2. Redistributions in binary form must reproduce the above copyright
1269955daeSpooka * notice, this list of conditions and the following disclaimer in the
1369955daeSpooka * documentation and/or other materials provided with the distribution.
1469955daeSpooka *
1569955daeSpooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1669955daeSpooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1769955daeSpooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1869955daeSpooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1969955daeSpooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2069955daeSpooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2169955daeSpooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2269955daeSpooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2369955daeSpooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2469955daeSpooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2569955daeSpooka * SUCH DAMAGE.
2669955daeSpooka */
2769955daeSpooka
2869955daeSpooka #include <sys/cdefs.h>
29*97f8debdSpgoyette __KERNEL_RCSID(0, "$NetBSD: pci_at_mainbus.c,v 1.11 2022/03/31 19:30:17 pgoyette Exp $");
3069955daeSpooka
3169955daeSpooka #include <sys/param.h>
3269955daeSpooka #include <sys/conf.h>
3369955daeSpooka #include <sys/device.h>
3469955daeSpooka #include <sys/mbuf.h>
3569955daeSpooka #include <sys/stat.h>
3669955daeSpooka #include <sys/bus.h>
3769955daeSpooka
3869955daeSpooka #include <dev/pci/pcivar.h>
3969955daeSpooka #include <machine/bus_private.h>
4069955daeSpooka
4169955daeSpooka #include "ioconf.c"
4269955daeSpooka
436bb51422Spooka #include <rump-sys/kern.h>
446bb51422Spooka #include <rump-sys/vfs.h>
4569955daeSpooka
4636505d0eSpooka #include "pci_user.h"
4736505d0eSpooka
RUMP_COMPONENT(RUMP_COMPONENT_DEV)4869955daeSpooka RUMP_COMPONENT(RUMP_COMPONENT_DEV)
4969955daeSpooka {
5078921906Spooka extern const struct cdevsw pci_cdevsw;
5178921906Spooka devmajor_t cmaj, bmaj;
5278921906Spooka int error;
5369955daeSpooka
5478921906Spooka bmaj = cmaj = -1;
5578921906Spooka if ((error = devsw_attach("pci", NULL, &bmaj,
5678921906Spooka &pci_cdevsw, &cmaj)) != 0) {
5778921906Spooka printf("pci: devsw_attach failed: %d\n", error);
5878921906Spooka return;
5978921906Spooka }
6078921906Spooka
61*97f8debdSpgoyette config_init_component(cfdriver_ioconf_pci,
62*97f8debdSpgoyette cfattach_ioconf_pci, cfdata_ioconf_pci);
63*97f8debdSpgoyette
6478921906Spooka if ((error = rump_vfs_makedevnodes(S_IFCHR, "/dev/pci", '0',
6578921906Spooka cmaj, 0, 4)) != 0)
66e1b2b6b0Spooka printf("pci: failed to create /dev/pci nodes: %d\n", error);
6769955daeSpooka }
6869955daeSpooka
RUMP_COMPONENT(RUMP_COMPONENT_DEV_AFTERMAINBUS)6969955daeSpooka RUMP_COMPONENT(RUMP_COMPONENT_DEV_AFTERMAINBUS)
7069955daeSpooka {
7169955daeSpooka struct pcibus_attach_args pba;
7269955daeSpooka device_t mainbus;
7369955daeSpooka
7469955daeSpooka /* XXX: attach args should come from elsewhere */
7569955daeSpooka memset(&pba, 0, sizeof(pba));
76fcfbee34Spooka pba.pba_bus = 0;
7769955daeSpooka pba.pba_iot = (bus_space_tag_t)0;
7869955daeSpooka pba.pba_memt = (bus_space_tag_t)1;
7969955daeSpooka pba.pba_dmat = (void *)0x20;
8069955daeSpooka #ifdef _LP64
8169955daeSpooka pba.pba_dmat64 = (void *)0x40;
8269955daeSpooka #endif
8369955daeSpooka pba.pba_flags = PCI_FLAGS_MEM_OKAY |
84a50c0670Smaya PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
8536505d0eSpooka
8636505d0eSpooka #ifdef RUMPCOMP_USERFEATURE_PCI_IOSPACE
8736505d0eSpooka int error;
8836505d0eSpooka
8936505d0eSpooka error = rumpcomp_pci_iospace_init();
9036505d0eSpooka if (!error) {
9169955daeSpooka pba.pba_flags |= PCI_FLAGS_IO_OKAY;
9236505d0eSpooka } else {
9336505d0eSpooka aprint_error("pci: I/O space init error %d, I/O space not "
9436505d0eSpooka "available\n", error);
9536505d0eSpooka }
9669955daeSpooka #endif
9769955daeSpooka
9869955daeSpooka mainbus = device_find_by_driver_unit("mainbus", 0);
9969955daeSpooka if (!mainbus)
10069955daeSpooka panic("no mainbus. use maintaxi instead?");
1012685996bSthorpej config_found(mainbus, &pba, pcibusprint,
102c7fb772bSthorpej CFARGS(.iattr = "pcibus"));
10369955daeSpooka }
104