Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/extres/syscon/syscon_generic.c
Show All 40 Lines | |||||
#include <sys/kernel.h> | #include <sys/kernel.h> | ||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/rman.h> | #include <sys/rman.h> | ||||
#include <machine/bus.h> | #include <machine/bus.h> | ||||
#include <dev/fdt/simplebus.h> | |||||
#include <dev/ofw/ofw_bus.h> | #include <dev/ofw/ofw_bus.h> | ||||
#include <dev/ofw/ofw_bus_subr.h> | #include <dev/ofw/ofw_bus_subr.h> | ||||
#include "syscon_if.h" | #include "syscon_if.h" | ||||
#include "syscon.h" | #include "syscon.h" | ||||
#include "syscon_generic.h" | #include "syscon_generic.h" | ||||
MALLOC_DECLARE(M_SYSCON); | MALLOC_DECLARE(M_SYSCON); | ||||
static uint32_t syscon_generic_read_4(struct syscon *syscon, bus_size_t offset); | static uint32_t syscon_generic_read_4(struct syscon *syscon, bus_size_t offset); | ||||
static int syscon_generic_write_4(struct syscon *syscon, bus_size_t offset, | static int syscon_generic_write_4(struct syscon *syscon, bus_size_t offset, | ||||
uint32_t val); | uint32_t val); | ||||
static int syscon_generic_modify_4(struct syscon *syscon, bus_size_t offset, | static int syscon_generic_modify_4(struct syscon *syscon, bus_size_t offset, | ||||
uint32_t clear_bits, uint32_t set_bits); | uint32_t clear_bits, uint32_t set_bits); | ||||
static int syscon_generic_get_handle(device_t dev, struct syscon **syscon); | |||||
/* | /* | ||||
* Generic syscon driver (FDT) | * Generic syscon driver (FDT) | ||||
*/ | */ | ||||
static struct ofw_compat_data compat_data[] = { | static struct ofw_compat_data compat_data[] = { | ||||
{"syscon", 1}, | {"syscon", 1}, | ||||
{NULL, 0} | {NULL, 0} | ||||
}; | }; | ||||
#define SYSCON_LOCK(_sc) mtx_lock_spin(&(_sc)->mtx) | #define SYSCON_LOCK(_sc) mtx_lock_spin(&(_sc)->mtx) | ||||
#define SYSCON_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->mtx) | #define SYSCON_UNLOCK(_sc) mtx_unlock_spin(&(_sc)->mtx) | ||||
#define SYSCON_LOCK_INIT(_sc) mtx_init(&(_sc)->mtx, \ | #define SYSCON_LOCK_INIT(_sc) mtx_init(&(_sc)->mtx, \ | ||||
device_get_nameunit((_sc)->dev), "syscon", MTX_SPIN) | device_get_nameunit((_sc)->dev), "syscon", MTX_SPIN) | ||||
#define SYSCON_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->mtx); | #define SYSCON_LOCK_DESTROY(_sc) mtx_destroy(&(_sc)->mtx); | ||||
#define SYSCON_ASSERT_LOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_OWNED); | #define SYSCON_ASSERT_LOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_OWNED); | ||||
#define SYSCON_ASSERT_UNLOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_NOTOWNED); | #define SYSCON_ASSERT_UNLOCKED(_sc) mtx_assert(&(_sc)->mtx, MA_NOTOWNED); | ||||
static syscon_method_t syscon_generic_methods[] = { | static syscon_method_t syscon_generic_methods[] = { | ||||
SYSCONMETHOD(syscon_read_4, syscon_generic_read_4), | SYSCONMETHOD(syscon_read_4, syscon_generic_read_4), | ||||
SYSCONMETHOD(syscon_write_4, syscon_generic_write_4), | SYSCONMETHOD(syscon_write_4, syscon_generic_write_4), | ||||
SYSCONMETHOD(syscon_modify_4, syscon_generic_modify_4), | SYSCONMETHOD(syscon_modify_4, syscon_generic_modify_4), | ||||
SYSCONMETHOD_END | SYSCONMETHOD_END | ||||
}; | }; | ||||
DEFINE_CLASS_1(syscon_generic, syscon_generic_class, syscon_generic_methods, | DEFINE_CLASS_1(syscon_generic_syscon, syscon_generic_class, | ||||
0, syscon_class); | syscon_generic_methods, 0, syscon_class); | ||||
static uint32_t | static uint32_t | ||||
syscon_generic_read_4(struct syscon *syscon, bus_size_t offset) | syscon_generic_read_4(struct syscon *syscon, bus_size_t offset) | ||||
{ | { | ||||
struct syscon_generic_softc *sc; | struct syscon_generic_softc *sc; | ||||
uint32_t val; | uint32_t val; | ||||
sc = device_get_softc(syscon->pdev); | sc = device_get_softc(syscon->pdev); | ||||
Show All 31 Lines | syscon_generic_modify_4(struct syscon *syscon, bus_size_t offset, | ||||
val &= ~clear_bits; | val &= ~clear_bits; | ||||
val |= set_bits; | val |= set_bits; | ||||
bus_write_4(sc->mem_res, offset, val); | bus_write_4(sc->mem_res, offset, val); | ||||
SYSCON_UNLOCK(sc); | SYSCON_UNLOCK(sc); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
syscon_generic_get_handle(device_t dev, struct syscon **syscon) | |||||
{ | |||||
struct syscon_generic_softc *sc; | |||||
sc = device_get_softc(dev); | |||||
*syscon = sc->syscon; | |||||
if (*syscon == NULL) | |||||
return (ENODEV); | |||||
return (0); | |||||
} | |||||
static int | |||||
syscon_generic_probe(device_t dev) | syscon_generic_probe(device_t dev) | ||||
{ | { | ||||
if (!ofw_bus_status_okay(dev)) | if (!ofw_bus_status_okay(dev)) | ||||
return (ENXIO); | return (ENXIO); | ||||
if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) | if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) | ||||
return (ENXIO); | return (ENXIO); | ||||
device_set_desc(dev, "syscon"); | device_set_desc(dev, "syscon"); | ||||
if (!bootverbose) | if (!bootverbose) | ||||
device_quiet(dev); | device_quiet(dev); | ||||
if (ofw_bus_is_compatible(dev, "simple-bus")) { | |||||
return (BUS_PROBE_DEFAULT); | |||||
} | |||||
return (BUS_PROBE_GENERIC); | return (BUS_PROBE_GENERIC); | ||||
} | } | ||||
static int | static int | ||||
syscon_generic_attach(device_t dev) | syscon_generic_attach(device_t dev) | ||||
{ | { | ||||
struct syscon_generic_softc *sc; | struct syscon_generic_softc *sc; | ||||
int rid; | int rid; | ||||
Show All 11 Lines | syscon_generic_attach(device_t dev) | ||||
SYSCON_LOCK_INIT(sc); | SYSCON_LOCK_INIT(sc); | ||||
sc->syscon = syscon_create_ofw_node(dev, &syscon_generic_class, | sc->syscon = syscon_create_ofw_node(dev, &syscon_generic_class, | ||||
ofw_bus_get_node(dev)); | ofw_bus_get_node(dev)); | ||||
if (sc->syscon == NULL) { | if (sc->syscon == NULL) { | ||||
device_printf(dev, "Failed to create/register syscon\n"); | device_printf(dev, "Failed to create/register syscon\n"); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
if (ofw_bus_is_compatible(dev, "simple-bus")) | |||||
simplebus_attach(sc->dev); | |||||
mmel: simplebus_attach is public function and should be used here. | |||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
syscon_generic_detach(device_t dev) | syscon_generic_detach(device_t dev) | ||||
{ | { | ||||
struct syscon_generic_softc *sc; | struct syscon_generic_softc *sc; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
if (sc->syscon != NULL) { | if (sc->syscon != NULL) { | ||||
syscon_unregister(sc->syscon); | syscon_unregister(sc->syscon); | ||||
free(sc->syscon, M_SYSCON); | free(sc->syscon, M_SYSCON); | ||||
} | } | ||||
if (ofw_bus_is_compatible(dev, "simple-bus")) | |||||
Not Done Inline Actionssimplebus_detach() should be declared public and should be called from here mmel: simplebus_detach() should be declared public and should be called from here | |||||
simplebus_detach(sc->dev); | |||||
SYSCON_LOCK_DESTROY(sc); | SYSCON_LOCK_DESTROY(sc); | ||||
if (sc->mem_res != NULL) | if (sc->mem_res != NULL) | ||||
bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res); | bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->mem_res); | ||||
return (0); | return (0); | ||||
} | } | ||||
static device_method_t syscon_generic_dmethods[] = { | static device_method_t syscon_generic_dmethods[] = { | ||||
Not Done Inline ActionsThis clock interface is not common and thus cannot be added into common (universal) driver mmel: This clock interface is not common and thus cannot be added into common (universal) driver | |||||
/* Device interface */ | /* Device interface */ | ||||
DEVMETHOD(device_probe, syscon_generic_probe), | DEVMETHOD(device_probe, syscon_generic_probe), | ||||
DEVMETHOD(device_attach, syscon_generic_attach), | DEVMETHOD(device_attach, syscon_generic_attach), | ||||
DEVMETHOD(device_detach, syscon_generic_detach), | DEVMETHOD(device_detach, syscon_generic_detach), | ||||
DEVMETHOD(syscon_get_handle, syscon_generic_get_handle), | |||||
DEVMETHOD_END | DEVMETHOD_END | ||||
}; | }; | ||||
DEFINE_CLASS_0(syscon_generic, syscon_generic_driver, syscon_generic_dmethods, | DEFINE_CLASS_1(syscon_generic, syscon_generic_driver, syscon_generic_dmethods, | ||||
sizeof(struct syscon_generic_softc)); | sizeof(struct syscon_generic_softc), simplebus_driver); | ||||
static devclass_t syscon_generic_devclass; | static devclass_t syscon_generic_devclass; | ||||
EARLY_DRIVER_MODULE(syscon_generic, simplebus, syscon_generic_driver, | EARLY_DRIVER_MODULE(syscon_generic, simplebus, syscon_generic_driver, | ||||
syscon_generic_devclass, 0, 0, BUS_PASS_DEFAULT); | syscon_generic_devclass, 0, 0, BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE); | ||||
MODULE_VERSION(syscon_generic, 1); | MODULE_VERSION(syscon_generic, 1); | ||||
simplebus_attach is public function and should be used here.