| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: pci_intr_machdep.c,v 1.19 2011/04/04 20:37:55 dyoung Exp $ */ | | 1 | /* $NetBSD: pci_intr_machdep.c,v 1.20 2011/08/01 11:08:03 drochner 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,35 +63,36 @@ | | | @@ -63,35 +63,36 @@ |
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.19 2011/04/04 20:37:55 dyoung Exp $"); | | 76 | __KERNEL_RCSID(0, "$NetBSD: pci_intr_machdep.c,v 1.20 2011/08/01 11:08:03 drochner 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/errno.h> | | 82 | #include <sys/errno.h> |
83 | #include <sys/device.h> | | 83 | #include <sys/device.h> |
84 | #include <sys/intr.h> | | 84 | #include <sys/intr.h> |
| | | 85 | #include <sys/malloc.h> |
85 | | | 86 | |
86 | #include <dev/pci/pcivar.h> | | 87 | #include <dev/pci/pcivar.h> |
87 | | | 88 | |
88 | #include "ioapic.h" | | 89 | #include "ioapic.h" |
89 | #include "eisa.h" | | 90 | #include "eisa.h" |
90 | #include "acpica.h" | | 91 | #include "acpica.h" |
91 | #include "opt_mpbios.h" | | 92 | #include "opt_mpbios.h" |
92 | #include "opt_acpi.h" | | 93 | #include "opt_acpi.h" |
93 | | | 94 | |
94 | #if NIOAPIC > 0 || NACPICA > 0 | | 95 | #if NIOAPIC > 0 || NACPICA > 0 |
95 | #include <machine/i82093var.h> | | 96 | #include <machine/i82093var.h> |
96 | #include <machine/mpconfig.h> | | 97 | #include <machine/mpconfig.h> |
97 | #include <machine/mpbiosvar.h> | | 98 | #include <machine/mpbiosvar.h> |
| @@ -315,13 +316,103 @@ pci_intr_disestablish(pci_chipset_tag_t | | | @@ -315,13 +316,103 @@ pci_intr_disestablish(pci_chipset_tag_t |
315 | if ((pc->pc_present & PCI_OVERRIDE_INTR_ESTABLISH) != 0) { | | 316 | if ((pc->pc_present & PCI_OVERRIDE_INTR_ESTABLISH) != 0) { |
316 | (*pc->pc_ov->ov_intr_disestablish)(pc->pc_ctx, | | 317 | (*pc->pc_ov->ov_intr_disestablish)(pc->pc_ctx, |
317 | pc, cookie); | | 318 | pc, cookie); |
318 | return; | | 319 | return; |
319 | } | | 320 | } |
320 | if (pc->pc_super != NULL) { | | 321 | if (pc->pc_super != NULL) { |
321 | pci_intr_disestablish(pc->pc_super, cookie); | | 322 | pci_intr_disestablish(pc->pc_super, cookie); |
322 | return; | | 323 | return; |
323 | } | | 324 | } |
324 | } | | 325 | } |
325 | | | 326 | |
326 | intr_disestablish(cookie); | | 327 | intr_disestablish(cookie); |
327 | } | | 328 | } |
| | | 329 | |
| | | 330 | #if NIOAPIC > 0 |
| | | 331 | /* |
| | | 332 | * experimental support for MSI, does support a single vector, |
| | | 333 | * no MSI-X, 8-bit APIC IDs |
| | | 334 | * (while it doesn't need the ioapic technically, it borrows |
| | | 335 | * from its kernel support) |
| | | 336 | */ |
| | | 337 | |
| | | 338 | /* dummies, needed by common intr_establish code */ |
| | | 339 | static void |
| | | 340 | msipic_hwmask(struct pic *pic, int pin) |
| | | 341 | { |
| | | 342 | } |
| | | 343 | static void |
| | | 344 | msipic_addroute(struct pic *pic, struct cpu_info *ci, |
| | | 345 | int pin, int vec, int type) |
| | | 346 | { |
| | | 347 | } |
| | | 348 | |
| | | 349 | static struct pic msi_pic = { |
| | | 350 | .pic_name = "msi", |
| | | 351 | .pic_type = PIC_SOFT, |
| | | 352 | .pic_vecbase = 0, |
| | | 353 | .pic_apicid = 0, |
| | | 354 | .pic_lock = __SIMPLELOCK_UNLOCKED, |
| | | 355 | .pic_hwmask = msipic_hwmask, |
| | | 356 | .pic_hwunmask = msipic_hwmask, |
| | | 357 | .pic_addroute = msipic_addroute, |
| | | 358 | .pic_delroute = msipic_addroute, |
| | | 359 | .pic_edge_stubs = ioapic_edge_stubs, |
| | | 360 | }; |
| | | 361 | |
| | | 362 | struct msi_hdl { |
| | | 363 | struct intrhand *ih; |
| | | 364 | pci_chipset_tag_t pc; |
| | | 365 | pcitag_t tag; |
| | | 366 | int co; |
| | | 367 | }; |
| | | 368 | |
| | | 369 | void * |
| | | 370 | pci_msi_establish(struct pci_attach_args *pa, int level, |
| | | 371 | int (*func)(void *), void *arg) |
| | | 372 | { |
| | | 373 | int co; |
| | | 374 | void *ih; |
| | | 375 | struct msi_hdl *msih; |
| | | 376 | struct cpu_info *ci; |
| | | 377 | struct intrsource *s; |
| | | 378 | u_int32_t cr; |
| | | 379 | |
| | | 380 | if (!pci_get_capability(pa->pa_pc, pa->pa_tag, PCI_CAP_MSI, &co, 0)) |
| | | 381 | return NULL; |
| | | 382 | |
| | | 383 | ih = intr_establish(-1, &msi_pic, -1, IST_EDGE, level, |
| | | 384 | func, arg, 0); |
| | | 385 | if (!ih) |
| | | 386 | return NULL; |
| | | 387 | |
| | | 388 | msih = malloc(sizeof(*msih), M_DEVBUF, M_WAITOK); |
| | | 389 | msih->ih = ih; |
| | | 390 | msih->pc = pa->pa_pc; |
| | | 391 | msih->tag = pa->pa_tag; |
| | | 392 | msih->co = co; |
| | | 393 | |
| | | 394 | ci = msih->ih->ih_cpu; |
| | | 395 | s = ci->ci_isources[msih->ih->ih_slot]; |
| | | 396 | cr = pci_conf_read(pa->pa_pc, pa->pa_tag, co); |
| | | 397 | pci_conf_write(pa->pa_pc, pa->pa_tag, co + 4, |
| | | 398 | 0xfee00000 | ci->ci_cpuid << 12); |
| | | 399 | if (cr & 0x800000) { |
| | | 400 | pci_conf_write(pa->pa_pc, pa->pa_tag, co + 8, 0); |
| | | 401 | pci_conf_write(pa->pa_pc, pa->pa_tag, co + 12, |
| | | 402 | s->is_idtvec | 0x4000); |
| | | 403 | } else |
| | | 404 | pci_conf_write(pa->pa_pc, pa->pa_tag, co + 8, |
| | | 405 | s->is_idtvec | 0x4000); |
| | | 406 | pci_conf_write(pa->pa_pc, pa->pa_tag, co, 0x10000); |
| | | 407 | return ih; |
| | | 408 | } |
| | | 409 | |
| | | 410 | void |
| | | 411 | pci_msi_disestablish(void *ih) |
| | | 412 | { |
| | | 413 | struct msi_hdl *msih = ih; |
| | | 414 | |
| | | 415 | pci_conf_write(msih->pc, msih->tag, msih->co, 0); |
| | | 416 | intr_disestablish(msih->ih); |
| | | 417 | } |
| | | 418 | #endif |