xref: /openbsd/sys/dev/acpi/acpimcfg.c (revision 09467b48)
1 /* $OpenBSD: acpimcfg.c,v 1.4 2018/08/19 08:23:47 kettenis Exp $ */
2 /*
3  * Copyright (c) 2010 Mark Kettenis <kettenis@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <sys/param.h>
19 #include <sys/systm.h>
20 #include <sys/device.h>
21 
22 #include <dev/acpi/acpireg.h>
23 #include <dev/acpi/acpivar.h>
24 #include <dev/pci/pcivar.h>
25 
26 int acpimcfg_match(struct device *, void *, void *);
27 void acpimcfg_attach(struct device *, struct device *, void *);
28 
29 struct cfattach acpimcfg_ca = {
30 	sizeof(struct device), acpimcfg_match, acpimcfg_attach
31 };
32 
33 struct cfdriver acpimcfg_cd = {
34 	NULL, "acpimcfg", DV_DULL
35 };
36 
37 int
38 acpimcfg_match(struct device *parent, void *match, void *aux)
39 {
40 	struct acpi_attach_args *aaa = aux;
41 	struct acpi_table_header *hdr;
42 
43 	/*
44 	 * If we do not have a table, it is not us
45 	 */
46 	if (aaa->aaa_table == NULL)
47 		return (0);
48 
49 	/*
50 	 * If it is an MCFG table, we can attach
51 	 */
52 	hdr = (struct acpi_table_header *)aaa->aaa_table;
53 	if (memcmp(hdr->signature, MCFG_SIG, sizeof(MCFG_SIG) - 1) != 0)
54 		return (0);
55 
56 	return (1);
57 }
58 
59 void
60 acpimcfg_attach(struct device *parent, struct device *self, void *aux)
61 {
62 	struct acpi_attach_args *aaa = aux;
63 	struct acpi_mcfg *mcfg = (struct acpi_mcfg *)aaa->aaa_table;
64 	caddr_t addr = (caddr_t)(mcfg + 1);
65 
66 	printf("\n");
67 
68 	while (addr < (caddr_t)mcfg + mcfg->hdr.length) {
69 		struct acpi_mcfg_entry *entry = (struct acpi_mcfg_entry *)addr;
70 
71 		printf("%s: addr 0x%llx, bus %d-%d\n", self->dv_xname,
72 		    entry->base_address, entry->min_bus_number, entry->max_bus_number);
73 
74 		pci_mcfg_init(aaa->aaa_memt, entry->base_address,
75 		     entry->segment, entry->min_bus_number, entry->max_bus_number);
76 		addr += sizeof(struct acpi_mcfg_entry);
77 	}
78 }
79