Resguardo inicial

This commit is contained in:
lastdragon
2026-09-06 12:53:21 -06:00
parent 662efe3c2a
commit ad2088d178
94853 changed files with 43200404 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# Xillybus devices
#
config XILLYBUS_CLASS
tristate
config XILLYBUS
tristate "Xillybus generic FPGA interface"
depends on PCI || OF
select CRC32
select XILLYBUS_CLASS
help
Xillybus is a generic interface for peripherals designed on
programmable logic (FPGA). The driver probes the hardware for
its capabilities, and creates device files accordingly.
If unsure, say N.
if XILLYBUS
config XILLYBUS_PCIE
tristate "Xillybus over PCIe"
depends on PCI_MSI
help
Set to M if you want Xillybus to use PCI Express for communicating
with the FPGA. The module will be called xillybus_pcie.
config XILLYBUS_OF
tristate "Xillybus over Device Tree"
depends on OF && HAS_DMA && HAS_IOMEM
help
Set to M if you want Xillybus to find its resources from the
Open Firmware Flattened Device Tree. If the target is an embedded
system, say M. The module will be called xillybus_of.
endif # if XILLYBUS
# XILLYUSB doesn't depend on XILLYBUS
config XILLYUSB
tristate "XillyUSB: Xillybus generic FPGA interface for USB"
depends on USB
select CRC32
select XILLYBUS_CLASS
help
XillyUSB is the Xillybus variant which uses USB for communicating
with the FPGA.
Set to M if you want Xillybus to use USB for communicating with
the FPGA. The module will be called xillyusb.
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: GPL-2.0-only
#
# Makefile for Xillybus driver
#
obj-$(CONFIG_XILLYBUS_CLASS) += xillybus_class.o
obj-$(CONFIG_XILLYBUS) += xillybus_core.o
obj-$(CONFIG_XILLYBUS_PCIE) += xillybus_pcie.o
obj-$(CONFIG_XILLYBUS_OF) += xillybus_of.o
obj-$(CONFIG_XILLYUSB) += xillyusb.o
@@ -0,0 +1,126 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* linux/drivers/misc/xillybus.h
*
* Copyright 2011 Xillybus Ltd, http://xillybus.com
*
* Header file for the Xillybus FPGA/host framework.
*/
#ifndef __XILLYBUS_H
#define __XILLYBUS_H
#include <linux/list.h>
#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/interrupt.h>
#include <linux/sched.h>
#include <linux/cdev.h>
#include <linux/spinlock.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>
struct xilly_endpoint_hardware;
struct xilly_buffer {
void *addr;
dma_addr_t dma_addr;
int end_offset; /* Counting elements, not bytes */
};
struct xilly_idt_handle {
unsigned char *chandesc;
unsigned char *names;
int names_len;
int entries;
};
/*
* Read-write confusion: wr_* and rd_* notation sticks to FPGA view, so
* wr_* buffers are those consumed by read(), since the FPGA writes to them
* and vice versa.
*/
struct xilly_channel {
struct xilly_endpoint *endpoint;
int chan_num;
int log2_element_size;
int seekable;
struct xilly_buffer **wr_buffers; /* FPGA writes, driver reads! */
int num_wr_buffers;
unsigned int wr_buf_size; /* In bytes */
int wr_fpga_buf_idx;
int wr_host_buf_idx;
int wr_host_buf_pos;
int wr_empty;
int wr_ready; /* Significant only when wr_empty == 1 */
int wr_sleepy;
int wr_eof;
int wr_hangup;
spinlock_t wr_spinlock;
struct mutex wr_mutex;
wait_queue_head_t wr_wait;
wait_queue_head_t wr_ready_wait;
int wr_ref_count;
int wr_synchronous;
int wr_allow_partial;
int wr_exclusive_open;
int wr_supports_nonempty;
struct xilly_buffer **rd_buffers; /* FPGA reads, driver writes! */
int num_rd_buffers;
unsigned int rd_buf_size; /* In bytes */
int rd_fpga_buf_idx;
int rd_host_buf_pos;
int rd_host_buf_idx;
int rd_full;
spinlock_t rd_spinlock;
struct mutex rd_mutex;
wait_queue_head_t rd_wait;
int rd_ref_count;
int rd_allow_partial;
int rd_synchronous;
int rd_exclusive_open;
struct delayed_work rd_workitem;
unsigned char rd_leftovers[4];
};
struct xilly_endpoint {
struct device *dev;
struct module *owner;
int dma_using_dac; /* =1 if 64-bit DMA is used, =0 otherwise. */
__iomem void *registers;
int fatal_error;
struct mutex register_mutex;
wait_queue_head_t ep_wait;
int num_channels; /* EXCLUDING message buffer */
struct xilly_channel **channels;
int msg_counter;
int failed_messages;
int idtlen;
u32 *msgbuf_addr;
dma_addr_t msgbuf_dma_addr;
unsigned int msg_buf_size;
};
struct xilly_mapping {
struct device *device;
dma_addr_t dma_addr;
size_t size;
int direction;
};
irqreturn_t xillybus_isr(int irq, void *data);
struct xilly_endpoint *xillybus_init_endpoint(struct device *dev);
int xillybus_endpoint_discovery(struct xilly_endpoint *endpoint);
void xillybus_endpoint_remove(struct xilly_endpoint *endpoint);
#endif /* __XILLYBUS_H */
@@ -0,0 +1,256 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright 2021 Xillybus Ltd, http://xillybus.com
*
* Driver for the Xillybus class
*/
#include <linux/types.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include "xillybus_class.h"
MODULE_DESCRIPTION("Driver for Xillybus class");
MODULE_AUTHOR("Eli Billauer, Xillybus Ltd.");
MODULE_ALIAS("xillybus_class");
MODULE_LICENSE("GPL v2");
static DEFINE_MUTEX(unit_mutex);
static LIST_HEAD(unit_list);
static const struct class xillybus_class = {
.name = "xillybus",
};
#define UNITNAMELEN 16
struct xilly_unit {
struct list_head list_entry;
void *private_data;
struct cdev *cdev;
char name[UNITNAMELEN];
int major;
int lowest_minor;
int num_nodes;
};
int xillybus_init_chrdev(struct device *dev,
const struct file_operations *fops,
struct module *owner,
void *private_data,
unsigned char *idt, unsigned int len,
int num_nodes,
const char *prefix, bool enumerate)
{
int rc;
dev_t mdev;
int i;
char devname[48];
struct device *device;
size_t namelen;
struct xilly_unit *unit, *u;
unit = kzalloc_obj(*unit);
if (!unit)
return -ENOMEM;
mutex_lock(&unit_mutex);
if (!enumerate)
snprintf(unit->name, UNITNAMELEN, "%s", prefix);
for (i = 0; enumerate; i++) {
snprintf(unit->name, UNITNAMELEN, "%s_%02d",
prefix, i);
enumerate = false;
list_for_each_entry(u, &unit_list, list_entry)
if (!strcmp(unit->name, u->name)) {
enumerate = true;
break;
}
}
rc = alloc_chrdev_region(&mdev, 0, num_nodes, unit->name);
if (rc) {
dev_warn(dev, "Failed to obtain major/minors");
goto fail_obtain;
}
unit->major = MAJOR(mdev);
unit->lowest_minor = MINOR(mdev);
unit->num_nodes = num_nodes;
unit->private_data = private_data;
unit->cdev = cdev_alloc();
if (!unit->cdev) {
rc = -ENOMEM;
goto unregister_chrdev;
}
unit->cdev->ops = fops;
unit->cdev->owner = owner;
rc = cdev_add(unit->cdev, MKDEV(unit->major, unit->lowest_minor),
unit->num_nodes);
if (rc) {
dev_err(dev, "Failed to add cdev.\n");
/* kobject_put() is normally done by cdev_del() */
kobject_put(&unit->cdev->kobj);
goto unregister_chrdev;
}
for (i = 0; i < num_nodes; i++) {
namelen = strnlen(idt, len);
if (namelen == len) {
dev_err(dev, "IDT's list of names is too short. This is exceptionally weird, because its CRC is OK\n");
rc = -ENODEV;
goto unroll_device_create;
}
snprintf(devname, sizeof(devname), "%s_%s",
unit->name, idt);
len -= namelen + 1;
idt += namelen + 1;
device = device_create(&xillybus_class,
NULL,
MKDEV(unit->major,
i + unit->lowest_minor),
NULL,
"%s", devname);
if (IS_ERR(device)) {
dev_err(dev, "Failed to create %s device. Aborting.\n",
devname);
rc = -ENODEV;
goto unroll_device_create;
}
}
if (len) {
dev_err(dev, "IDT's list of names is too long. This is exceptionally weird, because its CRC is OK\n");
rc = -ENODEV;
goto unroll_device_create;
}
list_add_tail(&unit->list_entry, &unit_list);
dev_info(dev, "Created %d device files.\n", num_nodes);
mutex_unlock(&unit_mutex);
return 0;
unroll_device_create:
for (i--; i >= 0; i--)
device_destroy(&xillybus_class, MKDEV(unit->major,
i + unit->lowest_minor));
cdev_del(unit->cdev);
unregister_chrdev:
unregister_chrdev_region(MKDEV(unit->major, unit->lowest_minor),
unit->num_nodes);
fail_obtain:
mutex_unlock(&unit_mutex);
kfree(unit);
return rc;
}
EXPORT_SYMBOL(xillybus_init_chrdev);
void xillybus_cleanup_chrdev(void *private_data,
struct device *dev)
{
int minor;
struct xilly_unit *unit = NULL, *iter;
mutex_lock(&unit_mutex);
list_for_each_entry(iter, &unit_list, list_entry)
if (iter->private_data == private_data) {
unit = iter;
break;
}
if (!unit) {
dev_err(dev, "Weird bug: Failed to find unit\n");
mutex_unlock(&unit_mutex);
return;
}
for (minor = unit->lowest_minor;
minor < (unit->lowest_minor + unit->num_nodes);
minor++)
device_destroy(&xillybus_class, MKDEV(unit->major, minor));
cdev_del(unit->cdev);
unregister_chrdev_region(MKDEV(unit->major, unit->lowest_minor),
unit->num_nodes);
dev_info(dev, "Removed %d device files.\n",
unit->num_nodes);
list_del(&unit->list_entry);
kfree(unit);
mutex_unlock(&unit_mutex);
}
EXPORT_SYMBOL(xillybus_cleanup_chrdev);
int xillybus_find_inode(struct inode *inode,
void **private_data, int *index)
{
int minor = iminor(inode);
int major = imajor(inode);
struct xilly_unit *unit = NULL, *iter;
mutex_lock(&unit_mutex);
list_for_each_entry(iter, &unit_list, list_entry)
if (iter->major == major &&
minor >= iter->lowest_minor &&
minor < (iter->lowest_minor + iter->num_nodes)) {
unit = iter;
break;
}
if (!unit) {
mutex_unlock(&unit_mutex);
return -ENODEV;
}
*private_data = unit->private_data;
*index = minor - unit->lowest_minor;
mutex_unlock(&unit_mutex);
return 0;
}
EXPORT_SYMBOL(xillybus_find_inode);
static int __init xillybus_class_init(void)
{
return class_register(&xillybus_class);
}
static void __exit xillybus_class_exit(void)
{
class_unregister(&xillybus_class);
}
module_init(xillybus_class_init);
module_exit(xillybus_class_exit);
@@ -0,0 +1,30 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright 2021 Xillybus Ltd, http://www.xillybus.com
*
* Header file for the Xillybus class
*/
#ifndef __XILLYBUS_CLASS_H
#define __XILLYBUS_CLASS_H
#include <linux/types.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/module.h>
int xillybus_init_chrdev(struct device *dev,
const struct file_operations *fops,
struct module *owner,
void *private_data,
unsigned char *idt, unsigned int len,
int num_nodes,
const char *prefix, bool enumerate);
void xillybus_cleanup_chrdev(void *private_data,
struct device *dev);
int xillybus_find_inode(struct inode *inode,
void **private_data, int *index);
#endif /* __XILLYBUS_CLASS_H */
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,84 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* linux/drivers/misc/xillybus_of.c
*
* Copyright 2011 Xillybus Ltd, http://xillybus.com
*
* Driver for the Xillybus FPGA/host framework using Open Firmware.
*/
#include <linux/module.h>
#include <linux/device.h>
#include <linux/slab.h>
#include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/err.h>
#include "xillybus.h"
MODULE_DESCRIPTION("Xillybus driver for Open Firmware");
MODULE_AUTHOR("Eli Billauer, Xillybus Ltd.");
MODULE_ALIAS("xillybus_of");
MODULE_LICENSE("GPL v2");
static const char xillyname[] = "xillybus_of";
/* Match table for of_platform binding */
static const struct of_device_id xillybus_of_match[] = {
{ .compatible = "xillybus,xillybus-1.00.a", },
{ .compatible = "xlnx,xillybus-1.00.a", }, /* Deprecated */
{}
};
MODULE_DEVICE_TABLE(of, xillybus_of_match);
static int xilly_drv_probe(struct platform_device *op)
{
struct device *dev = &op->dev;
struct xilly_endpoint *endpoint;
int rc;
int irq;
endpoint = xillybus_init_endpoint(dev);
if (!endpoint)
return -ENOMEM;
dev_set_drvdata(dev, endpoint);
endpoint->owner = THIS_MODULE;
endpoint->registers = devm_platform_ioremap_resource(op, 0);
if (IS_ERR(endpoint->registers))
return PTR_ERR(endpoint->registers);
irq = platform_get_irq(op, 0);
rc = devm_request_irq(dev, irq, xillybus_isr, 0, xillyname, endpoint);
if (rc) {
dev_err(endpoint->dev,
"Failed to register IRQ handler. Aborting.\n");
return -ENODEV;
}
return xillybus_endpoint_discovery(endpoint);
}
static void xilly_drv_remove(struct platform_device *op)
{
struct device *dev = &op->dev;
struct xilly_endpoint *endpoint = dev_get_drvdata(dev);
xillybus_endpoint_remove(endpoint);
}
static struct platform_driver xillybus_platform_driver = {
.probe = xilly_drv_probe,
.remove = xilly_drv_remove,
.driver = {
.name = xillyname,
.of_match_table = xillybus_of_match,
},
};
module_platform_driver(xillybus_platform_driver);
@@ -0,0 +1,127 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* linux/drivers/misc/xillybus_pcie.c
*
* Copyright 2011 Xillybus Ltd, http://xillybus.com
*
* Driver for the Xillybus FPGA/host framework using PCI Express.
*/
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include "xillybus.h"
MODULE_DESCRIPTION("Xillybus driver for PCIe");
MODULE_AUTHOR("Eli Billauer, Xillybus Ltd.");
MODULE_ALIAS("xillybus_pcie");
MODULE_LICENSE("GPL v2");
#define PCI_DEVICE_ID_XILLYBUS 0xebeb
#define PCI_VENDOR_ID_ACTEL 0x11aa
#define PCI_VENDOR_ID_LATTICE 0x1204
static const char xillyname[] = "xillybus_pcie";
static const struct pci_device_id xillyids[] = {
{PCI_DEVICE(PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_XILLYBUS)},
{PCI_DEVICE(PCI_VENDOR_ID_ALTERA, PCI_DEVICE_ID_XILLYBUS)},
{PCI_DEVICE(PCI_VENDOR_ID_ACTEL, PCI_DEVICE_ID_XILLYBUS)},
{PCI_DEVICE(PCI_VENDOR_ID_LATTICE, PCI_DEVICE_ID_XILLYBUS)},
{ /* End: all zeroes */ }
};
static int xilly_probe(struct pci_dev *pdev,
const struct pci_device_id *ent)
{
struct xilly_endpoint *endpoint;
int rc;
endpoint = xillybus_init_endpoint(&pdev->dev);
if (!endpoint)
return -ENOMEM;
pci_set_drvdata(pdev, endpoint);
endpoint->owner = THIS_MODULE;
rc = pcim_enable_device(pdev);
if (rc) {
dev_err(endpoint->dev,
"pcim_enable_device() failed. Aborting.\n");
return rc;
}
/* L0s has caused packet drops. No power saving, thank you. */
pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S);
if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
dev_err(endpoint->dev,
"Incorrect BAR configuration. Aborting.\n");
return -ENODEV;
}
rc = pcim_iomap_regions(pdev, 0x01, xillyname);
if (rc) {
dev_err(endpoint->dev,
"pcim_iomap_regions() failed. Aborting.\n");
return rc;
}
endpoint->registers = pcim_iomap_table(pdev)[0];
pci_set_master(pdev);
/* Set up a single MSI interrupt */
if (pci_enable_msi(pdev)) {
dev_err(endpoint->dev,
"Failed to enable MSI interrupts. Aborting.\n");
return -ENODEV;
}
rc = devm_request_irq(&pdev->dev, pdev->irq, xillybus_isr, 0,
xillyname, endpoint);
if (rc) {
dev_err(endpoint->dev,
"Failed to register MSI handler. Aborting.\n");
return -ENODEV;
}
/*
* Some (old and buggy?) hardware drops 64-bit addressed PCIe packets,
* even when the PCIe driver claims that a 64-bit mask is OK. On the
* other hand, on some architectures, 64-bit addressing is mandatory.
* So go for the 64-bit mask only when failing is the other option.
*/
if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
endpoint->dma_using_dac = 0;
} else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
endpoint->dma_using_dac = 1;
} else {
dev_err(endpoint->dev, "Failed to set DMA mask. Aborting.\n");
return -ENODEV;
}
return xillybus_endpoint_discovery(endpoint);
}
static void xilly_remove(struct pci_dev *pdev)
{
struct xilly_endpoint *endpoint = pci_get_drvdata(pdev);
xillybus_endpoint_remove(endpoint);
}
MODULE_DEVICE_TABLE(pci, xillyids);
static struct pci_driver xillybus_driver = {
.name = xillyname,
.id_table = xillyids,
.probe = xilly_probe,
.remove = xilly_remove,
};
module_pci_driver(xillybus_driver);
File diff suppressed because it is too large Load Diff