#ifdef CONFIG_PPC_SMLPAR /** * vio_cmo_pool - A pool of IO memory for CMO use * * @size: The size of the pool in bytes * @free: The amount of free memory in the pool
*/ struct vio_cmo_pool {
size_t size;
size_t free;
};
/* How many ms to delay queued balance work */ #define VIO_CMO_BALANCE_DELAY 100
/* Portion out IO memory to CMO devices by this chunk size */ #define VIO_CMO_BALANCE_CHUNK 131072
/** * vio_cmo_dev_entry - A device that is CMO-enabled and requires entitlement * * @vio_dev: struct vio_dev pointer * @list: pointer to other devices on bus that are being tracked
*/ struct vio_cmo_dev_entry { struct vio_dev *viodev; struct list_head list;
};
/** * vio_cmo - VIO bus accounting structure for CMO entitlement * * @lock: spinlock for entire structure * @balance_q: work queue for balancing system entitlement * @device_list: list of CMO-enabled devices requiring entitlement * @entitled: total system entitlement in bytes * @reserve: pool of memory from which devices reserve entitlement, incl. spare * @excess: pool of excess entitlement not needed for device reserves or spare * @spare: IO memory for device hotplug functionality * @min: minimum necessary for system operation * @desired: desired memory for system operation * @curr: bytes currently allocated * @high: high water mark for IO data usage
*/ staticstruct vio_cmo {
spinlock_t lock; struct delayed_work balance_q; struct list_head device_list;
size_t entitled; struct vio_cmo_pool reserve; struct vio_cmo_pool excess;
size_t spare;
size_t min;
size_t desired;
size_t curr;
size_t high;
} vio_cmo;
/** * vio_cmo_OF_devices - Count the number of OF devices that have DMA windows
*/ staticint vio_cmo_num_OF_devs(void)
{ struct device_node *node_vroot; int count = 0;
/* * Count the number of vdevice entries with an * ibm,my-dma-window OF property
*/
node_vroot = of_find_node_by_name(NULL, "vdevice"); if (node_vroot) { struct device_node *of_node; struct property *prop;
/** * vio_cmo_alloc - allocate IO memory for CMO-enable devices * * @viodev: VIO device requesting IO memory * @size: size of allocation requested * * Allocations come from memory reserved for the devices and any excess * IO memory available to all devices. The spare pool used to service * hotplug must be equal to %VIO_CMO_MIN_ENT for the excess pool to be * made available. * * Return codes: * 0 for successful allocation and -ENOMEM for a failure
*/ staticinlineint vio_cmo_alloc(struct vio_dev *viodev, size_t size)
{ unsignedlong flags;
size_t reserve_free = 0;
size_t excess_free = 0; int ret = -ENOMEM;
spin_lock_irqsave(&vio_cmo.lock, flags);
/* Determine the amount of free entitlement available in reserve */ if (viodev->cmo.entitled > viodev->cmo.allocated)
reserve_free = viodev->cmo.entitled - viodev->cmo.allocated;
/* If spare is not fulfilled, the excess pool can not be used. */ if (vio_cmo.spare >= VIO_CMO_MIN_ENT)
excess_free = vio_cmo.excess.free;
/* The request can be satisfied */ if ((reserve_free + excess_free) >= size) {
vio_cmo.curr += size; if (vio_cmo.curr > vio_cmo.high)
vio_cmo.high = vio_cmo.curr;
viodev->cmo.allocated += size;
size -= min(reserve_free, size);
vio_cmo.excess.free -= size;
ret = 0;
}
/** * vio_cmo_dealloc - deallocate IO memory from CMO-enable devices * @viodev: VIO device freeing IO memory * @size: size of deallocation * * IO memory is freed by the device back to the correct memory pools. * The spare pool is replenished first from either memory pool, then * the reserve pool is used to reduce device entitlement, the excess * pool is used to increase the reserve pool toward the desired entitlement * target, and then the remaining memory is returned to the pools. *
*/ staticinlinevoid vio_cmo_dealloc(struct vio_dev *viodev, size_t size)
{ unsignedlong flags;
size_t spare_needed = 0;
size_t excess_freed = 0;
size_t reserve_freed = size;
size_t tmp; int balance = 0;
/* Amount of memory freed from the excess pool */ if (viodev->cmo.allocated > viodev->cmo.entitled) {
excess_freed = min(reserve_freed, (viodev->cmo.allocated -
viodev->cmo.entitled));
reserve_freed -= excess_freed;
}
/* Spare is a subset of the reserve pool, replenish it first. */
spare_needed = VIO_CMO_MIN_ENT - vio_cmo.spare;
/* * Replenish the spare in the reserve pool from the excess pool. * This moves entitlement into the reserve pool.
*/ if (spare_needed && excess_freed) {
tmp = min(excess_freed, spare_needed);
vio_cmo.excess.size -= tmp;
vio_cmo.reserve.size += tmp;
vio_cmo.spare += tmp;
excess_freed -= tmp;
spare_needed -= tmp;
balance = 1;
}
/* * Replenish the spare in the reserve pool from the reserve pool. * This removes entitlement from the device down to VIO_CMO_MIN_ENT, * if needed, and gives it to the spare pool. The amount of used * memory in this pool does not change.
*/ if (spare_needed && reserve_freed) {
tmp = min3(spare_needed, reserve_freed, (viodev->cmo.entitled - VIO_CMO_MIN_ENT));
/* * Increase the reserve pool until the desired allocation is met. * Move an allocation freed from the excess pool into the reserve * pool and schedule a balance operation.
*/ if (excess_freed && (vio_cmo.desired > vio_cmo.reserve.size)) {
tmp = min(excess_freed, (vio_cmo.desired - vio_cmo.reserve.size));
/* Return memory from the excess pool to that pool */ if (excess_freed)
vio_cmo.excess.free += excess_freed;
if (balance)
schedule_delayed_work(&vio_cmo.balance_q, VIO_CMO_BALANCE_DELAY);
spin_unlock_irqrestore(&vio_cmo.lock, flags);
}
/** * vio_cmo_entitlement_update - Manage system entitlement changes * * @new_entitlement: new system entitlement to attempt to accommodate * * Increases in entitlement will be used to fulfill the spare entitlement * and the rest is given to the excess pool. Decreases, if they are * possible, come from the excess pool and from unused device entitlement * * Returns: 0 on success, -ENOMEM when change can not be made
*/ int vio_cmo_entitlement_update(size_t new_entitlement)
{ struct vio_dev *viodev; struct vio_cmo_dev_entry *dev_ent; unsignedlong flags;
size_t avail, delta, tmp;
/* * Need to check how much unused entitlement each device can * sacrifice to fulfill entitlement change.
*/
list_for_each_entry(dev_ent, &vio_cmo.device_list, list) { if (avail >= delta) break;
/* Take entitlement from the excess pool first */
tmp = min(vio_cmo.excess.free, delta);
vio_cmo.excess.size -= tmp;
vio_cmo.excess.free -= tmp;
delta -= tmp;
/* * Remove all but VIO_CMO_MIN_ENT bytes from devices * until entitlement change is served
*/
list_for_each_entry(dev_ent, &vio_cmo.device_list, list) { if (!delta) break;
/** * vio_cmo_balance - Balance entitlement among devices * * @work: work queue structure for this operation * * Any system entitlement above the minimum needed for devices, or * already allocated to devices, can be distributed to the devices. * The list of devices is iterated through to recalculate the desired * entitlement level and to determine how much entitlement above the * minimum entitlement is allocated to devices. * * Small chunks of the available entitlement are given to devices until * their requirements are fulfilled or there is no entitlement left to give. * Upon completion sizes of the reserve and excess pools are calculated. * * The system minimum entitlement level is also recalculated here. * Entitlement will be reserved for devices even after vio_bus_remove to * accommodate reloading the driver. The OF tree is walked to count the * number of devices present and this will remove entitlement for devices * that have actually left the system after having vio_bus_remove called.
*/ staticvoid vio_cmo_balance(struct work_struct *work)
{ struct vio_cmo *cmo; struct vio_dev *viodev; struct vio_cmo_dev_entry *dev_ent; unsignedlong flags;
size_t avail = 0, level, chunk, need; int devcount = 0, fulfilled;
/* * Determine how much entitlement is available and reset device * entitlements
*/
avail = cmo->entitled - cmo->spare;
list_for_each_entry(dev_ent, &vio_cmo.device_list, list) {
viodev = dev_ent->viodev;
devcount++;
viodev->cmo.entitled = VIO_CMO_MIN_ENT;
cmo->desired += (viodev->cmo.desired - VIO_CMO_MIN_ENT);
avail -= max_t(size_t, viodev->cmo.allocated, VIO_CMO_MIN_ENT);
}
/* * Having provided each device with the minimum entitlement, loop * over the devices portioning out the remaining entitlement * until there is nothing left.
*/
level = VIO_CMO_MIN_ENT; while (avail) {
fulfilled = 0;
list_for_each_entry(dev_ent, &vio_cmo.device_list, list) {
viodev = dev_ent->viodev;
if (viodev->cmo.desired <= level) {
fulfilled++; continue;
}
/* * Give the device up to VIO_CMO_BALANCE_CHUNK * bytes of entitlement, but do not exceed the * desired level of entitlement for the device.
*/
chunk = min_t(size_t, avail, VIO_CMO_BALANCE_CHUNK);
chunk = min(chunk, (viodev->cmo.desired -
viodev->cmo.entitled));
viodev->cmo.entitled += chunk;
/* * If the memory for this entitlement increase was * already allocated to the device it does not come * from the available pool being portioned out.
*/
need = max(viodev->cmo.allocated, viodev->cmo.entitled)-
max(viodev->cmo.allocated, level);
avail -= need;
} if (fulfilled == devcount) break;
level += VIO_CMO_BALANCE_CHUNK;
}
/* Calculate new reserve and excess pool sizes */
cmo->reserve.size = cmo->min;
cmo->excess.free = 0;
cmo->excess.size = 0;
need = 0;
list_for_each_entry(dev_ent, &vio_cmo.device_list, list) {
viodev = dev_ent->viodev; /* Calculated reserve size above the minimum entitlement */ if (viodev->cmo.entitled)
cmo->reserve.size += (viodev->cmo.entitled -
VIO_CMO_MIN_ENT); /* Calculated used excess entitlement */ if (viodev->cmo.allocated > viodev->cmo.entitled)
need += viodev->cmo.allocated - viodev->cmo.entitled;
}
cmo->excess.size = cmo->entitled - cmo->reserve.size;
cmo->excess.free = cmo->excess.size - need;
/** * vio_cmo_set_dev_desired - Set desired entitlement for a device * * @viodev: struct vio_dev for device to alter * @desired: new desired entitlement level in bytes * * For use by devices to request a change to their entitlement at runtime or * through sysfs. The desired entitlement level is changed and a balancing * of system resources is scheduled to run in the future.
*/ void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired)
{ unsignedlong flags; struct vio_cmo_dev_entry *dev_ent; int found = 0;
if (!firmware_has_feature(FW_FEATURE_CMO)) return;
spin_lock_irqsave(&vio_cmo.lock, flags); if (desired < VIO_CMO_MIN_ENT)
desired = VIO_CMO_MIN_ENT;
/* * Changes will not be made for devices not in the device list. * If it is not in the device list, then no driver is loaded * for the device and it can not receive entitlement.
*/
list_for_each_entry(dev_ent, &vio_cmo.device_list, list) if (viodev == dev_ent->viodev) {
found = 1; break;
} if (!found) {
spin_unlock_irqrestore(&vio_cmo.lock, flags); return;
}
/* Increase/decrease in desired device entitlement */ if (desired >= viodev->cmo.desired) { /* Just bump the bus and device values prior to a balance*/
vio_cmo.desired += desired - viodev->cmo.desired;
viodev->cmo.desired = desired;
} else { /* Decrease bus and device values for desired entitlement */
vio_cmo.desired -= viodev->cmo.desired - desired;
viodev->cmo.desired = desired; /* * If less entitlement is desired than current entitlement, move * any reserve memory in the change region to the excess pool.
*/ if (viodev->cmo.entitled > desired) {
vio_cmo.reserve.size -= viodev->cmo.entitled - desired;
vio_cmo.excess.size += viodev->cmo.entitled - desired; /* * If entitlement moving from the reserve pool to the * excess pool is currently unused, add to the excess * free counter.
*/ if (viodev->cmo.allocated < viodev->cmo.entitled)
vio_cmo.excess.free += viodev->cmo.entitled -
max(viodev->cmo.allocated, desired);
viodev->cmo.entitled = desired;
}
}
schedule_delayed_work(&vio_cmo.balance_q, 0);
spin_unlock_irqrestore(&vio_cmo.lock, flags);
}
/** * vio_cmo_bus_probe - Handle CMO specific bus probe activities * * @viodev - Pointer to struct vio_dev for device * * Determine the devices IO memory entitlement needs, attempting * to satisfy the system minimum entitlement at first and scheduling * a balance operation to take care of the rest at a later time. * * Returns: 0 on success, -EINVAL when device doesn't support CMO, and * -ENOMEM when entitlement is not available for device or * device entry. *
*/ staticint vio_cmo_bus_probe(struct vio_dev *viodev)
{ struct vio_cmo_dev_entry *dev_ent; struct device *dev = &viodev->dev; struct iommu_table *tbl; struct vio_driver *viodrv = to_vio_driver(dev->driver); unsignedlong flags;
size_t size; bool dma_capable = false;
tbl = get_iommu_table_base(dev);
/* A device requires entitlement if it has a DMA window property */ switch (viodev->family) { case VDEVICE: if (of_get_property(viodev->dev.of_node, "ibm,my-dma-window", NULL))
dma_capable = true; break; case PFO:
dma_capable = false; break; default:
dev_warn(dev, "unknown device family: %d\n", viodev->family);
BUG(); break;
}
/* Configure entitlement for the device. */ if (dma_capable) { /* Check that the driver is CMO enabled and get desired DMA */ if (!viodrv->get_desired_dma) {
dev_err(dev, "%s: device driver does not support CMO\n",
__func__); return -EINVAL;
}
/* * If the needs for vio_cmo.min have not changed since they * were last set, the number of devices in the OF tree has * been constant and the IO memory for this is already in * the reserve pool.
*/ if (vio_cmo.min == ((vio_cmo_num_OF_devs() + 1) *
VIO_CMO_MIN_ENT)) { /* Updated desired entitlement if device requires it */ if (size)
vio_cmo.desired += (viodev->cmo.desired -
VIO_CMO_MIN_ENT);
} else {
size_t tmp;
/** * vio_cmo_bus_remove - Handle CMO specific bus removal activities * * @viodev - Pointer to struct vio_dev for device * * Remove the device from the cmo device list. The minimum entitlement * will be reserved for the device as long as it is in the system. The * rest of the entitlement the device had been allocated will be returned * to the system.
*/ staticvoid vio_cmo_bus_remove(struct vio_dev *viodev)
{ struct vio_cmo_dev_entry *dev_ent; unsignedlong flags;
size_t tmp;
spin_lock_irqsave(&vio_cmo.lock, flags); if (viodev->cmo.allocated) {
dev_err(&viodev->dev, "%s: device had %lu bytes of IO " "allocated after remove operation.\n",
__func__, viodev->cmo.allocated);
BUG();
}
/* * Remove the device from the device list being maintained for * CMO enabled devices.
*/
list_for_each_entry(dev_ent, &vio_cmo.device_list, list) if (viodev == dev_ent->viodev) {
list_del(&dev_ent->list);
kfree(dev_ent); break;
}
/* * Devices may not require any entitlement and they do not need * to be processed. Otherwise, return the device's entitlement * back to the pools.
*/ if (viodev->cmo.entitled) { /* * This device has not yet left the OF tree, it's * minimum entitlement remains in vio_cmo.min and * vio_cmo.desired
*/
vio_cmo.desired -= (viodev->cmo.desired - VIO_CMO_MIN_ENT);
/* * Save min allocation for device in reserve as long * as it exists in OF tree as determined by later * balance operation
*/
viodev->cmo.entitled -= VIO_CMO_MIN_ENT;
/* Replenish spare from freed reserve pool */ if (viodev->cmo.entitled && (vio_cmo.spare < VIO_CMO_MIN_ENT)) {
tmp = min(viodev->cmo.entitled, (VIO_CMO_MIN_ENT -
vio_cmo.spare));
vio_cmo.spare += tmp;
viodev->cmo.entitled -= tmp;
}
/* Remaining reserve goes to excess pool */
vio_cmo.excess.size += viodev->cmo.entitled;
vio_cmo.excess.free += viodev->cmo.entitled;
vio_cmo.reserve.size -= viodev->cmo.entitled;
/* * Until the device is removed it will keep a * minimum entitlement; this will guarantee that * a module unload/load will result in a success.
*/
viodev->cmo.entitled = VIO_CMO_MIN_ENT;
viodev->cmo.desired = VIO_CMO_MIN_ENT;
atomic_set(&viodev->cmo.allocs_failed, 0);
}
/** * vio_cmo_bus_init - CMO entitlement initialization at bus init time * * Set up the reserve and excess entitlement pools based on available * system entitlement and the number of devices in the OF tree that * require entitlement in the reserve pool.
*/ staticvoid vio_cmo_bus_init(void)
{ struct hvcall_mpp_data mpp_data; int err;
/* Get current system entitlement */
err = h_get_mpp(&mpp_data);
/* * On failure, continue with entitlement set to 0, will panic() * later when spare is reserved.
*/ if (err != H_SUCCESS) {
printk(KERN_ERR "%s: unable to determine system IO "\ "entitlement. (%d)\n", __func__, err);
vio_cmo.entitled = 0;
} else {
vio_cmo.entitled = mpp_data.entitled_mem;
}
/* Set reservation and check against entitlement */
vio_cmo.spare = VIO_CMO_MIN_ENT;
vio_cmo.reserve.size = vio_cmo.spare;
vio_cmo.reserve.size += (vio_cmo_num_OF_devs() *
VIO_CMO_MIN_ENT); if (vio_cmo.reserve.size > vio_cmo.entitled) {
printk(KERN_ERR "%s: insufficient system entitlement\n",
__func__);
panic("%s: Insufficient system entitlement", __func__);
}
/** * vio_h_cop_sync - Perform a synchronous PFO co-processor operation * * @vdev - Pointer to a struct vio_dev for device * @op - Pointer to a struct vio_pfo_op for the operation parameters * * Calls the hypervisor to synchronously perform the PFO operation * described in @op. In the case of a busy response from the hypervisor, * the operation will be re-submitted indefinitely unless a non-zero timeout * is specified or an error occurs. The timeout places a limit on when to * stop re-submitting a operation, the total time can be exceeded if an * operation is in progress. * * If op->hcall_ret is not NULL, this will be set to the return from the * last h_cop_op call or it will be 0 if an error not involving the h_call * was encountered. * * Returns: * 0 on success, * -EINVAL if the h_call fails due to an invalid parameter, * -E2BIG if the h_call can not be performed synchronously, * -EBUSY if a timeout is specified and has elapsed, * -EACCES if the memory area for data/status has been rescinded, or * -EPERM if a hardware fault has been indicated
*/ int vio_h_cop_sync(struct vio_dev *vdev, struct vio_pfo_op *op)
{ struct device *dev = &vdev->dev; unsignedlong deadline = 0; long hret = 0; int ret = 0;
if (op->timeout)
deadline = jiffies + msecs_to_jiffies(op->timeout);
switch (hret) { case H_SUCCESS:
ret = 0; break; case H_OP_MODE: case H_TOO_BIG:
ret = -E2BIG; break; case H_RESCINDED:
ret = -EACCES; break; case H_HARDWARE:
ret = -EPERM; break; case H_NOT_ENOUGH_RESOURCES: case H_RESOURCE: case H_BUSY:
ret = -EBUSY; break; default:
ret = -EINVAL; break;
}
if (firmware_has_feature(FW_FEATURE_LPAR))
tbl->it_ops = &iommu_table_lpar_multi_ops; else
tbl->it_ops = &iommu_table_pseries_ops;
return iommu_init_table(tbl, -1, 0, 0);
}
/** * vio_match_device: - Tell if a VIO device has a matching * VIO device id structure. * @ids: array of VIO device id structures to search in * @dev: the VIO device structure to match against * * Used by a driver to check whether a VIO device present in the * system is in its list of supported devices. Returns the matching * vio_device_id structure or NULL if there is no match.
*/ staticconststruct vio_device_id *vio_match_device( conststruct vio_device_id *ids, conststruct vio_dev *dev)
{ while (ids->type[0] != '\0') { if ((strncmp(dev->type, ids->type, strlen(ids->type)) == 0) &&
of_device_is_compatible(dev->dev.of_node,
ids->compat)) return ids;
ids++;
} return NULL;
}
/* * Convert from struct device to struct vio_dev and pass to driver. * dev->driver has already been set by generic code because vio_bus_match * succeeded.
*/ staticint vio_bus_probe(struct device *dev)
{ struct vio_dev *viodev = to_vio_dev(dev); struct vio_driver *viodrv = to_vio_driver(dev->driver); conststruct vio_device_id *id; int error = -ENODEV;
if (!viodrv->probe) return error;
id = vio_match_device(viodrv->id_table, viodev); if (id) {
memset(&viodev->cmo, 0, sizeof(viodev->cmo)); if (firmware_has_feature(FW_FEATURE_CMO)) {
error = vio_cmo_bus_probe(viodev); if (error) return error;
}
error = viodrv->probe(viodev, id); if (error && firmware_has_feature(FW_FEATURE_CMO))
vio_cmo_bus_remove(viodev);
}
return error;
}
/* convert from struct device to struct vio_dev and pass to driver. */ staticvoid vio_bus_remove(struct device *dev)
{ struct vio_dev *viodev = to_vio_dev(dev); struct vio_driver *viodrv = to_vio_driver(dev->driver); struct device *devptr;
/* * Hold a reference to the device after the remove function is called * to allow for CMO accounting cleanup for the device.
*/
devptr = get_device(dev);
if (viodrv->remove)
viodrv->remove(viodev);
if (firmware_has_feature(FW_FEATURE_CMO))
vio_cmo_bus_remove(viodev);
if (dev->driver) {
viodrv = to_vio_driver(dev->driver); if (viodrv->shutdown)
viodrv->shutdown(viodev); elseif (kexec_in_progress)
vio_bus_remove(dev);
}
}
/** * vio_register_driver: - Register a new vio driver * @viodrv: The vio_driver structure to be registered.
*/ int __vio_register_driver(struct vio_driver *viodrv, struct module *owner, constchar *mod_name)
{ // vio_bus_type is only initialised for pseries if (!machine_is(pseries)) return -ENODEV;
if (tbl)
iommu_tce_table_put(tbl);
of_node_put(dev->of_node);
kfree(to_vio_dev(dev));
}
/** * vio_register_device_node: - Register a new vio device. * @of_node: The OF node for this device. * * Creates and initializes a vio_dev structure from the data in * of_node and adds it to the list of virtual devices. * Returns a pointer to the created vio_dev or NULL if node has * NULL device_type or compatible fields.
*/ struct vio_dev *vio_register_device_node(struct device_node *of_node)
{ struct vio_dev *viodev; struct device_node *parent_node; const __be32 *prop; enum vio_dev_family family;
/* * Determine if this node is a under the /vdevice node or under the * /ibm,platform-facilities node. This decides the device's family.
*/
parent_node = of_get_parent(of_node); if (parent_node) { if (of_node_is_type(parent_node, "ibm,platform-facilities"))
family = PFO; elseif (of_node_is_type(parent_node, "vdevice"))
family = VDEVICE; else {
pr_warn("%s: parent(%pOF) of %pOFn not recognized.\n",
__func__,
parent_node,
of_node);
of_node_put(parent_node); return NULL;
}
of_node_put(parent_node);
} else {
pr_warn("%s: could not determine the parent of node %pOFn.\n",
__func__, of_node); return NULL;
}
if (family == PFO) { if (of_property_read_bool(of_node, "interrupt-controller")) {
pr_debug("%s: Skipping the interrupt controller %pOFn.\n",
__func__, of_node); return NULL;
}
}
/* allocate a vio_dev for this node */
viodev = kzalloc(sizeof(struct vio_dev), GFP_KERNEL); if (viodev == NULL) {
pr_warn("%s: allocation failure for VIO device.\n", __func__); return NULL;
}
/* we need the 'device_type' property, in order to match with drivers */
viodev->family = family; if (viodev->family == VDEVICE) { unsignedint unit_address;
viodev->type = of_node_get_device_type(of_node); if (!viodev->type) {
pr_warn("%s: node %pOFn is missing the 'device_type' " "property.\n", __func__, of_node); goto out;
}
prop = of_get_property(of_node, "reg", NULL); if (prop == NULL) {
pr_warn("%s: node %pOFn missing 'reg'\n",
__func__, of_node); goto out;
}
unit_address = of_read_number(prop, 1);
dev_set_name(&viodev->dev, "%x", unit_address);
viodev->irq = irq_of_parse_and_map(of_node, 0);
viodev->unit_address = unit_address;
} else { /* PFO devices need their resource_id for submitting COP_OPs * This is an optional field for devices, but is required when
* performing synchronous ops */
prop = of_get_property(of_node, "ibm,resource-id", NULL); if (prop != NULL)
viodev->resource_id = of_read_number(prop, 1);
if (of_property_present(viodev->dev.of_node, "ibm,my-dma-window")) { if (firmware_has_feature(FW_FEATURE_CMO))
vio_cmo_set_dma_ops(viodev); else
set_dma_ops(&viodev->dev, &dma_iommu_ops);
/* needed to ensure proper operation of coherent allocations
* later, in case driver doesn't set it explicitly */
viodev->dev.coherent_dma_mask = DMA_BIT_MASK(64);
viodev->dev.dma_mask = &viodev->dev.coherent_dma_mask;
}
/* register with generic device framework */ if (device_register(&viodev->dev)) {
printk(KERN_ERR "%s: failed to register device %s\n",
__func__, dev_name(&viodev->dev));
put_device(&viodev->dev); return NULL;
}
return viodev;
out: /* Use this exit point for any return prior to device_register */
kfree(viodev);
/* * vio_bus_scan_for_devices - Scan OF and register each child device * @root_name - OF node name for the root of the subtree to search. * This must be non-NULL * * Starting from the root node provide, register the device node for * each child beneath the root.
*/ staticvoid __init vio_bus_scan_register_devices(char *root_name)
{ struct device_node *node_root, *node_child;
if (!root_name) return;
node_root = of_find_node_by_name(NULL, root_name); if (node_root) {
/* * Create struct vio_devices for each virtual device in * the device tree. Drivers will associate with them later.
*/
node_child = of_get_next_child(node_root, NULL); while (node_child) {
vio_register_device_node(node_child);
node_child = of_get_next_child(node_root, node_child);
}
of_node_put(node_root);
}
}
/** * vio_bus_init: - Initialize the virtual IO bus
*/ staticint __init vio_bus_init(void)
{ int err;
if (firmware_has_feature(FW_FEATURE_CMO))
vio_cmo_sysfs_init();
err = bus_register(&vio_bus_type); if (err) {
printk(KERN_ERR "failed to register VIO bus\n"); return err;
}
/* * The fake parent of all vio devices, just to give us * a nice directory
*/
err = device_register(&vio_bus_device.dev); if (err) {
printk(KERN_WARNING "%s: device_register returned %i\n",
__func__, err); return err;
}
if (firmware_has_feature(FW_FEATURE_CMO))
vio_cmo_bus_init();
/** * vio_get_attribute: - get attribute for virtual device * @vdev: The vio device to get property. * @which: The property/attribute to be extracted. * @length: Pointer to length of returned data size (unused if NULL). * * Calls prom.c's of_get_property() to return the value of the * attribute specified by @which
*/ constvoid *vio_get_attribute(struct vio_dev *vdev, char *which, int *length)
{ return of_get_property(vdev->dev.of_node, which, length);
}
EXPORT_SYMBOL(vio_get_attribute);
/* vio_find_name() - internal because only vio.c knows how we formatted the * kobject name
*/ staticstruct vio_dev *vio_find_name(constchar *name)
{ struct device *found;
found = bus_find_device_by_name(&vio_bus_type, NULL, name); if (!found) return NULL;
return to_vio_dev(found);
}
/** * vio_find_node - find an already-registered vio_dev * @vnode: device_node of the virtual device we're looking for * * Takes a reference to the embedded struct device which needs to be dropped * after use.
*/ struct vio_dev *vio_find_node(struct device_node *vnode)
{ char kobj_name[20]; struct device_node *vnode_parent;
vnode_parent = of_get_parent(vnode); if (!vnode_parent) return NULL;
/* construct the kobject name from the device node */ if (of_node_is_type(vnode_parent, "vdevice")) { const __be32 *prop;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.