| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: virtio_pci.c,v 1.40 2023/03/31 07:34:26 yamaguchi Exp $ */ | | 1 | /* $NetBSD: virtio_pci.c,v 1.41 2023/04/16 17:57:08 riastradh Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2020 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2020 The NetBSD Foundation, Inc. |
5 | * Copyright (c) 2012 Stefan Fritsch. | | 5 | * Copyright (c) 2012 Stefan Fritsch. |
6 | * Copyright (c) 2010 Minoura Makoto. | | 6 | * Copyright (c) 2010 Minoura Makoto. |
7 | * All rights reserved. | | 7 | * All rights reserved. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -18,27 +18,27 @@ | | | @@ -18,27 +18,27 @@ |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | */ | | 28 | */ |
29 | | | 29 | |
30 | #include <sys/cdefs.h> | | 30 | #include <sys/cdefs.h> |
31 | __KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.40 2023/03/31 07:34:26 yamaguchi Exp $"); | | 31 | __KERNEL_RCSID(0, "$NetBSD: virtio_pci.c,v 1.41 2023/04/16 17:57:08 riastradh Exp $"); |
32 | | | 32 | |
33 | #include <sys/param.h> | | 33 | #include <sys/param.h> |
34 | #include <sys/systm.h> | | 34 | #include <sys/systm.h> |
35 | #include <sys/kmem.h> | | 35 | #include <sys/kmem.h> |
36 | #include <sys/module.h> | | 36 | #include <sys/module.h> |
37 | #include <sys/endian.h> | | 37 | #include <sys/endian.h> |
38 | #include <sys/interrupt.h> | | 38 | #include <sys/interrupt.h> |
39 | #include <sys/syslog.h> | | 39 | #include <sys/syslog.h> |
40 | | | 40 | |
41 | #include <sys/device.h> | | 41 | #include <sys/device.h> |
42 | | | 42 | |
43 | #include <dev/pci/pcidevs.h> | | 43 | #include <dev/pci/pcidevs.h> |
44 | #include <dev/pci/pcireg.h> | | 44 | #include <dev/pci/pcireg.h> |
| @@ -323,28 +323,31 @@ virtio_pci_rescan(device_t self, const c | | | @@ -323,28 +323,31 @@ virtio_pci_rescan(device_t self, const c |
323 | | | 323 | |
324 | | | 324 | |
325 | static int | | 325 | static int |
326 | virtio_pci_detach(device_t self, int flags) | | 326 | virtio_pci_detach(device_t self, int flags) |
327 | { | | 327 | { |
328 | struct virtio_pci_softc * const psc = device_private(self); | | 328 | struct virtio_pci_softc * const psc = device_private(self); |
329 | struct virtio_softc * const sc = &psc->sc_sc; | | 329 | struct virtio_softc * const sc = &psc->sc_sc; |
330 | int r; | | 330 | int r; |
331 | | | 331 | |
332 | r = config_detach_children(self, flags); | | 332 | r = config_detach_children(self, flags); |
333 | if (r != 0) | | 333 | if (r != 0) |
334 | return r; | | 334 | return r; |
335 | | | 335 | |
336 | /* Check that child detached properly */ | | 336 | /* Check that child never attached, or detached properly */ |
337 | KASSERT(ISSET(sc->sc_child_flags, VIRTIO_CHILD_DETACHED)); | | 337 | KASSERTMSG(!ISSET(sc->sc_child_flags, |
| | | 338 | (VIRTIO_CHILD_ATTACH_FINISHED|VIRTIO_CHILD_ATTACH_FAILED)) || |
| | | 339 | ISSET(sc->sc_child_flags, VIRTIO_CHILD_DETACHED), |
| | | 340 | "%s: child flags %x", device_xname(self), sc->sc_child_flags); |
338 | KASSERT(sc->sc_vqs == NULL); | | 341 | KASSERT(sc->sc_vqs == NULL); |
339 | KASSERT(psc->sc_ihs_num == 0); | | 342 | KASSERT(psc->sc_ihs_num == 0); |
340 | | | 343 | |
341 | if (psc->sc_iosize) | | 344 | if (psc->sc_iosize) |
342 | bus_space_unmap(psc->sc_iot, psc->sc_ioh, | | 345 | bus_space_unmap(psc->sc_iot, psc->sc_ioh, |
343 | psc->sc_mapped_iosize); | | 346 | psc->sc_mapped_iosize); |
344 | psc->sc_iosize = 0; | | 347 | psc->sc_iosize = 0; |
345 | | | 348 | |
346 | return 0; | | 349 | return 0; |
347 | } | | 350 | } |
348 | | | 351 | |
349 | | | 352 | |
350 | static int | | 353 | static int |