Tue Mar 3 06:36:53 2015 UTC ()
Improve EHCI_PAGE macros and usage.

No functional change.


(skrll)
diff -r1.234.2.36 -r1.234.2.37 src/sys/dev/usb/ehci.c
diff -r1.34.14.4 -r1.34.14.5 src/sys/dev/usb/ehcireg.h

cvs diff -r1.234.2.36 -r1.234.2.37 src/sys/dev/usb/ehci.c (expand / switch to unified diff)

--- src/sys/dev/usb/ehci.c 2015/03/02 22:16:38 1.234.2.36
+++ src/sys/dev/usb/ehci.c 2015/03/03 06:36:53 1.234.2.37
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ehci.c,v 1.234.2.36 2015/03/02 22:16:38 skrll Exp $ */ 1/* $NetBSD: ehci.c,v 1.234.2.37 2015/03/03 06:36:53 skrll Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2004-2012 The NetBSD Foundation, Inc. 4 * Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net), Charles M. Hannum, 8 * by Lennart Augustsson (lennart@augustsson.net), Charles M. Hannum,
9 * Jeremy Morse (jeremy.morse@gmail.com), Jared D. McNeill 9 * Jeremy Morse (jeremy.morse@gmail.com), Jared D. McNeill
10 * (jmcneill@invisible.ca) and Matthew R. Green (mrg@eterna.com.au). 10 * (jmcneill@invisible.ca) and Matthew R. Green (mrg@eterna.com.au).
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -43,27 +43,27 @@ @@ -43,27 +43,27 @@
43 43
44/* 44/*
45 * TODO: 45 * TODO:
46 * 1) hold off explorations by companion controllers until ehci has started. 46 * 1) hold off explorations by companion controllers until ehci has started.
47 * 47 *
48 * 2) The hub driver needs to handle and schedule the transaction translator, 48 * 2) The hub driver needs to handle and schedule the transaction translator,
49 * to assign place in frame where different devices get to go. See chapter 49 * to assign place in frame where different devices get to go. See chapter
50 * on hubs in USB 2.0 for details. 50 * on hubs in USB 2.0 for details.
51 * 51 *
52 * 3) Command failures are not recovered correctly. 52 * 3) Command failures are not recovered correctly.
53 */ 53 */
54 54
55#include <sys/cdefs.h> 55#include <sys/cdefs.h>
56__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.234.2.36 2015/03/02 22:16:38 skrll Exp $"); 56__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.234.2.37 2015/03/03 06:36:53 skrll Exp $");
57 57
58#include "ohci.h" 58#include "ohci.h"
59#include "uhci.h" 59#include "uhci.h"
60#include "opt_usb.h" 60#include "opt_usb.h"
61 61
62#include <sys/param.h> 62#include <sys/param.h>
63 63
64#include <sys/bus.h> 64#include <sys/bus.h>
65#include <sys/cpu.h> 65#include <sys/cpu.h>
66#include <sys/device.h> 66#include <sys/device.h>
67#include <sys/kernel.h> 67#include <sys/kernel.h>
68#include <sys/kmem.h> 68#include <sys/kmem.h>
69#include <sys/mutex.h> 69#include <sys/mutex.h>
@@ -2825,32 +2825,32 @@ ehci_alloc_sqtd_chain(struct ehci_pipe * @@ -2825,32 +2825,32 @@ ehci_alloc_sqtd_chain(struct ehci_pipe *
2825 if (curoffs + curlen != len || 2825 if (curoffs + curlen != len ||
2826 ((curlen % mps) == 0 && !rd && curlen != 0 && 2826 ((curlen % mps) == 0 && !rd && curlen != 0 &&
2827 (flags & USBD_FORCE_SHORT_XFER))) { 2827 (flags & USBD_FORCE_SHORT_XFER))) {
2828 next = ehci_alloc_sqtd(sc); 2828 next = ehci_alloc_sqtd(sc);
2829 if (next == NULL) 2829 if (next == NULL)
2830 goto nomem; 2830 goto nomem;
2831 nextphys = htole32(next->physaddr); 2831 nextphys = htole32(next->physaddr);
2832 } else { 2832 } else {
2833 next = NULL; 2833 next = NULL;
2834 nextphys = EHCI_NULL; 2834 nextphys = EHCI_NULL;
2835 } 2835 }
2836 2836
2837 /* Find number of pages we'll be using, insert dma addresses */ 2837 /* Find number of pages we'll be using, insert dma addresses */
2838 pages = EHCI_PAGE(curlen + EHCI_PAGE_SIZE - 1) >> 12; 2838 pages = EHCI_NPAGES(curlen);
2839 KASSERT(pages <= EHCI_QTD_NBUFFERS); 2839 KASSERT(pages <= EHCI_QTD_NBUFFERS);
2840 pageoffs = EHCI_PAGE(curoffs); 2840 pageoffs = EHCI_PAGE(curoffs);
2841 for (i = 0; i < pages; i++) { 2841 for (i = 0; i < pages; i++) {
2842 a = DMAADDR(dma, pageoffs + i * EHCI_PAGE_SIZE); 2842 a = DMAADDR(dma, pageoffs + i * EHCI_PAGE_SIZE);
2843 cur->qtd.qtd_buffer[i] = htole32(a & 0xFFFFF000); 2843 cur->qtd.qtd_buffer[i] = htole32(EHCI_PAGE(a));
2844 /* Cast up to avoid compiler warnings */ 2844 /* Cast up to avoid compiler warnings */
2845 cur->qtd.qtd_buffer_hi[i] = htole32((uint64_t)a >> 32); 2845 cur->qtd.qtd_buffer_hi[i] = htole32((uint64_t)a >> 32);
2846 } 2846 }
2847 2847
2848 /* First buffer pointer requires a page offset to start at */ 2848 /* First buffer pointer requires a page offset to start at */
2849 va = (vaddr_t)KERNADDR(dma, curoffs); 2849 va = (vaddr_t)KERNADDR(dma, curoffs);
2850 cur->qtd.qtd_buffer[0] |= htole32(EHCI_PAGE_OFFSET(va)); 2850 cur->qtd.qtd_buffer[0] |= htole32(EHCI_PAGE_OFFSET(va));
2851 2851
2852 cur->nextqtd = next; 2852 cur->nextqtd = next;
2853 cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys; 2853 cur->qtd.qtd_next = cur->qtd.qtd_altnext = nextphys;
2854 cur->qtd.qtd_status = 2854 cur->qtd.qtd_status =
2855 htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen)); 2855 htole32(qtdstatus | EHCI_QTD_SET_BYTES(curlen));
2856 cur->xfer = xfer; 2856 cur->xfer = xfer;

