Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/asmc/asmc.c
| Show First 20 Lines • Show All 412 Lines • ▼ Show 20 Lines | asmc_probe(device_t dev) | ||||||||||
| if (rv > 0) | if (rv > 0) | ||||||||||
| return (rv); | return (rv); | ||||||||||
| product = kern_getenv("smbios.system.product"); | product = kern_getenv("smbios.system.product"); | ||||||||||
| device_set_descf(dev, "Apple %s", product ? product : "SMC"); | device_set_descf(dev, "Apple %s", product ? product : "SMC"); | ||||||||||
| freeenv(product); | freeenv(product); | ||||||||||
| return (rv); | return (rv); | ||||||||||
| } | } | ||||||||||
| /* | |||||||||||
| * Try PIO first; fall back to MMIO for T2 Macs. | |||||||||||
| */ | |||||||||||
| static int | static int | ||||||||||
| asmc_attach(device_t dev) | asmc_try_probe(device_t dev) | ||||||||||
| { | { | ||||||||||
| int i, j; | |||||||||||
| int ret; | |||||||||||
| char name[2]; | |||||||||||
| struct asmc_softc *sc = device_get_softc(dev); | struct asmc_softc *sc = device_get_softc(dev); | ||||||||||
| struct sysctl_ctx_list *sysctlctx; | |||||||||||
| struct sysctl_oid *sysctlnode; | |||||||||||
| /* | sc->sc_ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT, | ||||||||||
| * Try MMIO first (T2 Macs expose SMC via memory-mapped I/O). | &sc->sc_rid_port, RF_ACTIVE); | ||||||||||
| * Fall back to standard I/O port if MMIO is not available. | if (sc->sc_ioport != NULL) | ||||||||||
| */ | return (0); | ||||||||||
| sc->sc_rid_mem = 0; | sc->sc_rid_mem = 0; | ||||||||||
| sc->sc_iomem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, | sc->sc_iomem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, | ||||||||||
| &sc->sc_rid_mem, RF_ACTIVE); | &sc->sc_rid_mem, RF_ACTIVE); | ||||||||||
| if (sc->sc_iomem != NULL) { | if (sc->sc_iomem != NULL) { | ||||||||||
| if (asmc_mmio_probe(dev) == 0) { | if (asmc_mmio_probe(dev) == 0) { | ||||||||||
| sc->sc_is_mmio = 1; | sc->sc_is_mmio = true; | ||||||||||
| device_printf(dev, "using MMIO backend (T2)\n"); | device_printf(dev, "using MMIO backend (T2)\n"); | ||||||||||
| } else { | return (0); | ||||||||||
| } | |||||||||||
| bus_release_resource(dev, SYS_RES_MEMORY, | bus_release_resource(dev, SYS_RES_MEMORY, | ||||||||||
| sc->sc_rid_mem, sc->sc_iomem); | sc->sc_rid_mem, sc->sc_iomem); | ||||||||||
| sc->sc_iomem = NULL; | sc->sc_iomem = NULL; | ||||||||||
| } | } | ||||||||||
adrian: Just change this to if (sc->sc_ioport == NULL) so you don't need the empty section | |||||||||||
Done Inline Actions
ngie: | |||||||||||
Done Inline ActionsI had it empty because i don't know if T1 Mac will need it.. seuros: I had it empty because i don't know if T1 Mac will need it..
We still need to test this driver… | |||||||||||
Not Done Inline Actions
I can confirm that after this lands (I have a '16 MBP, which has a T1 chip). ngie: > I had it empty because i don't know if T1 Mac will need it..
> We still need to test this… | |||||||||||
| } | |||||||||||
| if (!sc->sc_is_mmio) { | |||||||||||
| sc->sc_ioport = bus_alloc_resource_any(dev, SYS_RES_IOPORT, | |||||||||||
| &sc->sc_rid_port, RF_ACTIVE); | |||||||||||
| if (sc->sc_ioport == NULL) { | |||||||||||
| device_printf(dev, "unable to allocate IO port\n"); | device_printf(dev, "unable to allocate IO port\n"); | ||||||||||
| ret = ENOMEM; | return (ENOMEM); | ||||||||||
| goto err; | |||||||||||
| } | } | ||||||||||
| } | |||||||||||
| static int | |||||||||||
Done Inline Actions
I know this requires additional changes, but this seems best expressed via a bool quantity (true/false). ngie: I know this requires additional changes, but this seems best expressed via a bool quantity… | |||||||||||
| asmc_attach(device_t dev) | |||||||||||
| { | |||||||||||
| int i, j; | |||||||||||
| int ret; | |||||||||||
| char name[2]; | |||||||||||
| struct asmc_softc *sc = device_get_softc(dev); | |||||||||||
| struct sysctl_ctx_list *sysctlctx; | |||||||||||
| struct sysctl_oid *sysctlnode; | |||||||||||
| ret = asmc_try_probe(dev); | |||||||||||
| if (ret != 0) | |||||||||||
| goto err; | |||||||||||
Not Done Inline ActionsThis logic seems like a good candidate for another helper probe function for clarity and to make the logic cleaner for humans to parse. ngie: This logic seems like a good candidate for another helper probe function for clarity and to… | |||||||||||
| sysctlctx = device_get_sysctl_ctx(dev); | sysctlctx = device_get_sysctl_ctx(dev); | ||||||||||
| sysctlnode = device_get_sysctl_tree(dev); | sysctlnode = device_get_sysctl_tree(dev); | ||||||||||
| /* Mutex may already be initialized by asmc_mmio_probe() */ | /* Mutex may already be initialized by asmc_mmio_probe() */ | ||||||||||
| if (!mtx_initialized(&sc->sc_mtx)) | if (!mtx_initialized(&sc->sc_mtx)) | ||||||||||
| mtx_init(&sc->sc_mtx, "asmc", NULL, MTX_SPIN); | mtx_init(&sc->sc_mtx, "asmc", NULL, MTX_SPIN); | ||||||||||
| /* Read SMC revision, key count, fan count */ | /* Read SMC revision, key count, fan count */ | ||||||||||
| ▲ Show 20 Lines • Show All 2,069 Lines • Show Last 20 Lines | |||||||||||
Just change this to if (sc->sc_ioport == NULL) so you don't need the empty section