<commit_before>/*
 * Generic bridge to memory-mapped hardware
 *
 * Author: <NAME> <<EMAIL>>
 *
 * This file is licensed under the terms of the GNU General Public License
 * version 2.  This program is licensed "as is" without any warranty of any
 * kind, whether express or implied.
 */

#define DEBUG
#include <linux/version.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
#include <linux/of.h>
#include <linux/poll.h>
#include <linux/uaccess.h>
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <linux/sched.h>
#include <linux/clk.h>
#include <linux/ioctl.h>
#include <linux/dma-buf.h>
#include <linux/vmalloc.h>
#include <linux/slab.h>
#include <linux/scatterlist.h>

#include "zynqportal.h"

#define DRIVER_NAME        "zynqportal"
#define DRIVER_DESCRIPTION "Generic userspace hardware bridge"
#define DRIVER_VERSION     "0.1"

#ifdef DEBUG // was KERN_DEBUG
#define driver_devel(format, ...) \
        do { \
                printk(format, ## __VA_ARGS__); \
        } while (0)
#else
#define driver_devel(format, ...)
#endif

struct portal_data {
        struct miscdevice misc; /* must be first element (pointer passed to misc_register) */
        wait_queue_head_t wait_queue;
        dma_addr_t        dev_base_phys;
        void             *ind_reg_base_virt;
        unsigned char     portal_irq;
        int               irq_requested;
};

/*
 * Local helper functions
 */
static void dump_ind_regs(const char *prefix, struct portal_data *portal_data)
{
        int i;
        for (i = 0; i < 10; i++) {
                unsigned long regval = readl(portal_data->ind_reg_base_virt + i*4);
                driver_devel("%s reg %x value %08lx\n", prefix, i*4, regval);
        }
}

static irqreturn_t portal_isr(int irq, void *dev_id)
{
        struct portal_data *portal_data = (struct portal_data *)dev_id;

        //dump_ind_regs("ISR a", portal_data);
        driver_devel("%s %s %d basevirt %p\n", __func__, portal_data->misc.name, irq, portal_data->ind_reg_base_virt);
        u32 int_status = readl(portal_data->ind_reg_base_virt + 0);
        driver_devel("stat %x\n", int_status);
        u32 int_en  = readl(portal_data->ind_reg_base_virt + 4);
        driver_devel("%s IRQ %s %d %x %x\n", __func__, portal_data->misc.name, irq, int_status, int_en);

        if (int_status) {
                // disable interrupt.  this will be enabled by user mode
                // driver  after all the HW->SW FIFOs have been emptied
                writel(0, portal_data->ind_reg_base_virt + 0x4);

                //dump_ind_regs("ISR b", portal_data);
                wake_up_interruptible(&portal_data->wait_queue);
                return IRQ_HANDLED;
        }
        return IRQ_NONE;
}

/*
 * file_operations functions<commit_msg>remove a bit of debug output from isr.<commit_after>/*
 * Generic bridge to memory-mapped hardware
 *
 * Author: <NAME> <<EMAIL>>
 *
 * This file is licensed under the terms of the GNU General Public License
 * version 2.  This program is licensed "as is" without any warranty of any
 * kind, whether express or implied.
 */

#define DEBUG
#include <linux/version.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/interrupt.h>
#include <linux/of.h>
#include <linux/poll.h>
#include <linux/uaccess.h>
#include <linux/miscdevice.h>
#include <linux/platform_device.h>
#include <linux/sched.h>
#include <linux/clk.h>
#include <linux/ioctl.h>
#include <linux/dma-buf.h>
#include <linux/vmalloc.h>
#include <linux/slab.h>
#include <linux/scatterlist.h>

#include "zynqportal.h"

#define DRIVER_NAME        "zynqportal"
#define DRIVER_DESCRIPTION "Generic userspace hardware bridge"
#define DRIVER_VERSION     "0.1"

#ifdef DEBUG // was KERN_DEBUG
#define driver_devel(format, ...) \
        do { \
                printk(format, ## __VA_ARGS__); \
        } while (0)
#else
#define driver_devel(format, ...)
#endif

struct portal_data {
        struct miscdevice misc; /* must be first element (pointer passed to misc_register) */
        wait_queue_head_t wait_queue;
        dma_addr_t        dev_base_phys;
        void             *ind_reg_base_virt;
        unsigned char     portal_irq;
        int               irq_requested;
};

/*
 * Local helper functions
 */
static void dump_ind_regs(const char *prefix, struct portal_data *portal_data)
{
        int i;
        for (i = 0; i < 10; i++) {
                unsigned long regval = readl(portal_data->ind_reg_base_virt + i*4);
                driver_devel("%s reg %x value %08lx\n", prefix, i*4, regval);
        }
}

static irqreturn_t portal_isr(int irq, void *dev_id)
{
        struct portal_data *portal_data = (struct portal_data *)dev_id;

        //dump_ind_regs("ISR a", portal_data);
        //driver_devel("%s %s %d basevirt %p\n", __func__, portal_data->misc.name, irq, portal_data->ind_reg_base_virt);
        u32 int_status = readl(portal_data->ind_reg_base_virt + 0);
        //driver_devel("stat %x\n", int_status);
        u32 int_en  = readl(portal_data->ind_reg_base_virt + 4);
        driver_devel("%s IRQ %s %d %x %x\n", __func__, portal_data->misc.name, irq, int_status, int_en);

        if (int_status) {
                // disable interrupt.  this will be enabled by user mode
                // driver  after all the HW->SW FIFOs have been emptied
                writel(0, portal_data->ind_reg_base_virt + 0x4);

                //dump_ind_regs("ISR b", portal_data);
                wake_up_interruptible(&portal_data->wait_queue);
                return IRQ_HANDLED;
        }
        return IRQ_NONE;
}

/*
 * file_operations functions
{'fraction_non_alphanumeric': 0.1199721399965175, 'fraction_numerical': 0.006965000870625109, 'mean_word_length': 2.7616240995415846, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6936278', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1906, 'n_words': 490}