static dma_addr_t ps3_ioc0_map_single(struct device *_dev, void *ptr, size_t size, enum dma_data_direction direction) { struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); int result; unsigned long bus_addr; u64 iopte_flag; iopte_flag = IOPTE_M; switch (direction) { case DMA_BIDIRECTIONAL: iopte_flag |= IOPTE_PP_R | IOPTE_PP_W | IOPTE_SO_RW; break; case DMA_TO_DEVICE: iopte_flag |= IOPTE_PP_R | IOPTE_SO_R; break; case DMA_FROM_DEVICE: iopte_flag |= IOPTE_PP_W | IOPTE_SO_RW; break; default: /* not happned */ BUG(); }; result = ps3_dma_map(dev->d_region, (unsigned long)ptr, size, &bus_addr, iopte_flag); if (result) { pr_debug("%s:%d: ps3_dma_map failed (%d)\n", __func__, __LINE__, result); } return bus_addr; }
/* Allocates a contiguous real buffer and creates mappings over it. * Returns the virtual address of the buffer and sets dma_handle * to the dma address (mapping) of the first page. */ static void * ps3_alloc_coherent(struct device *_dev, size_t size, dma_addr_t *dma_handle, gfp_t flag) { int result; struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); unsigned long virt_addr; flag &= ~(__GFP_DMA | __GFP_HIGHMEM); flag |= __GFP_ZERO; virt_addr = __get_free_pages(flag, get_order(size)); if (!virt_addr) { pr_debug("%s:%d: get_free_pages failed\n", __func__, __LINE__); goto clean_none; } result = ps3_dma_map(dev->d_region, virt_addr, size, dma_handle, IOPTE_PP_W | IOPTE_PP_R | IOPTE_SO_RW | IOPTE_M); if (result) { pr_debug("%s:%d: ps3_dma_map failed (%d)\n", __func__, __LINE__, result); BUG_ON("check region type"); goto clean_alloc; } return (void*)virt_addr; clean_alloc: free_pages(virt_addr, get_order(size)); clean_none: dma_handle = NULL; return NULL; }
static int ps3_system_bus_match(struct device *_dev, struct device_driver *_drv) { int result; struct ps3_system_bus_driver *drv = ps3_drv_to_system_bus_drv(_drv); struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); if (!dev->match_sub_id) result = dev->match_id == drv->match_id; else result = dev->match_sub_id == drv->match_sub_id && dev->match_id == drv->match_id; if (result) pr_info("%s:%d: dev=%u.%u(%s), drv=%u.%u(%s): match\n", __func__, __LINE__, dev->match_id, dev->match_sub_id, dev_name(&dev->core), drv->match_id, drv->match_sub_id, drv->core.name); else pr_debug("%s:%d: dev=%u.%u(%s), drv=%u.%u(%s): miss\n", __func__, __LINE__, dev->match_id, dev->match_sub_id, dev_name(&dev->core), drv->match_id, drv->match_sub_id, drv->core.name); return result; }
static void ps3_free_coherent(struct device *_dev, size_t size, void *vaddr, dma_addr_t dma_handle) { struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); ps3_dma_unmap(dev->d_region, dma_handle, size); free_pages((unsigned long)vaddr, get_order(size)); }
static ssize_t modalias_show(struct device *_dev, struct device_attribute *a, char *buf) { struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); int len = snprintf(buf, PAGE_SIZE, "ps3:%d\n", dev->match_id); return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; }
static int ps3_system_bus_uevent(struct device *_dev, struct kobj_uevent_env *env) { struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); if (add_uevent_var(env, "MODALIAS=ps3:%d", dev->match_id)) return -ENOMEM; return 0; }
static void ps3_unmap_page(struct device *_dev, dma_addr_t dma_addr, size_t size, enum dma_data_direction direction, struct dma_attrs *attrs) { struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); int result; result = ps3_dma_unmap(dev->d_region, dma_addr, size); if (result) { pr_debug("%s:%d: ps3_dma_unmap failed (%d)\n", __func__, __LINE__, result); } }
static int ps3_system_bus_match(struct device *_dev, struct device_driver *_drv) { int result; struct ps3_system_bus_driver *drv = ps3_drv_to_system_bus_drv(_drv); struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); result = dev->match_id == drv->match_id; pr_info("%s:%d: dev=%u(%s), drv=%u(%s): %s\n", __func__, __LINE__, dev->match_id, dev->core.bus_id, drv->match_id, drv->core.name, (result ? "match" : "miss")); return result; }
static int ps3_system_bus_uevent(struct device *_dev, char **envp, int num_envp, char *buffer, int buffer_size) { struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); int i = 0, length = 0; if (add_uevent_var(envp, num_envp, &i, buffer, buffer_size, &length, "MODALIAS=ps3:%d", dev->match_id)) return -ENOMEM; envp[i] = NULL; return 0; }
static dma_addr_t ps3_sb_map_single(struct device *_dev, void *ptr, size_t size, enum dma_data_direction direction, struct dma_attrs *attrs) { struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); int result; unsigned long bus_addr; result = ps3_dma_map(dev->d_region, (unsigned long)ptr, size, &bus_addr, IOPTE_PP_R | IOPTE_PP_W | IOPTE_SO_RW | IOPTE_M); if (result) { pr_debug("%s:%d: ps3_dma_map failed (%d)\n", __func__, __LINE__, result); } return bus_addr; }
static int ps3_system_bus_remove(struct device *_dev) { int result = 0; struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); struct ps3_system_bus_driver *drv; BUG_ON(!dev); pr_debug(" -> %s:%d: %s\n", __func__, __LINE__, _dev->bus_id); drv = ps3_system_bus_dev_to_system_bus_drv(dev); BUG_ON(!drv); if (drv->remove) result = drv->remove(dev); else dev_dbg(&dev->core, "%s:%d %s: no remove method\n", __func__, __LINE__, drv->core.name); pr_debug(" <- %s:%d: %s\n", __func__, __LINE__, dev_name(&dev->core)); return result; }
static int ps3_system_bus_probe(struct device *_dev) { int result = 0; struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); struct ps3_system_bus_driver *drv; BUG_ON(!dev); pr_debug(" -> %s:%d: %s\n", __func__, __LINE__, _dev->bus_id); drv = ps3_system_bus_dev_to_system_bus_drv(dev); BUG_ON(!drv); if (drv->probe) result = drv->probe(dev); else pr_debug("%s:%d: %s no probe method\n", __func__, __LINE__, dev->core.bus_id); pr_debug(" <- %s:%d: %s\n", __func__, __LINE__, dev->core.bus_id); return result; }
static dma_addr_t ps3_sb_map_page(struct device *_dev, struct page *page, unsigned long offset, size_t size, enum dma_data_direction direction, struct dma_attrs *attrs) { struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); int result; dma_addr_t bus_addr; void *ptr = page_address(page) + offset; result = ps3_dma_map(dev->d_region, (unsigned long)ptr, size, &bus_addr, CBE_IOPTE_PP_R | CBE_IOPTE_PP_W | CBE_IOPTE_SO_RW | CBE_IOPTE_M); if (result) { pr_debug("%s:%d: ps3_dma_map failed (%d)\n", __func__, __LINE__, result); } return bus_addr; }
static int ps3_sb_map_sg(struct device *_dev, struct scatterlist *sgl, int nents, enum dma_data_direction direction, struct dma_attrs *attrs) { #if defined(CONFIG_PS3_DYNAMIC_DMA) BUG_ON("do"); return -EPERM; #else struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); struct scatterlist *sg; int i; for_each_sg(sgl, sg, nents, i) { int result = ps3_dma_map(dev->d_region, sg_phys(sg), sg->length, &sg->dma_address, 0); if (result) { pr_debug("%s:%d: ps3_dma_map failed (%d)\n", __func__, __LINE__, result); return -EINVAL; } sg->dma_length = sg->length; }
static void ps3_system_bus_shutdown(struct device *_dev) { struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); struct ps3_system_bus_driver *drv; BUG_ON(!dev); dev_dbg(&dev->core, " -> %s:%d: match_id %d\n", __func__, __LINE__, dev->match_id); if (!dev->core.driver) { dev_dbg(&dev->core, "%s:%d: no driver bound\n", __func__, __LINE__); return; } drv = ps3_system_bus_dev_to_system_bus_drv(dev); BUG_ON(!drv); dev_dbg(&dev->core, "%s:%d: %s -> %s\n", __func__, __LINE__, dev_name(&dev->core), drv->core.name); if (drv->shutdown) drv->shutdown(dev); else if (drv->remove) { dev_dbg(&dev->core, "%s:%d %s: no shutdown, calling remove\n", __func__, __LINE__, drv->core.name); drv->remove(dev); } else { dev_dbg(&dev->core, "%s:%d %s: no shutdown method\n", __func__, __LINE__, drv->core.name); BUG(); } dev_dbg(&dev->core, " <- %s:%d\n", __func__, __LINE__); }
static void ps3_system_bus_release_device(struct device *_dev) { struct ps3_system_bus_device *dev = ps3_dev_to_system_bus_dev(_dev); kfree(dev); }