Fri Jul 24 06:49:58 2015 UTC ()
fix pci_intr_alloc(..., NULL, 0). reported nonaka@n.o


(knakahara)
diff -r1.34 -r1.35 src/sys/arch/x86/pci/pci_intr_machdep.c

cvs diff -r1.34 -r1.35 src/sys/arch/x86/pci/pci_intr_machdep.c (expand / switch to unified diff)

--- src/sys/arch/x86/pci/pci_intr_machdep.c 2015/07/21 03:10:42 1.34
+++ src/sys/arch/x86/pci/pci_intr_machdep.c 2015/07/24 06:49:58 1.35
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pci_intr_machdep.c,v 1.34 2015/07/21 03:10:42 knakahara Exp $ */ 1/* $NetBSD: pci_intr_machdep.c,v 1.35 2015/07/24 06:49:58 knakahara Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997, 1998, 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997, 1998, 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -63,27 +63,27 @@ @@ -63,27 +63,27 @@
63/* 63/*
64 * Machine-specific functions for PCI autoconfiguration. 64 * Machine-specific functions for PCI autoconfiguration.
65 * 65 *
66 * On PCs, there are two methods of generating PCI configuration cycles. 66 * On PCs, there are two methods of generating PCI configuration cycles.
67 * We try to detect the appropriate mechanism for this machine and set 67 * We try to detect the appropriate mechanism for this machine and set
68 * up a few function pointers to access the correct method directly. 68 * up a few function pointers to access the correct method directly.
69 * 69 *
70 * The configuration method can be hard-coded in the config file by 70 * The configuration method can be hard-coded in the config file by
71 * using `options PCI_CONF_MODE=N', where `N' is the configuration mode 71 * using `options PCI_CONF_MODE=N', where `N' is the configuration mode
72 * as defined section 3.6.4.1, `Generating Configuration Cycles'. 72 * as defined section 3.6.4.1, `Generating Configuration Cycles'.
73 */ 73 */
74 74
75#include <sys/cdefs.h> 75#include <sys/cdefs.h>
76__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.34 2015/07/21 03:10:42 knakahara Exp $"); 76__KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.35 2015/07/24 06:49:58 knakahara Exp $");
77 77
78#include <sys/types.h> 78#include <sys/types.h>
79#include <sys/param.h> 79#include <sys/param.h>
80#include <sys/time.h> 80#include <sys/time.h>
81#include <sys/systm.h> 81#include <sys/systm.h>
82#include <sys/cpu.h> 82#include <sys/cpu.h>
83#include <sys/errno.h> 83#include <sys/errno.h>
84#include <sys/device.h> 84#include <sys/device.h>
85#include <sys/intr.h> 85#include <sys/intr.h>
86#include <sys/kmem.h> 86#include <sys/kmem.h>
87#include <sys/malloc.h> 87#include <sys/malloc.h>
88 88
89#include <dev/pci/pcivar.h> 89#include <dev/pci/pcivar.h>
@@ -474,50 +474,52 @@ pci_intr_alloc(const struct pci_attach_a @@ -474,50 +474,52 @@ pci_intr_alloc(const struct pci_attach_a
474 msix_count = counts[PCI_INTR_TYPE_MSIX]; 474 msix_count = counts[PCI_INTR_TYPE_MSIX];
475 /* FALLTHROUGH */ 475 /* FALLTHROUGH */
476 case PCI_INTR_TYPE_MSI: 476 case PCI_INTR_TYPE_MSI:
477 msi_count = counts[PCI_INTR_TYPE_MSI]; 477 msi_count = counts[PCI_INTR_TYPE_MSI];
478 /* FALLTHROUGH */ 478 /* FALLTHROUGH */
479 case PCI_INTR_TYPE_INTX: 479 case PCI_INTR_TYPE_INTX:
480 intx_count = counts[PCI_INTR_TYPE_INTX]; 480 intx_count = counts[PCI_INTR_TYPE_INTX];
481 break; 481 break;
482 default: 482 default:
483 return EINVAL; 483 return EINVAL;
484 } 484 }
485 } 485 }
486 486
487 memset(counts, 0, sizeof(counts[0]) * PCI_INTR_TYPE_SIZE); 487 if (counts != NULL)
 488 memset(counts, 0, sizeof(counts[0]) * PCI_INTR_TYPE_SIZE);
488 error = EINVAL; 489 error = EINVAL;
489 490
490 /* try MSI-X */ 491 /* try MSI-X */
491 if (msix_count == -1) /* use hardware max */ 492 if (msix_count == -1) /* use hardware max */
492 msix_count = pci_msix_count(pa); 493 msix_count = pci_msix_count(pa);
493 if (msix_count > 0) { 494 if (msix_count > 0) {
494 error = pci_msix_alloc_exact(pa, ihps, msix_count); 495 error = pci_msix_alloc_exact(pa, ihps, msix_count);
495 if (error == 0) { 496 if (error == 0) {
 497 KASSERTMSG(counts != NULL,
 498 "If MSI-X is used, counts must not be NULL.");
496 counts[PCI_INTR_TYPE_MSIX] = msix_count; 499 counts[PCI_INTR_TYPE_MSIX] = msix_count;
497 goto out; 500 goto out;
498 } 501 }
499 } 502 }
500 503
501 /* try MSI */ 504 /* try MSI */
502 if (msi_count == -1) /* use hardware max */ 505 if (msi_count == -1) /* use hardware max */
503 msi_count = pci_msi_count(pa); 506 msi_count = pci_msi_count(pa);
504 if (msi_count > 0) { 507 if (msi_count > 0) {
505 error = pci_msi_alloc_exact(pa, ihps, msi_count); 508 error = pci_msi_alloc_exact(pa, ihps, msi_count);
506 if (error == 0) { 509 if (error == 0) {
507 if (counts != NULL) { 510 if (counts != NULL)
508 counts[PCI_INTR_TYPE_MSI] = msi_count; 511 counts[PCI_INTR_TYPE_MSI] = msi_count;
509 goto out; 512 goto out;
510 } 
511 } 513 }
512 } 514 }
513 515
514 /* try INTx */ 516 /* try INTx */
515 if (intx_count != 0) { /* The number of INTx is always 1. */ 517 if (intx_count != 0) { /* The number of INTx is always 1. */
516 error = pci_intx_alloc(pa, ihps); 518 error = pci_intx_alloc(pa, ihps);
517 if (error == 0) { 519 if (error == 0) {
518 if (counts != NULL) 520 if (counts != NULL)
519 counts[PCI_INTR_TYPE_INTX] = 1; 521 counts[PCI_INTR_TYPE_INTX] = 1;
520 } 522 }
521 } 523 }
522 524
523 out: 525 out: