Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sh: Store Queue API rework.

Rewrite the store queue API for a per-cpu interface in the driver
model. The old miscdevice is dropped, due to TASK_SIZE limitations,
and no one was using it anyways.

Carve up and allocate store queue space with a bitmap, back sq
mapping objects with a slab cache, and let userspace worry about
its own prefetching.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>

+261 -324
+256 -306
arch/sh/kernel/cpu/sh4/sq.c
··· 1 1 /* 2 - * arch/sh/kernel/cpu/sq.c 2 + * arch/sh/kernel/cpu/sh4/sq.c 3 3 * 4 4 * General management API for SH-4 integrated Store Queues 5 5 * 6 - * Copyright (C) 2001, 2002, 2003, 2004 Paul Mundt 6 + * Copyright (C) 2001 - 2006 Paul Mundt 7 7 * Copyright (C) 2001, 2002 M. R. Brown 8 - * 9 - * Some of this code has been adopted directly from the old arch/sh/mm/sq.c 10 - * hack that was part of the LinuxDC project. For all intents and purposes, 11 - * this is a completely new interface that really doesn't have much in common 12 - * with the old zone-based approach at all. In fact, it's only listed here for 13 - * general completeness. 14 8 * 15 9 * This file is subject to the terms and conditions of the GNU General Public 16 10 * License. See the file "COPYING" in the main directory of this archive 17 11 * for more details. 18 12 */ 19 13 #include <linux/init.h> 14 + #include <linux/cpu.h> 15 + #include <linux/bitmap.h> 16 + #include <linux/sysdev.h> 20 17 #include <linux/kernel.h> 21 18 #include <linux/module.h> 22 19 #include <linux/slab.h> 23 - #include <linux/list.h> 24 - #include <linux/proc_fs.h> 25 - #include <linux/miscdevice.h> 26 20 #include <linux/vmalloc.h> 27 21 #include <linux/mm.h> 28 22 #include <asm/io.h> 29 23 #include <asm/page.h> 30 24 #include <asm/cacheflush.h> 31 - #include <asm/mmu_context.h> 32 25 #include <asm/cpu/sq.h> 33 26 34 - static LIST_HEAD(sq_mapping_list); 35 - static DEFINE_SPINLOCK(sq_mapping_lock); 27 + struct sq_mapping; 36 28 37 - /** 38 - * sq_flush - Flush (prefetch) the store queue cache 39 - * @addr: the store queue address to flush 40 - * 41 - * Executes a prefetch instruction on the specified store queue cache, 42 - * so that the cached data is written to physical memory. 43 - */ 44 - inline void sq_flush(void *addr) 45 - { 46 - __asm__ __volatile__ ("pref @%0" : : "r" (addr) : "memory"); 47 - } 29 + struct sq_mapping { 30 + const char *name; 31 + 32 + unsigned long sq_addr; 33 + unsigned long addr; 34 + unsigned int size; 35 + 36 + struct sq_mapping *next; 37 + }; 38 + 39 + static struct sq_mapping *sq_mapping_list; 40 + static DEFINE_SPINLOCK(sq_mapping_lock); 41 + static kmem_cache_t *sq_cache; 42 + static unsigned long *sq_bitmap; 43 + 44 + #define store_queue_barrier() \ 45 + do { \ 46 + (void)ctrl_inl(P4SEG_STORE_QUE); \ 47 + ctrl_outl(0, P4SEG_STORE_QUE + 0); \ 48 + ctrl_outl(0, P4SEG_STORE_QUE + 8); \ 49 + } while (0); 48 50 49 51 /** 50 52 * sq_flush_range - Flush (prefetch) a specific SQ range ··· 59 57 void sq_flush_range(unsigned long start, unsigned int len) 60 58 { 61 59 volatile unsigned long *sq = (unsigned long *)start; 62 - unsigned long dummy; 63 60 64 61 /* Flush the queues */ 65 62 for (len >>= 5; len--; sq += 8) 66 - sq_flush((void *)sq); 63 + prefetchw((void *)sq); 67 64 68 65 /* Wait for completion */ 69 - dummy = ctrl_inl(P4SEG_STORE_QUE); 70 - 71 - ctrl_outl(0, P4SEG_STORE_QUE + 0); 72 - ctrl_outl(0, P4SEG_STORE_QUE + 8); 66 + store_queue_barrier(); 73 67 } 74 68 75 - static struct sq_mapping *__sq_alloc_mapping(unsigned long virt, unsigned long phys, unsigned long size, const char *name) 69 + static inline void sq_mapping_list_add(struct sq_mapping *map) 76 70 { 77 - struct sq_mapping *map; 71 + struct sq_mapping **p, *tmp; 78 72 79 - if (virt + size > SQ_ADDRMAX) 80 - return ERR_PTR(-ENOSPC); 73 + spin_lock_irq(&sq_mapping_lock); 81 74 82 - map = kmalloc(sizeof(struct sq_mapping), GFP_KERNEL); 83 - if (!map) 84 - return ERR_PTR(-ENOMEM); 75 + p = &sq_mapping_list; 76 + while ((tmp = *p) != NULL) 77 + p = &tmp->next; 85 78 86 - INIT_LIST_HEAD(&map->list); 79 + map->next = tmp; 80 + *p = map; 87 81 88 - map->sq_addr = virt; 89 - map->addr = phys; 90 - map->size = size + 1; 91 - map->name = name; 92 - 93 - list_add(&map->list, &sq_mapping_list); 94 - 95 - return map; 82 + spin_unlock_irq(&sq_mapping_lock); 96 83 } 97 84 98 - static unsigned long __sq_get_next_addr(void) 85 + static inline void sq_mapping_list_del(struct sq_mapping *map) 99 86 { 100 - if (!list_empty(&sq_mapping_list)) { 101 - struct list_head *pos, *tmp; 87 + struct sq_mapping **p, *tmp; 102 88 103 - /* 104 - * Read one off the list head, as it will have the highest 105 - * mapped allocation. Set the next one up right above it. 106 - * 107 - * This is somewhat sub-optimal, as we don't look at 108 - * gaps between allocations or anything lower then the 109 - * highest-level allocation. 110 - * 111 - * However, in the interest of performance and the general 112 - * lack of desire to do constant list rebalancing, we don't 113 - * worry about it. 114 - */ 115 - list_for_each_safe(pos, tmp, &sq_mapping_list) { 116 - struct sq_mapping *entry; 89 + spin_lock_irq(&sq_mapping_lock); 117 90 118 - entry = list_entry(pos, typeof(*entry), list); 119 - 120 - return entry->sq_addr + entry->size; 91 + for (p = &sq_mapping_list; (tmp = *p); p = &tmp->next) 92 + if (tmp == map) { 93 + *p = tmp->next; 94 + break; 121 95 } 122 - } 123 96 124 - return P4SEG_STORE_QUE; 97 + spin_unlock_irq(&sq_mapping_lock); 125 98 } 126 99 127 - /** 128 - * __sq_remap - Perform a translation from the SQ to a phys addr 129 - * @map: sq mapping containing phys and store queue addresses. 130 - * 131 - * Maps the store queue address specified in the mapping to the physical 132 - * address specified in the mapping. 133 - */ 134 - static struct sq_mapping *__sq_remap(struct sq_mapping *map) 100 + static int __sq_remap(struct sq_mapping *map, unsigned long flags) 135 101 { 136 - unsigned long flags, pteh, ptel; 102 + #if defined(CONFIG_MMU) 137 103 struct vm_struct *vma; 138 - pgprot_t pgprot; 139 104 105 + vma = __get_vm_area(map->size, VM_ALLOC, map->sq_addr, SQ_ADDRMAX); 106 + if (!vma) 107 + return -ENOMEM; 108 + 109 + vma->phys_addr = map->addr; 110 + 111 + if (remap_area_pages((unsigned long)vma->addr, vma->phys_addr, 112 + map->size, flags)) { 113 + vunmap(vma->addr); 114 + return -EAGAIN; 115 + } 116 + #else 140 117 /* 141 118 * Without an MMU (or with it turned off), this is much more 142 119 * straightforward, as we can just load up each queue's QACR with 143 120 * the physical address appropriately masked. 144 121 */ 145 - 146 122 ctrl_outl(((map->addr >> 26) << 2) & 0x1c, SQ_QACR0); 147 123 ctrl_outl(((map->addr >> 26) << 2) & 0x1c, SQ_QACR1); 124 + #endif 148 125 149 - #ifdef CONFIG_MMU 150 - /* 151 - * With an MMU on the other hand, things are slightly more involved. 152 - * Namely, we have to have a direct mapping between the SQ addr and 153 - * the associated physical address in the UTLB by way of setting up 154 - * a virt<->phys translation by hand. We do this by simply specifying 155 - * the SQ addr in UTLB.VPN and the associated physical address in 156 - * UTLB.PPN. 157 - * 158 - * Notably, even though this is a special case translation, and some 159 - * of the configuration bits are meaningless, we're still required 160 - * to have a valid ASID context in PTEH. 161 - * 162 - * We could also probably get by without explicitly setting PTEA, but 163 - * we do it here just for good measure. 164 - */ 165 - spin_lock_irqsave(&sq_mapping_lock, flags); 166 - 167 - pteh = map->sq_addr; 168 - ctrl_outl((pteh & MMU_VPN_MASK) | get_asid(), MMU_PTEH); 169 - 170 - ptel = map->addr & PAGE_MASK; 171 - 172 - if (cpu_data->flags & CPU_HAS_PTEA) 173 - ctrl_outl(((ptel >> 28) & 0xe) | (ptel & 0x1), MMU_PTEA); 174 - 175 - pgprot = pgprot_noncached(PAGE_KERNEL); 176 - 177 - ptel &= _PAGE_FLAGS_HARDWARE_MASK; 178 - ptel |= pgprot_val(pgprot); 179 - ctrl_outl(ptel, MMU_PTEL); 180 - 181 - __asm__ __volatile__ ("ldtlb" : : : "memory"); 182 - 183 - spin_unlock_irqrestore(&sq_mapping_lock, flags); 184 - 185 - /* 186 - * Next, we need to map ourselves in the kernel page table, so that 187 - * future accesses after a TLB flush will be handled when we take a 188 - * page fault. 189 - * 190 - * Theoretically we could just do this directly and not worry about 191 - * setting up the translation by hand ahead of time, but for the 192 - * cases where we want a one-shot SQ mapping followed by a quick 193 - * writeout before we hit the TLB flush, we do it anyways. This way 194 - * we at least save ourselves the initial page fault overhead. 195 - */ 196 - vma = __get_vm_area(map->size, VM_ALLOC, map->sq_addr, SQ_ADDRMAX); 197 - if (!vma) 198 - return ERR_PTR(-ENOMEM); 199 - 200 - vma->phys_addr = map->addr; 201 - 202 - if (remap_area_pages((unsigned long)vma->addr, vma->phys_addr, 203 - map->size, pgprot_val(pgprot))) { 204 - vunmap(vma->addr); 205 - return NULL; 206 - } 207 - #endif /* CONFIG_MMU */ 208 - 209 - return map; 126 + return 0; 210 127 } 211 128 212 129 /** ··· 133 212 * @phys: Physical address of mapping. 134 213 * @size: Length of mapping. 135 214 * @name: User invoking mapping. 215 + * @flags: Protection flags. 136 216 * 137 217 * Remaps the physical address @phys through the next available store queue 138 218 * address of @size length. @name is logged at boot time as well as through 139 - * the procfs interface. 140 - * 141 - * A pre-allocated and filled sq_mapping pointer is returned, and must be 142 - * cleaned up with a call to sq_unmap() when the user is done with the 143 - * mapping. 219 + * the sysfs interface. 144 220 */ 145 - struct sq_mapping *sq_remap(unsigned long phys, unsigned int size, const char *name) 221 + unsigned long sq_remap(unsigned long phys, unsigned int size, 222 + const char *name, unsigned long flags) 146 223 { 147 224 struct sq_mapping *map; 148 - unsigned long virt, end; 225 + unsigned long end; 149 226 unsigned int psz; 227 + int ret, page; 150 228 151 229 /* Don't allow wraparound or zero size */ 152 230 end = phys + size - 1; 153 - if (!size || end < phys) 154 - return NULL; 231 + if (unlikely(!size || end < phys)) 232 + return -EINVAL; 155 233 /* Don't allow anyone to remap normal memory.. */ 156 - if (phys < virt_to_phys(high_memory)) 157 - return NULL; 234 + if (unlikely(phys < virt_to_phys(high_memory))) 235 + return -EINVAL; 158 236 159 237 phys &= PAGE_MASK; 238 + size = PAGE_ALIGN(end + 1) - phys; 160 239 161 - size = PAGE_ALIGN(end + 1) - phys; 162 - virt = __sq_get_next_addr(); 163 - psz = (size + (PAGE_SIZE - 1)) / PAGE_SIZE; 164 - map = __sq_alloc_mapping(virt, phys, size, name); 240 + map = kmem_cache_alloc(sq_cache, GFP_KERNEL); 241 + if (unlikely(!map)) 242 + return -ENOMEM; 165 243 166 - printk("sqremap: %15s [%4d page%s] va 0x%08lx pa 0x%08lx\n", 167 - map->name ? map->name : "???", 168 - psz, psz == 1 ? " " : "s", 169 - map->sq_addr, map->addr); 244 + map->addr = phys; 245 + map->size = size; 246 + map->name = name; 170 247 171 - return __sq_remap(map); 248 + page = bitmap_find_free_region(sq_bitmap, 0x04000000, 249 + get_order(map->size)); 250 + if (unlikely(page < 0)) { 251 + ret = -ENOSPC; 252 + goto out; 253 + } 254 + 255 + map->sq_addr = P4SEG_STORE_QUE + (page << PAGE_SHIFT); 256 + 257 + ret = __sq_remap(map, flags); 258 + if (unlikely(ret != 0)) 259 + goto out; 260 + 261 + psz = (size + (PAGE_SIZE - 1)) >> PAGE_SHIFT; 262 + pr_info("sqremap: %15s [%4d page%s] va 0x%08lx pa 0x%08lx\n", 263 + likely(map->name) ? map->name : "???", 264 + psz, psz == 1 ? " " : "s", 265 + map->sq_addr, map->addr); 266 + 267 + sq_mapping_list_add(map); 268 + 269 + return map->sq_addr; 270 + 271 + out: 272 + kmem_cache_free(sq_cache, map); 273 + return ret; 172 274 } 173 275 174 276 /** ··· 202 258 * sq_remap(). Also frees up the pte that was previously inserted into 203 259 * the kernel page table and discards the UTLB translation. 204 260 */ 205 - void sq_unmap(struct sq_mapping *map) 261 + void sq_unmap(unsigned long vaddr) 206 262 { 207 - if (map->sq_addr > (unsigned long)high_memory) 208 - vfree((void *)(map->sq_addr & PAGE_MASK)); 263 + struct sq_mapping **p, *map; 264 + struct vm_struct *vma; 265 + int page; 209 266 210 - list_del(&map->list); 211 - kfree(map); 212 - } 267 + for (p = &sq_mapping_list; (map = *p); p = &map->next) 268 + if (map->sq_addr == vaddr) 269 + break; 213 270 214 - /** 215 - * sq_clear - Clear a store queue range 216 - * @addr: Address to start clearing from. 217 - * @len: Length to clear. 218 - * 219 - * A quick zero-fill implementation for clearing out memory that has been 220 - * remapped through the store queues. 221 - */ 222 - void sq_clear(unsigned long addr, unsigned int len) 223 - { 224 - int i; 225 - 226 - /* Clear out both queues linearly */ 227 - for (i = 0; i < 8; i++) { 228 - ctrl_outl(0, addr + i + 0); 229 - ctrl_outl(0, addr + i + 8); 271 + if (unlikely(!map)) { 272 + printk("%s: bad store queue address 0x%08lx\n", 273 + __FUNCTION__, vaddr); 274 + return; 230 275 } 231 276 232 - sq_flush_range(addr, len); 233 - } 277 + page = (map->sq_addr - P4SEG_STORE_QUE) >> PAGE_SHIFT; 278 + bitmap_release_region(sq_bitmap, page, get_order(map->size)); 234 279 235 - /** 236 - * sq_vma_unmap - Unmap a VMA range 237 - * @area: VMA containing range. 238 - * @addr: Start of range. 239 - * @len: Length of range. 240 - * 241 - * Searches the sq_mapping_list for a mapping matching the sq addr @addr, 242 - * and subsequently frees up the entry. Further cleanup is done by generic 243 - * code. 244 - */ 245 - static void sq_vma_unmap(struct vm_area_struct *area, 246 - unsigned long addr, size_t len) 247 - { 248 - struct list_head *pos, *tmp; 249 - 250 - list_for_each_safe(pos, tmp, &sq_mapping_list) { 251 - struct sq_mapping *entry; 252 - 253 - entry = list_entry(pos, typeof(*entry), list); 254 - 255 - if (entry->sq_addr == addr) { 256 - /* 257 - * We could probably get away without doing the tlb flush 258 - * here, as generic code should take care of most of this 259 - * when unmapping the rest of the VMA range for us. Leave 260 - * it in for added sanity for the time being.. 261 - */ 262 - __flush_tlb_page(get_asid(), entry->sq_addr & PAGE_MASK); 263 - 264 - list_del(&entry->list); 265 - kfree(entry); 266 - 267 - return; 268 - } 280 + #ifdef CONFIG_MMU 281 + vma = remove_vm_area((void *)(map->sq_addr & PAGE_MASK)); 282 + if (!vma) { 283 + printk(KERN_ERR "%s: bad address 0x%08lx\n", 284 + __FUNCTION__, map->sq_addr); 285 + return; 269 286 } 287 + #endif 288 + 289 + sq_mapping_list_del(map); 290 + 291 + kmem_cache_free(sq_cache, map); 270 292 } 271 293 272 - /** 273 - * sq_vma_sync - Sync a VMA range 274 - * @area: VMA containing range. 275 - * @start: Start of range. 276 - * @len: Length of range. 277 - * @flags: Additional flags. 294 + /* 295 + * Needlessly complex sysfs interface. Unfortunately it doesn't seem like 296 + * there is any other easy way to add things on a per-cpu basis without 297 + * putting the directory entries somewhere stupid and having to create 298 + * links in sysfs by hand back in to the per-cpu directories. 278 299 * 279 - * Synchronizes an sq mapped range by flushing the store queue cache for 280 - * the duration of the mapping. 281 - * 282 - * Used internally for user mappings, which must use msync() to prefetch 283 - * the store queue cache. 300 + * Some day we may want to have an additional abstraction per store 301 + * queue, but considering the kobject hell we already have to deal with, 302 + * it's simply not worth the trouble. 284 303 */ 285 - static int sq_vma_sync(struct vm_area_struct *area, 286 - unsigned long start, size_t len, unsigned int flags) 287 - { 288 - sq_flush_range(start, len); 304 + static struct kobject *sq_kobject[NR_CPUS]; 289 305 290 - return 0; 291 - } 292 - 293 - static struct vm_operations_struct sq_vma_ops = { 294 - .unmap = sq_vma_unmap, 295 - .sync = sq_vma_sync, 306 + struct sq_sysfs_attr { 307 + struct attribute attr; 308 + ssize_t (*show)(char *buf); 309 + ssize_t (*store)(const char *buf, size_t count); 296 310 }; 297 311 298 - /** 299 - * sq_mmap - mmap() for /dev/cpu/sq 300 - * @file: unused. 301 - * @vma: VMA to remap. 302 - * 303 - * Remap the specified vma @vma through the store queues, and setup associated 304 - * information for the new mapping. Also build up the page tables for the new 305 - * area. 306 - */ 307 - static int sq_mmap(struct file *file, struct vm_area_struct *vma) 312 + #define to_sq_sysfs_attr(attr) container_of(attr, struct sq_sysfs_attr, attr) 313 + 314 + static ssize_t sq_sysfs_show(struct kobject *kobj, struct attribute *attr, 315 + char *buf) 308 316 { 309 - unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 310 - unsigned long size = vma->vm_end - vma->vm_start; 311 - struct sq_mapping *map; 317 + struct sq_sysfs_attr *sattr = to_sq_sysfs_attr(attr); 312 318 313 - /* 314 - * We're not interested in any arbitrary virtual address that has 315 - * been stuck in the VMA, as we already know what addresses we 316 - * want. Save off the size, and reposition the VMA to begin at 317 - * the next available sq address. 318 - */ 319 - vma->vm_start = __sq_get_next_addr(); 320 - vma->vm_end = vma->vm_start + size; 319 + if (likely(sattr->show)) 320 + return sattr->show(buf); 321 321 322 - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); 323 - 324 - vma->vm_flags |= VM_IO | VM_RESERVED; 325 - 326 - map = __sq_alloc_mapping(vma->vm_start, offset, size, "Userspace"); 327 - 328 - if (io_remap_pfn_range(vma, map->sq_addr, map->addr >> PAGE_SHIFT, 329 - size, vma->vm_page_prot)) 330 - return -EAGAIN; 331 - 332 - vma->vm_ops = &sq_vma_ops; 333 - 334 - return 0; 322 + return -EIO; 335 323 } 336 324 337 - #ifdef CONFIG_PROC_FS 338 - static int sq_mapping_read_proc(char *buf, char **start, off_t off, 339 - int len, int *eof, void *data) 325 + static ssize_t sq_sysfs_store(struct kobject *kobj, struct attribute *attr, 326 + const char *buf, size_t count) 340 327 { 341 - struct list_head *pos; 328 + struct sq_sysfs_attr *sattr = to_sq_sysfs_attr(attr); 329 + 330 + if (likely(sattr->store)) 331 + return sattr->store(buf, count); 332 + 333 + return -EIO; 334 + } 335 + 336 + static ssize_t mapping_show(char *buf) 337 + { 338 + struct sq_mapping **list, *entry; 342 339 char *p = buf; 343 340 344 - list_for_each_prev(pos, &sq_mapping_list) { 345 - struct sq_mapping *entry; 346 - 347 - entry = list_entry(pos, typeof(*entry), list); 348 - 349 - p += sprintf(p, "%08lx-%08lx [%08lx]: %s\n", entry->sq_addr, 350 - entry->sq_addr + entry->size - 1, entry->addr, 351 - entry->name); 352 - } 341 + for (list = &sq_mapping_list; (entry = *list); list = &entry->next) 342 + p += sprintf(p, "%08lx-%08lx [%08lx]: %s\n", 343 + entry->sq_addr, entry->sq_addr + entry->size, 344 + entry->addr, entry->name); 353 345 354 346 return p - buf; 355 347 } 356 - #endif 357 348 358 - static struct file_operations sq_fops = { 359 - .owner = THIS_MODULE, 360 - .mmap = sq_mmap, 349 + static ssize_t mapping_store(const char *buf, size_t count) 350 + { 351 + unsigned long base = 0, len = 0; 352 + 353 + sscanf(buf, "%lx %lx", &base, &len); 354 + if (!base) 355 + return -EIO; 356 + 357 + if (likely(len)) { 358 + int ret = sq_remap(base, len, "Userspace", 359 + pgprot_val(PAGE_SHARED)); 360 + if (ret < 0) 361 + return ret; 362 + } else 363 + sq_unmap(base); 364 + 365 + return count; 366 + } 367 + 368 + static struct sq_sysfs_attr mapping_attr = 369 + __ATTR(mapping, 0644, mapping_show, mapping_store); 370 + 371 + static struct attribute *sq_sysfs_attrs[] = { 372 + &mapping_attr.attr, 373 + NULL, 361 374 }; 362 375 363 - static struct miscdevice sq_dev = { 364 - .minor = STORE_QUEUE_MINOR, 365 - .name = "sq", 366 - .fops = &sq_fops, 376 + static struct sysfs_ops sq_sysfs_ops = { 377 + .show = sq_sysfs_show, 378 + .store = sq_sysfs_store, 379 + }; 380 + 381 + static struct kobj_type ktype_percpu_entry = { 382 + .sysfs_ops = &sq_sysfs_ops, 383 + .default_attrs = sq_sysfs_attrs, 384 + }; 385 + 386 + static int __devinit sq_sysdev_add(struct sys_device *sysdev) 387 + { 388 + unsigned int cpu = sysdev->id; 389 + struct kobject *kobj; 390 + 391 + sq_kobject[cpu] = kzalloc(sizeof(struct kobject), GFP_KERNEL); 392 + if (unlikely(!sq_kobject[cpu])) 393 + return -ENOMEM; 394 + 395 + kobj = sq_kobject[cpu]; 396 + kobj->parent = &sysdev->kobj; 397 + kobject_set_name(kobj, "%s", "sq"); 398 + kobj->ktype = &ktype_percpu_entry; 399 + 400 + return kobject_register(kobj); 401 + } 402 + 403 + static int __devexit sq_sysdev_remove(struct sys_device *sysdev) 404 + { 405 + unsigned int cpu = sysdev->id; 406 + struct kobject *kobj = sq_kobject[cpu]; 407 + 408 + kobject_unregister(kobj); 409 + return 0; 410 + } 411 + 412 + static struct sysdev_driver sq_sysdev_driver = { 413 + .add = sq_sysdev_add, 414 + .remove = __devexit_p(sq_sysdev_remove), 367 415 }; 368 416 369 417 static int __init sq_api_init(void) 370 418 { 371 - int ret; 419 + unsigned int nr_pages = 0x04000000 >> PAGE_SHIFT; 420 + unsigned int size = (nr_pages + (BITS_PER_LONG - 1)) / BITS_PER_LONG; 421 + int ret = -ENOMEM; 422 + 372 423 printk(KERN_NOTICE "sq: Registering store queue API.\n"); 373 424 374 - create_proc_read_entry("sq_mapping", 0, 0, sq_mapping_read_proc, 0); 425 + sq_cache = kmem_cache_create("store_queue_cache", 426 + sizeof(struct sq_mapping), 0, 0, 427 + NULL, NULL); 428 + if (unlikely(!sq_cache)) 429 + return ret; 375 430 376 - ret = misc_register(&sq_dev); 377 - if (ret) 378 - remove_proc_entry("sq_mapping", NULL); 431 + sq_bitmap = kzalloc(size, GFP_KERNEL); 432 + if (unlikely(!sq_bitmap)) 433 + goto out; 434 + 435 + ret = sysdev_driver_register(&cpu_sysdev_class, &sq_sysdev_driver); 436 + if (unlikely(ret != 0)) 437 + goto out; 438 + 439 + return 0; 440 + 441 + out: 442 + kfree(sq_bitmap); 443 + kmem_cache_destroy(sq_cache); 379 444 380 445 return ret; 381 446 } 382 447 383 448 static void __exit sq_api_exit(void) 384 449 { 385 - misc_deregister(&sq_dev); 386 - remove_proc_entry("sq_mapping", NULL); 450 + sysdev_driver_unregister(&cpu_sysdev_class, &sq_sysdev_driver); 451 + kfree(sq_bitmap); 452 + kmem_cache_destroy(sq_cache); 387 453 } 388 454 389 455 module_init(sq_api_init); ··· 402 448 MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>, M. R. Brown <mrbrown@0xd6.org>"); 403 449 MODULE_DESCRIPTION("Simple API for SH-4 integrated Store Queues"); 404 450 MODULE_LICENSE("GPL"); 405 - MODULE_ALIAS_MISCDEV(STORE_QUEUE_MINOR); 406 451 407 452 EXPORT_SYMBOL(sq_remap); 408 453 EXPORT_SYMBOL(sq_unmap); 409 - EXPORT_SYMBOL(sq_clear); 410 - EXPORT_SYMBOL(sq_flush); 411 454 EXPORT_SYMBOL(sq_flush_range); 412 -
+5 -18
include/asm-sh/cpu-sh4/sq.h
··· 17 17 * Store queues range from e0000000-e3fffffc, allowing approx. 64MB to be 18 18 * mapped to any physical address space. Since data is written (and aligned) 19 19 * to 32-byte boundaries, we need to be sure that all allocations are aligned. 20 - */ 20 + */ 21 21 #define SQ_SIZE 32 22 22 #define SQ_ALIGN_MASK (~(SQ_SIZE - 1)) 23 23 #define SQ_ALIGN(addr) (((addr)+SQ_SIZE-1) & SQ_ALIGN_MASK) ··· 26 26 #define SQ_QACR1 (P4SEG_REG_BASE + 0x3c) 27 27 #define SQ_ADDRMAX (P4SEG_STORE_QUE + 0x04000000) 28 28 29 - struct sq_mapping { 30 - const char *name; 31 - 32 - unsigned long sq_addr; 33 - unsigned long addr; 34 - unsigned int size; 35 - 36 - struct list_head list; 37 - }; 38 - 39 29 /* arch/sh/kernel/cpu/sh4/sq.c */ 40 - extern struct sq_mapping *sq_remap(unsigned long phys, unsigned int size, const char *name); 41 - extern void sq_unmap(struct sq_mapping *map); 42 - 43 - extern void sq_clear(unsigned long addr, unsigned int len); 44 - extern void sq_flush(void *addr); 45 - extern void sq_flush_range(unsigned long start, unsigned int len); 30 + unsigned long sq_remap(unsigned long phys, unsigned int size, 31 + const char *name, unsigned long flags); 32 + void sq_unmap(unsigned long vaddr); 33 + void sq_flush_range(unsigned long start, unsigned int len); 46 34 47 35 #endif /* __ASM_CPU_SH4_SQ_H */ 48 -