Changeset 679 for GPL/trunk/lib32/misc.c


Ignore:
Timestamp:
Mar 18, 2021, 8:57:36 PM (4 years ago)
Author:
David Azarewicz
Message:

Merge changes from Paul's uniaud32next branch.

Location:
GPL/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • GPL/trunk

  • GPL/trunk/lib32/misc.c

    r598 r679  
    2929#include <linux/fs.h>
    3030#include <linux/poll.h>
    31 #define CONFIG_PROC_FS
     31#define CONFIG_PROC_FS 1
    3232#include <linux/proc_fs.h>
    3333#include <asm/uaccess.h>
     
    3838#include <linux/workqueue.h>
    3939#include <linux/firmware.h>
     40#include <linux/ctype.h>
    4041#include <dbgos2.h>
    4142
     
    8485    return 0;
    8586}
     87
     88//******************************************************************************
     89//Save error message in szLastALSAError; if card init failed, then we will
     90//print it in drv32\init.cpp
     91//******************************************************************************
     92int dev_dbg(const struct device *dev, const char * fmt, ...)
     93{
     94    va_list argptr;                /* -> variable argument list */
     95
     96    char *pszLastALSAError;
     97
     98    pszLastALSAError= iLastError ? szLastALSAError2 : szLastALSAError1;
     99
     100    va_start(argptr, fmt);           /* get pointer to argument list */
     101    vsprintf(pszLastALSAError, fmt, argptr);
     102//    strcat(pszLastALSAError, "\r");
     103    va_end(argptr);                /* done with variable arguments */
     104
     105    if(szOverrunTest1 != 0xCC || szOverrunTest2 != 0xCC) {
     106        DebugInt3();
     107    }
     108
     109        StringOut(pszLastALSAError);
     110//    rprintf( (pszLastALSAError) );
     111    if(++iLastError > 1) {
     112        iLastError = 0;
     113    }
     114    return 0;
     115}
     116//******************************************************************************
     117int pcm_dbg(struct snd_pcm *dev, const char * fmt, ...)
     118{
     119    va_list argptr;                /* -> variable argument list */
     120
     121    char *pszLastALSAError;
     122
     123    pszLastALSAError= iLastError ? szLastALSAError2 : szLastALSAError1;
     124
     125    va_start(argptr, fmt);           /* get pointer to argument list */
     126    vsprintf(pszLastALSAError, fmt, argptr);
     127//    strcat(pszLastALSAError, "\r");
     128    va_end(argptr);                /* done with variable arguments */
     129
     130    if(szOverrunTest1 != 0xCC || szOverrunTest2 != 0xCC) {
     131        DebugInt3();
     132    }
     133
     134        StringOut(pszLastALSAError);
     135//    rprintf( (pszLastALSAError) );
     136    if(++iLastError > 1) {
     137        iLastError = 0;
     138    }
     139    return 0;
     140}
     141//******************************************************************************
     142int codec_dbg(struct hda_codec *dev, const char * fmt, ...)
     143{
     144    va_list argptr;                /* -> variable argument list */
     145
     146    char *pszLastALSAError;
     147
     148    pszLastALSAError= iLastError ? szLastALSAError2 : szLastALSAError1;
     149
     150    va_start(argptr, fmt);           /* get pointer to argument list */
     151    vsprintf(pszLastALSAError, fmt, argptr);
     152//    strcat(pszLastALSAError, "\r");
     153    va_end(argptr);                /* done with variable arguments */
     154
     155    if(szOverrunTest1 != 0xCC || szOverrunTest2 != 0xCC) {
     156        DebugInt3();
     157    }
     158
     159        StringOut(pszLastALSAError);
     160//    rprintf( (pszLastALSAError) );
     161    if(++iLastError > 1) {
     162        iLastError = 0;
     163    }
     164    return 0;
     165}
    86166//******************************************************************************
    87167//******************************************************************************
     
    169249//******************************************************************************
    170250//******************************************************************************
     251struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
     252        struct proc_dir_entry *parent){
     253    struct proc_dir_entry *proc;
     254    proc = (struct proc_dir_entry *)kmalloc(sizeof(struct proc_dir_entry), 0);
     255    memset(proc, 0, sizeof(struct proc_dir_entry));
     256
     257    proc->name   = name;
     258    proc->parent = parent;
     259
     260    return proc;
     261}
     262//******************************************************************************
     263//******************************************************************************
     264struct proc_dir_entry *proc_mkdir(const char *name, struct proc_dir_entry *parent)
     265{
     266    return proc_mkdir_mode(name, S_IRUGO | S_IXUGO, parent);
     267}
     268//******************************************************************************
     269//******************************************************************************
     270struct proc_dir_entry *proc_symlink(const char *name, struct proc_dir_entry *parent, const char *dest)
     271{
     272    struct proc_dir_entry *proc;
     273    proc = (struct proc_dir_entry *)kmalloc(sizeof(struct proc_dir_entry), 0);
     274    memset(proc, 0, sizeof(struct proc_dir_entry));
     275
     276    proc->name   = name;
     277    proc->parent = parent;
     278    proc->data = (void*)dest;
     279
     280    return proc;
     281}
     282//******************************************************************************
     283//******************************************************************************
    171284int fasync_helper(int a, struct file *b, int c, struct fasync_struct **d)
    172285{
     
    175288//******************************************************************************
    176289//******************************************************************************
    177 void kill_fasync(struct fasync_struct *a, int b, int c)
     290void kill_fasync(struct fasync_struct **a, int b, int c)
    178291{
    179292}
     
    273386                run_workqueue(wq);
    274387        } else {
    275                 wait_queue_t wait;
     388                struct wait_queue_entry wait;
    276389
    277390                init_waitqueue_entry(&wait, current);
     
    399512//******************************************************************************
    400513//******************************************************************************
    401 void *memdup_user(void __user *src, size_t len)
     514void *memdup_user(const void __user *src, size_t len)
    402515{
    403516        void *p = kmalloc(len, GFP_KERNEL);
     
    425538//******************************************************************************
    426539//******************************************************************************
    427 int schedule_work(struct work_struct *works)
    428 {
    429 #ifndef TARGET_OS2
    430         return kernel_thread(work_caller, works, 0) >= 0;
    431 #else
    432         return 1;
     540struct workqueue_struct *system_wq;
     541
     542int schedule_work(struct work_struct *work)
     543{
     544#ifndef TARGET_OS2 // crashes
     545        return queue_work(system_wq, work);
    433546#endif
    434 }
     547        return 0;
     548}
     549
    435550//******************************************************************************
    436551//******************************************************************************
     
    517632        return -EINVAL;
    518633}
     634//******************************************************************************
     635//******************************************************************************
     636
     637static void u32_swap(void *a, void *b, int size)
     638{
     639        u32 t = *(u32 *)a;
     640        *(u32 *)a = *(u32 *)b;
     641        *(u32 *)b = t;
     642}
     643
     644static void generic_swap(void *a, void *b, int size)
     645{
     646        char t;
     647
     648        do {
     649                t = *(char *)a;
     650                *(char *)a++ = *(char *)b;
     651                *(char *)b++ = t;
     652        } while (--size > 0);
     653}
     654
     655/**
     656 * sort - sort an array of elements
     657 * @base: pointer to data to sort
     658 * @num: number of elements
     659 * @size: size of each element
     660 * @cmp_func: pointer to comparison function
     661 * @swap_func: pointer to swap function or NULL
     662 *
     663 * This function does a heapsort on the given array. You may provide a
     664 * swap_func function optimized to your element type.
     665 *
     666 * Sorting time is O(n log n) both on average and worst-case. While
     667 * qsort is about 20% faster on average, it suffers from exploitable
     668 * O(n*n) worst-case behavior and extra memory requirements that make
     669 * it less suitable for kernel use.
     670 */
     671
     672void sort(void *base, size_t num, size_t size,
     673          int (*cmp_func)(const void *, const void *),
     674          void (*swap_func)(void *, void *, int size))
     675{
     676        /* pre-scale counters for performance */
     677        int i = (num/2 - 1) * size, n = num * size, c, r;
     678
     679        if (!swap_func)
     680                swap_func = (size == 4 ? u32_swap : generic_swap);
     681
     682        /* heapify */
     683        for ( ; i >= 0; i -= size) {
     684                for (r = i; r * 2 + size < n; r  = c) {
     685                        c = r * 2 + size;
     686                        if (c < n - size &&
     687                                        cmp_func(base + c, base + c + size) < 0)
     688                                c += size;
     689                        if (cmp_func(base + r, base + c) >= 0)
     690                                break;
     691                        swap_func(base + r, base + c, size);
     692                }
     693        }
     694
     695        /* sort */
     696        for (i = n - size; i > 0; i -= size) {
     697                swap_func(base, base + i, size);
     698                for (r = 0; r * 2 + size < i; r = c) {
     699                        c = r * 2 + size;
     700                        if (c < i - size &&
     701                                        cmp_func(base + c, base + c + size) < 0)
     702                                c += size;
     703                        if (cmp_func(base + r, base + c) >= 0)
     704                                break;
     705                        swap_func(base + r, base + c, size);
     706                }
     707        }
     708}
     709//******************************************************************************
     710//******************************************************************************
     711
     712/**
     713 * hex_to_bin - convert a hex digit to its real value
     714 * @ch: ascii character represents hex digit
     715 *
     716 * hex_to_bin() converts one hex digit to its actual value or -1 in case of bad
     717 * input.
     718 */
     719int hex_to_bin(char ch)
     720{
     721        if ((ch >= '0') && (ch <= '9'))
     722                return ch - '0';
     723        ch = tolower(ch);
     724        if ((ch >= 'a') && (ch <= 'f'))
     725                return ch - 'a' + 10;
     726        return -1;
     727}
     728//******************************************************************************
     729
     730
     731/*
     732 * stream_open is used by subsystems that want stream-like file descriptors.
     733 * Such file descriptors are not seekable and don't have notion of position
     734 * (file.f_pos is always 0). Contrary to file descriptors of other regular
     735 * files, .read() and .write() can run simultaneously.
     736 *
     737 * stream_open never fails and is marked to return int so that it could be
     738 * directly used as file_operations.open .
     739 */
     740int stream_open(struct inode *inode, struct file *filp)
     741{
     742        filp->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE | FMODE_ATOMIC_POS);
     743        //DAZ f_mode is 16 bit so FMODE_STREAM doesn't fit, but we don't use this on OS/2.
     744        //filp->f_mode |= FMODE_STREAM;
     745        return 0;
     746}
     747
     748/**
     749 * alloc_pages_exact - allocate pages with the given size
     750 * @size: the size to allocate in bytes
     751 * @gfp_flags: the allocation conditions, GFP_XXX
     752 *
     753 * Allocates the physically contiguous pages with the given size.
     754 *
     755 * Return: The pointer of the buffer, or %NULL if no enough memory.
     756 */
     757void *alloc_pages_exact(size_t size, gfp_t gfp_flags)
     758{
     759        int pg;
     760
     761        if (WARN_ON(!size))
     762                return NULL;
     763        if (WARN_ON(!gfp_flags))
     764                return NULL;
     765        gfp_flags |= __GFP_COMP;        /* compound page lets parts be mapped */
     766        pg = get_order(size);
     767        return (void *) __get_free_pages(gfp_flags, pg);
     768}
     769
     770/**
     771 * free_pages_exact - release the pages
     772 * @ptr: the buffer pointer to release
     773 * @size: the allocated buffer size
     774 *
     775 * Releases the buffer allocated via snd_malloc_pages().
     776 */
     777void free_pages_exact(void *ptr, size_t size)
     778{
     779        int pg;
     780
     781        if (ptr == NULL)
     782                return;
     783        pg = get_order(size);
     784        free_pages((unsigned long) ptr, pg);
     785}
Note: See TracChangeset for help on using the changeset viewer.