forked from KolibriOS/kolibrios
1) small optimisation
2) build with ddk headers and libs git-svn-id: svn://kolibrios.org@1600 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
e5b8886135
commit
404bf32ac0
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
Bool FindPciDevice()
|
bool FindUSBControllers()
|
||||||
{
|
{
|
||||||
Bool retval = FALSE;
|
bool retval = false;
|
||||||
u32_t bus, last_bus;
|
u32_t bus, last_bus;
|
||||||
PCITAG tag;
|
PCITAG tag;
|
||||||
|
|
||||||
@ -35,9 +35,8 @@ Bool FindPciDevice()
|
|||||||
if (! pcicmd & PCI_COMMAND_IO)
|
if (! pcicmd & PCI_COMMAND_IO)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
hc = (hc_t*)malloc(sizeof(hc_t));
|
hc = (hc_t*)kmalloc(sizeof(hc_t), 0);
|
||||||
memset(hc, 0, sizeof(hc_t));
|
INIT_LIST_HEAD(&hc->list);
|
||||||
link_initialize(&hc->link);
|
|
||||||
|
|
||||||
hc->pciId = PciRead32(bus,devfn, 0);
|
hc->pciId = PciRead32(bus,devfn, 0);
|
||||||
hc->PciTag = pciTag(bus,(devfn>>3)&0x1F,devfn&0x7);
|
hc->PciTag = pciTag(bus,(devfn>>3)&0x1F,devfn&0x7);
|
||||||
@ -45,7 +44,7 @@ Bool FindPciDevice()
|
|||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++)
|
||||||
{
|
{
|
||||||
u32_t base;
|
u32_t base;
|
||||||
Bool validSize;
|
bool validSize;
|
||||||
|
|
||||||
base = PciRead32(bus,devfn, PCI_MAP_REG_START + (i << 2));
|
base = PciRead32(bus,devfn, PCI_MAP_REG_START + (i << 2));
|
||||||
if(base)
|
if(base)
|
||||||
@ -59,9 +58,164 @@ Bool FindPciDevice()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
list_prepend(&hc->link, &hc_list);
|
list_add_tail(&hc->list, &hc_list);
|
||||||
retval = TRUE;
|
retval = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return retval;
|
return retval;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
|
||||||
|
/* these helpers provide future and backwards compatibility
|
||||||
|
* for accessing popular PCI BAR info */
|
||||||
|
#define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
|
||||||
|
#define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end)
|
||||||
|
#define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags)
|
||||||
|
#define pci_resource_len(dev,bar) \
|
||||||
|
((pci_resource_start((dev), (bar)) == 0 && \
|
||||||
|
pci_resource_end((dev), (bar)) == \
|
||||||
|
pci_resource_start((dev), (bar))) ? 0 : \
|
||||||
|
\
|
||||||
|
(pci_resource_end((dev), (bar)) - \
|
||||||
|
pci_resource_start((dev), (bar)) + 1))
|
||||||
|
|
||||||
|
static int __devinit mmio_resource_enabled(struct pci_dev *pdev, int idx)
|
||||||
|
{
|
||||||
|
return pci_resource_start(pdev, idx) && mmio_enabled(pdev);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
|
||||||
|
{
|
||||||
|
int wait_time, delta;
|
||||||
|
void __iomem *base, *op_reg_base;
|
||||||
|
u32 hcc_params, val;
|
||||||
|
u8 offset, cap_length;
|
||||||
|
int count = 256/4;
|
||||||
|
int tried_handoff = 0;
|
||||||
|
|
||||||
|
if (!mmio_resource_enabled(pdev, 0))
|
||||||
|
return;
|
||||||
|
|
||||||
|
base = pci_ioremap_bar(pdev, 0);
|
||||||
|
if (base == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
cap_length = readb(base);
|
||||||
|
op_reg_base = base + cap_length;
|
||||||
|
|
||||||
|
/* EHCI 0.96 and later may have "extended capabilities"
|
||||||
|
* spec section 5.1 explains the bios handoff, e.g. for
|
||||||
|
* booting from USB disk or using a usb keyboard
|
||||||
|
*/
|
||||||
|
hcc_params = readl(base + EHCI_HCC_PARAMS);
|
||||||
|
offset = (hcc_params >> 8) & 0xff;
|
||||||
|
while (offset && --count) {
|
||||||
|
u32 cap;
|
||||||
|
int msec;
|
||||||
|
|
||||||
|
pci_read_config_dword(pdev, offset, &cap);
|
||||||
|
switch (cap & 0xff) {
|
||||||
|
case 1: /* BIOS/SMM/... handoff support */
|
||||||
|
if ((cap & EHCI_USBLEGSUP_BIOS)) {
|
||||||
|
dev_dbg(&pdev->dev, "EHCI: BIOS handoff\n");
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/* aleksey_gorelov@phoenix.com reports that some systems need SMI forced on,
|
||||||
|
* but that seems dubious in general (the BIOS left it off intentionally)
|
||||||
|
* and is known to prevent some systems from booting. so we won't do this
|
||||||
|
* unless maybe we can determine when we're on a system that needs SMI forced.
|
||||||
|
*/
|
||||||
|
/* BIOS workaround (?): be sure the
|
||||||
|
* pre-Linux code receives the SMI
|
||||||
|
*/
|
||||||
|
pci_read_config_dword(pdev,
|
||||||
|
offset + EHCI_USBLEGCTLSTS,
|
||||||
|
&val);
|
||||||
|
pci_write_config_dword(pdev,
|
||||||
|
offset + EHCI_USBLEGCTLSTS,
|
||||||
|
val | EHCI_USBLEGCTLSTS_SOOE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* some systems get upset if this semaphore is
|
||||||
|
* set for any other reason than forcing a BIOS
|
||||||
|
* handoff..
|
||||||
|
*/
|
||||||
|
pci_write_config_byte(pdev, offset + 3, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if boot firmware now owns EHCI, spin till
|
||||||
|
* it hands it over.
|
||||||
|
*/
|
||||||
|
msec = 1000;
|
||||||
|
while ((cap & EHCI_USBLEGSUP_BIOS) && (msec > 0)) {
|
||||||
|
tried_handoff = 1;
|
||||||
|
msleep(10);
|
||||||
|
msec -= 10;
|
||||||
|
pci_read_config_dword(pdev, offset, &cap);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cap & EHCI_USBLEGSUP_BIOS) {
|
||||||
|
/* well, possibly buggy BIOS... try to shut
|
||||||
|
* it down, and hope nothing goes too wrong
|
||||||
|
*/
|
||||||
|
dev_warn(&pdev->dev, "EHCI: BIOS handoff failed"
|
||||||
|
" (BIOS bug?) %08x\n", cap);
|
||||||
|
pci_write_config_byte(pdev, offset + 2, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* just in case, always disable EHCI SMIs */
|
||||||
|
pci_write_config_dword(pdev,
|
||||||
|
offset + EHCI_USBLEGCTLSTS,
|
||||||
|
0);
|
||||||
|
|
||||||
|
/* If the BIOS ever owned the controller then we
|
||||||
|
* can't expect any power sessions to remain intact.
|
||||||
|
*/
|
||||||
|
if (tried_handoff)
|
||||||
|
writel(0, op_reg_base + EHCI_CONFIGFLAG);
|
||||||
|
break;
|
||||||
|
case 0: /* illegal reserved capability */
|
||||||
|
cap = 0;
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
default:
|
||||||
|
dev_warn(&pdev->dev, "EHCI: unrecognized capability "
|
||||||
|
"%02x\n", cap & 0xff);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
offset = (cap >> 8) & 0xff;
|
||||||
|
}
|
||||||
|
if (!count)
|
||||||
|
dev_printk(KERN_DEBUG, &pdev->dev, "EHCI: capability loop?\n");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* halt EHCI & disable its interrupts in any case
|
||||||
|
*/
|
||||||
|
val = readl(op_reg_base + EHCI_USBSTS);
|
||||||
|
if ((val & EHCI_USBSTS_HALTED) == 0) {
|
||||||
|
val = readl(op_reg_base + EHCI_USBCMD);
|
||||||
|
val &= ~EHCI_USBCMD_RUN;
|
||||||
|
writel(val, op_reg_base + EHCI_USBCMD);
|
||||||
|
|
||||||
|
wait_time = 2000;
|
||||||
|
delta = 100;
|
||||||
|
do {
|
||||||
|
writel(0x3f, op_reg_base + EHCI_USBSTS);
|
||||||
|
udelay(delta);
|
||||||
|
wait_time -= delta;
|
||||||
|
val = readl(op_reg_base + EHCI_USBSTS);
|
||||||
|
if ((val == ~(u32)0) || (val & EHCI_USBSTS_HALTED)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (wait_time > 0);
|
||||||
|
}
|
||||||
|
writel(0, op_reg_base + EHCI_USBINTR);
|
||||||
|
writel(0x3f, op_reg_base + EHCI_USBSTS);
|
||||||
|
|
||||||
|
iounmap(base);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -118,7 +118,7 @@ reset_needed:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Bool init_hc(hc_t *hc)
|
bool init_hc(hc_t *hc)
|
||||||
{
|
{
|
||||||
int port;
|
int port;
|
||||||
u32_t ifl;
|
u32_t ifl;
|
||||||
@ -212,7 +212,7 @@ Bool init_hc(hc_t *hc)
|
|||||||
status = in16(hc->iobase + USBPORTSC1 + (port * 2));
|
status = in16(hc->iobase + USBPORTSC1 + (port * 2));
|
||||||
if(status & 1)
|
if(status & 1)
|
||||||
{
|
{
|
||||||
udev_t *dev = malloc(sizeof(udev_t));
|
udev_t *dev = kmalloc(sizeof(udev_t),0);
|
||||||
|
|
||||||
out16(hc->iobase + USBPORTSC1 + (port * 2), 0x0E);
|
out16(hc->iobase + USBPORTSC1 + (port * 2), 0x0E);
|
||||||
|
|
||||||
@ -222,10 +222,9 @@ Bool init_hc(hc_t *hc)
|
|||||||
status = in16(hc->iobase + USBPORTSC1 + (port * 2));
|
status = in16(hc->iobase + USBPORTSC1 + (port * 2));
|
||||||
dbgprintf("port%d status %x\n", port, status);
|
dbgprintf("port%d status %x\n", port, status);
|
||||||
|
|
||||||
link_initialize(&dev->link);
|
INIT_LIST_HEAD(&dev->list);
|
||||||
dev->id = 0;
|
|
||||||
dev->host = hc;
|
dev->host = hc;
|
||||||
dev->addr = 0;
|
|
||||||
dev->port = port;
|
dev->port = port;
|
||||||
dev->ep0_size = 8;
|
dev->ep0_size = 8;
|
||||||
dev->status = status;
|
dev->status = status;
|
||||||
@ -244,7 +243,7 @@ Bool init_hc(hc_t *hc)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if(set_address(dev)) {
|
if(set_address(dev)) {
|
||||||
list_prepend(&dev->link, &newdev_list);
|
list_add_tail(&dev->list, &newdev_list);
|
||||||
hc->port_map |= 1<<port;
|
hc->port_map |= 1<<port;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -255,7 +254,7 @@ Bool init_hc(hc_t *hc)
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
return TRUE;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
u16_t __attribute__((aligned(16)))
|
u16_t __attribute__((aligned(16)))
|
||||||
@ -269,7 +268,7 @@ SETUP(0) IN(1) IN(0) IN(1)...OUT(0)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
Bool set_address(udev_t *dev)
|
bool set_address(udev_t *dev)
|
||||||
{
|
{
|
||||||
static udev_id = 0;
|
static udev_id = 0;
|
||||||
static udev_addr = 0;
|
static udev_addr = 0;
|
||||||
@ -292,7 +291,7 @@ Bool set_address(udev_t *dev)
|
|||||||
req_addr[1] = address;
|
req_addr[1] = address;
|
||||||
|
|
||||||
if( !ctrl_request(dev, &req_addr, DOUT, NULL, 0))
|
if( !ctrl_request(dev, &req_addr, DOUT, NULL, 0))
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
dev->addr = address;
|
dev->addr = address;
|
||||||
dev->id = (++udev_id << 8) | address;
|
dev->id = (++udev_id << 8) | address;
|
||||||
@ -303,12 +302,12 @@ Bool set_address(udev_t *dev)
|
|||||||
data[1] = 0;
|
data[1] = 0;
|
||||||
|
|
||||||
if( !ctrl_request(dev, &req_descr, DIN, data, 8))
|
if( !ctrl_request(dev, &req_descr, DIN, data, 8))
|
||||||
return FALSE;
|
return false;
|
||||||
|
|
||||||
dev_descr_t *descr = (dev_descr_t*)&data;
|
dev_descr_t *descr = (dev_descr_t*)&data;
|
||||||
dev->ep0_size = descr->bMaxPacketSize0;
|
dev->ep0_size = descr->bMaxPacketSize0;
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
request_t *create_request(udev_t *dev, endp_t *enp, u32_t dir,
|
request_t *create_request(udev_t *dev, endp_t *enp, u32_t dir,
|
||||||
@ -317,12 +316,12 @@ request_t *create_request(udev_t *dev, endp_t *enp, u32_t dir,
|
|||||||
td_t *td, *td_prev;
|
td_t *td, *td_prev;
|
||||||
addr_t data_dma;
|
addr_t data_dma;
|
||||||
|
|
||||||
request_t *rq = (request_t*)malloc(sizeof(request_t));
|
size_t packet_size = enp->size;
|
||||||
|
size_t size = req_size;
|
||||||
|
|
||||||
link_initialize(&rq->link);
|
request_t *rq = (request_t*)kmalloc(sizeof(request_t),0);
|
||||||
|
|
||||||
rq->td_head = 0;
|
INIT_LIST_HEAD(&rq->list);
|
||||||
rq->td_tail = 0;
|
|
||||||
|
|
||||||
rq->data = (addr_t)data;
|
rq->data = (addr_t)data;
|
||||||
rq->size = req_size;
|
rq->size = req_size;
|
||||||
@ -333,8 +332,13 @@ request_t *create_request(udev_t *dev, endp_t *enp, u32_t dir,
|
|||||||
|
|
||||||
td_prev = NULL;
|
td_prev = NULL;
|
||||||
|
|
||||||
while(req_size >= enp->size)
|
while(size > 0)
|
||||||
{
|
{
|
||||||
|
if ( size < packet_size)
|
||||||
|
{
|
||||||
|
packet_size = size;
|
||||||
|
};
|
||||||
|
|
||||||
td = alloc_td();
|
td = alloc_td();
|
||||||
td->link = 1;
|
td->link = 1;
|
||||||
|
|
||||||
@ -344,34 +348,15 @@ request_t *create_request(udev_t *dev, endp_t *enp, u32_t dir,
|
|||||||
if( td_prev )
|
if( td_prev )
|
||||||
td_prev->link = td->dma | 4;
|
td_prev->link = td->dma | 4;
|
||||||
td->status = 0x00800000 | dev->speed;
|
td->status = 0x00800000 | dev->speed;
|
||||||
td->token = TOKEN(enp->size,enp->toggle,enp->address,
|
td->token = TOKEN(packet_size,enp->toggle,enp->address,
|
||||||
dev->addr,dir);
|
dev->addr,dir);
|
||||||
td->buffer = data_dma;
|
td->buffer = data_dma;
|
||||||
td->bk = td_prev;
|
td->bk = td_prev;
|
||||||
|
|
||||||
td_prev = td;
|
td_prev = td;
|
||||||
|
|
||||||
data_dma+= enp->size;
|
data_dma+= packet_size;
|
||||||
req_size-= enp->size;
|
size-= packet_size;
|
||||||
enp->toggle ^= DATA1;
|
|
||||||
}
|
|
||||||
if(req_size)
|
|
||||||
{
|
|
||||||
td = alloc_td();
|
|
||||||
td->link = 1;
|
|
||||||
|
|
||||||
if(rq->td_head == NULL)
|
|
||||||
rq->td_head = td;
|
|
||||||
|
|
||||||
if( td_prev )
|
|
||||||
td_prev->link = td->dma | 4;
|
|
||||||
|
|
||||||
td->status = 0x00800000 | dev->speed;
|
|
||||||
td->token = TOKEN( req_size, enp->toggle, enp->address,
|
|
||||||
dev->addr, dir);
|
|
||||||
td->buffer = data_dma;
|
|
||||||
td->bk = td_prev;
|
|
||||||
|
|
||||||
enp->toggle ^= DATA1;
|
enp->toggle ^= DATA1;
|
||||||
}
|
}
|
||||||
rq->td_tail = td;
|
rq->td_tail = td;
|
||||||
@ -387,7 +372,7 @@ request_t *create_request(udev_t *dev, endp_t *enp, u32_t dir,
|
|||||||
return rq;
|
return rq;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool ctrl_request(udev_t *dev, void *req, u32_t pid,
|
bool ctrl_request(udev_t *dev, void *req, u32_t pid,
|
||||||
void *data, size_t req_size)
|
void *data, size_t req_size)
|
||||||
{
|
{
|
||||||
size_t packet_size = dev->ep0_size;
|
size_t packet_size = dev->ep0_size;
|
||||||
@ -397,7 +382,7 @@ Bool ctrl_request(udev_t *dev, void *req, u32_t pid,
|
|||||||
td_t *td0, *td, *td_prev;
|
td_t *td0, *td, *td_prev;
|
||||||
qh_t *qh;
|
qh_t *qh;
|
||||||
addr_t data_dma = 0;
|
addr_t data_dma = 0;
|
||||||
Bool retval;
|
bool retval;
|
||||||
|
|
||||||
td0 = alloc_td();
|
td0 = alloc_td();
|
||||||
|
|
||||||
@ -411,8 +396,13 @@ Bool ctrl_request(udev_t *dev, void *req, u32_t pid,
|
|||||||
|
|
||||||
td_prev = td0;
|
td_prev = td0;
|
||||||
|
|
||||||
while(size >= packet_size)
|
while(size > 0)
|
||||||
{
|
{
|
||||||
|
if ( size < packet_size)
|
||||||
|
{
|
||||||
|
packet_size = size;
|
||||||
|
};
|
||||||
|
|
||||||
td = alloc_td();
|
td = alloc_td();
|
||||||
td_prev->link = td->dma | 4;
|
td_prev->link = td->dma | 4;
|
||||||
td->status = 0x00800000 | dev->speed;
|
td->status = 0x00800000 | dev->speed;
|
||||||
@ -426,21 +416,6 @@ Bool ctrl_request(udev_t *dev, void *req, u32_t pid,
|
|||||||
size-= packet_size;
|
size-= packet_size;
|
||||||
toggle ^= DATA1;
|
toggle ^= DATA1;
|
||||||
}
|
}
|
||||||
if(size)
|
|
||||||
{
|
|
||||||
td = alloc_td();
|
|
||||||
td_prev->link = td->dma | 4;
|
|
||||||
td->status = 0x00800000 | dev->speed;
|
|
||||||
td->token = ((size-1)<<21)|toggle|(dev->addr<<8)|pid;
|
|
||||||
td->buffer = data_dma;
|
|
||||||
td->bk = td_prev;
|
|
||||||
|
|
||||||
td_prev = td;
|
|
||||||
|
|
||||||
data_dma+= packet_size;
|
|
||||||
size-= packet_size;
|
|
||||||
toggle ^= DATA1;
|
|
||||||
}
|
|
||||||
|
|
||||||
td = alloc_td();
|
td = alloc_td();
|
||||||
td_prev->link = td->dma | 4;
|
td_prev->link = td->dma | 4;
|
||||||
@ -480,8 +455,8 @@ Bool ctrl_request(udev_t *dev, void *req, u32_t pid,
|
|||||||
dbgprintf("td status %x\n",td->status);
|
dbgprintf("td status %x\n",td->status);
|
||||||
dbgprintf("qh %x \n", qh->qelem);
|
dbgprintf("qh %x \n", qh->qelem);
|
||||||
|
|
||||||
retval = FALSE;
|
retval = false;
|
||||||
} else retval = TRUE;
|
} else retval = true;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -494,7 +469,7 @@ Bool ctrl_request(udev_t *dev, void *req, u32_t pid,
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Bool init_device(udev_t *dev)
|
bool init_device(udev_t *dev)
|
||||||
{
|
{
|
||||||
static u16_t __attribute__((aligned(16)))
|
static u16_t __attribute__((aligned(16)))
|
||||||
req_descr[4] = {0x0680,0x0100,0x0000,18};
|
req_descr[4] = {0x0680,0x0100,0x0000,18};
|
||||||
@ -586,7 +561,7 @@ Bool init_device(udev_t *dev)
|
|||||||
break;
|
break;
|
||||||
case USB_CLASS_HID:
|
case USB_CLASS_HID:
|
||||||
dev->conf = conf;
|
dev->conf = conf;
|
||||||
list_remove(&dev->link);
|
list_del(&dev->list);
|
||||||
return init_hid(dev);
|
return init_hid(dev);
|
||||||
|
|
||||||
case USB_CLASS_PRINTER:
|
case USB_CLASS_PRINTER:
|
||||||
|
@ -16,7 +16,7 @@ struct hid_descriptor {
|
|||||||
|
|
||||||
void create_hid_mouse(udev_t *dev, endpoint_descr_t *en_d);
|
void create_hid_mouse(udev_t *dev, endpoint_descr_t *en_d);
|
||||||
|
|
||||||
Bool init_hid(udev_t *dev)
|
bool init_hid(udev_t *dev)
|
||||||
{
|
{
|
||||||
interface_descr_t *interface;
|
interface_descr_t *interface;
|
||||||
struct hid_descriptor *hds;
|
struct hid_descriptor *hds;
|
||||||
@ -96,11 +96,11 @@ Bool init_hid(udev_t *dev)
|
|||||||
if( interface->bInterfaceProtocol == 2)
|
if( interface->bInterfaceProtocol == 2)
|
||||||
create_hid_mouse(dev, ep);
|
create_hid_mouse(dev, ep);
|
||||||
// }
|
// }
|
||||||
return TRUE;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Bool mouse_handler(udev_t *dev, struct tag_request *rq)
|
bool mouse_handler(udev_t *dev, struct tag_request *rq)
|
||||||
{
|
{
|
||||||
td_t *td;
|
td_t *td;
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ Bool mouse_handler(udev_t *dev, struct tag_request *rq)
|
|||||||
td->status = 0x00800000 | dev->speed;
|
td->status = 0x00800000 | dev->speed;
|
||||||
td->token ^= DATA1;
|
td->token ^= DATA1;
|
||||||
|
|
||||||
return TRUE;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
void create_hid_mouse(udev_t *dev, endpoint_descr_t *en_d)
|
void create_hid_mouse(udev_t *dev, endpoint_descr_t *en_d)
|
||||||
@ -142,13 +142,12 @@ void create_hid_mouse(udev_t *dev, endpoint_descr_t *en_d)
|
|||||||
enp.size = en_d->wMaxPacketSize;
|
enp.size = en_d->wMaxPacketSize;
|
||||||
enp.toggle = DATA0;
|
enp.toggle = DATA0;
|
||||||
|
|
||||||
packet = malloc(enp.size);
|
packet = kzalloc(enp.size, 0);
|
||||||
memset(packet, 0, enp.size);
|
|
||||||
|
|
||||||
rq = create_request(dev, &enp, DIN, packet, enp.size);
|
rq = create_request(dev, &enp, DIN, packet, enp.size);
|
||||||
rq->handler = &mouse_handler;
|
rq->handler = &mouse_handler;
|
||||||
|
|
||||||
list_prepend(&rq->link, &rq_list);
|
list_add_tail(&rq->list, &rq_list);
|
||||||
|
|
||||||
dbgprintf("create_hid_mouse\n");
|
dbgprintf("create_hid_mouse\n");
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,21 @@
|
|||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
FASM = e:/fasm/fasm.exe
|
|
||||||
CFLAGS = -c -O2 -fomit-frame-pointer -fno-builtin-printf
|
CFLAGS = -c -O2 -fomit-frame-pointer -fno-builtin-printf
|
||||||
LDRHD = -shared -T ld.x -s --file-alignment 32
|
LDFLAGS = -nostdlib -shared -s -Map usb.map --image-base 0\
|
||||||
|
--file-alignment 512 --section-alignment 4096
|
||||||
|
|
||||||
|
DEFINES = -D__KERNEL__ -DCONFIG_X86_32
|
||||||
|
|
||||||
|
DRV_TOPDIR = $(CURDIR)/../..
|
||||||
|
|
||||||
|
DRV_INCLUDES = $(DRV_TOPDIR)/include
|
||||||
|
|
||||||
|
INCLUDES = -I$(DRV_INCLUDES) \
|
||||||
|
-I$(DRV_INCLUDES)/linux
|
||||||
|
|
||||||
|
LIBPATH = $(DRV_TOPDIR)/ddk
|
||||||
|
|
||||||
INCLUDES = -I ../../include
|
|
||||||
|
|
||||||
HFILES:= ../../include/types.h \
|
|
||||||
../../include/syscall.h \
|
|
||||||
../../include/link.h \
|
|
||||||
../../include/pci.h \
|
|
||||||
usb.h
|
|
||||||
|
|
||||||
SRC_DEP:= pci.inc \
|
SRC_DEP:= pci.inc \
|
||||||
detect.inc \
|
detect.inc \
|
||||||
@ -21,17 +26,18 @@ USB_SRC:= usb.c
|
|||||||
|
|
||||||
USB_OBJ:= usb.obj
|
USB_OBJ:= usb.obj
|
||||||
|
|
||||||
|
LIBS:= -ldrv -lcore
|
||||||
|
|
||||||
USB = usb.dll
|
USB = usb.dll
|
||||||
|
|
||||||
all: $(USB)
|
all: $(USB)
|
||||||
|
|
||||||
$(USB): $(USB_OBJ) $(SRC_DEP) $(HFILES) Makefile
|
$(USB): $(USB_OBJ) $(SRC_DEP) $(HFILES) Makefile
|
||||||
wlink name usb.dll SYS nt_dll lib libdrv op offset=0 op nod op maxe=25 op el op STUB=stub.exe op START=_drvEntry @usb.lk
|
ld $(LDFLAGS) -L$(LIBPATH) -T usb.lds -o $@ $(USB_OBJ) $(LIBS)
|
||||||
kpack.exe usb.dll usb.drv
|
kpack.exe usb.dll usb.drv
|
||||||
|
|
||||||
usb.obj : usb.c $(SRC_DEP) $(HFILES) Makefile
|
usb.obj : usb.c $(SRC_DEP) $(HFILES) Makefile
|
||||||
$(CC) $(INCLUDES) $(CFLAGS) -o usb.obj usb.c
|
$(CC) $(DEFINES) $(INCLUDES) $(CFLAGS) -o usb.obj usb.c
|
||||||
|
|
||||||
%.obj : %.c $(HFILES)
|
%.obj : %.c $(HFILES)
|
||||||
$(CC) $(CFLAGS) -o $@ $<
|
$(CC) $(CFLAGS) -o $@ $<
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
u32_t pciGetBaseSize(int bus, int devfn, int index,
|
u32_t pciGetBaseSize(int bus, int devfn, int index,
|
||||||
Bool destructive, Bool *min)
|
bool destructive, bool *min)
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
u32_t addr1;
|
u32_t addr1;
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "types.h"
|
#include <kernel.h>
|
||||||
#include "link.h"
|
#include <mutex.h>
|
||||||
|
#include <pci.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
//#include <stdio.h>
|
||||||
#include <malloc.h>
|
//#include <malloc.h>
|
||||||
#include <memory.h>
|
//#include <memory.h>
|
||||||
|
|
||||||
#include "pci.h"
|
|
||||||
|
|
||||||
#include "syscall.h"
|
#include <syscall.h>
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
|
|
||||||
|
|
||||||
int __stdcall srv_usb(ioctl_t *io);
|
int __stdcall srv_usb(ioctl_t *io);
|
||||||
|
|
||||||
Bool init_hc(hc_t *hc);
|
bool init_hc(hc_t *hc);
|
||||||
|
|
||||||
static slab_t qh_slab;
|
static slab_t qh_slab;
|
||||||
static slab_t td_slab;
|
static slab_t td_slab;
|
||||||
|
|
||||||
static link_t hc_list;
|
LIST_HEAD( hc_list );
|
||||||
static link_t newdev_list;
|
LIST_HEAD( newdev_list );
|
||||||
static link_t rq_list;
|
LIST_HEAD( rq_list );
|
||||||
|
|
||||||
u32_t __stdcall drvEntry(int action)
|
u32_t drvEntry(int action, char *cmdline)
|
||||||
{
|
{
|
||||||
u32_t retval;
|
u32_t retval;
|
||||||
hc_t *hc;
|
hc_t *hc;
|
||||||
@ -41,11 +41,7 @@ u32_t __stdcall drvEntry(int action)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
list_initialize(&hc_list);
|
if( !FindUSBControllers() ) {
|
||||||
list_initialize(&newdev_list);
|
|
||||||
list_initialize(&rq_list);
|
|
||||||
|
|
||||||
if( !FindPciDevice() ) {
|
|
||||||
dbgprintf("no uhci devices found\n");
|
dbgprintf("no uhci devices found\n");
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
@ -86,19 +82,19 @@ u32_t __stdcall drvEntry(int action)
|
|||||||
|
|
||||||
hc = (hc_t*)hc_list.next;
|
hc = (hc_t*)hc_list.next;
|
||||||
|
|
||||||
while( &hc->link != &hc_list)
|
while( &hc->list != &hc_list)
|
||||||
{
|
{
|
||||||
init_hc(hc);
|
init_hc(hc);
|
||||||
hc = (hc_t*)hc->link.next;
|
hc = (hc_t*)hc->list.next;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbgprintf("\n");
|
dbgprintf("\n");
|
||||||
|
|
||||||
dev = (udev_t*)newdev_list.next;
|
dev = (udev_t*)newdev_list.next;
|
||||||
while( &dev->link != &newdev_list)
|
while( &dev->list != &newdev_list)
|
||||||
{
|
{
|
||||||
udev_t *tmp = dev;
|
udev_t *tmp = dev;
|
||||||
dev = (udev_t*)dev->link.next;
|
dev = (udev_t*)dev->list.next;
|
||||||
|
|
||||||
if(tmp->id != 0)
|
if(tmp->id != 0)
|
||||||
init_device(tmp);
|
init_device(tmp);
|
||||||
@ -110,7 +106,7 @@ u32_t __stdcall drvEntry(int action)
|
|||||||
request_t *rq;
|
request_t *rq;
|
||||||
|
|
||||||
rq = (request_t*)rq_list.next;
|
rq = (request_t*)rq_list.next;
|
||||||
while( &rq->link != &rq_list)
|
while( &rq->list != &rq_list)
|
||||||
{
|
{
|
||||||
qh_t *qh;
|
qh_t *qh;
|
||||||
td_t *td;
|
td_t *td;
|
||||||
@ -122,19 +118,19 @@ u32_t __stdcall drvEntry(int action)
|
|||||||
qh->qelem = td->dma;
|
qh->qelem = td->dma;
|
||||||
|
|
||||||
__asm__ __volatile__ ("":::"memory");
|
__asm__ __volatile__ ("":::"memory");
|
||||||
rq = (request_t*)rq->link.next;
|
rq = (request_t*)rq->list.next;
|
||||||
};
|
};
|
||||||
|
|
||||||
delay(10/10);
|
delay(10/10);
|
||||||
|
|
||||||
rq = (request_t*)rq_list.next;
|
rq = (request_t*)rq_list.next;
|
||||||
while( &rq->link != &rq_list)
|
while( &rq->list != &rq_list)
|
||||||
{
|
{
|
||||||
request_t *tmp;
|
request_t *tmp;
|
||||||
td_t *td;
|
td_t *td;
|
||||||
|
|
||||||
tmp = rq;
|
tmp = rq;
|
||||||
rq = (request_t*)rq->link.next;
|
rq = (request_t*)rq->list.next;
|
||||||
|
|
||||||
td = tmp->td_head;
|
td = tmp->td_head;
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
typedef struct list_head list_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int available; /**< Count of available items in this slab. */
|
int available; /**< Count of available items in this slab. */
|
||||||
@ -38,7 +40,7 @@ typedef struct
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
link_t link;
|
list_t list;
|
||||||
|
|
||||||
addr_t iobase;
|
addr_t iobase;
|
||||||
|
|
||||||
@ -184,7 +186,7 @@ typedef struct __attribute__ ((packed))
|
|||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
link_t link;
|
list_t list;
|
||||||
u32_t id;
|
u32_t id;
|
||||||
|
|
||||||
hc_t *host;
|
hc_t *host;
|
||||||
@ -205,14 +207,14 @@ typedef struct
|
|||||||
|
|
||||||
typedef struct tag_request
|
typedef struct tag_request
|
||||||
{
|
{
|
||||||
link_t link;
|
list_t list;
|
||||||
td_t *td_head;
|
td_t *td_head;
|
||||||
td_t *td_tail;
|
td_t *td_tail;
|
||||||
addr_t data;
|
addr_t data;
|
||||||
size_t size;
|
size_t size;
|
||||||
udev_t *dev;
|
udev_t *dev;
|
||||||
u32_t type;
|
u32_t type;
|
||||||
Bool (*handler)(udev_t *dev, struct tag_request *rq);
|
bool (*handler)(udev_t *dev, struct tag_request *rq);
|
||||||
}request_t;
|
}request_t;
|
||||||
|
|
||||||
|
|
||||||
@ -221,22 +223,23 @@ typedef struct tag_request
|
|||||||
#define TOKEN( size, toggle, ep, addr, pid) \
|
#define TOKEN( size, toggle, ep, addr, pid) \
|
||||||
( (((size)-1)<<21)|(toggle)|(((ep)&0xF)<<15)|((addr)<<8)|(pid))
|
( (((size)-1)<<21)|(toggle)|(((ep)&0xF)<<15)|((addr)<<8)|(pid))
|
||||||
|
|
||||||
Bool ctrl_request(udev_t *dev, void *req, u32_t dir,
|
bool FindUSBControllers();
|
||||||
|
|
||||||
|
bool ctrl_request(udev_t *dev, void *req, u32_t dir,
|
||||||
void *data, size_t req_size);
|
void *data, size_t req_size);
|
||||||
|
|
||||||
|
bool set_address(udev_t *dev);
|
||||||
|
|
||||||
Bool set_address(udev_t *dev);
|
bool init_device(udev_t *dev);
|
||||||
|
|
||||||
Bool init_device(udev_t *dev);
|
bool init_hid(udev_t *dev);
|
||||||
|
|
||||||
Bool init_hid(udev_t *dev);
|
|
||||||
|
|
||||||
struct boot_packet
|
struct boot_packet
|
||||||
{
|
{
|
||||||
u8_t buttons;
|
u8_t buttons;
|
||||||
i8_t x;
|
char x;
|
||||||
i8_t y;
|
char y;
|
||||||
i8_t z;
|
char z;
|
||||||
}__attribute__ ((packed));
|
}__attribute__ ((packed));
|
||||||
|
|
||||||
#define DOUT 0xE1
|
#define DOUT 0xE1
|
||||||
|
56
drivers/usb/uhci/usb.lds
Normal file
56
drivers/usb/uhci/usb.lds
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
|
||||||
|
|
||||||
|
OUTPUT_FORMAT(pei-i386)
|
||||||
|
|
||||||
|
ENTRY("_drvEntry")
|
||||||
|
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
. = SIZEOF_HEADERS;
|
||||||
|
. = ALIGN(__section_alignment__);
|
||||||
|
|
||||||
|
.text __image_base__ + ( __section_alignment__ < 0x1000 ? . : __section_alignment__ ) :
|
||||||
|
|
||||||
|
{
|
||||||
|
*(.text) *(.rdata)
|
||||||
|
}
|
||||||
|
|
||||||
|
.data ALIGN(__section_alignment__) :
|
||||||
|
{
|
||||||
|
*(.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
.bss ALIGN(__section_alignment__):
|
||||||
|
{
|
||||||
|
*(.bss)
|
||||||
|
*(COMMON)
|
||||||
|
}
|
||||||
|
|
||||||
|
/DISCARD/ :
|
||||||
|
{
|
||||||
|
*(.debug$S)
|
||||||
|
*(.debug$T)
|
||||||
|
*(.debug$F)
|
||||||
|
*(.drectve)
|
||||||
|
*(.edata)
|
||||||
|
}
|
||||||
|
|
||||||
|
.idata ALIGN(__section_alignment__):
|
||||||
|
{
|
||||||
|
SORT(*)(.idata$2)
|
||||||
|
SORT(*)(.idata$3)
|
||||||
|
/* These zeroes mark the end of the import list. */
|
||||||
|
LONG (0); LONG (0); LONG (0); LONG (0); LONG (0);
|
||||||
|
SORT(*)(.idata$4)
|
||||||
|
SORT(*)(.idata$5)
|
||||||
|
SORT(*)(.idata$6)
|
||||||
|
SORT(*)(.idata$7)
|
||||||
|
}
|
||||||
|
|
||||||
|
.reloc ALIGN(__section_alignment__) :
|
||||||
|
{
|
||||||
|
*(.reloc)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,22 +0,0 @@
|
|||||||
IMP
|
|
||||||
_KernelAlloc core.KernelAlloc,
|
|
||||||
_KernelFree core.KernelFree,
|
|
||||||
_UserAlloc core.UserAlloc,
|
|
||||||
_UserFree core.UserFree,
|
|
||||||
_MapIoMem core.MapIoMem,
|
|
||||||
_GetPgAddr core.GetPgAddr,
|
|
||||||
_PciApi core.PciApi,
|
|
||||||
_PciRead8 core.PciRead8,
|
|
||||||
_PciRead16 core.PciRead16,
|
|
||||||
_PciRead32 core.PciRead32,
|
|
||||||
_PciWrite16 core.PciWrite16,
|
|
||||||
_PciWrite32 core.PciWrite32,
|
|
||||||
_RegService core.RegService,
|
|
||||||
_SysMsgBoardStr core.SysMsgBoardStr,
|
|
||||||
_Delay core.Delay,
|
|
||||||
_SetMouseData core.SetMouseData
|
|
||||||
|
|
||||||
|
|
||||||
FIL usb.obj,
|
|
||||||
vsprintf.obj,
|
|
||||||
icompute.obj
|
|
Loading…
Reference in New Issue
Block a user