add ``check free resource rage code''

for PC-Card which has no address in cis.
This commit is contained in:
MIHIRA Sanpei Yoshiro 2000-09-21 13:13:00 +00:00
parent fe44e2ea94
commit 45d54d7ee2
3 changed files with 33 additions and 11 deletions

View File

@ -491,7 +491,7 @@ assign_driver(struct card *cp)
char name[128];
int i, fd;
sprintf(name, CARD_DEVICE, 0); /* XXX sanpei */
sprintf(name, CARD_DEVICE, 0); /* XXX */
fd = open(name, O_RDWR);
resource.type = SYS_RES_IRQ;
@ -534,7 +534,7 @@ assign_card_index(struct cis * cis)
char name[128];
int i, fd;
sprintf(name, CARD_DEVICE, 0); /* XXX sanpei */
sprintf(name, CARD_DEVICE, 0); /* XXX */
fd = open(name, O_RDWR);
resource.type = SYS_RES_IOPORT;
@ -683,12 +683,34 @@ assign_io(struct slot *sp)
sio->size = 1 << cp->io_addr;
}
if (sio->addr == 0) {
int i = bit_fns(io_avail, IOPORTS,
sio->size, sio->size);
if (i < 0) {
return (-1);
struct pccard_resource res;
char name[128];
int i, j, fd;
sprintf(name, CARD_DEVICE, 0); /* XXX */
fd = open(name, O_RDWR);
res.type = SYS_RES_IOPORT;
res.size = sio->size;
for (i = 0; i < IOPORTS; i++) {
j = bit_fns(io_avail, IOPORTS, i,
sio->size, sio->size);
res.min = j;
res.max = j + sio->size ;
if (ioctl(fd, PIOCSRESOURCE, &res) < 0) {
perror("ioctl (PIOCSRESOURCE)");
exit(1);
}
if (res.resource_addr == j)
break;
}
sio->addr = i;
if (j < 0) {
return (-1);
} else {
sio->addr = j;
}
close(fd);
}
bit_nclear(io_avail, sio->addr,
sio->addr + sio->size - 1);

View File

@ -163,7 +163,7 @@ void slot_change(struct slot *);
/* util.c functions */
unsigned long alloc_memory(int);
int bit_fns(bitstr_t *, int, int, int);
int bit_fns(bitstr_t *, int, int, int, int);
void die(char *);
void execute(struct cmd *, struct slot *);
void logmsg(const char *, ...);

View File

@ -150,12 +150,12 @@ newstr(char *p)
* least count number.
*/
int
bit_fns(bitstr_t *nm, int nbits, int count, int step)
bit_fns(bitstr_t *nm, int nbits, int min, int count, int step)
{
int i, j;
int found = 0;
for (i = 0; i < nbits; i += step)
for (i = min; i < nbits; i += step)
for (j = i, found = 0; j < nbits; j++)
if (bit_test(nm, j)) {
if (++found == count)
@ -173,7 +173,7 @@ alloc_memory(int size)
{
int i;
i = bit_fns(mem_avail, MEMBLKS, size / MEMUNIT + (size % MEMUNIT != 0), 1);
i = bit_fns(mem_avail, MEMBLKS, 0, size / MEMUNIT + (size % MEMUNIT != 0), 1);
if (i < 0)
return (0);
bit_nclear(mem_avail, i, i + size / MEMUNIT + (size % MEMUNIT != 0) - 1);