Lots of good links to historical firearms info.
Keep in mind, however, that the D&D rules already hold Medieval realism at arms length in order to make the game more fun. I would highly recommend doing with firearms what seems more fun than worrying about realism in a game that already deals in abstractions.
It seems to me the two roads to go down would be:
1. Simple to use... once per combat. Simple weapons, but they take many rounds to reload. The game effect is going to be that everyone that can afford one is going to carry them (assuming they do decent damage) and use them in the first round. People with quickdraw and multiple attacks will want to carry around a bunch of them. That could be fun. Certainly introduces a new dynamic.
2. Hard to use, but worth learning. Exotic weapons, no harder to reload than a crossbow, but probably more damage (or better crits). This is the DMG approach, more or less. This approach means that only a few people will carry them, but those that do will get a lot of use of out them. In the end, it becomes more of a flavor thing than anything. They're basically exotic crossbows.
Two possible missteps:
1. Armor penetration. Yeah, firearms eventually became good at this. But so did bows. So did certain melee weapons. It seems a strange time to introduce the very real aspect of armor penetration for firearms but not other weapons. Plus, you have the complication of magic armor--is it so easily penetrated? If you use an armor as DR variant, this could work. Otherwise, I think it's too wonky for D&D.
2. Explosive misfire chances. Unless you're already using some kind of fumble rules (which personally, I don't feel are worth it in the end--I don't think the d20 offers enough variation to make the chance realistic, which is also why I don't consider the 1 an auto miss and a 20 an auto hit) it seems odd that firearms carry this danger and other weapons don't. It seems odd to me that if you have 20 riflemen line up fire their weapons, one will have his gun blow up in his face every time. But maybe it's years of playing Rolemaster long ago that have turned me off of that kind of thing.
Also, when thinking about "how firearms changed the real world" keep in mind that D&D isn't the real world. There are still spells, manticores and ghosts to deal with. Even if the enemy nation next door has cannons, your castle walls aren't useless in that they protect you from the owlbears and dire wolves prowling the countryside. Even if enemy humans carry guns that can puncture your armor, you'll still want to wear it to protect you from dragon claws and teeth.
Lastly, don't forget that in a D&D world with firearms, magical firearms and ammunition are likely to be as common as any other kind of magical weapons.