Changeset 105
- Timestamp:
- May 19, 2007, 7:29:33 AM (18 years ago)
- Location:
- GPL/branches/alsa-resync1/alsa-kernel
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
GPL/branches/alsa-resync1/alsa-kernel/core/misc.c
r92 r105 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 * 20 20 */ 21 21 22 #define __NO_VERSION__ 22 23 #include <sound/driver.h> 24 #include <linux/init.h> 25 #include <linux/sched.h> 26 #include <linux/time.h> 27 #include <sound/core.h> 28 29 #ifdef TARGET_OS2 23 30 #include <linux/firmware.h> 31 #endif /* TARGET_OS2 */ 32 24 33 int snd_task_name(struct task_struct *task, char *name, size_t size) 25 34 { … … 32 41 return 0; 33 42 } 34 35 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)36 37 int try_inc_mod_count(struct module *module)38 {39 __MOD_INC_USE_COUNT(module);40 return 1;41 }42 43 struct resource snd_compat_mem_region;44 45 struct resource *snd_compat_request_region(unsigned long start, unsigned long size, const char *name)46 {47 struct resource *resource;48 49 resource = snd_kcalloc(sizeof(struct resource), GFP_KERNEL);50 if (resource == NULL)51 return NULL;52 if (check_region(start, size)) {53 kfree(resource);54 return NULL;55 }56 snd_wrapper_request_region(start, size, name);57 resource->name = name;58 resource->start = start;59 resource->end = start + size - 1;60 resource->flags = IORESOURCE_IO;61 return resource;62 }63 64 int snd_compat_release_resource(struct resource *resource)65 {66 snd_runtime_check(resource != NULL, return -EINVAL);67 if (resource == &snd_compat_mem_region)68 return 0;69 release_region(resource->start, (resource->end - resource->start) + 1);70 kfree(resource);71 return 0;72 }73 74 #endif75 76 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) && defined(CONFIG_PCI)77 78 /*79 * Registration of PCI drivers and handling of hot-pluggable devices.80 */81 82 static LIST_HEAD(pci_drivers);83 84 struct pci_driver_mapping {85 struct pci_dev *dev;86 struct pci_driver *drv;87 unsigned long dma_mask;88 void *driver_data;89 };90 91 #define PCI_MAX_MAPPINGS 6492 static struct pci_driver_mapping drvmap [PCI_MAX_MAPPINGS] = { { NULL, } , };93 94 95 static struct pci_driver_mapping *get_pci_driver_mapping(struct pci_dev *dev)96 {97 int i;98 99 for (i = 0; i < PCI_MAX_MAPPINGS; i++)100 if (drvmap[i].dev == dev)101 return &drvmap[i];102 return NULL;103 }104 105 void * snd_pci_compat_get_driver_data (struct pci_dev *dev)106 {107 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);108 if (map)109 return map->driver_data;110 return NULL;111 }112 113 114 void snd_pci_compat_set_driver_data (struct pci_dev *dev, void *driver_data)115 {116 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);117 if (map)118 map->driver_data = driver_data;119 }120 121 122 unsigned long snd_pci_compat_get_dma_mask (struct pci_dev *dev)123 {124 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);125 if (map)126 return map->dma_mask;127 return 0;128 }129 130 131 void snd_pci_compat_set_dma_mask (struct pci_dev *dev, unsigned long mask)132 {133 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);134 if (map)135 map->dma_mask = mask;136 }137 138 139 const struct pci_device_id * snd_pci_compat_match_device(const struct pci_device_id *ids, struct pci_dev *dev)140 {141 u16 subsystem_vendor, subsystem_device;142 143 pci_read_config_word(dev, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);144 pci_read_config_word(dev, PCI_SUBSYSTEM_ID, &subsystem_device);145 146 while (ids->vendor || ids->subvendor || ids->class_mask) {147 if ((ids->vendor == PCI_ANY_ID || ids->vendor == dev->vendor) &&148 (ids->device == PCI_ANY_ID || ids->device == dev->device) &&149 (ids->subvendor == PCI_ANY_ID || ids->subvendor == subsystem_vendor) &&150 (ids->subdevice == PCI_ANY_ID || ids->subdevice == subsystem_device) &&151 !((ids->class ^ dev->class) & ids->class_mask))152 return ids;153 ids++;154 }155 return NULL;156 }157 158 static int snd_pci_announce_device(struct pci_driver *drv, struct pci_dev *dev)159 {160 int i;161 const struct pci_device_id *id;162 163 if (drv->id_table) {164 id = snd_pci_compat_match_device(drv->id_table, dev);165 if (!id)166 return 0;167 } else {168 id = NULL;169 }170 for (i = 0; i < PCI_MAX_MAPPINGS; i++) {171 if (drvmap[i].dev == NULL) {172 drvmap[i].dev = dev;173 drvmap[i].drv = drv;174 drvmap[i].dma_mask = ~0UL;175 break;176 }177 }178 if (i >= PCI_MAX_MAPPINGS)179 return 0;180 if (drv->probe(dev, id) < 0) {181 drvmap[i].dev = NULL;182 return 0;183 }184 return 1;185 }186 187 int snd_pci_compat_register_driver(struct pci_driver *drv)188 {189 struct pci_dev *dev;190 int count = 0;191 192 list_add_tail(&drv->node, &pci_drivers);193 pci_for_each_dev(dev) {194 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);195 if (! map)196 count += snd_pci_announce_device(drv, dev);197 }198 return count;199 }200 201 void snd_pci_compat_unregister_driver(struct pci_driver *drv)202 {203 struct pci_dev *dev;204 205 list_del(&drv->node);206 pci_for_each_dev(dev) {207 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);208 if (map && map->drv == drv) {209 if (drv->remove)210 drv->remove(dev);211 map->dev = NULL;212 map->drv = NULL;213 }214 }215 }216 217 unsigned long snd_pci_compat_get_size (struct pci_dev *dev, int n_base)218 {219 u32 l, sz;220 int reg = PCI_BASE_ADDRESS_0 + (n_base << 2);221 222 pci_read_config_dword (dev, reg, &l);223 if (l == 0xffffffff)224 return 0;225 226 pci_write_config_dword (dev, reg, ~0);227 pci_read_config_dword (dev, reg, &sz);228 pci_write_config_dword (dev, reg, l);229 230 if (!sz || sz == 0xffffffff)231 return 0;232 if ((l & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_MEMORY) {233 sz = ~(sz & PCI_BASE_ADDRESS_MEM_MASK);234 } else {235 sz = ~(sz & PCI_BASE_ADDRESS_IO_MASK) & 0xffff;236 }237 238 return sz;239 }240 241 int snd_pci_compat_get_flags (struct pci_dev *dev, int n_base)242 {243 unsigned long foo = dev->base_address[n_base] & PCI_BASE_ADDRESS_SPACE;244 int flags = 0;245 246 if (foo == 0)247 flags |= IORESOURCE_MEM;248 if (foo == 1)249 flags |= IORESOURCE_IO;250 251 return flags;252 }253 254 /*255 * Set power management state of a device. For transitions from state D3256 * it isn't as straightforward as one could assume since many devices forget257 * their configuration space during wakeup. Returns old power state.258 */259 int snd_pci_compat_set_power_state(struct pci_dev *dev, int new_state)260 {261 u32 base[5], romaddr;262 u16 pci_command, pwr_command;263 u8 pci_latency, pci_cacheline;264 int i, old_state;265 int pm = snd_pci_compat_find_capability(dev, PCI_CAP_ID_PM);266 267 if (!pm)268 return 0;269 pci_read_config_word(dev, pm + PCI_PM_CTRL, &pwr_command);270 old_state = pwr_command & PCI_PM_CTRL_STATE_MASK;271 if (old_state == new_state)272 return old_state;273 if (old_state == 3) {274 pci_read_config_word(dev, PCI_COMMAND, &pci_command);275 pci_write_config_word(dev, PCI_COMMAND, pci_command & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));276 for (i = 0; i < 5; i++)277 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + i*4, &base[i]);278 pci_read_config_dword(dev, PCI_ROM_ADDRESS, &romaddr);279 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency);280 pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &pci_cacheline);281 pci_write_config_word(dev, pm + PCI_PM_CTRL, new_state);282 for (i = 0; i < 5; i++)283 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + i*4, base[i]);284 pci_write_config_dword(dev, PCI_ROM_ADDRESS, romaddr);285 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);286 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, pci_cacheline);287 pci_write_config_byte(dev, PCI_LATENCY_TIMER, pci_latency);288 pci_write_config_word(dev, PCI_COMMAND, pci_command);289 } else290 pci_write_config_word(dev, pm + PCI_PM_CTRL, (pwr_command & ~PCI_PM_CTRL_STATE_MASK) | new_state);291 return old_state;292 }293 294 /*295 * Initialize device before it's used by a driver. Ask low-level code296 * to enable I/O and memory. Wake up the device if it was suspended.297 * Beware, this function can fail.298 */299 int snd_pci_compat_enable_device(struct pci_dev *dev)300 {301 u16 pci_command;302 303 pci_read_config_word(dev, PCI_COMMAND, &pci_command);304 pci_write_config_word(dev, PCI_COMMAND, pci_command | (PCI_COMMAND_IO | PCI_COMMAND_MEMORY));305 snd_pci_compat_set_power_state(dev, 0);306 return 0;307 }308 309 int snd_pci_compat_find_capability(struct pci_dev *dev, int cap)310 {311 u16 status;312 u8 pos, id;313 int ttl = 48;314 315 pci_read_config_word(dev, PCI_STATUS, &status);316 if (!(status & PCI_STATUS_CAP_LIST))317 return 0;318 pci_read_config_byte(dev, PCI_CAPABILITY_LIST, &pos);319 while (ttl-- && pos >= 0x40) {320 pos &= ~3;321 pci_read_config_byte(dev, pos + PCI_CAP_LIST_ID, &id);322 if (id == 0xff)323 break;324 if (id == cap)325 return pos;326 pci_read_config_byte(dev, pos + PCI_CAP_LIST_NEXT, &pos);327 }328 return 0;329 }330 331 static void *snd_pci_compat_alloc_consistent1(unsigned long dma_mask,332 unsigned long size,333 int hop)334 {335 void *res;336 337 if (++hop > 10)338 return NULL;339 res = snd_malloc_pages(size, GFP_KERNEL | (dma_mask <= 0x00ffffff ? GFP_DMA : 0));340 if (res == NULL)341 return NULL;342 if ((virt_to_bus(res) & ~dma_mask) ||343 ((virt_to_bus(res) + size - 1) & ~dma_mask)) {344 void *res1 = snd_pci_compat_alloc_consistent1(dma_mask, size, hop);345 snd_free_pages(res, size);346 return res1;347 }348 return res;349 }350 351 void *snd_pci_compat_alloc_consistent(struct pci_dev *dev,352 long size,353 dma_addr_t *dmaaddr)354 {355 unsigned long dma_mask = snd_pci_compat_get_dma_mask(dev);356 void *res = snd_pci_compat_alloc_consistent1(dma_mask, size, 0);357 if (res != NULL)358 *dmaaddr = (dma_addr_t)virt_to_bus(res);359 return res;360 }361 362 void snd_pci_compat_free_consistent(struct pci_dev *dev, long size, void *ptr, dma_addr_t dmaaddr)363 {364 snd_runtime_check(bus_to_virt(dmaaddr) == ptr, return);365 snd_free_pages(ptr, size);366 }367 368 int snd_pci_compat_dma_supported(struct pci_dev *dev, dma_addr_t mask)369 {370 return 1;371 }372 373 #endif /* kernel version < 2.3.0 && CONFIG_PCI */374 375 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) && defined(CONFIG_APM)376 377 #include <linux/apm_bios.h>378 379 static spinlock_t pm_devs_lock = SPIN_LOCK_UNLOCKED;380 static LIST_HEAD(pm_devs);381 382 #ifdef CONFIG_PCI383 static struct pm_dev *pci_compat_pm_dev;384 static int pci_compat_pm_callback(struct pm_dev *pdev, pm_request_t rqst, void *data)385 {386 struct pci_dev *dev;387 switch (rqst) {388 case PM_SUSPEND:389 pci_for_each_dev(dev) {390 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);391 if (map->drv && map->drv->suspend)392 map->drv->suspend(dev);393 }394 break;395 case PM_RESUME:396 pci_for_each_dev(dev) {397 struct pci_driver_mapping *map = get_pci_driver_mapping(dev);398 if (map->drv && map->drv->resume)399 map->drv->resume(dev);400 }401 break;402 }403 return 0;404 }405 #endif406 407 static int snd_apm_callback(apm_event_t ev)408 {409 struct list_head *entry;410 pm_request_t rqst;411 void *data;412 int status;413 414 switch (ev) {415 case APM_SYS_SUSPEND:416 case APM_USER_SUSPEND:417 case APM_CRITICAL_SUSPEND:418 rqst = PM_SUSPEND;419 data = (void *)3;420 break;421 case APM_NORMAL_RESUME:422 case APM_CRITICAL_RESUME:423 case APM_STANDBY_RESUME: /* ??? */424 rqst = PM_RESUME;425 data = (void *)0;426 break;427 default:428 return 0;429 }430 for (entry = pm_devs.next; entry != &pm_devs; entry = entry->next) {431 struct pm_dev *dev = list_entry(entry, struct pm_dev, entry);432 if ((status = pm_send(dev, rqst, data)))433 return status;434 }435 return 0;436 }437 438 int __init pm_init(void)439 {440 if (apm_register_callback(snd_apm_callback))441 snd_printk("apm_register_callback failure!\n");442 #ifdef CONFIG_PCI443 pci_compat_pm_dev = pm_register(PM_PCI_DEV, 0, pci_compat_pm_callback);444 #endif445 return 0;446 }447 448 void __exit pm_done(void)449 {450 #ifdef CONFIG_PCI451 if (pci_compat_pm_dev)452 pm_unregister(pci_compat_pm_dev);453 #endif454 apm_unregister_callback(snd_apm_callback);455 }456 457 struct pm_dev *pm_register(pm_dev_t type,458 unsigned long id,459 pm_callback callback)460 {461 struct pm_dev *dev = kmalloc(sizeof(struct pm_dev), GFP_KERNEL);462 463 if (dev) {464 unsigned long flags;465 466 memset(dev, 0, sizeof(*dev));467 dev->type = type;468 dev->id = id;469 dev->callback = callback;470 471 spin_lock_irqsave(&pm_devs_lock, flags);472 list_add(&dev->entry, &pm_devs);473 spin_unlock_irqrestore(&pm_devs_lock, flags);474 }475 return dev;476 }477 478 void pm_unregister(struct pm_dev *dev)479 {480 if (dev) {481 unsigned long flags;482 483 spin_lock_irqsave(&pm_devs_lock, flags);484 list_del(&dev->entry);485 spin_unlock_irqrestore(&pm_devs_lock, flags);486 487 kfree(dev);488 }489 }490 491 int pm_send(struct pm_dev *dev, pm_request_t rqst, void *data)492 {493 int status = 0;494 int prev_state, next_state;495 496 switch (rqst) {497 case PM_SUSPEND:498 case PM_RESUME:499 prev_state = dev->state;500 next_state = (int) data;501 if (prev_state != next_state) {502 if (dev->callback)503 status = (*dev->callback)(dev, rqst, data);504 if (!status) {505 dev->state = next_state;506 dev->prev_state = prev_state;507 }508 } else {509 dev->prev_state = prev_state;510 }511 break;512 default:513 if (dev->callback)514 status = (*dev->callback)(dev, rqst, data);515 break;516 }517 return status;518 }519 520 #endif /* kernel version < 2.3.0 && CONFIG_APM */521 43 522 44 static void run_workqueue(struct workqueue_struct *wq) -
GPL/branches/alsa-resync1/alsa-kernel/core/pcm_lib.c
r34 r105 21 21 */ 22 22 23 #define __NO_VERSION__ 23 24 #include <sound/driver.h> 25 #include <linux/slab.h> 26 #include <linux/time.h> 27 #include <sound/core.h> 24 28 #include <sound/control.h> 25 29 #include <sound/info.h> -
GPL/branches/alsa-resync1/alsa-kernel/core/pcm_memory.c
r34 r105 20 20 */ 21 21 22 #define __NO_VERSION__ 22 23 #include <sound/driver.h> 24 #include <asm/io.h> 25 #include <linux/time.h> 26 #include <sound/core.h> 23 27 #include <sound/pcm.h> 24 28 #include <sound/info.h> -
GPL/branches/alsa-resync1/alsa-kernel/core/pcm_native.c
r77 r105 20 20 */ 21 21 22 #define __NO_VERSION__ 22 23 #include <sound/driver.h> 24 #include <linux/mm.h> 25 #include <linux/file.h> 26 #include <linux/slab.h> 27 #include <linux/time.h> 28 #include <sound/core.h> 23 29 #include <sound/control.h> 24 30 #include <sound/info.h> … … 26 32 #include <sound/pcm_params.h> 27 33 #include <sound/minors.h> 28 #include <linux/file.h>29 34 30 35 /* -
GPL/branches/alsa-resync1/alsa-kernel/core/pcm_timer.c
r34 r105 16 16 * You should have received a copy of the GNU General Public License 17 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 19 * 20 20 */ 21 21 22 #define __NO_VERSION__ 22 23 #include <sound/driver.h> 24 #include <linux/time.h> 25 #include <sound/core.h> 23 26 #include <sound/pcm.h> 24 27 #include <sound/timer.h> 28 29 #define chip_t snd_pcm_substream_t 25 30 26 31 /* -
GPL/branches/alsa-resync1/alsa-kernel/core/sgbuf.c
r32 r105 20 20 */ 21 21 22 #ifdef TARGET_OS2 22 23 #include <sound/driver.h> 24 #include <sound/core.h> 23 25 #include <sound/info.h> 26 #endif /* TARGET_OS2 */ 24 27 #include <sound/memalloc.h> 25 28 -
GPL/branches/alsa-resync1/alsa-kernel/include/sound/driver.h
r102 r105 50 50 */ 51 51 52 #ifdef TARGET_OS2 53 #include <linux/errno.h> 54 #include <linux/mm.h> /* poll, pagemap, or vmalloc? */ 55 #endif /* TARGET_OS2 */ 56 52 57 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 4, 0) 53 58 #if defined(__i386__) || defined(__ppc__)
Note:
See TracChangeset
for help on using the changeset viewer.