cvs diff -r1.34.14.4 -r1.34.14.5 src/sys/dev/usb/ehcireg.h (expand / switch to unified diff)

--- src/sys/dev/usb/ehcireg.h 2015/02/01 08:45:04 1.34.14.4
+++ src/sys/dev/usb/ehcireg.h 2015/03/03 06:36:53 1.34.14.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ehcireg.h,v 1.34.14.4 2015/02/01 08:45:04 skrll Exp $ */ 1/* $NetBSD: ehcireg.h,v 1.34.14.5 2015/03/03 06:36:53 skrll Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc. 4 * Copyright (c) 2001, 2004 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net). 8 * by Lennart Augustsson (lennart@augustsson.net).
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -178,30 +178,32 @@ @@ -178,30 +178,32 @@
178#define EHCI_USBMODE 0xa8 /* USB Device mode */ 178#define EHCI_USBMODE 0xa8 /* USB Device mode */
179#define EHCI_USBMODE_SDIS __BIT(4) /* Stream disable mode 1=act */ 179#define EHCI_USBMODE_SDIS __BIT(4) /* Stream disable mode 1=act */
180#define EHCI_USBMODE_SLOM __BIT(3) /* setup lockouts on */ 180#define EHCI_USBMODE_SLOM __BIT(3) /* setup lockouts on */
181#define EHCI_USBMODE_ES __BIT(2) /* Endian Select ES=1 */ 181#define EHCI_USBMODE_ES __BIT(2) /* Endian Select ES=1 */
182#define EHCI_USBMODE_CM __BITS(0,1) /* Controller Mode */ 182#define EHCI_USBMODE_CM __BITS(0,1) /* Controller Mode */
183#define EHCI_USBMODE_CM_IDLE 0x00 /* Idle (combo host/device) */ 183#define EHCI_USBMODE_CM_IDLE 0x00 /* Idle (combo host/device) */
184#define EHCI_USBMODE_CM_DEV 0x02 /* Device Controller */ 184#define EHCI_USBMODE_CM_DEV 0x02 /* Device Controller */
185#define EHCI_USBMODE_CM_HOST 0x03 /* Host Controller */ 185#define EHCI_USBMODE_CM_HOST 0x03 /* Host Controller */
186 186
187#define EHCI_FLALIGN_ALIGN 0x1000 187#define EHCI_FLALIGN_ALIGN 0x1000
188#define EHCI_MAX_PORTS 16 /* only 4 bits available in EHCI_HCS_N_PORTS */ 188#define EHCI_MAX_PORTS 16 /* only 4 bits available in EHCI_HCS_N_PORTS */
189 189
190/* No data structure may cross a page boundary. */ 190/* No data structure may cross a page boundary. */
191#define EHCI_PAGE_SIZE 0x1000 191#define EHCI_PAGE_SHIFT 12
192#define EHCI_PAGE_MASK (EHCI_PAGE_SIZE - 1) 192#define EHCI_PAGE_SIZE (1 << EHCI_PAGE_SHIFT)
193#define EHCI_PAGE(x) ((x) & ~EHCI_PAGE_MASK) 193#define EHCI_PAGE_MASK (EHCI_PAGE_SIZE - 1)
194#define EHCI_PAGE_OFFSET(x) ((x) & EHCI_PAGE_MASK) 194#define EHCI_PAGE(x) ((x) & ~EHCI_PAGE_MASK)
 195#define EHCI_PAGE_OFFSET(x) ((x) & EHCI_PAGE_MASK)
 196#define EHCI_NPAGES(x) (((x) + EHCI_PAGE_MASK) >> EHCI_PAGE_SHIFT)
195 197
196typedef uint32_t ehci_link_t; 198typedef uint32_t ehci_link_t;
197#define EHCI_LINK_TERMINATE 0x00000001 199#define EHCI_LINK_TERMINATE 0x00000001
198#define EHCI_LINK_TYPE(x) ((x) & 0x00000006) 200#define EHCI_LINK_TYPE(x) ((x) & 0x00000006)
199#define EHCI_LINK_ITD 0x0 201#define EHCI_LINK_ITD 0x0
200#define EHCI_LINK_QH 0x2 202#define EHCI_LINK_QH 0x2
201#define EHCI_LINK_SITD 0x4 203#define EHCI_LINK_SITD 0x4
202#define EHCI_LINK_FSTN 0x6 204#define EHCI_LINK_FSTN 0x6
203#define EHCI_LINK_ADDR(x) ((x) &~ 0x1f) 205#define EHCI_LINK_ADDR(x) ((x) &~ 0x1f)
204 206
205typedef uint32_t ehci_physaddr_t; 207typedef uint32_t ehci_physaddr_t;
206 208
207typedef uint32_t ehci_isoc_trans_t; 209typedef uint32_t ehci_isoc_trans_t;