5 #include <linux/list.h>
8 #include <linux/module.h>
9 #include <linux/slab.h>
35 static void agp_3_5_dev_list_sort(
struct agp_3_5_dev *
list,
unsigned int ndevs)
49 cur->
maxbw = (nistat >> 16) & 0xff;
53 agp_3_5_dev_list_insert(head, tmp);
63 static int agp_3_5_isochronous_node_enable(
struct agp_bridge_data *bridge,
82 struct isoch_data *master,
target;
83 unsigned int cdev = 0;
84 u32 mnistat, tnistat, tstatus, mcmd;
87 u32 tot_bw = 0, tot_n = 0, tot_rq = 0, y_max, rq_isoch, rq_async;
88 u32 step, rem, rem_isoch, rem_async;
116 agp_3_5_dev_list_sort(dev_list, ndevs);
122 target.maxbw = (tnistat >> 16) & 0xff;
123 target.n = (tnistat >> 8) & 0xff;
124 target.y = (tnistat >> 6) & 0x3;
125 target.l = (tnistat >> 3) & 0x7;
126 target.rq = (tstatus >> 24) & 0xff;
143 master[
cdev].maxbw = (mnistat >> 16) & 0xff;
144 master[
cdev].n = (mnistat >> 8) & 0xff;
145 master[
cdev].y = (mnistat >> 6) & 0x3;
148 tot_bw += master[
cdev].maxbw;
149 y_max =
max(y_max, master[cdev].
y);
155 if (tot_bw > target.maxbw) {
156 dev_err(&td->
dev,
"isochronous bandwidth required "
157 "by AGP 3.0 devices exceeds that which is supported by "
158 "the AGP 3.0 bridge!\n");
172 tnicmd &= ~(0x3 << 6);
173 tnicmd |= target.y << 6;
178 target.n = (tnistat >> 8) & 0xff;
181 for (cdev=0; cdev<ndevs; cdev++) {
182 master[
cdev].y = target.y;
183 master[
cdev].n = master[
cdev].maxbw / (master[
cdev].y + 1);
185 tot_n += master[
cdev].n;
190 if (tot_n > target.n) {
192 "transactions per period required by AGP 3.0 devices "
193 "exceeds that which is supported by the AGP 3.0 "
201 rem = target.n - tot_n;
208 for (cdev=0; cdev<ndevs; cdev++) {
217 if (master[cdev].
y > 0x1)
218 master[
cdev].rq *= (1 << (master[
cdev].y - 1));
220 tot_rq += master[
cdev].rq;
222 master[ndevs-1].n += rem;
226 rq_isoch = (target.y > 0x1) ? target.n * (1 << (target.y - 1)) : target.n;
227 rq_async = target.rq - rq_isoch;
231 if (tot_rq > rq_isoch) {
232 dev_err(&td->
dev,
"number of request queue slots "
233 "required by the isochronous bandwidth requested by "
234 "AGP 3.0 devices exceeds the number provided by the "
235 "AGP 3.0 bridge!\n");
242 step = rq_async / ndevs;
243 rem_async = step + (rq_async % ndevs);
244 rem_isoch = rq_isoch - tot_rq;
248 for (cdev=0; cdev<ndevs; cdev++) {
249 cur = master[
cdev].dev;
254 master[
cdev].rq += (cdev == ndevs - 1)
255 ? (rem_async + rem_isoch) :
step;
260 mnicmd &= ~(0xff << 8);
261 mnicmd &= ~(0x3 << 6);
262 mcmd &= ~(0xff << 24);
264 mnicmd |= master[
cdev].n << 8;
265 mnicmd |= master[
cdev].y << 6;
266 mcmd |= master[
cdev].rq << 24;
286 static void agp_3_5_nonisochronous_node_enable(
struct agp_bridge_data *bridge,
293 unsigned int cdev = 0;
297 trq = (tstatus >> 24) & 0xff;
300 rem = mrq + (trq % ndevs);
306 mcmd &= ~(0xff << 24);
307 mcmd |= ((cdev == ndevs - 1) ? rem : mrq) << 24;
321 u32 tstatus, mstatus, ncapid;
326 unsigned int ndevs = 0;
331 isoch = (tstatus >> 17) & 0x1;
335 arqsz = (tstatus >> 13) & 0x7;
345 head = &dev_list->
list;
346 INIT_LIST_HEAD(head);
354 switch ((dev->
class >>8) & 0xff00) {
362 dev_info(&td->
dev,
"wacky, found unclassified AGP device %s [%04x/%04x]\n",
396 pci_read_config_word(dev,
PCI_STATUS, &mpstat);
403 pci_read_config_dword(dev, mcapndx, &ncapid);
404 if ((ncapid & 0xff) != 2)
405 mcapndx = (ncapid >> 8) & 0xff;
407 while (((ncapid & 0xff) != 2) && (mcapndx != 0));
411 dev_err(&td->
dev,
"woah! Non-AGP device %s on "
412 "secondary bus of AGP 3.5 bridge!\n",
420 dev_err(&td->
dev,
"woah! AGP 2.0 device %s on "
421 "secondary bus of AGP 3.5 bridge operating "
422 "with AGP 3.0 electricals!\n", pci_name(dev));
431 if (((mstatus >> 3) & 0x1) == 0) {
432 dev_err(&td->
dev,
"woah! AGP 3.x device %s not "
433 "operating in AGP 3.x mode on secondary bus "
434 "of AGP 3.5 bridge operating with AGP 3.0 "
435 "electricals!\n", pci_name(dev));
447 ret = agp_3_5_isochronous_node_enable(bridge, dev_list, ndevs);
449 dev_info(&td->
dev,
"something bad happened setting "
450 "up isochronous xfers; falling back to "
451 "non-isochronous xfer mode\n");
456 agp_3_5_nonisochronous_node_enable(bridge, dev_list, ndevs);
460 for (pos=head->
next; pos!=head; ) {