1 /* $OpenBSD: gscpm.c,v 1.10 2020/07/06 13:33:07 pirofti Exp $ */ 2 /* 3 * Copyright (c) 2004 Alexander Yurchenko <grange@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 /* 19 * National Semiconductor Geode SC1100 SMI/ACPI module. 20 */ 21 22 #include <sys/param.h> 23 #include <sys/systm.h> 24 #include <sys/device.h> 25 #include <sys/kernel.h> 26 #include <sys/timetc.h> 27 28 #include <machine/bus.h> 29 30 #include <dev/pci/pcireg.h> 31 #include <dev/pci/pcivar.h> 32 #include <dev/pci/pcidevs.h> 33 34 #include <i386/pci/gscpmreg.h> 35 36 struct gscpm_softc { 37 struct device sc_dev; 38 39 pci_chipset_tag_t sc_pc; 40 pcitag_t sc_tag; 41 bus_space_tag_t sc_iot; 42 bus_space_handle_t sc_acpi_ioh; 43 }; 44 45 int gscpm_match(struct device *, void *, void *); 46 void gscpm_attach(struct device *, struct device *, void *); 47 48 void gscpm_setperf(int); 49 50 u_int gscpm_get_timecount(struct timecounter *tc); 51 52 struct timecounter gscpm_timecounter = { 53 gscpm_get_timecount, /* get_timecount */ 54 0, /* no poll_pps */ 55 0xffffff, /* counter_mask */ 56 3579545, /* frequency */ 57 "GSCPM", /* name */ 58 1000, /* quality */ 59 NULL, /* private bits */ 60 0 /* expose to user */ 61 }; 62 63 struct cfattach gscpm_ca = { 64 sizeof (struct gscpm_softc), 65 gscpm_match, 66 gscpm_attach 67 }; 68 69 struct cfdriver gscpm_cd = { 70 NULL, "gscpm", DV_DULL 71 }; 72 73 #if 0 74 static void *gscpm_cookie; /* XXX */ 75 #endif 76 77 int 78 gscpm_match(struct device *parent, void *match, void *aux) 79 { 80 struct pci_attach_args *pa = aux; 81 82 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NS && 83 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NS_SC1100_SMI) 84 return (1); 85 86 return (0); 87 } 88 89 void 90 gscpm_attach(struct device *parent, struct device *self, void *aux) 91 { 92 struct gscpm_softc *sc = (struct gscpm_softc *)self; 93 struct pci_attach_args *pa = aux; 94 pcireg_t csr, acpibase; 95 96 sc->sc_pc = pa->pa_pc; 97 sc->sc_tag = pa->pa_tag; 98 sc->sc_iot = pa->pa_iot; 99 100 /* Enable I/O space */ 101 csr = pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_COMMAND_STATUS_REG); 102 pci_conf_write(sc->sc_pc, sc->sc_tag, PCI_COMMAND_STATUS_REG, 103 csr | PCI_COMMAND_IO_ENABLE); 104 105 /* Map ACPI registers */ 106 acpibase = pci_conf_read(sc->sc_pc, sc->sc_tag, GSCPM_ACPIBASE); 107 if (PCI_MAPREG_IO_ADDR(acpibase) == 0 || 108 bus_space_map(sc->sc_iot, PCI_MAPREG_IO_ADDR(acpibase), 109 GSCPM_ACPISIZE, 0, &sc->sc_acpi_ioh)) { 110 printf(": failed to map ACPI registers\n"); 111 return; 112 } 113 114 printf("\n"); 115 116 /* Hook into the kern_tc */ 117 gscpm_timecounter.tc_priv = sc; 118 tc_init(&gscpm_timecounter); 119 120 /* XXX: disabled due to unresolved yet hardware errata */ 121 #if 0 122 /* Hook into the hw.setperf sysctl */ 123 gscpm_cookie = sc; 124 cpu_setperf = gscpm_setperf; 125 #endif 126 127 } 128 129 u_int 130 gscpm_get_timecount(struct timecounter *tc) 131 { 132 struct gscpm_softc *sc = tc->tc_priv; 133 134 return (bus_space_read_4(sc->sc_iot, sc->sc_acpi_ioh, GSCPM_PM_TMR)); 135 } 136 137 #if 0 138 void 139 gscpm_setperf(int level) 140 { 141 struct gscpm_softc *sc = gscpm_cookie; 142 int i; 143 u_int32_t pctl; 144 145 pctl = bus_space_read_4(sc->sc_iot, sc->sc_acpi_ioh, GSCPM_P_CNT); 146 147 if (level == 100) { 148 /* 100 is a maximum perfomance, disable throttling */ 149 pctl &= ~GSCPM_P_CNT_THTEN; 150 } else { 151 for (i = 0; i < GSCPM_THT_LEVELS; i++) 152 if (level >= gscpm_tht[i].level) 153 break; 154 pctl = (0xf0 | GSCPM_P_CNT_THTEN | 155 GSCPM_P_CNT_CLK(gscpm_tht[i].value)); 156 } 157 158 /* Update processor control register */ 159 bus_space_write_4(sc->sc_iot, sc->sc_acpi_ioh, GSCPM_P_CNT, pctl); 160 } 161 #endif 162