2 * HighPoint RAID Driver for FreeBSD
4 * Copyright (C) 2005-2011 HighPoint Technologies, Inc. All Rights Reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <dev/hpt27xx/hpt27xx_config.h>
33 #include <dev/hpt27xx/os_bsd.h>
35 BUS_ADDRESS get_dmapool_phy_addr(void *osext, void * dmapool_virt_addr);
38 HPT_U8 os_inb (void *port) { return inb((unsigned)(HPT_UPTR)port); }
39 HPT_U16 os_inw (void *port) { return inw((unsigned)(HPT_UPTR)port); }
40 HPT_U32 os_inl (void *port) { return inl((unsigned)(HPT_UPTR)port); }
42 void os_outb (void *port, HPT_U8 value) { outb((unsigned)(HPT_UPTR)port, (value)); }
43 void os_outw (void *port, HPT_U16 value) { outw((unsigned)(HPT_UPTR)port, (value)); }
44 void os_outl (void *port, HPT_U32 value) { outl((unsigned)(HPT_UPTR)port, (value)); }
46 void os_insw (void *port, HPT_U16 *buffer, HPT_U32 count)
47 { insw((unsigned)(HPT_UPTR)port, (void *)buffer, count); }
49 void os_outsw(void *port, HPT_U16 *buffer, HPT_U32 count)
50 { outsw((unsigned)(HPT_UPTR)port, (void *)buffer, count); }
52 HPT_U32 __dummy_reg = 0;
54 /* PCI configuration space */
55 HPT_U8 os_pci_readb (void *osext, HPT_U8 offset)
57 return pci_read_config(((PHBA)osext)->pcidev, offset, 1);
60 HPT_U16 os_pci_readw (void *osext, HPT_U8 offset)
62 return pci_read_config(((PHBA)osext)->pcidev, offset, 2);
65 HPT_U32 os_pci_readl (void *osext, HPT_U8 offset)
67 return pci_read_config(((PHBA)osext)->pcidev, offset, 4);
70 void os_pci_writeb (void *osext, HPT_U8 offset, HPT_U8 value)
72 pci_write_config(((PHBA)osext)->pcidev, offset, value, 1);
75 void os_pci_writew (void *osext, HPT_U8 offset, HPT_U16 value)
77 pci_write_config(((PHBA)osext)->pcidev, offset, value, 2);
80 void os_pci_writel (void *osext, HPT_U8 offset, HPT_U32 value)
82 pci_write_config(((PHBA)osext)->pcidev, offset, value, 4);
85 BUS_ADDRESS get_dmapool_phy_addr(void *osext, void * dmapool_virt_addr)
87 return (BUS_ADDRESS)vtophys(dmapool_virt_addr);
90 /* PCI space access */
91 HPT_U8 pcicfg_read_byte (HPT_U8 bus, HPT_U8 dev, HPT_U8 func, HPT_U8 reg)
93 return (HPT_U8)pci_cfgregread(bus, dev, func, reg, 1);
95 HPT_U32 pcicfg_read_dword(HPT_U8 bus, HPT_U8 dev, HPT_U8 func, HPT_U8 reg)
97 return (HPT_U32)pci_cfgregread(bus, dev, func, reg, 4);
99 void pcicfg_write_byte (HPT_U8 bus, HPT_U8 dev, HPT_U8 func, HPT_U8 reg, HPT_U8 v)
101 pci_cfgregwrite(bus, dev, func, reg, v, 1);
103 void pcicfg_write_dword(HPT_U8 bus, HPT_U8 dev, HPT_U8 func, HPT_U8 reg, HPT_U32 v)
105 pci_cfgregwrite(bus, dev, func, reg, v, 4);
106 }/* PCI space access */
108 void *os_map_pci_bar(
115 PHBA hba = (PHBA)osext;
118 hba->pcibar[index].rid = 0x10 + index * 4;
119 base = pci_read_config(hba->pcidev, hba->pcibar[index].rid, 4);
122 hba->pcibar[index].type = SYS_RES_IOPORT;
123 hba->pcibar[index].res = bus_alloc_resource_any(hba->pcidev,
124 hba->pcibar[index].type, &hba->pcibar[index].rid, RF_ACTIVE);
125 hba->pcibar[index].base = (void *)(unsigned long)(base & ~0x1);
127 hba->pcibar[index].type = SYS_RES_MEMORY;
128 hba->pcibar[index].res = bus_alloc_resource_any(hba->pcidev,
129 hba->pcibar[index].type, &hba->pcibar[index].rid, RF_ACTIVE);
130 hba->pcibar[index].base = (char *)rman_get_virtual(hba->pcibar[index].res) + offset;
133 return hba->pcibar[index].base;
136 void os_unmap_pci_bar(void *osext, void *base)
138 PHBA hba = (PHBA)osext;
141 for (index=0; index<6; index++) {
142 if (hba->pcibar[index].base==base) {
143 bus_release_resource(hba->pcidev, hba->pcibar[index].type,
144 hba->pcibar[index].rid, hba->pcibar[index].res);
145 hba->pcibar[index].base = 0;
151 void freelist_reserve(struct freelist *list, void *osext, HPT_UINT size, HPT_UINT count)
153 PVBUS_EXT vbus_ext = osext;
155 if (vbus_ext->ext_type!=EXT_TYPE_VBUS)
156 vbus_ext = ((PHBA)osext)->vbus_ext;
158 list->next = vbus_ext->freelist_head;
159 vbus_ext->freelist_head = list;
164 list->reserved_count =
169 void *freelist_get(struct freelist *list)
173 HPT_ASSERT(list->head);
175 list->head = *(void **)result;
182 void freelist_put(struct freelist * list, void *p)
184 HPT_ASSERT(list->dma==0);
186 *(void **)p = list->head;
190 void freelist_reserve_dma(struct freelist *list, void *osext, HPT_UINT size, HPT_UINT alignment, HPT_UINT count)
192 PVBUS_EXT vbus_ext = osext;
194 if (vbus_ext->ext_type!=EXT_TYPE_VBUS)
195 vbus_ext = ((PHBA)osext)->vbus_ext;
197 list->next = vbus_ext->freelist_dma_head;
198 vbus_ext->freelist_dma_head = list;
200 list->alignment = alignment;
204 list->reserved_count =
209 void *freelist_get_dma(struct freelist *list, BUS_ADDRESS *busaddr)
212 HPT_ASSERT(list->dma);
213 result = freelist_get(list);
215 *busaddr = *(BUS_ADDRESS *)((void **)result+1);
219 void freelist_put_dma(struct freelist *list, void *p, BUS_ADDRESS busaddr)
221 HPT_ASSERT(list->dma);
223 *(void **)p = list->head;
224 *(BUS_ADDRESS *)((void **)p+1) = busaddr;
228 HPT_U32 os_get_stamp(void)
231 do { stamp = random(); } while (stamp==0);
235 void os_stallexec(HPT_U32 microseconds)
240 static void os_timer_for_ldm(void *arg)
242 PVBUS_EXT vbus_ext = (PVBUS_EXT)arg;
243 ldm_on_timer((PVBUS)vbus_ext->vbus);
246 void os_request_timer(void * osext, HPT_U32 interval)
248 PVBUS_EXT vbus_ext = osext;
250 HPT_ASSERT(vbus_ext->ext_type==EXT_TYPE_VBUS);
252 #if (__FreeBSD_version >= 1000510)
253 callout_reset_sbt(&vbus_ext->timer, SBT_1US * interval, 0,
254 os_timer_for_ldm, vbus_ext, 0);
256 untimeout(os_timer_for_ldm, vbus_ext, vbus_ext->timer);
257 vbus_ext->timer = timeout(os_timer_for_ldm, vbus_ext, interval * hz / 1000000);
261 HPT_TIME os_query_time(void)
263 return ticks * (1000000 / hz);
266 void os_schedule_task(void *osext, OSM_TASK *task)
268 PVBUS_EXT vbus_ext = osext;
270 HPT_ASSERT(task->next==0);
272 if (vbus_ext->tasks==0)
273 vbus_ext->tasks = task;
275 OSM_TASK *t = vbus_ext->tasks;
276 while (t->next) t = t->next;
280 if (vbus_ext->worker.ta_context)
281 TASK_ENQUEUE(&vbus_ext->worker);
284 int os_revalidate_device(void *osext, int id)
290 int os_query_remove_device(void *osext, int id)
295 HPT_U8 os_get_vbus_seq(void *osext)
297 return ((PVBUS_EXT)osext)->sim->path_id;
300 int os_printk(char *fmt, ...)
303 static char buf[512];
306 vsnprintf(buf, sizeof(buf), fmt, args);
308 return printf("%s: %s\n", driver_name, buf);
312 void os_check_stack(const char *location, int size){}
314 void __os_dbgbreak(const char *file, int line)
316 printf("*** break at %s:%d ***", file, line);
320 int hpt_dbg_level = 1;