HelenOS sources
This source file includes following definitions.
- mac_get_pio_window
- mac_add_fun
- mac_dev_add
- mac_get_resources
- mac_enable_interrupt
- main
#include <ddf/driver.h>
#include <ddf/log.h>
#include <errno.h>
#include <ops/hw_res.h>
#include <ops/pio_window.h>
#include <stdio.h>
#include <sysinfo.h>
#define NAME "mac"
typedef struct {
hw_resource_list_t hw_resources;
pio_window_t pio_window;
} mac_fun_t;
static hw_resource_t adb_res[] = {
{
.type = IO_RANGE,
.res.io_range = {
.address = 0,
.size = 0x2000,
.relative = true,
.endianness = BIG_ENDIAN
}
},
{
.type = INTERRUPT,
.res.interrupt = {
.irq = 0
}
},
};
static mac_fun_t adb_data = {
.hw_resources = {
sizeof(adb_res) / sizeof(adb_res[0]),
adb_res
},
.pio_window = {
.io = {
.base = 0,
.size = 0x2000
}
}
};
static hw_resource_t pci_conf_regs[] = {
{
.type = IO_RANGE,
.res.io_range = {
.address = 0xfec00000,
.size = 4,
.relative = false,
.endianness = LITTLE_ENDIAN
}
},
{
.type = IO_RANGE,
.res.io_range = {
.address = 0xfee00000,
.size = 4,
.relative = false,
.endianness = LITTLE_ENDIAN
}
}
};
static mac_fun_t pci_data = {
.hw_resources = {
2,
pci_conf_regs
}
};
static ddf_dev_ops_t mac_fun_ops;
static mac_fun_t *mac_fun(ddf_fun_t *ddf_fun)
{
return ddf_fun_data_get(ddf_fun);
}
static pio_window_t *mac_get_pio_window(ddf_fun_t *ddf_fun)
{
mac_fun_t *fun = mac_fun(ddf_fun);
return &fun->pio_window;
}
static bool mac_add_fun(ddf_dev_t *dev, const char *name,
const char *str_match_id, mac_fun_t *fun_proto)
{
ddf_msg(LVL_DEBUG, "Adding new function '%s'.", name);
printf("mac: Adding new function '%s'.\n", name);
ddf_fun_t *fnode = NULL;
errno_t rc;
fnode = ddf_fun_create(dev, fun_inner, name);
if (fnode == NULL)
goto failure;
mac_fun_t *fun = ddf_fun_data_alloc(fnode, sizeof(mac_fun_t));
*fun = *fun_proto;
rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
if (rc != EOK)
goto failure;
ddf_fun_set_ops(fnode, &mac_fun_ops);
if (ddf_fun_bind(fnode) != EOK) {
ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
goto failure;
}
printf("mac: Added new function '%s' (str=%s).\n", name, str_match_id);
return true;
failure:
if (fnode != NULL)
ddf_fun_destroy(fnode);
ddf_msg(LVL_ERROR, "Failed adding function '%s'.", name);
return false;
}
static errno_t mac_dev_add(ddf_dev_t *dev)
{
errno_t rc;
uintptr_t cuda_physical;
sysarg_t cuda_inr;
#if 0
if (!mac_add_fun(dev, "pci0", "intel_pci", &pci_data)) {
ddf_msg(LVL_ERROR, "Failed to add PCI function for Mac platform.");
return EIO;
}
#else
(void)pci_data;
#endif
rc = sysinfo_get_value("cuda.address.physical", &cuda_physical);
if (rc != EOK)
return EIO;
rc = sysinfo_get_value("cuda.inr", &cuda_inr);
if (rc != EOK)
return EIO;
adb_data.pio_window.io.base = cuda_physical;
adb_res[1].res.interrupt.irq = cuda_inr;
if (!mac_add_fun(dev, "adb", "cuda_adb", &adb_data)) {
ddf_msg(LVL_ERROR, "Failed to add ADB function for Mac platform.");
return EIO;
}
return EOK;
}
static driver_ops_t mac_ops = {
.dev_add = &mac_dev_add
};
static driver_t mac_driver = {
.name = NAME,
.driver_ops = &mac_ops
};
static hw_resource_list_t *mac_get_resources(ddf_fun_t *fnode)
{
mac_fun_t *fun = mac_fun(fnode);
assert(fun != NULL);
return &fun->hw_resources;
}
static errno_t mac_enable_interrupt(ddf_fun_t *fun, int irq)
{
return false;
}
static pio_window_ops_t fun_pio_window_ops = {
.get_pio_window = &mac_get_pio_window
};
static hw_res_ops_t fun_hw_res_ops = {
.get_resource_list = &mac_get_resources,
.enable_interrupt = &mac_enable_interrupt
};
int main(int argc, char *argv[])
{
printf("%s: HelenOS Mac platform driver\n", NAME);
ddf_log_init(NAME);
mac_fun_ops.interfaces[HW_RES_DEV_IFACE] = &fun_hw_res_ops;
mac_fun_ops.interfaces[PIO_WINDOW_DEV_IFACE] = &fun_pio_window_ops;
return ddf_driver_main(&mac_driver);
}
HelenOS homepage, sources at GitHub