LibXenon
Bare-metal Xbox 360 homebrew library
Loading...
Searching...
No Matches
usb_os.c
Go to the documentation of this file.
1/*
2 Custom IOS Module (EHCI)
3
4 Copyright (C) 2008 neimod.
5 Copyright (C) 2009 kwiirk.
6 Copyright (C) 2009 Hermes.
7 Copyright (C) 2009 Waninkoko.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22*/
23
24#include <stdlib.h>
25#include <string.h>
26#include <time/time.h>
27#include <ppc/cache.h>
28
29#include "ehci_types.h"
30#include "ehci.h"
31#include "usb.h"
32
33/* Heap */
34static u32 heapspace[0x10000] __attribute__((aligned(32)));
35
36/* Variables */
37static u8 *aligned_mem = 0;
38static u8 *aligned_base = 0;
39
40
41void *ehci_maligned(int size, int alignement, int crossing)
42{
43 if (!aligned_mem) {
44 aligned_base = (u8 *)(((u32)heapspace + 4095) & ~4095);
45 aligned_mem = aligned_base;
46 }
47
48 u32 addr = (u32)aligned_mem;
49
50 alignement--;
51
52 /* Calculate aligned address */
53 addr += alignement;
54 addr &= ~alignement;
55
56 if (((addr + size - 1) & ~(crossing - 1)) != (addr & ~(crossing - 1)))
57 addr = (addr + size - 1) & ~(crossing - 1);
58
59 aligned_mem = (void *)(addr + size);
60
61 /* Clear buffer */
62 memset((void *)addr, 0, size);
63
64 return (void *)addr;
65}
66
68{
69 return (dma_addr_t)(((u32)a)&0x7fffffff);
70}
71
72dma_addr_t ehci_dma_map_to(void *buf, size_t len)
73{
74 memdcbst(buf, len);
75 return (dma_addr_t)(((u32)buf)&0x7fffffff);
76}
77
78dma_addr_t ehci_dma_map_from(void *buf, size_t len)
79{
80 memdcbst(buf, len);
81 return (dma_addr_t)(((u32)buf)&0x7fffffff);
82}
83
84dma_addr_t ehci_dma_map_bidir(void *buf, size_t len)
85{
86 memdcbst(buf, len);
87 return (dma_addr_t)(((u32)buf)&0x7fffffff);
88}
89
90void ehci_dma_unmap_to(dma_addr_t buf,size_t len)
91{
92 memdcbf((void *)(buf|0x80000000), len);
93}
94
95void ehci_dma_unmap_from(dma_addr_t buf, size_t len)
96{
97 memdcbf((void *)(buf|0x80000000), len);
98}
99
100void ehci_dma_unmap_bidir(dma_addr_t buf, size_t len)
101{
102 memdcbf((void *)(buf|0x80000000), len);
103}
104
105void ehci_usleep(int time)
106{
107 udelay(time);
108}
109
110void ehci_msleep(int time)
111{
112 mdelay(time);
113}
114
115
116void *USB_Alloc(int size)
117{
118 return malloc(size);
119}
120
121void USB_Free(void *ptr)
122{
123 return free(ptr);
124}
void memdcbf(void *addr, int len)
void memdcbst(void *addr, int len)
#define dma_addr_t
Definition: ehci_types.h:12
u32 ptr
Definition: iso9660.c:536
u32 size
Definition: iso9660.c:537
unsigned int __mf_uintptr_t __attribute__((__mode__(__pointer__)))
Definition: mf-runtime.h:34
void mdelay(int u)
Definition: time.c:17
void udelay(int u)
Definition: time.c:12
dma_addr_t ehci_dma_map_bidir(void *buf, size_t len)
Definition: usb_os.c:84
void USB_Free(void *ptr)
Definition: usb_os.c:121
dma_addr_t ehci_dma_map_to(void *buf, size_t len)
Definition: usb_os.c:72
void ehci_dma_unmap_bidir(dma_addr_t buf, size_t len)
Definition: usb_os.c:100
void * USB_Alloc(int size)
Definition: usb_os.c:116
dma_addr_t ehci_dma_map_from(void *buf, size_t len)
Definition: usb_os.c:78
void * ehci_maligned(int size, int alignement, int crossing)
Definition: usb_os.c:41
void ehci_msleep(int time)
Definition: usb_os.c:110
void ehci_usleep(int time)
Definition: usb_os.c:105
void ehci_dma_unmap_from(dma_addr_t buf, size_t len)
Definition: usb_os.c:95
dma_addr_t ehci_virt_to_dma(void *a)
Definition: usb_os.c:67
void ehci_dma_unmap_to(dma_addr_t buf, size_t len)
Definition: usb_os.c:90
uint8_t u8
8bit unsigned integer
Definition: xetypes.h:12
uint32_t u32
32bit unsigned integer
Definition: xetypes.h:14