cardbus.c (109623) | cardbus.c (109925) |
---|---|
1/* 2 * Copyright (c) 2000,2001 Jonathan Chen. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * 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 26 * SUCH DAMAGE. 27 * | 1/* 2 * Copyright (c) 2000,2001 Jonathan Chen. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * 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 26 * SUCH DAMAGE. 27 * |
28 * $FreeBSD: head/sys/dev/cardbus/cardbus.c 109623 2003-01-21 08:56:16Z alfred $ | 28 * $FreeBSD: head/sys/dev/cardbus/cardbus.c 109925 2003-01-27 05:47:01Z imp $ |
29 */ 30 31/* 32 * Cardbus Bus Driver 33 * 34 * much of the bus code was stolen directly from sys/pci/pci.c 35 * (Copyright (c) 1997, Stefan Esser <se@freebsd.org>) 36 * --- 47 unchanged lines hidden (view full) --- 84 u_int flags); 85static int cardbus_attach(device_t cbdev); 86static int cardbus_attach_card(device_t cbdev); 87static int cardbus_child_location_str(device_t cbdev, device_t child, 88 char *, size_t len); 89static int cardbus_child_pnpinfo_str(device_t cbdev, device_t child, 90 char *, size_t len); 91static __inline void cardbus_clear_command_bit(device_t cbdev, device_t child, | 29 */ 30 31/* 32 * Cardbus Bus Driver 33 * 34 * much of the bus code was stolen directly from sys/pci/pci.c 35 * (Copyright (c) 1997, Stefan Esser <se@freebsd.org>) 36 * --- 47 unchanged lines hidden (view full) --- 84 u_int flags); 85static int cardbus_attach(device_t cbdev); 86static int cardbus_attach_card(device_t cbdev); 87static int cardbus_child_location_str(device_t cbdev, device_t child, 88 char *, size_t len); 89static int cardbus_child_pnpinfo_str(device_t cbdev, device_t child, 90 char *, size_t len); 91static __inline void cardbus_clear_command_bit(device_t cbdev, device_t child, |
92 u_int16_t bit); | 92 uint16_t bit); |
93static void cardbus_delete_resource(device_t cbdev, device_t child, 94 int type, int rid); 95static void cardbus_delete_resource_method(device_t cbdev, device_t child, 96 int type, int rid); 97static int cardbus_detach(device_t cbdev); 98static int cardbus_detach_card(device_t cbdev); 99static void cardbus_device_setup_regs(device_t brdev, int b, int s, int f, 100 pcicfgregs *cfg); --- 16 unchanged lines hidden (view full) --- 117static int cardbus_print_resources(struct resource_list *rl, 118 const char *name, int type, const char *format); 119static void cardbus_print_verbose(struct cardbus_devinfo *dinfo); 120static int cardbus_probe(device_t cbdev); 121static void cardbus_probe_nomatch(device_t cbdev, device_t child); 122static struct cardbus_devinfo *cardbus_read_device(device_t brdev, int b, 123 int s, int f); 124static void cardbus_read_extcap(device_t cbdev, pcicfgregs *cfg); | 93static void cardbus_delete_resource(device_t cbdev, device_t child, 94 int type, int rid); 95static void cardbus_delete_resource_method(device_t cbdev, device_t child, 96 int type, int rid); 97static int cardbus_detach(device_t cbdev); 98static int cardbus_detach_card(device_t cbdev); 99static void cardbus_device_setup_regs(device_t brdev, int b, int s, int f, 100 pcicfgregs *cfg); --- 16 unchanged lines hidden (view full) --- 117static int cardbus_print_resources(struct resource_list *rl, 118 const char *name, int type, const char *format); 119static void cardbus_print_verbose(struct cardbus_devinfo *dinfo); 120static int cardbus_probe(device_t cbdev); 121static void cardbus_probe_nomatch(device_t cbdev, device_t child); 122static struct cardbus_devinfo *cardbus_read_device(device_t brdev, int b, 123 int s, int f); 124static void cardbus_read_extcap(device_t cbdev, pcicfgregs *cfg); |
125static u_int32_t cardbus_read_config_method(device_t cbdev, | 125static uint32_t cardbus_read_config_method(device_t cbdev, |
126 device_t child, int reg, int width); 127static int cardbus_read_ivar(device_t cbdev, device_t child, int which, 128 u_long *result); 129static void cardbus_release_all_resources(device_t cbdev, 130 struct cardbus_devinfo *dinfo); 131static int cardbus_release_resource(device_t cbdev, device_t child, 132 int type, int rid, struct resource *r); 133static __inline void cardbus_set_command_bit(device_t cbdev, device_t child, | 126 device_t child, int reg, int width); 127static int cardbus_read_ivar(device_t cbdev, device_t child, int which, 128 u_long *result); 129static void cardbus_release_all_resources(device_t cbdev, 130 struct cardbus_devinfo *dinfo); 131static int cardbus_release_resource(device_t cbdev, device_t child, 132 int type, int rid, struct resource *r); 133static __inline void cardbus_set_command_bit(device_t cbdev, device_t child, |
134 u_int16_t bit); | 134 uint16_t bit); |
135static int cardbus_set_powerstate_method(device_t cbdev, device_t child, 136 int state); 137static int cardbus_set_resource(device_t cbdev, device_t child, int type, 138 int rid, u_long start, u_long count, struct resource *res); 139static int cardbus_set_resource_method(device_t cbdev, device_t child, 140 int type, int rid, u_long start, u_long count); 141static int cardbus_setup_intr(device_t cbdev, device_t child, 142 struct resource *irq, int flags, driver_intr_t *intr, 143 void *arg, void **cookiep); 144static int cardbus_teardown_intr(device_t cbdev, device_t child, 145 struct resource *irq, void *cookie); 146static void cardbus_write_config_method(device_t cbdev, device_t child, | 135static int cardbus_set_powerstate_method(device_t cbdev, device_t child, 136 int state); 137static int cardbus_set_resource(device_t cbdev, device_t child, int type, 138 int rid, u_long start, u_long count, struct resource *res); 139static int cardbus_set_resource_method(device_t cbdev, device_t child, 140 int type, int rid, u_long start, u_long count); 141static int cardbus_setup_intr(device_t cbdev, device_t child, 142 struct resource *irq, int flags, driver_intr_t *intr, 143 void *arg, void **cookiep); 144static int cardbus_teardown_intr(device_t cbdev, device_t child, 145 struct resource *irq, void *cookie); 146static void cardbus_write_config_method(device_t cbdev, device_t child, |
147 int reg, u_int32_t val, int width); | 147 int reg, uint32_t val, int width); |
148static int cardbus_write_ivar(device_t cbdev, device_t child, int which, 149 uintptr_t value); 150 151/************************************************************************/ 152/* Probe/Attach */ 153/************************************************************************/ 154 155static int --- 791 unchanged lines hidden (view full) --- 947 948 switch (which) { 949 case PCI_IVAR_ETHADDR: 950 /* 951 * The generic accessor doesn't deal with failure, so 952 * we set the return value, then return an error. 953 */ 954 if ((dinfo->fepresent & (1 << TPL_FUNCE_LAN_NID)) == 0) { | 148static int cardbus_write_ivar(device_t cbdev, device_t child, int which, 149 uintptr_t value); 150 151/************************************************************************/ 152/* Probe/Attach */ 153/************************************************************************/ 154 155static int --- 791 unchanged lines hidden (view full) --- 947 948 switch (which) { 949 case PCI_IVAR_ETHADDR: 950 /* 951 * The generic accessor doesn't deal with failure, so 952 * we set the return value, then return an error. 953 */ 954 if ((dinfo->fepresent & (1 << TPL_FUNCE_LAN_NID)) == 0) { |
955 *((u_int8_t **) result) = NULL; | 955 *((uint8_t **) result) = NULL; |
956 return (EINVAL); 957 } | 956 return (EINVAL); 957 } |
958 *((u_int8_t **) result) = dinfo->funce.lan.nid; | 958 *((uint8_t **) result) = dinfo->funce.lan.nid; |
959 break; 960 case PCI_IVAR_SUBVENDOR: 961 *result = cfg->subvendor; 962 break; 963 case PCI_IVAR_SUBDEVICE: 964 *result = cfg->subdevice; 965 break; 966 case PCI_IVAR_VENDOR: --- 77 unchanged lines hidden (view full) --- 1044/* 1045 * PCI power manangement 1046 */ 1047static int 1048cardbus_set_powerstate_method(device_t cbdev, device_t child, int state) 1049{ 1050 struct cardbus_devinfo *dinfo = device_get_ivars(child); 1051 pcicfgregs *cfg = &dinfo->pci.cfg; | 959 break; 960 case PCI_IVAR_SUBVENDOR: 961 *result = cfg->subvendor; 962 break; 963 case PCI_IVAR_SUBDEVICE: 964 *result = cfg->subdevice; 965 break; 966 case PCI_IVAR_VENDOR: --- 77 unchanged lines hidden (view full) --- 1044/* 1045 * PCI power manangement 1046 */ 1047static int 1048cardbus_set_powerstate_method(device_t cbdev, device_t child, int state) 1049{ 1050 struct cardbus_devinfo *dinfo = device_get_ivars(child); 1051 pcicfgregs *cfg = &dinfo->pci.cfg; |
1052 u_int16_t status; | 1052 uint16_t status; |
1053 int result; 1054 1055 if (cfg->pp_cap != 0) { 1056 status = PCI_READ_CONFIG(cbdev, child, cfg->pp_status, 2) 1057 & ~PCIM_PSTAT_DMASK; 1058 result = 0; 1059 switch (state) { 1060 case PCI_POWERSTATE_D0: --- 28 unchanged lines hidden (view full) --- 1089 return (result); 1090} 1091 1092static int 1093cardbus_get_powerstate_method(device_t cbdev, device_t child) 1094{ 1095 struct cardbus_devinfo *dinfo = device_get_ivars(child); 1096 pcicfgregs *cfg = &dinfo->pci.cfg; | 1053 int result; 1054 1055 if (cfg->pp_cap != 0) { 1056 status = PCI_READ_CONFIG(cbdev, child, cfg->pp_status, 2) 1057 & ~PCIM_PSTAT_DMASK; 1058 result = 0; 1059 switch (state) { 1060 case PCI_POWERSTATE_D0: --- 28 unchanged lines hidden (view full) --- 1089 return (result); 1090} 1091 1092static int 1093cardbus_get_powerstate_method(device_t cbdev, device_t child) 1094{ 1095 struct cardbus_devinfo *dinfo = device_get_ivars(child); 1096 pcicfgregs *cfg = &dinfo->pci.cfg; |
1097 u_int16_t status; | 1097 uint16_t status; |
1098 int result; 1099 1100 if (cfg->pp_cap != 0) { 1101 status = PCI_READ_CONFIG(cbdev, child, cfg->pp_status, 2); 1102 switch (status & PCIM_PSTAT_DMASK) { 1103 case PCIM_PSTAT_D0: 1104 result = PCI_POWERSTATE_D0; 1105 break; --- 12 unchanged lines hidden (view full) --- 1118 } 1119 } else { 1120 /* No support, device is always at D0 */ 1121 result = PCI_POWERSTATE_D0; 1122 } 1123 return (result); 1124} 1125 | 1098 int result; 1099 1100 if (cfg->pp_cap != 0) { 1101 status = PCI_READ_CONFIG(cbdev, child, cfg->pp_status, 2); 1102 switch (status & PCIM_PSTAT_DMASK) { 1103 case PCIM_PSTAT_D0: 1104 result = PCI_POWERSTATE_D0; 1105 break; --- 12 unchanged lines hidden (view full) --- 1118 } 1119 } else { 1120 /* No support, device is always at D0 */ 1121 result = PCI_POWERSTATE_D0; 1122 } 1123 return (result); 1124} 1125 |
1126static u_int32_t | 1126static uint32_t |
1127cardbus_read_config_method(device_t cbdev, device_t child, int reg, int width) 1128{ 1129 struct cardbus_devinfo *dinfo = device_get_ivars(child); 1130 pcicfgregs *cfg = &dinfo->pci.cfg; 1131 1132 return PCIB_READ_CONFIG(device_get_parent(cbdev), 1133 cfg->bus, cfg->slot, cfg->func, reg, width); 1134} 1135 1136static void 1137cardbus_write_config_method(device_t cbdev, device_t child, int reg, | 1127cardbus_read_config_method(device_t cbdev, device_t child, int reg, int width) 1128{ 1129 struct cardbus_devinfo *dinfo = device_get_ivars(child); 1130 pcicfgregs *cfg = &dinfo->pci.cfg; 1131 1132 return PCIB_READ_CONFIG(device_get_parent(cbdev), 1133 cfg->bus, cfg->slot, cfg->func, reg, width); 1134} 1135 1136static void 1137cardbus_write_config_method(device_t cbdev, device_t child, int reg, |
1138 u_int32_t val, int width) | 1138 uint32_t val, int width) |
1139{ 1140 struct cardbus_devinfo *dinfo = device_get_ivars(child); 1141 pcicfgregs *cfg = &dinfo->pci.cfg; 1142 1143 PCIB_WRITE_CONFIG(device_get_parent(cbdev), 1144 cfg->bus, cfg->slot, cfg->func, reg, val, width); 1145} 1146 1147static __inline void | 1139{ 1140 struct cardbus_devinfo *dinfo = device_get_ivars(child); 1141 pcicfgregs *cfg = &dinfo->pci.cfg; 1142 1143 PCIB_WRITE_CONFIG(device_get_parent(cbdev), 1144 cfg->bus, cfg->slot, cfg->func, reg, val, width); 1145} 1146 1147static __inline void |
1148cardbus_set_command_bit(device_t cbdev, device_t child, u_int16_t bit) | 1148cardbus_set_command_bit(device_t cbdev, device_t child, uint16_t bit) |
1149{ | 1149{ |
1150 u_int16_t command; | 1150 uint16_t command; |
1151 1152 command = PCI_READ_CONFIG(cbdev, child, PCIR_COMMAND, 2); 1153 command |= bit; 1154 PCI_WRITE_CONFIG(cbdev, child, PCIR_COMMAND, command, 2); 1155} 1156 1157static __inline void | 1151 1152 command = PCI_READ_CONFIG(cbdev, child, PCIR_COMMAND, 2); 1153 command |= bit; 1154 PCI_WRITE_CONFIG(cbdev, child, PCIR_COMMAND, command, 2); 1155} 1156 1157static __inline void |
1158cardbus_clear_command_bit(device_t cbdev, device_t child, u_int16_t bit) | 1158cardbus_clear_command_bit(device_t cbdev, device_t child, uint16_t bit) |
1159{ | 1159{ |
1160 u_int16_t command; | 1160 uint16_t command; |
1161 1162 command = PCI_READ_CONFIG(cbdev, child, PCIR_COMMAND, 2); 1163 command &= ~bit; 1164 PCI_WRITE_CONFIG(cbdev, child, PCIR_COMMAND, command, 2); 1165} 1166 1167static void 1168cardbus_enable_busmaster_method(device_t cbdev, device_t child) --- 97 unchanged lines hidden --- | 1161 1162 command = PCI_READ_CONFIG(cbdev, child, PCIR_COMMAND, 2); 1163 command &= ~bit; 1164 PCI_WRITE_CONFIG(cbdev, child, PCIR_COMMAND, command, 2); 1165} 1166 1167static void 1168cardbus_enable_busmaster_method(device_t cbdev, device_t child) --- 97 unchanged lines hidden --- |